Copyright © 2015 – Curt Hill Minecraft Blocks Properties and Methods.

Slides:



Advertisements
Similar presentations
Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Advertisements

Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Copyright 2003Curt Hill Hash indexes Are they better or worse than a B+Tree?
CIS162AD Inheritance 09_inheritance.ppt. CIS162AD2 Overview of Topics  Inheritance  Virtual Methods used for Overriding  Constructors & Inheritance.
1 Fall 2009ACS-1903 The break And continue Statements a break statement can be used to abnormally terminate a loop. use of the break statement in loops.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
Transformation of Java Card into Diet Java Semester Project Presentation Erich Laube.
1 Fall 2008ACS-1903 for Loop Reading files String conversions Random class.
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao
Object Oriented Design: Identifying Objects
Copyright © Curt Hill Sounds, Resource Packs, JSON What more would you want?
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.
Important UDK Classes How they fit together Copyright © 2015 – Curt Hill.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
C#/Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
F27SA1 Software Development 1 3. Java Programming 2 Greg Michaelson.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Applications Development
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright Curt Hill Variables What are they? Why do we need them?
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Inheritance (Part 5) Odds and ends 1. Static Methods and Inheritance  there is a significant difference between calling a static method and calling a.
Copyright © 2015 Curt Hill Java for Minecraft Those things you should know.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
Copyright © Curt Hill Formatting Reals Outputs other than normal.
Animation in Minecraft Movement within Movement Copyright © 2015 – Curt Hill.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Copyright © Curt Hill Applets A different type of program.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Speed Tree Let’s Make a Forest Copyright © 2015 – Curt Hill.
Copyright © 2015 Curt Hill UDK Animation with Kismet and Matinee Visual Scripting.
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ) reading:
An introduction to arrays, continued. Recall from last time… public static void main ( String args[] ) { //define number of rooms final int N = 100; //define.
Recipes How to craft items from others Copyright © 2015 Curt Hill.
Lecture 3: Blocks 1 TEALS MINECRAFT PROJECT. MINECRAFT BLOCKS Blocks form the terrain & buildings in the Minecraft world. Blocks can change appearance,
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Lecture 6: Basic Entities TEALS MINECRAFT PROJECT.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Introduction to programming in java Lecture 16 Random.
Copyright © 2015 – Curt Hill Your First Mod Creating an Item and Block in Eclipse using Forge Annotations! Inheritance! Proxies! Oh my!
A Review or Brief Introduction
Using SLK and Flex++ Followed by a Demo
Are they better or worse than a B+Tree?
Introduction to C++ October 2, 2017.
TEALS Minecraft Project
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
The Random Class and its Methods
Methods Additional Topics
Variables and Their scope
Arrays
Other displays Saving Arrays Using fors to process
Making something known
The Java switch Statement
CIS 199 Final Review.
First Window Builder Program
The IF Revisited A few more things Copyright © Curt Hill.
Presentation transcript:

Copyright © 2015 – Curt Hill Minecraft Blocks Properties and Methods

Introduction Blocks are basic to Minecraft The environment is constructed from blocks We have seen how to construct blocks and to give them textures We now delve into some of their properties and methods Most properties have a set method Copyright © 2015 – Curt Hill

Recall There are several things that you should recall from the first mod presentation –Making a derivation of Block –Building the constructor –Invoking the ancestral constructor with super –Setting the name –Setting the texture –Putting into a tab –Registering the block We will not redo those here Copyright © 2015 – Curt Hill

Generally The properties and methods are generally in Block We change using a set method –Sometimes there is a get method, other times not If this is a derived class we may go after properties directly Sometimes the property has a different type than the set method We may add properties and methods but do not expect the game to use them Copyright © 2015 – Curt Hill

Hardness blockHardness is a float setHardness(float) is the method Determines difficulty in breaking the block –Higher numbers indicate harder items The next screen has a partial table of hardnesses Copyright © 2015 – Curt Hill

Hardness Copyright © 2015 – Curt Hill BlockHardnessBlockHardnessBlockHardness Grass0Melon1.0Iron bars5.0 Fire0Stone1.5Anvil5.0 TNT0Wood2.0Block Iron5 Snow0.2Bricks2.0Block Coal5 Glass pane0.3Craft Table2.5Obsidian50 Ladder0.4Gold ore3.0Lava100 Ice0.5Coal Ore3.0BedrockInfinite

Reality Hardness determines how many time you must hit it depending on tool –(In reality, we have hardness and brittleness and others as well – consider glass and iron) The hardness determines the wear on tools Copyright © 2015 – Curt Hill

Resistance How does it hold up to a blast Field is float blockResistance Method is setResistance(float) Resistance is similar to hardness –The higher the number the less damage The resistance and hardness values do not have to correlate Copyright © 2015 – Curt Hill

Resistance Copyright © 2015 – Curt Hill BlockResistanceBlockResistanceBlockResistance Grass0Melon5Iron bars30 Fire0Wood10Block Coal 30 TNT0Craft Table 12.5Block Iron 30 Snow1Gold ore15Lava500 Glass pane 1.5Coal Ore15Obsidian6000 Ladder2Stone30Anvil6000 Ice2.5Bricks30Bedrock18,000,000

Sounds What sound does the block make stepSound is Block.SoundType Method: setStepSound (Block.SoundType) There are several static sounds See the next table Copyright © 2015 – Curt Hill

Static Sounds Copyright © 2015 – Curt Hill soundTypeAnvilsoundTypeMetal soundTypeClothsoundTypePiston soundTypeGlasssoundTypeSand soundTypeGrasssoundTypeSnow soundTypeGravelsoundTypeStone soundTypeLaddersoundTypeWood

Opacity How much light may pass through the block boolean opaque –No method sets this –boolean isOpaqueCube() shows int lightOpacity –setLightOpacity(int) –Also int getLightOpacity() Opaque is 16, translucent is 0 The texture must allow light through This may affect reflectivity Copyright © 2015 – Curt Hill

Light Level How much light does this emit? –Normally none int lightValue setLightLevel (float) No light is 0, full sunlight is 1.0 Notice local variable and method do not match –It appears that 0 is no light and 15 is full –Exceeding 0-1 bounds gives the rendering engine fits Copyright © 2015 – Curt Hill

Luninescent Block Copyright © 2015 – Curt Hill

Behavior Most of what we have seen so far are static properties We typically set them near to construction time and then never touch them again Next we look at dynamic things –Harvesting –Event handlers These do not typically work in creative modeg Copyright © 2015 – Curt Hill

The Harvest Harvesting is when a block is broken and yields an item This is managed by a several things: –Method setHarvestLevel –Overridden method getItemDropped –Overridden method quantityDropped Copyright © 2015 – Curt Hill

Harvest Level What tool at what level breaks the block setHarvestLevel(String, int) The string is a tool name The int determines how long it takes Any registered tool should work Copyright © 2015 – Curt Hill

Dropping an Item Once the block is broken two methods are called to drop something quantityDropped returns the integer number to make getItemDropped returns an Item handle Both of these should be prefixed Copyright © 2015 – Curt Hill

quantityDropped Signature: public int quantityDropped (Random r); We will consider Random next Use random to determine how many you return There are others as well Copyright © 2015 – Curt Hill

Random This is not part of the game, but is in java.util.Random Gives a variety of random number forms Has a variety of methods that give random values Copyright © 2015 – Curt Hill

Random Methods Has a variety of methods of form: –nextX() –Where x is a type –nextInt, nextBoolean, nextDouble, etc –These give a uniform distribution nextInt(int n) gives integer in range 0-(n-1) nextGaussian gives a normally distributed double in range 0-1 Copyright © 2015 – Curt Hill

GetItemDropped Signature: public Item getItemDropped (int meta, Random random, int fortune) Where: –meta is metadata about the item –fortune is intended to increase production The return is a registered item –An unregistered item crashes the system Copyright © 2015 – Curt Hill

The Item You may return any item you want that is registered If there is only one type of Item to return then have a static variable hold it You may use the Random variable to choose one of several items to return This is where GameRegistry.findItem can be used Copyright © 2015 – Curt Hill

Example Copyright © 2015 – Curt Hill

The Ons There are a variety of methods that start with on These are all event handlers They all need to be prefixed Typically they need to also call the super.on… method to make sure other functions continue Today we look at two –onEntityWalking –onEntityCollidedWithBlock Copyright © 2015 – Curt Hill

onEntityCollidedWithBlock This event occurs when an entity collides with this block The signature: public void onEntityCollidedWithBlock( World w, int p_1, int p_2, int p_3, Entity ent) Copyright © 2015 – Curt Hill

onEntityWalking This event occurs when an entity walks over the block The signature: public void onEntityWalking( World w, int p_1, int p_2, int p_3, Entity ent) Copyright © 2015 – Curt Hill

Some others of interest Copyright © 2015 – Curt Hill onBlockExploded (World w, int x, int y, int z, Explosion exp) onNeighborChange (IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ)

An Example What will follow is some code on a new block: LightBlock This uses several of these properties and methods Copyright © 2015 – Curt Hill

Light Block Beginnings Copyright © 2015 – Curt Hill public class LightBlock extends Block{ // For harvest Item drop=null; // For light output boolean bright = false;

Light Block Constructor Copyright © 2015 – Curt Hill public LightBlock(Material mat){ super(mat); setBlockName("LightBlock"); setBlockTextureName( CurtMod.MODID + ":LightBlock"); setCreativeTab( CreativeTabs.tabBlock); setHarvestLevel("pickaxe",8); setStepSound(Block.soundTypeMetal); setLightLevel(0.05f); drop = CurtModItems.curtItem; } // For harvest Item drop=null; // For light output boolean bright = false;

getItemDropped Copyright © 2015 – Curt public Item getItemDropped( int meta, Random random, int fortune){ return drop; }

Better Copyright © 2015 – Curt public Item getItemDropped(int meta, Random random, int fortune){ Item drop=null; int r = random.nextInt(3); switch(r){ case 0: drop = GameRegistry.findItem( "minecraft", "feather"); break; … case 2: drop = GameRegistry.findItem( "minecraft", "emerald"); break; } // Case end return drop; }

quantityDropped Copyright © 2015 – Curt public int quantityDropped (Random random){ // range is [1-4] int result = random.nextInt(3)+1; return result; } // quantity dropped

Collisions 1 Copyright © 2015 – Curt Hill public class public void onEntityCollidedWithBlock (World w, int p_1, int p_2, int p_3, Entity ent){ super.onEntityCollidedWithBlock (w,p_1, p_2, p_3,ent); // See next page

Collisions 2 Copyright © 2015 – Curt Hill // Flip the light emitting float light; if(bright) light = 0.05F; else light = 0.95F; bright = !bright; setLightLevel(light); }

Walked on Copyright © 2015 – Curt public void onEntityWalking( World w, int p_1, int p_2, int p_3, Entity ent){ super.onEntityWalking( w, p_1,p_2,p_3,ent); float light; if(bright) light = 0.05F; else light = 0.95F; bright = !bright; setLightLevel(light); }

More to Come Another thing that is fundamental to the play of the game is recipes –How are simpler things transformed into tools? This we must cover in another presentation Copyright © 2015 – Curt Hill