Java Reference
In-Depth Information
In this chapter we'll cover a bunch of new Java language tools:
• Use objects : bundles of variables and functions
• Use the right import for a package
• Use new to create objects
Plugins Have Objects
You may have heard of object-oriented programming or that Java is an “object-
oriented language.” That's what we're talking about in this chapter: using
objects to represent elements of the Minecraft game, from players to cows.
You can do anything in code that you could do in the game, and then some.
This comes down to working with mostly three kinds of things: blocks, items,
and entities.
Everything in Minecraft Is an Object
The Minecraft world is filled with blocks . Every location in the game has a
block, which might be made of air or another material. Blocks can exist in
the world and in a player's inventory. Anything in a player's inventory is
represented by an item .
In this world of blocks you have entities , which includes players, creepers,
and cows. Items in motion are also entities—an arrow in flight or a snowball
or a potion that's being flung. And all of these are objects.
Everything in our plugins is an object: locations, blocks, entities, cows,
creepers, players, and even the plugin itself. All objects, all the time.
So now the real fun starts! You have variables holding data, and you have
instructions expressed as functions, including some control statements to
repeat bits of code or make decisions, and now we'll see how to put them all
together into objects.
Try This Yourself
Let's try a little demonstration of objects in Minecraft. In the downloaded code
there's a plugin called NameCow . Go there now and install that plugin, as shown
in the following command line session.
Search WWH ::

Custom Search