Java Reference
In-Depth Information
The function we've been using to set block types is also straightforward:
public static void setBlockAt(Location loc, BlockType type) {
loc.getWorld().setBlockAt(loc, type);
Although a Block has its own setType , that doesn't make the change in the world
like we want. So instead, we use the World 's setBlockAt() function. By always
using the helper function, we're sure to always use the correct version.
Plugin: FlyingCreeper
Here's a plugin that shows spawning two entities: a bat and a creeper. We'll
make the creeper ride the bat, and then turn the bat invisible using a potion
effect. The result is a nightmarish, terrifying, flying creeper.
Here are the guts of the plugin. Notice I'm not using the helper functions to
spawn this time; instead I'm using the factory calls directly, as I'm using a
slightly different version of spawn .
Location loc = me.getLocation();
loc.setY(loc.getY() + 5);
EntityFactory factory = Canary.factory().getEntityFactory();
EntityLiving bat = factory.newEntityLiving(EntityType.BAT, loc);
EntityLiving creep = factory.newEntityLiving(EntityType.CREEPER, loc);
PotionFactory potfact = Canary.factory().getPotionFactory();
PotionEffect potion =
Integer .MAX_VALUE, 1);
All Entity objects can have riders. In theory, you could even ride primed TNT.
But I wouldn't advise it. Here we're going to have the creeper ride the bat by
spawning the bat with a creeper rider (the argument to spawn ).
Next we need to turn the bat invisible to make the flying creeper look more
convincing. Fortunately, all LivingEntity objects can use potion effects. 3 We'll
create a new potion effect, which lets us specify the effect's type, duration,
and magnitude:
PotionEffect (PotionEffectType type, int duration, int amplifier)
All potion effect types are listed at
api/potion/PotionType.html .
Search WWH ::

Custom Search