@SubscribeEvent public static void onEntityDeath(LivingDeathEvent event) { // if villager death drops are enabled, if the newly dead entity is a villager, and that villager was killed by a player... if ((ModConfiguration.enableDeathDrops) && (event.getEntityLiving() instanceof EntityVillager) && (event.getSource().getTrueSource() instanceof EntityPlayerMP)) { // iterate through the itemstacks in the villager's inventory InventoryBasic inventory = ((EntityVillager)event.getEntityLiving()).getVillagerInventory(); for (int i = 0; i < inventory.getSizeInventory(); i++) { // remove the stack from the inventory and spawn it in the world ItemStack stack = inventory.getStackInSlot(i); if (stack != ItemStack.EMPTY) { event.getEntityLiving().entityDropItem(stack, 0.0F); } } } }
/** * Convert this zombie into a villager. */ protected void convertToVillager() { EntityVillager entityvillager = new EntityVillager(this.worldObj); entityvillager.copyLocationAndAnglesFrom(this); entityvillager.onInitialSpawn(this.worldObj.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null); entityvillager.setLookingForHome(); if (this.isChild()) { entityvillager.setGrowingAge(-24000); } this.worldObj.removeEntity(this); entityvillager.setNoAI(this.isAIDisabled()); if (this.hasCustomName()) { entityvillager.setCustomNameTag(this.getCustomNameTag()); entityvillager.setAlwaysRenderNameTag(this.getAlwaysRenderNameTag()); } this.worldObj.spawnEntityInWorld(entityvillager); entityvillager.addPotionEffect(new PotionEffect(Potion.confusion.id, 200, 0)); this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1017, new BlockPos((int)this.posX, (int)this.posY, (int)this.posZ), 0); }
@Override protected void convertToVillager() { EntityVillager villager = new EntityVillager(worldObj); villager.copyLocationAndAnglesFrom(this); villager.onSpawnWithEgg((IEntityLivingData) null); villager.setLookingForHome(); villager.setProfession(getType()); if (isChild()) villager.setGrowingAge(-24000); worldObj.removeEntity(this); worldObj.spawnEntityInWorld(villager); villager.addPotionEffect(new PotionEffect(Potion.confusion.id, 200, 0)); worldObj.playAuxSFXAtEntity(null, 1017, (int) posX, (int) posY, (int) posZ, 0); }
/** * Returns whether the EntityAIBase should begin execution. */ public boolean shouldExecute() { if (!this.theGolem.worldObj.isDaytime()) { return false; } else if (this.theGolem.getRNG().nextInt(8000) != 0) { return false; } else { this.theVillager = (EntityVillager)this.theGolem.worldObj.findNearestEntityWithinAABB(EntityVillager.class, this.theGolem.getEntityBoundingBox().expand(6.0D, 2.0D, 6.0D), this.theGolem); return this.theVillager != null; } }
/** * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. */ protected ResourceLocation getEntityTexture(EntityVillager entity) { switch (entity.getProfession()) { case 0: return farmerVillagerTextures; case 1: return librarianVillagerTextures; case 2: return priestVillagerTextures; case 3: return smithVillagerTextures; case 4: return butcherVillagerTextures; default: return villagerTextures; } }
/** * Allows the render to do any OpenGL state modifications necessary before the model is rendered. Args: * entityLiving, partialTickTime */ protected void preRenderCallback(EntityVillager entitylivingbaseIn, float partialTickTime) { float f = 0.9375F; if (entitylivingbaseIn.getGrowingAge() < 0) { f = (float)((double)f * 0.5D); this.shadowSize = 0.25F; } else { this.shadowSize = 0.5F; } GlStateManager.scale(f, f, f); }
protected void spawnVillagers(World worldIn, StructureBoundingBox p_74893_2_, int p_74893_3_, int p_74893_4_, int p_74893_5_, int p_74893_6_) { if (this.villagersSpawned < p_74893_6_) { for (int i = this.villagersSpawned; i < p_74893_6_; ++i) { int j = this.getXWithOffset(p_74893_3_ + i, p_74893_5_); int k = this.getYWithOffset(p_74893_4_); int l = this.getZWithOffset(p_74893_3_ + i, p_74893_5_); if (!p_74893_2_.isVecInside(new BlockPos(j, k, l))) { break; } ++this.villagersSpawned; EntityVillager entityvillager = new EntityVillager(worldIn); entityvillager.setLocationAndAngles((double)j + 0.5D, (double)k, (double)l + 0.5D, 0.0F, 0.0F); entityvillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null); entityvillager.setProfession(this.func_180779_c(i, entityvillager.getProfession())); worldIn.spawnEntityInWorld(entityvillager); } } }
public Color getEntityColor() { if ((entity instanceof EntityAnimal)) { return Color.white; } if ((entity instanceof EntityMob)) { return Color.red; } if ((entity instanceof EntitySlime)) { return Color.green; } if ((entity instanceof EntityVillager)) { return new Color(245, 245, 220); } if ((entity instanceof EntityBat)) { return Color.BLACK; } if ((entity instanceof EntitySquid)) { return Color.PINK; } return Color.white; }
/** * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. */ protected ResourceLocation getEntityTexture(EntityVillager entity) { switch (entity.getProfession()) { case 0: return FARMER_VILLAGER_TEXTURES; case 1: return LIBRARIAN_VILLAGER_TEXTURES; case 2: return PRIEST_VILLAGER_TEXTURES; case 3: return SMITH_VILLAGER_TEXTURES; case 4: return BUTCHER_VILLAGER_TEXTURES; case 5: default: return VILLAGER_TEXTURES; } }
/** * Allows the render to do state modifications necessary before the model is rendered. */ protected void preRenderCallback(EntityVillager entitylivingbaseIn, float partialTickTime) { float f = 0.9375F; if (entitylivingbaseIn.getGrowingAge() < 0) { f = (float)((double)f * 0.5D); this.shadowSize = 0.25F; } else { this.shadowSize = 0.5F; } GlStateManager.scale(f, f, f); }
private void handleVillagers(int x, int y, List<IWidget> locatedTextures) { locatedTextures.add(new LocatedEntity(EntityVillager.class, x + 70, y + 95, 2F)); LocatedEntity locatedEntity = new LocatedEntity(EntityVillager.class, x + 215, y + 125, 2F); EntityVillager villager = (EntityVillager) locatedEntity.entity; // villager.setProfession(ConfigHandler.general.villagerMechanicID); locatedTextures.add(locatedEntity); }
@SubscribeEvent public static void entitySpawned(EntityJoinWorldEvent event){ // This only runs server side if(event.getWorld().isRemote)return; if(EntityVillager.class.isInstance(event.getEntity()) && !event.getEntity().getEntityData().getBoolean(tagName)){ if(ConfigHandler.LOGGING){ LogManager.getLogger().log(Level.INFO, "A villager spawned at x" + event.getEntity().posX + "z" + event.getEntity().posZ + " and has been added to the data list."); } // set this to true to inform future calls of this code that this villager has been handled. event.getEntity().getEntityData().setBoolean(tagName, true); // have to use the MathHelper workaround because chunkX and chunkZ are 0 on spawn NBTDataHandler.incrementVillagersSpawnedForChunk(event.getWorld().provider.getDimension(), MathHelper.floor(event.getEntity().posX / 16.0D), MathHelper.floor(event.getEntity().posZ / 16.0D)); } }
/** * Checks if the specified entity is a passive * * @param e The entity * @return Whether or not the entity is a passive */ public static boolean isPassive(Entity e) { if (e instanceof EntityPigZombie) return !isAngry((EntityPigZombie) e); if (e instanceof EntityIronGolem) return !isAngry((EntityIronGolem) e); if (e instanceof EntityPolarBear) return !isAngry((EntityPolarBear) e); if (e instanceof EntityAnimal) return true; if (e instanceof EntitySquid) return true; if (e instanceof EntityBat) return true; if (e instanceof EntityVillager) return true; if (e instanceof EntitySnowman) return true; return false; }
public void replaceList(IMerchant merchant, MerchantRecipeList list) { if(merchant instanceof EntityVillager) { replaceTradeList((EntityVillager) merchant,list); } else { merchant.setRecipes(list); } }
public static void replaceTradeList(EntityVillager villager, MerchantRecipeList newlist) { if (buyingList == null) buyingList = ReflectionHelper.findField(EntityVillager.class, "buyingList", "field_70963_i"); if (villager != null) { try { buyingList.set(villager, newlist); } catch (IllegalAccessException e) { e.printStackTrace(); } } }
@Override protected void initializeInventories() { super.initializeInventories(); villager = this.addSimpleInventory(1, "villager", EnumDyeColor.BROWN, "Villager Mob Imprisonment Tool", new BoundingRectangle(145, 61, 18, 18), (stack, integer) -> stack.getItem() instanceof MobImprisonmentToolItem && ItemRegistry.mobImprisonmentToolItem.containsEntity(stack) && ItemRegistry.mobImprisonmentToolItem.getEntityFromStack(stack, this.world, false) instanceof EntityVillager, (stack, integer) -> true, false, null); input = this.addSimpleInventory(1, "input", EnumDyeColor.BLUE, "Trade input", new BoundingRectangle(52, 61, 18, 18), (stack, integer) -> true, (stack, integer) -> false, false, null); output = this.addSimpleInventory(1, "output", EnumDyeColor.ORANGE, "Trade output", new BoundingRectangle(112, 61, 18, 18), (stack, integer) -> false, (stack, integer) -> true, false, null); }
@SubscribeEvent public void onChunkPopulated(PopulateChunkEvent.Post event) { EntityVillager villager = new EntityVillager(event.getWorld(), VillagerRegistry.getId(HarshenVillagers.VALOR)); BlockPos pos = event.getWorld().getTopSolidOrLiquidBlock(new BlockPos(event.getChunkX() * 16 + event.getRand().nextInt(16), 0, event.getChunkZ() * 16 + event.getRand().nextInt(16))); villager.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), villager.rotationYaw, villager.rotationPitch); if(event.isHasVillageGenerated()) if(event.getRand().nextFloat() < 0.1f) event.getWorld().spawnEntity(villager); }
public VillagerTradeItemForItem(ItemStack buyingItem, EntityVillager.PriceInfo buyingPrice, ItemStack sellingItem, EntityVillager.PriceInfo sellingPrice) { this.buyingItemStack = buyingItem; this.buyingPriceInfo = buyingPrice; this.sellingItemStack = sellingItem; this.sellingPriceInfo = sellingPrice; }
@SubscribeEvent public static void onPlayerEntityInteract(PlayerInteractEvent.EntityInteract event) { // if the villager inventory gui is enabled, if the entity being interacted with is a villager, and if the player is sneaking... if ((ModConfiguration.enableInventoryGui) && (event.getTarget() instanceof EntityVillager) && (EntityUtils.getFlag(event.getEntityPlayer(), 2))) { // if opening the gui requires the player to not be holding anything, check to ensure that the player isn't holding anything if (!ModConfiguration.requireEmptyHand || (ModConfiguration.requireEmptyHand && event.getEntityPlayer().inventory.getCurrentItem().isEmpty())) { // if the event is running on the server if (!event.getWorld().isRemote) { // cast the entity to type EntityVillager EntityVillager villager = (EntityVillager)event.getTarget(); // get the entity id of the villager int entityId = villager.getEntityId(); // and read it's profession and career from it's nbt data NBTTagCompound compound = new NBTTagCompound(); villager.writeEntityToNBT(compound); int professionId = compound.getInteger("Profession"); int careerId = compound.getInteger("Career"); // send a message to the client to tell it what the villager's career is NETWORK.sendTo(new VillagerCareerMessage(entityId, careerId), (EntityPlayerMP)event.getEntityPlayer()); // open the inventory gui FMLNetworkHandler.openGui(event.getEntityPlayer(), VillagerInventoryMod.INSTANCE, ModGuiHandler.GUI_VILLAGER_INVENTORY, event.getWorld(), entityId, professionId, careerId); } // cancel the event which would show the trading gui event.setCanceled(true); } } }
public ContainerVillagerInventory(IInventory playerInventory, final InventoryBasic villagerInventoryIn, final EntityVillager villager, EntityPlayer player) { this.villagerInventory = villagerInventoryIn; this.villager = villager; this.villagerInventory.setCustomName(this.villager.getDisplayName().getUnformattedText()); villagerInventoryIn.openInventory(player); // villager inventory slots int offsetX = 17; int offsetY = 20; for (int col = 0; col < 8; col++) { this.addSlotToContainer(new Slot(villagerInventoryIn, col, offsetX + col * 18, offsetY)); } // player inventory offsetX = 8; offsetY = 51; for (int row = 0; row < 3; row++) { for (int col = 0; col < 9; col++) { this.addSlotToContainer(new Slot(playerInventory, col + row * 9 + 9, offsetX + col * 18, offsetY + row * 18)); } } // player hotbar inventory offsetY = 109; for (int col = 0; col < 9; col++) { this.addSlotToContainer(new Slot(playerInventory, col, offsetX + col * 18, offsetY)); } }
public static void onSetProfession(EntityVillager entity, VillagerProfession prof) { int network = INSTANCE.professions.getId(prof); if (network == -1 || prof != INSTANCE.professions.getObjectById(network)) { throw new RuntimeException("Attempted to set villager profession to unregistered profession: " + network + " " + prof); } if (network != entity.getProfession()) entity.setProfession(network); }
@Override public boolean isMobType(Entity entity) { return entity.isCreatureType(EnumCreatureType.CREATURE, false) || entity.isCreatureType(EnumCreatureType.AMBIENT, false) || entity.isCreatureType(EnumCreatureType.WATER_CREATURE, false) || entity instanceof EntityVillager || entity instanceof EntityGolem; }
@SubscribeEvent public void entityStruckByLightning(EntityStruckByLightningEvent event) { if (EtFuturum.enableVillagerTurnsIntoWitch && event.entity instanceof EntityVillager) { EntityVillager villager = (EntityVillager) event.entity; if (!villager.worldObj.isRemote) { EntityWitch witch = new EntityWitch(villager.worldObj); witch.copyLocationAndAnglesFrom(villager); witch.onSpawnWithEgg(null); villager.worldObj.spawnEntityInWorld(witch); villager.setDead(); } } }
/** * This method gets called when the entity kills another one. */ public void onKillEntity(EntityLivingBase entityLivingIn) { super.onKillEntity(entityLivingIn); if ((this.worldObj.getDifficulty() == EnumDifficulty.NORMAL || this.worldObj.getDifficulty() == EnumDifficulty.HARD) && entityLivingIn instanceof EntityVillager) { if (this.worldObj.getDifficulty() != EnumDifficulty.HARD && this.rand.nextBoolean()) { return; } EntityVillager entityvillager = (EntityVillager)entityLivingIn; EntityZombie entityzombie = new EntityZombie(this.worldObj); entityzombie.copyLocationAndAnglesFrom(entityLivingIn); this.worldObj.removeEntity(entityLivingIn); entityzombie.onInitialSpawn(this.worldObj.getDifficultyForLocation(new BlockPos(entityzombie)), new EntityZombie.GroupData(false, true)); entityzombie.setVillagerType(entityvillager.getProfessionForge()); entityzombie.setChild(entityLivingIn.isChild()); entityzombie.setNoAI(entityvillager.isAIDisabled()); if (entityvillager.hasCustomName()) { entityzombie.setCustomNameTag(entityvillager.getCustomNameTag()); entityzombie.setAlwaysRenderNameTag(entityvillager.getAlwaysRenderNameTag()); } this.worldObj.spawnEntityInWorld(entityzombie); this.worldObj.playEvent((EntityPlayer)null, 1026, new BlockPos((int)this.posX, (int)this.posY, (int)this.posZ), 0); } }
private void giveBirth() { EntityVillager entityvillager = this.villagerObj.createChild(this.mate); this.mate.setGrowingAge(6000); this.villagerObj.setGrowingAge(6000); this.mate.setIsWillingToMate(false); this.villagerObj.setIsWillingToMate(false); entityvillager.setGrowingAge(-24000); entityvillager.setLocationAndAngles(this.villagerObj.posX, this.villagerObj.posY, this.villagerObj.posZ, 0.0F, 0.0F); this.worldObj.spawnEntityInWorld(entityvillager); this.worldObj.setEntityState(entityvillager, (byte)12); }
private void updateNumVillagers() { List<EntityVillager> list = this.worldObj.<EntityVillager>getEntitiesWithinAABB(EntityVillager.class, new AxisAlignedBB((double)(this.center.getX() - this.villageRadius), (double)(this.center.getY() - 4), (double)(this.center.getZ() - this.villageRadius), (double)(this.center.getX() + this.villageRadius), (double)(this.center.getY() + 4), (double)(this.center.getZ() + this.villageRadius))); this.numVillagers = list.size(); if (this.numVillagers == 0) { this.playerReputation.clear(); } }
/** * Convert this zombie into a villager. */ protected void convertToVillager() { EntityVillager entityvillager = new EntityVillager(this.worldObj); entityvillager.copyLocationAndAnglesFrom(this); entityvillager.onInitialSpawn(this.worldObj.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null); entityvillager.setLookingForHome(); if (this.isChild()) { entityvillager.setGrowingAge(-24000); } this.worldObj.removeEntity(this); entityvillager.setNoAI(this.isAIDisabled()); if (this.getVillagerTypeForge() != null) entityvillager.setProfession(this.getVillagerTypeForge()); else entityvillager.setProfession(0); if (this.hasCustomName()) { entityvillager.setCustomNameTag(this.getCustomNameTag()); entityvillager.setAlwaysRenderNameTag(this.getAlwaysRenderNameTag()); } this.worldObj.spawnEntityInWorld(entityvillager); entityvillager.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 200, 0)); this.worldObj.playEvent((EntityPlayer)null, 1027, new BlockPos((int)this.posX, (int)this.posY, (int)this.posZ), 0); }
protected void applyEntityAI() { this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityVillager.class, 1.0D, true)); this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityIronGolem.class, 1.0D, true)); this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityPigZombie.class})); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityVillager.class, false)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true)); }
/** * This method gets called when the entity kills another one. */ public void onKillEntity(EntityLivingBase entityLivingIn) { super.onKillEntity(entityLivingIn); if ((this.worldObj.getDifficulty() == EnumDifficulty.NORMAL || this.worldObj.getDifficulty() == EnumDifficulty.HARD) && entityLivingIn instanceof EntityVillager) { if (this.worldObj.getDifficulty() != EnumDifficulty.HARD && this.rand.nextBoolean()) { return; } EntityLiving entityliving = (EntityLiving)entityLivingIn; EntityZombie entityzombie = new EntityZombie(this.worldObj); entityzombie.copyLocationAndAnglesFrom(entityLivingIn); this.worldObj.removeEntity(entityLivingIn); entityzombie.onInitialSpawn(this.worldObj.getDifficultyForLocation(new BlockPos(entityzombie)), (IEntityLivingData)null); entityzombie.setVillager(true); if (entityLivingIn.isChild()) { entityzombie.setChild(true); } entityzombie.setNoAI(entityliving.isAIDisabled()); if (entityliving.hasCustomName()) { entityzombie.setCustomNameTag(entityliving.getCustomNameTag()); entityzombie.setAlwaysRenderNameTag(entityliving.getAlwaysRenderNameTag()); } this.worldObj.spawnEntityInWorld(entityzombie); this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1016, new BlockPos((int)this.posX, (int)this.posY, (int)this.posZ), 0); } }
/** * Execute a one shot task or start executing a continuous task */ public void startExecuting() { super.startExecuting(); if (this.villager.canAbondonItems() && this.closestEntity instanceof EntityVillager && ((EntityVillager)this.closestEntity).wantsMoreFood()) { this.interactionDelay = 10; } else { this.interactionDelay = 0; } }
protected void spawnVillagers(World worldIn, StructureBoundingBox structurebb, int x, int y, int z, int count) { if (this.villagersSpawned < count) { for (int i = this.villagersSpawned; i < count; ++i) { int j = this.getXWithOffset(x + i, z); int k = this.getYWithOffset(y); int l = this.getZWithOffset(x + i, z); if (!structurebb.isVecInside(new BlockPos(j, k, l))) { break; } ++this.villagersSpawned; if (this.isZombieInfested) { EntityZombieVillager entityzombievillager = new EntityZombieVillager(worldIn); entityzombievillager.setLocationAndAngles((double)j + 0.5D, (double)k, (double)l + 0.5D, 0.0F, 0.0F); entityzombievillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityzombievillager)), (IEntityLivingData)null); entityzombievillager.func_190733_a(this.chooseProfession(i, 0)); entityzombievillager.enablePersistence(); worldIn.spawnEntityInWorld(entityzombievillager); } else { EntityVillager entityvillager = new EntityVillager(worldIn); entityvillager.setLocationAndAngles((double)j + 0.5D, (double)k, (double)l + 0.5D, 0.0F, 0.0F); entityvillager.setProfession(this.chooseProfession(i, worldIn.rand.nextInt(6))); entityvillager.func_190672_a(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null, false); worldIn.spawnEntityInWorld(entityvillager); } } } }