Java Reference
In-Depth Information
A quick look through the Canary documentation for events under net.canary- reveals just what we need: a ChunkLoadedHook when a part of the
world is loaded, and a ChunkUnloadHook when it's deleted. So each time a new
16×16 chunk of the world gets loaded, we'll get an event. One minor nit: the
chunk tells us which chunk it is in a grid of chunks; you have to multiply by
16 to get a real-world coordinate.
Our to-do list now includes these items:
•Add an DamageHook event handler so the cow doesn't die.
•Add getClosestPlayer so each cow can find a nearby target.
•Add ChunkLoadedHook to spawn cows in a 16×16 area.
•Add the ChunkUnloadHook to remove cows from that chunk.
•Set up a task timer so each cow can find a target, jump, and explode if
•Manage the allCows in all these functions (add to it on spawn, delete it on
death, or unload).
Phew! That's a bit of work. But all of these activities are using functions and
skills we've used already, so I won't bore you with a lengthy play-by-play.
Here is the code in its entirety for you to read over and crib from as you need.
package creepercow;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;
import net.canarymod.plugin.Plugin;
import net.canarymod.logger.Logman;
import net.canarymod.Canary;
import net.canarymod.commandsys.*;
import net.canarymod.api.entity.Entity;
import net.canarymod.hook.HookHandler;
import net.canarymod.api.inventory.ItemType;
import net.canarymod.api.entity.EntityType;
import net.canarymod.api.entity.EntityType;
Search WWH ::

Custom Search