Minecraft An Introduction Copyright © 2015 – Curt Hill Introduction • A curious phenomenon! • A game with many modes • It trades good graphics for incharacter environment creation • May be played by very young but still has interest for the mature Copyright © 2015 – Curt Hill History • Original developer was Markus Persson in 2009 • Inspired by several previous games that it was transcended • Mojang was the owning company • Purchased by Microsoft for 2.5 billion dollars • Is available on PCs, Macs, Android, iPad, XBox, PlayStation and numerous other platforms Copyright © 2015 – Curt Hill Characteristics • Open world type • First or third person • Several modes of play – – – – – Survival Creative Adventure Spectator Demo • Single and multiple player Copyright © 2015 – Curt Hill Modes • Survival mode – Scavenger hunt to gather resources – Creating tools is part of game • Creative – Create environments and objects – None of the limits of survival mode • Adventure – Set down in a created world – Author limited creation and destruction Copyright © 2015 – Curt Hill Java • Minecraft is a game that is completely written in Java • This is both good and bad • The Good – Nearly platform independent – Lots of Java programmers – Decompilable • The Bad – Somewhat slower – Decompilable Copyright © 2015 – Curt Hill Decompilable • The decompiler has been a dream in CS for decades • It takes an executable and produces the high level language that produced it • In general this is a dream that cannot be done • However, in Java it is possible Copyright © 2015 – Curt Hill What makes Java different? • There is only one compiler – Makes it easy to see characteristic code constructions and infer what caused them • Each class must be in a file that has the same name – Even when packed into a jar file • The reflection feature – ability to examine and modify the structure and behavior of an object at runtime Copyright © 2015 – Curt Hill Reflection Again • Reflection gives us the ability to ask a class if it has a particular method • It also allows us to call that method • To look for methods not knowing if we will find them and execute them if we do: String s = … Method mthd = foo.getClass() .getMethod(s, null); method.invoke(foo, null); • We did not know what the name was until we found it Copyright © 2015 – Curt Hill Good and Bad? • The decompilability issue is both good and bad • For the owners their code is exposed – They are somewhat protected by copyright – Derived code could be disguised and marketed by a competitor • For the modders we can change anything – More power than in most modifiable games Copyright © 2015 – Curt Hill Obfuscation • The owner’s answer is obfuscation • The word means to confuse or disguise • The process generally involves: – Transforming the names into meaningless ones – Refactoring classes – Reorganizing flow of control • To be useful in this case it must be done and undone by program Copyright © 2015 – Curt Hill Process • The author’s need to be able to write, debug and maintain code in its original, highly understandable form • They then obfuscate by program • The new Java code should execute in a functionally equivalent way – A bug reported in the production code should also be present in the pristine code – Otherwise it is a obfuscation bug Copyright © 2015 – Curt Hill The Modder’s Problem • How can we alter this obfuscated code? • Someone has figured this out – There is a de-obfuscator that restores reasonable names • The MCP toolkit and Minecraft Forge has the tools needed to de- and reobfuscate as well as decompilers – Neither of these are officially connected to Mojang Copyright © 2015 – Curt Hill Relationship • Recently Mojang has been rather cooperative with the modders • In Curt’s Occasionally Humble Opinion they have legal grounds to eliminate these people or at least harass them enough to make it not worth while – They have chosen not to do so – This is likely that the modding community has increased rather than decreased revenues Copyright © 2015 – Curt Hill Java Again • Recall that Java has dynamic binding • When a method call is executed for the first time the class file is loaded from disk or elsewhere – It did not have to be in memory before the call • This allows objects to be dynamically loaded into memory without the program knowing anything about it before it started Copyright © 2015 – Curt Hill Structure of the Game • Like many multi-player games there are two main components – A server – A client • Both are Java programs and are subject to our change • They communicate using packets over the internet Copyright © 2015 – Curt Hill Client and Server • The client is interested in three main things: – Catching and interpreting keyboard commands – Displaying the current scene on the monitor – Communicating with the server on what is going on • The server is the communications relay – What has been reported by any client is reported to all the rest Copyright © 2015 – Curt Hill Infinite Loops • The client stays in an infinite loop • The goal is to go through the loop 20 times a second – This is a tick • The tick based items include updates to the world – Communication to and from the server – Monitoring the keyboard/mouse • Rendering is not tick based • All the server processing is tick based Copyright © 2015 – Curt Hill Client Again • The Minecraft client is actually somewhat more than that • A server was integrated into the client – This facilitates group play on a LAN • Thus there are two programs – The server without the client (stand alone or dedicated) – The client with the server • We also have the issues of proxies Copyright © 2015 – Curt Hill Proxies • Code in a mod could run in two places: the integrated server (part of the client) or the stand alone server • If this code references code in the client then one of two things can happen: – In the integrated server all is good – In the stand alone server it crashes • We thus need classes with different methods depending on the location Copyright © 2015 – Curt Hill Proxies Again • A typical solution is to have a common proxy – This determines the needed method signatures • We take derivations of this for the server proxy and client proxy • An annotation will show the system which one to load • Usually client and server have same signatures but do different things – A rendering method would be empty on the server Copyright © 2015 – Curt Hill Classes • Minecraft is largely constructed from a few classes • Most of these classes have many derivations • In this presentation we will mention them • Other presentations will discuss them more fully Copyright © 2015 – Curt Hill • Block Classes – Describes how to draw and how it reacts to events (behavior) • Item – Anything that a player can carry such as a sword • Entity – Anything that can move around • TileEntity – Used when more data than a block is needed Copyright © 2015 – Curt Hill Finally • • • • • Plenty of more to consider Licenses Establishing the forge environment Creating a simple mod Lots more Copyright © 2015 – Curt Hill