use of net.minecraft.entity.passive.EntityVillager in project MineFactoryReloaded by powercrystals.
the class TileEntitySewer method updateEntity.
@Override
public void updateEntity() {
super.updateEntity();
if (worldObj.isRemote) {
return;
}
_tick++;
if (_nextSewerCheckTick <= worldObj.getTotalWorldTime()) {
Area a = new Area(BlockPosition.fromFactoryTile(this), _areaManager.getRadius(), 0, 0);
_jammed = false;
for (BlockPosition bp : a.getPositionsBottomFirst()) {
if (worldObj.getBlockId(bp.x, bp.y, bp.z) == MineFactoryReloadedCore.machineBlocks.get(0).blockID && worldObj.getBlockMetadata(bp.x, bp.y, bp.z) == Machine.Sewer.getMeta() && !(bp.x == xCoord && bp.y == yCoord && bp.z == zCoord)) {
_jammed = true;
break;
}
}
_nextSewerCheckTick = worldObj.getTotalWorldTime() + 800 + worldObj.rand.nextInt(800);
}
if (_tick >= 31 && !_jammed) {
_tick = 0;
List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, _areaManager.getHarvestArea().toAxisAlignedBB());
double massFound = 0;
for (Object o : entities) {
if (o instanceof EntityAnimal || o instanceof EntityVillager) {
massFound += Math.pow(((EntityLiving) o).boundingBox.getAverageEdgeLength(), 2);
} else if (o instanceof EntityPlayer && ((EntityPlayer) o).isSneaking()) {
massFound += Math.pow(((EntityLiving) o).boundingBox.getAverageEdgeLength(), 2);
}
}
if (massFound > 0) {
_tank.fill(LiquidDictionary.getLiquid("sewage", (int) (25 * massFound)), true);
} else // TODO: add a second tank to the sewer for essence
if (_tank.getLiquid() == null || _tank.getLiquid().isLiquidEqual(LiquidDictionary.getLiquid("mobEssence", 1))) {
int maxAmount = Math.max(_tank.getCapacity() - (_tank.getLiquid() != null ? _tank.getLiquid().amount : 0), 0);
if (maxAmount < 0) {
return;
}
entities = worldObj.getEntitiesWithinAABB(EntityXPOrb.class, _areaManager.getHarvestArea().toAxisAlignedBB());
for (Object o : entities) {
Entity e = (Entity) o;
if (e != null & e instanceof EntityXPOrb && !e.isDead) {
EntityXPOrb orb = (EntityXPOrb) o;
int found = Math.min(orb.xpValue, maxAmount);
orb.xpValue -= found;
if (orb.xpValue <= 0) {
orb.setDead();
found = Math.max(found, 0);
}
if (found > 0) {
found = (int) (found * 66.66666667f);
maxAmount -= found;
_tank.fill(LiquidDictionary.getLiquid("mobEssence", found), true);
if (maxAmount <= 0) {
break;
}
}
}
}
}
}
}
use of net.minecraft.entity.passive.EntityVillager in project Railcraft by Railcraft.
the class TileTradeStation method nextTrade.
public void nextTrade(int tradeSet) {
EntityVillager villager = new EntityVillager(worldObj);
villager.setProfession(profession);
MerchantRecipeList recipes = villager.getRecipes(null);
MerchantRecipe recipe = recipes.get(MiscTools.RANDOM.nextInt(recipes.size()));
recipeSlots.setInventorySlotContents(tradeSet * 3 + 0, recipe.getItemToBuy());
recipeSlots.setInventorySlotContents(tradeSet * 3 + 1, recipe.getSecondItemToBuy());
recipeSlots.setInventorySlotContents(tradeSet * 3 + 2, recipe.getItemToSell());
}
use of net.minecraft.entity.passive.EntityVillager in project BetterWithAddons by DaedalusGame.
the class WheatHandler method villagerFix.
@SubscribeEvent
public static void villagerFix(LivingEvent.LivingUpdateEvent event) {
if (!InteractionWheat.REPLACE_WHEAT_DROPS)
return;
if (event.getEntityLiving().getEntityWorld().isRemote)
return;
if (event.getEntityLiving() instanceof EntityVillager) {
EntityVillager villager = (EntityVillager) event.getEntityLiving();
InventoryBasic inventory = villager.getVillagerInventory();
ArrayList<ItemStack> itemstacks_created = new ArrayList<>();
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
ItemStack itemstack = inventory.getStackInSlot(i);
if (!itemstack.isEmpty()) {
Item item = itemstack.getItem();
if (item == Items.WHEAT && itemstack.getCount() >= 6) {
int wheat_consumed = itemstack.getCount() / 2 / 3 * 3;
int bread_produced = wheat_consumed / 2;
int seeds_produced = wheat_consumed / 2;
itemstack.shrink(wheat_consumed);
itemstacks_created.add(new ItemStack(Items.BREAD, bread_produced, 0));
itemstacks_created.add(new ItemStack(Items.WHEAT_SEEDS, seeds_produced, 0));
if (InteractionWheat.THRESH_WHEAT)
itemstacks_created.add(ModItems.materialWheat.getMaterial("hay", wheat_consumed));
}
if (itemstack.isEmpty()) {
inventory.setInventorySlotContents(i, ItemStack.EMPTY);
}
}
for (ItemStack stack : itemstacks_created) {
double y = villager.posY - 0.3 + (double) villager.getEyeHeight();
EntityItem entityitem = new EntityItem(villager.world, villager.posX, y, villager.posZ, stack);
entityitem.setDefaultPickupDelay();
villager.world.spawnEntity(entityitem);
}
}
}
}
Aggregations