Custom Entities
Custom Entities
Make your custom entity
- Create a class and name it whatever you want.
- Make your class extends CustomEntity class.
- Override as methods as you want.
Examples
- From Advanced Lucky Block plugin
EntityLuckyVillager
package com.LuckyBlock.customentities; import java.util.ArrayList; import java.util.List; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Villager; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.MerchantRecipe; import org.core.entity.CustomEntity; public class EntityLuckyVillager extends CustomEntity { int seconds = 4; @Override public Entity spawnFunction(Location loc){ Villager villager = (Villager)loc.getWorld().spawnEntity(loc, EntityType.VILLAGER); villager.setCustomName(ChatColor.YELLOW+"Lucky Villager"); villager.setCustomNameVisible(true); List<MerchantRecipe> recipes = new ArrayList<MerchantRecipe>(); MerchantRecipe rec1 = new MerchantRecipe(new ItemStack(Material.DIAMOND_BLOCK), 4); rec1.addIngredient(new ItemStack(Material.DIAMOND,9)); recipes.add(rec1); villager.setRecipes(recipes); return villager; } @Override protected void onDamage(EntityDamageEvent event){ event.setCancelled(true); seconds = 0; } @Override public Particle getDeathParticles(){ return Particle.HEART; } @Override protected void onTick(){ if(seconds > 1){ seconds--; save_def(); } else { entity.getWorld().createExplosion(entity.getLocation(), 4.5f); entity.remove(); } } @Override protected int getTickTime(){ return 20; } public int getSeconds(){ return seconds; } @Override protected void onSave(ConfigurationSection c){ c.set("Seconds", seconds); } @Override protected void onLoad(ConfigurationSection c){ seconds = c.getInt("Seconds"); } @Override public String getSpawnEggEntity(){ return "Villager"; } }
EntityKillerZombie
package com.LuckyBlock.customentities; import java.util.Arrays; import java.util.List; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Monster; import org.bukkit.entity.Player; import org.bukkit.entity.Zombie; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.core.entity.Immunity; public class EntityKillerZombie extends EntityKiller { protected int bounty; @Override public Entity spawnFunction(Location loc){ Zombie zombie = (Zombie)loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE); zombie.setMaxHealth(150); zombie.setHealth(150); zombie.setCustomName("Killer Zombie"); zombie.setCustomNameVisible(true); zombie.setBaby(false); zombie.setGlowing(true); zombie.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999, 0)); zombie.getEquipment().setHelmet(new ItemStack(Material.GLASS)); return zombie; } @Override public int getAttackDamage(){ return 9; } @Override protected boolean targetsNearbyEntities(){ return true; } @Override protected EntityType[] getTargets(){ return new EntityType[]{EntityType.SKELETON,EntityType.SPIDER,EntityType.ENDERMAN,EntityType.SILVERFISH,EntityType.WOLF, EntityType.IRON_GOLEM,EntityType.PLAYER,EntityType.CAVE_SPIDER,EntityType.COW,EntityType.CHICKEN,EntityType.SHEEP,EntityType.MUSHROOM_COW, EntityType.PIG_ZOMBIE}; } @Override protected void onTarget(EntityTargetLivingEntityEvent event){ boolean found = false; for(EntityType e : getTargets()){ if(event.getEntity().getType() == e){ found = true; } } if(!found){ event.setCancelled(true); } } @Override protected void onKillEntity(EntityDamageByEntityEvent event){ entity.getWorld().spawnParticle(Particle.REDSTONE, entity.getLocation(),130,0.4,0.8,0.4,0); int plus = 0; if(event.getEntity() instanceof Monster){ if(getByUUID(event.getEntity().getUniqueId()) != null && getByUUID(event.getEntity().getUniqueId()) instanceof EntityKillerZombie){ plus=((EntityKillerZombie)getByUUID(event.getEntity().getUniqueId())).bounty; } else { plus=1000; } } else if(event.getEntity() instanceof Player){ plus=2000; } else { plus=500; } bounty+=plus; save_def(); } public int getBounty(){ return bounty; } @Override protected boolean isAnimated(){ return true; } @Override protected List<String> getNames(){ return Arrays.asList(ChatColor.GOLD+"Killer Zombie",ChatColor.RED+"Killer Zombie",ChatColor.YELLOW+"Killer Zombie"); } @Override protected int getNamesDelay(){ return 2; } @Override public Immunity[] getImmuneTo(){ return new Immunity[]{Immunity.THORNS,Immunity.MAGIC,Immunity.PROJECTILE,Immunity.FIRE,Immunity.FIRE_TICK,Immunity.LAVA,Immunity.LIGHTNING}; } @Override public int getXp(){ return random.nextInt(600)+450; } @Override public double getDefense(){ return 10; } @Override protected void onSave(ConfigurationSection c){ c.set("Bounty", bounty); } @Override protected void onLoad(ConfigurationSection c){ bounty = c.getInt("Bounty"); } }
Available methods/functions
protected EntityType[] getTargets(); // protected boolean defaultDrops(); // public Entity spawnFunction(Location loc); // public final void remove(); // public ItemStack[] getDrops(); // protected int[] getPercents(); // protected List<String> getNames(); // protected int getNamesDelay(); // public int getXp(); // protected int getTickTime(); // public double getDefense(); // public Immunity[] getImmuneTo(); // protected boolean isAnimated(); // public int getAttackDamage(); // protected final void save_def(); // protected int xpsize(); // protected boolean targetsNearbyEntities(); // public Particle getDeathParticles(); //
Comments