O'Reilly logo

Learn to Program with Minecraft Plugins, 2nd Edition by Andy Hunt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Combine Data and Instructions into Objects

Suppose you were to write a game like Minecraft from scratch. You’d want to have a bunch of players in the game. Each one would have its own name, inventory, health points, and so on, but the structure of each player would be the same.

That is, every player object would have the same collection of variables (name, health, location, and so on) and the same functions that you’d want to run (set this player’s health, teleport the player to a new location, that sort of thing). That’s where objects come in. You’d create an object in Java to represent each player in the system. You’d write code to do things to a player, and that code would work no matter which specific player you were using at the time. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required