Java Reference
In-Depth Information
(target.getZ() - cowLoc.getZ()) * multFactor
);
cow.moveEntity(v.getX() + ( Math .random() * -0.1),
v.getY(),
v.getZ() + ( Math .random() * -0.1));
}
// Callback to run and execute body of task
public void run() {
if (cow.isOnGround()) { // otherwise it's still jumping
Location cowLoc = cow.getLocation();
Player p = cow.getWorld().getClosestPlayer(cow, 10000);
if (p == null) {
return ;
}
Location pLoc = p.getLocation();
double dist = distance(cowLoc, pLoc);
if (dist <= 4) {
explode();
} else if (dist <= 200) {
jump(pLoc);
}
}
}
}
You might notice that I didn't actually implement everything I mentioned in
my lists. For example, there's no check for spawning too many cows, and I
don't kill the target player directly. I may end up adding those, or just let it
be. Just because I thought I needed those elements doesn't mean I have to
write them yet. I can always add them later if needed.
And I might run into other problems that I hadn't thought about. For instance,
what happens to these cows when the server shuts down? The cows will still
be in the world, but they won't be CreeperCow s anymore, as the plugin doesn't
keep track of them. Maybe I should despawn the cows on shutdown. Or maybe
having extra cows isn't really a problem? Ah, software.
Try This Yourself
That was our journey with the CreeperCow plugin. Your journey with your plugin
will probably be a little different. But try to follow these same general steps:
figure out what parts you need, possibly using index cards, then write out a
sequence in English of what should happen. Take all that and create your
functions, pass around the data you need to, store the stuff you need to
 
 
Search WWH ::




Custom Search