Java Reference
In-Depth Information
public void onInteract(ItemUseHook event) {
Player player = event.getPlayer();
if (player.getItemHeld().getType() == ItemType.Leather) {
Location loc = player.getLocation();
loc.setY(loc.getY() + 2);
Cow victim = (Cow)spawnEntityLiving(loc, EntityType.COW);
Canary.getServer().addSynchronousTask( new CowTask(victim));
fling(player, victim, 3);
The ItemUseHook event can mean the player used one of many different items,
so first we'll need to check and see if the player is holding leather. If the
answer is no, we just ignore the event and life goes on.
But if the answer is yes, we'll use our fling helper method to increase the cow's
velocity—we want to fling it in the direction the player is facing. To do that,
we'll bump up the velocity by multiplying it by 3, as that seems to look pretty
cool. 1 So beginning at we spawn a cow, add the new scheduled task, set
its velocity using fling , and light it on fire.
Now as mentioned, there's a problem with a flaming cow (or anything on fire,
really). It won't stay on fire for long; it will burn up and die. So that's what
our scheduled task will take care of: it will keep the cow alive and watch for
it to land.
Here's the separate class that contains the runnable task:
package cowshooter;
import net.canarymod.Canary;
import net.canarymod.api.entity.EntityType;
import net.canarymod.tasks.ServerTask;
Sometimes you just have to experiment.
Search WWH ::

Custom Search