Search in sources :

Example 1 with InventoryBasic

use of net.minecraft.inventory.InventoryBasic in project NetherEx by LogicTechCorp.

the class EntityAIPigtificateInteract method updateTask.

@Override
public void updateTask() {
    super.updateTask();
    if (interactionDelay > 0) {
        --interactionDelay;
        if (interactionDelay == 0) {
            InventoryBasic inventorybasic = pigtificate.getInventory();
            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i) {
                ItemStack itemstack = inventorybasic.getStackInSlot(i);
                ItemStack itemstack1 = ItemStack.EMPTY;
                if (!itemstack.isEmpty()) {
                    Item item = itemstack.getItem();
                    if ((item == Item.getItemFromBlock(NetherExBlocks.PLANT_MUSHROOM_ELDER) && itemstack.getCount() > 7) || (item == NetherExItems.FOOD_MUSHROOM_ENOKI && itemstack.getCount() > 63)) {
                        int l = itemstack.getCount() / 2;
                        itemstack.shrink(l);
                        itemstack1 = new ItemStack(item, l, itemstack.getMetadata());
                    }
                    if (itemstack.isEmpty()) {
                        inventorybasic.setInventorySlotContents(i, ItemStack.EMPTY);
                    }
                }
                if (!itemstack1.isEmpty()) {
                    double d0 = pigtificate.posY - 0.30000001192092896D + (double) pigtificate.getEyeHeight();
                    EntityItem entityitem = new EntityItem(pigtificate.world, pigtificate.posX, d0, pigtificate.posZ, itemstack1);
                    float f1 = pigtificate.rotationYawHead;
                    float f2 = pigtificate.rotationPitch;
                    entityitem.motionX = (double) (-MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * 0.3F);
                    entityitem.motionZ = (double) (MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * 0.3F);
                    entityitem.motionY = (double) (-MathHelper.sin(f2 * 0.017453292F) * 0.3F + 0.1F);
                    entityitem.setDefaultPickupDelay();
                    pigtificate.world.spawnEntity(entityitem);
                    break;
                }
            }
        }
    }
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) Item(net.minecraft.item.Item) ItemStack(net.minecraft.item.ItemStack) InventoryBasic(net.minecraft.inventory.InventoryBasic) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with InventoryBasic

use of net.minecraft.inventory.InventoryBasic in project MorePlanets by SteveKunG.

the class EntityAINibiruVillagerHarvestFarmland method updateTask.

@Override
public void updateTask() {
    super.updateTask();
    this.theVillager.getLookHelper().setLookPosition(this.destinationBlock.getX() + 0.5D, this.destinationBlock.getY() + 1, this.destinationBlock.getZ() + 0.5D, 10.0F, this.theVillager.getVerticalFaceSpeed());
    if (this.getIsAboveDestination()) {
        World world = this.theVillager.world;
        BlockPos blockpos = this.destinationBlock.up();
        IBlockState iblockstate = world.getBlockState(blockpos);
        Block block = iblockstate.getBlock();
        if (this.field_179501_f == 0 && block instanceof BlockCropsMP && iblockstate.getValue(BlockCropsMP.AGE).intValue() == 7) {
            world.destroyBlock(blockpos, true);
        } else if (this.field_179501_f == 1 && block == Blocks.AIR) {
            InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();
            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i) {
                ItemStack itemStack = inventorybasic.getStackInSlot(i);
                boolean flag = false;
                if (!itemStack.isEmpty()) {
                    if (itemStack.getItem() == NibiruItems.INFECTED_WHEAT_SEEDS) {
                        world.setBlockState(blockpos, NibiruBlocks.INFECTED_WHEAT_BLOCK.getDefaultState(), 3);
                        flag = true;
                    } else if (itemStack.getItem() == NibiruItems.NIBIRU_FRUITS && itemStack.getItemDamage() == 6) {
                        world.setBlockState(blockpos, NibiruBlocks.TERRABERRY_BLOCK.getDefaultState(), 3);
                        flag = true;
                    }
                }
                if (flag) {
                    itemStack.shrink(1);
                    if (itemStack.getCount() <= 0) {
                        inventorybasic.setInventorySlotContents(i, ItemStack.EMPTY);
                    }
                    break;
                }
            }
        }
        this.field_179501_f = -1;
        this.runDelay = 10;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockCropsMP(stevekung.mods.moreplanets.util.blocks.BlockCropsMP) EntityAIMoveToBlock(net.minecraft.entity.ai.EntityAIMoveToBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) InventoryBasic(net.minecraft.inventory.InventoryBasic)

Example 3 with InventoryBasic

use of net.minecraft.inventory.InventoryBasic 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)

