Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2015 Curt Hill Java for Minecraft Those things you should know.

Similar presentations


Presentation on theme: "Copyright © 2015 Curt Hill Java for Minecraft Those things you should know."— Presentation transcript:

1 Copyright © 2015 Curt Hill Java for Minecraft Those things you should know

2 Introduction As you know Minecraft is written in Java In order to create mods for Minecraft there are parts of the language that you may not know and should This presentation should start to cover much of this –Well that is the hope anyway Copyright © 2015 Curt Hill

3 Topics General Pointers Final Visibility Annotations Class definition Inheritance and polymorphism Copyright © 2015 Curt Hill

4 General C++ and Java have much in common There is virtually no difference in: –Declarations and types –If –For –While –Do/while –Method calls Copyright © 2015 Curt Hill

5 Exceptions Java uses boolean instead of bool The conditional in if/for/while must be a Boolean The C/C++ scheme of zero is false, everything else is true is not allowed Copyright © 2015 Curt Hill

6 Visibility C++ sets its visibility in sections Java immediately prefixes any declaration with the visibility: protected class helper{…} Any item without a visibility has “friendly” visibility –This makes it public to anything in the same file and private to anything not in that file Every public class must be in a file of the same name Copyright © 2015 Curt Hill

7 Preprocessor Java has no preprocessor Thus it uses import instead of include Java also uses the package statement instead of namespaces Java has a larger role for final than C++ does const Copyright © 2015 Curt Hill

8 Final Java uses final instead of const Thus a constant variable uses the final declaration: final String VERSION = “1.1.4”; The final keyword may also be used in a class declaration: public final class some{…} –This indicates that no derivation may be made of class some Copyright © 2015 Curt Hill

9 Heap and Stack C/C++ allows any type to be on either the heap or stack Java only allows primitives and handles on the stack All objects must be on the heap and created with new Java only allows dots and not the -> Java does not allow delete, garbage collection is the only way to claim unused heap memory Copyright © 2015 Curt Hill

10 Pointers Java claims to have no pointers, it calls them handles instead –A handle is a restricted pointer Copyright © 2015 Curt Hill

11 Annotations Java annotations are a feature not present in C/C++ Annotations given hints to the compiler or run-time system An annotation starts with the @ followed by a word which determines the type of annotation An annotation may be followed by a parenthesized list of parameters There are some standard Java annotations and some particular to Minecraft Copyright © 2015 Curt Hill

12 Annotations Again @Override @Mod @Instance @SidedMod @EventHandler Annotations are not terminated by a semicolon Copyright © 2015 Curt Hill

13 @Override Standard Java annotation Tells the compiler that the method that follows overrides a method in the ancestral class If there is no method that this overrides a compile error occurs Usually this is a misspelled the name or made a mistake on the signature The compile error prevents a run-time or logic error Copyright © 2015 Curt Hill

14 @Mod Indicates to forge that this is the Base of a Mod class Three parameters: modid – a unique ID for the mod name – people readable name version – the version All three are strings Copyright © 2015 Curt Hill

15 @Instance The instantiation of the mod class What follows is usually a static instance of the mod class See the following example for @Mod and @Instance Copyright © 2015 Curt Hill

16 Example Here is some sample code: @Mod(modid = “CurtModID”,, name = “CurtMod”, version = “1.0.2”) public class CurtMod { … @Instance public static CurtMod instance = new CurtMod(); Copyright © 2015 Curt Hill

17 @SidedMod Announces which proxy is to be loaded depending on whether a client or server is running –Precedes the declaration Two parameters: –clientProxy –serverProxy May not use anything but a literal string See next slide for example Copyright © 2015 Curt Hill

18 Example Annotation and instance: @SidedProxy(serverSide= "edu.vscu.ServerProxy", clientSide= "edu.vscu.ClientProxy") public static CommonProxy proxy; CommonProxy was the ancestor of both ServerProxy and ClientProxy in this example Copyright © 2015 Curt Hill

19 @EventHandler Indicates that the method that follows will be an event handler Recall that event handlers are typically not called directly by code in the same file Instead called unpredictably by system code –In Minecraft’s case usually by the Forge or Minecraft itself Copyright © 2015 Curt Hill

20 Classes The class definition is slightly different than C++ Inheritance and polymorphism are as well These we will cover in their own presentation Copyright © 2015 Curt Hill

21 Finally It is possible, even likely, that despite this presentation you will find features in mod code that are confusing Ask! Copyright © 2015 Curt Hill


Download ppt "Copyright © 2015 Curt Hill Java for Minecraft Those things you should know."

Similar presentations


Ads by Google