Search in sources :

Example 11 with EntityVillager

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;
                        }
                    }
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) Area(powercrystals.core.position.Area) EntityLiving(net.minecraft.entity.EntityLiving) BlockPosition(powercrystals.core.position.BlockPosition) EntityVillager(net.minecraft.entity.passive.EntityVillager) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 12 with EntityVillager

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());
}
Also used : MerchantRecipeList(net.minecraft.village.MerchantRecipeList) MerchantRecipe(net.minecraft.village.MerchantRecipe) EntityVillager(net.minecraft.entity.passive.EntityVillager)

Example 13 with EntityVillager

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);
            }
        }
    }
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) Item(net.minecraft.item.Item) EntityVillager(net.minecraft.entity.passive.EntityVillager) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InventoryBasic(net.minecraft.inventory.InventoryBasic) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityVillager (net.minecraft.entity.passive.EntityVillager)13 EntityZombie (net.minecraft.entity.monster.EntityZombie)4 ItemStack (net.minecraft.item.ItemStack)4 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)3 MerchantRecipe (net.minecraft.village.MerchantRecipe)3 MerchantRecipeList (net.minecraft.village.MerchantRecipeList)3 ArrayList (java.util.ArrayList)2 EntityLiving (net.minecraft.entity.EntityLiving)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityItem (net.minecraft.entity.item.EntityItem)2 EntityPigZombie (net.minecraft.entity.monster.EntityPigZombie)2 EntityPig (net.minecraft.entity.passive.EntityPig)2 BlockPos (net.minecraft.util.math.BlockPos)2 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 LocatedEntity (igwmod.gui.LocatedEntity)1 List (java.util.List)1 Random (java.util.Random)1 EntityAIMoveToBlock (mods.railcraft.common.util.ai.EntityAIMoveToBlock)1 EntityAIWatchBlock (mods.railcraft.common.util.ai.EntityAIWatchBlock)1 Entity (net.minecraft.entity.Entity)1