Example 4 with InventoryBasic

use of net.minecraft.inventory.InventoryBasic in project MorePlanets by SteveKunG.

the class EntityAINibiruVillagerInteract method updateTask.

@Override
public void updateTask() {
    super.updateTask();
    if (this.interactionDelay > 0) {
        --this.interactionDelay;
        if (this.interactionDelay == 0) {
            InventoryBasic inventorybasic = this.villager.getVillagerInventory();
            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i) {
                ItemStack itemstack = inventorybasic.getStackInSlot(i);
                ItemStack itemstack1 = ItemStack.EMPTY;
                if (!itemstack.isEmpty()) {
                    Item item = itemstack.getItem();
                    if ((item == Items.BREAD || item == Items.POTATO || item == Items.CARROT) && itemstack.getCount() > 3) {
                        int l = itemstack.getCount() / 2;
                        itemstack.shrink(l);
                        itemstack1 = new ItemStack(item, l, itemstack.getMetadata());
                    } else if (item == Items.WHEAT && itemstack.getCount() > 5) {
                        int j = itemstack.getCount() / 2 / 3 * 3;
                        int k = j / 3;
                        itemstack.shrink(j);
                        itemstack1 = new ItemStack(Items.BREAD, k, 0);
                    }
                    if (itemstack.getCount() <= 0) {
                        inventorybasic.setInventorySlotContents(i, ItemStack.EMPTY);
                    }
                }
                if (itemstack1 != null) {
                    double d0 = this.villager.posY - 0.30000001192092896D + this.villager.getEyeHeight();
                    EntityItem entityitem = new EntityItem(this.villager.world, this.villager.posX, d0, this.villager.posZ, itemstack1);
                    float f = 0.3F;
                    float f1 = this.villager.rotationYawHead;
                    float f2 = this.villager.rotationPitch;
                    entityitem.motionX = -MathHelper.sin(f1 / 180.0F * (float) Math.PI) * MathHelper.cos(f2 / 180.0F * (float) Math.PI) * f;
                    entityitem.motionZ = MathHelper.cos(f1 / 180.0F * (float) Math.PI) * MathHelper.cos(f2 / 180.0F * (float) Math.PI) * f;
                    entityitem.motionY = -MathHelper.sin(f2 / 180.0F * (float) Math.PI) * f + 0.1F;
                    entityitem.setDefaultPickupDelay();
                    this.villager.world.spawnEntity(entityitem);
                    break;
                }
            }
        }
    }
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) Item(net.minecraft.item.Item) ItemStack(net.minecraft.item.ItemStack) InventoryBasic(net.minecraft.inventory.InventoryBasic) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

InventoryBasic (net.minecraft.inventory.InventoryBasic)4 ItemStack (net.minecraft.item.ItemStack)4 EntityItem (net.minecraft.entity.item.EntityItem)3 Item (net.minecraft.item.Item)3 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityAIMoveToBlock (net.minecraft.entity.ai.EntityAIMoveToBlock)1 EntityVillager (net.minecraft.entity.passive.EntityVillager)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 BlockCropsMP (stevekung.mods.moreplanets.util.blocks.BlockCropsMP)1