Java Code Examples for net.minecraft.entity.item.EntityItem#setDead()

The following examples show how to use net.minecraft.entity.item.EntityItem#setDead() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@SubscribeEvent
public void redstoneHandler(EntityJoinWorldEvent event) {
	if (event.getWorld().isRemote) {
		return;
	}

	if (event.getEntity() instanceof EntityItem && !(event.getEntity() instanceof EntityBurnableItem)) {
		EntityItem item = (EntityItem) event.getEntity();
		if (EntityBurnableItem.isBurnable(item.getItem())) {
			EntityBurnableItem newItem = new EntityBurnableItem(event.getWorld(), item.posX, item.posY, item.posZ, item.getItem());
			newItem.motionX = item.motionX;
			newItem.motionY = item.motionY;
			newItem.motionZ = item.motionZ;
			newItem.setPickupDelay(40);
			item.setDead();
			event.getWorld().spawnEntity(newItem);
		}
	}
}
 
Example 2
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
    EntityItem oldEntity = items.get(slot);

    if(oldEntity != null) {
        oldEntity.setDead();
    }

    if(stack != null && stack.stackSize > 0) {
        if(oldEntity != null && InventoryUtils.areItemStacksEqualStrict(oldEntity.getEntityItem(), stack)) {
            oldEntity.getEntityItem().stackSize = stack.stackSize;
            oldEntity.isDead = false;
        } else {
            items.set(slot, dropItem(stack));
        }
    }
}
 
Example 3
public static void destroyDrops(Entity entity, double d)
{

    if (!MoCreatures.proxy.destroyDrops) { return; }

    //List list = MoCreatures.mc.theWorld.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(d, d, d));
    List list = entity.worldObj.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(d, d, d));

    for (int i = 0; i < list.size(); i++)
    {
        Entity entity1 = (Entity) list.get(i);
        if (!(entity1 instanceof EntityItem))
        {
            continue;
        }
        EntityItem entityitem = (EntityItem) entity1;
        if ((entityitem != null) && (entityitem.age < 50))
        {
            entityitem.setDead();
        }
    }

}
 
Example 4
@Override
public Collection<ItemStack> collect(){
    List<ItemStack> col = new ArrayList<ItemStack>();
    int[] coords = housing.getCoords();
    int[] area = housing.getArea();
    int[] offset = housing.getOffset();

    AxisAlignedBB harvestBox = AxisAlignedBB.getBoundingBox(coords[0] + offset[0], coords[1] + offset[1], coords[2] + offset[2], coords[0] + offset[0] + area[0], coords[1] + offset[1] + area[1], coords[2] + offset[2] + area[2]);
    List<EntityItem> list = housing.getWorld().getEntitiesWithinAABB(EntityItem.class, harvestBox);

    for(EntityItem item : list) {
        if(!item.isDead) {
            ItemStack contained = item.getEntityItem();
            if(isAcceptedGermling(contained)) {
                col.add(contained.copy());
                item.setDead();
            }
        }
    }
    return col;
}
 
Example 5
@Override
public Collection<ItemStack> collect(){
    List<ItemStack> col = new ArrayList<ItemStack>();
    int[] coords = housing.getCoords();
    int[] area = housing.getArea();
    int[] offset = housing.getOffset();

    AxisAlignedBB harvestBox = AxisAlignedBB.getBoundingBox(coords[0] + offset[0], coords[1] + offset[1], coords[2] + offset[2], coords[0] + offset[0] + area[0], coords[1] + offset[1] + area[1], coords[2] + offset[2] + area[2]);
    List<EntityItem> list = housing.getWorld().getEntitiesWithinAABB(EntityItem.class, harvestBox);

    for(EntityItem item : list) {
        if(!item.isDead) {
            ItemStack contained = item.getEntityItem();
            if(isAcceptedGermling(contained)) {
                col.add(contained.copy());
                item.setDead();
            }
        }
    }
    return col;
}
 
Example 6
Source Project: TofuCraftReload   File: EntityTofunian.java    License: MIT License 5 votes vote down vote up
protected void updateEquipmentIfNeeded(EntityItem itemEntity) {
    ItemStack itemstack = itemEntity.getItem();

    if (this.canTofunianPickupItem(itemstack)) {
        ItemStack itemstack1 = this.getVillagerInventory().addItem(itemstack);

        if (itemstack1.isEmpty()) {
            itemEntity.setDead();
        } else {
            itemstack.setCount(itemstack1.getCount());
        }
    }
}
 
Example 7
Source Project: OpenModsLib   File: ItemUtils.java    License: MIT License 5 votes vote down vote up
public static void setEntityItemStack(EntityItem entity, @Nonnull ItemStack stack) {
	if (stack.isEmpty()) {
		entity.setDead();
	} else {
		entity.setItem(stack);
	}
}
 
Example 8
public ItemStack finish(EntityItem entity) {
	int count = output.getCount();
	ItemStack input = entity.getItem();
	if (input.isEmpty()) {
		entity.setDead();
		return ItemStack.EMPTY;
	}
	count *= input.getCount();
	ItemStack out = output.copy();
	out.setCount(count);
	return out;
}
 
Example 9
private void killNewItems( Set<EntityItem> before, Set<EntityItem> after )
{
    Iterator<EntityItem> it = after.iterator();
    while( it.hasNext() )
    {
        EntityItem item = it.next();
        if( !item.isDead && !before.contains( item ) )
        {
            item.setDead();
        }
    }
}
 
Example 10
public double[] clearStacksInChamber(Object... stacksToClear){
    int[] stackSizes = new int[stacksToClear.length];
    for(int i = 0; i < stacksToClear.length; i++) {
        stackSizes[i] = PneumaticRecipeRegistry.getItemAmount(stacksToClear[i]);
    }
    // default the output position to the middle of the chamber.
    double[] outputPosition = new double[]{multiBlockX + multiBlockSize / 2D, multiBlockY + 1.2D, multiBlockZ + multiBlockSize / 2D};

    // get the in world EntityItems
    AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(multiBlockX, multiBlockY, multiBlockZ, multiBlockX + multiBlockSize, multiBlockY + multiBlockSize, multiBlockZ + multiBlockSize);
    List<EntityItem> entities = worldObj.getEntitiesWithinAABB(EntityItem.class, bbBox);
    for(EntityItem entity : entities) {
        if(entity.isDead) continue;
        ItemStack entityStack = entity.getEntityItem();
        for(int l = 0; l < stacksToClear.length; l++) {
            if(PneumaticRecipeRegistry.isItemEqual(stacksToClear[l], entityStack) && stackSizes[l] > 0) {
                outputPosition[0] = entity.posX;
                outputPosition[1] = entity.posY;
                outputPosition[2] = entity.posZ;
                int removedItems = Math.min(stackSizes[l], entityStack.stackSize);
                stackSizes[l] -= removedItems;
                entityStack.stackSize -= removedItems;
                if(entityStack.stackSize <= 0) entity.setDead();
                break;
            }
        }
    }
    return outputPosition;
}
 
Example 11
@Override
protected boolean exportItem(int maxItems){
    ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata());
    if(tank.getFluid() != null) {
        TileEntity neighbor = IOHelper.getNeighbor(this, dir);
        if(neighbor instanceof IFluidHandler) {
            IFluidHandler fluidHandler = (IFluidHandler)neighbor;
            if(fluidHandler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
                FluidStack fluid = tank.getFluid().copy();
                fluid.amount = Math.min(maxItems * 100, tank.getFluid().amount - (leaveMaterial ? 1000 : 0));
                if(fluid.amount > 0) {
                    tank.getFluid().amount -= fluidHandler.fill(dir.getOpposite(), fluid, true);
                    if(tank.getFluidAmount() <= 0) tank.setFluid(null);
                    return true;
                }
            }
        }
    }

    if(worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
        for(EntityItem entity : getNeighborItems(this, dir)) {
            if(!entity.isDead) {
                List<ItemStack> returnedItems = new ArrayList<ItemStack>();
                if(FluidUtils.tryExtractingLiquid(this, entity.getEntityItem(), returnedItems)) {
                    if(entity.getEntityItem().stackSize <= 0) entity.setDead();
                    for(ItemStack stack : returnedItems) {
                        EntityItem item = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, stack);
                        item.motionX = entity.motionX;
                        item.motionY = entity.motionY;
                        item.motionZ = entity.motionZ;
                        worldObj.spawnEntityInWorld(item);
                    }
                    return true;
                }
            }
        }
    }

    if(getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
        if(worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
            FluidStack extractedFluid = drain(ForgeDirection.UNKNOWN, 1000, false);
            if(extractedFluid != null && extractedFluid.amount == 1000) {
                Block fluidBlock = extractedFluid.getFluid().getBlock();
                if(fluidBlock != null) {
                    drain(ForgeDirection.UNKNOWN, 1000, true);
                    worldObj.setBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, fluidBlock);
                }
            }
        }
    }

    return false;
}
 
Example 12
Source Project: NotEnoughItems   File: MagnetModeHandler.java    License: MIT License 4 votes vote down vote up
@SubscribeEvent
@SideOnly (Side.CLIENT)
public void clientTickEvent(TickEvent.ClientTickEvent event) {

    if (event.phase == Phase.END || Minecraft.getMinecraft().world == null) {
        return;
    }
    if (!NEIClientConfig.isMagnetModeEnabled()) {
        return;
    }
    EntityPlayer player = Minecraft.getMinecraft().player;

    Iterator<EntityItem> iterator = clientMagnetItems.iterator();
    while (iterator.hasNext()) {
        EntityItem item = iterator.next();
        if (item.cannotPickup()) {
            continue;
        }
        if (item.isDead) {
            iterator.remove();
        }
        if (item.getEntityData().getBoolean("PreventRemoteMovement")) {
            continue;
        }
        if (!NEIClientUtils.canItemFitInInventory(player, item.getItem())) {
            continue;
        }
        double dx = player.posX - item.posX;
        double dy = player.posY + player.getEyeHeight() - item.posY;
        double dz = player.posZ - item.posZ;
        double absxz = Math.sqrt(dx * dx + dz * dz);
        double absy = Math.abs(dy);
        if (absxz > DISTANCE_XZ || absy > DISTANCE_Y) {
            continue;
        }

        if (absxz > 1) {
            dx /= absxz;
            dz /= absxz;
        }

        if (absy > 1) {
            dy /= absy;
        }

        double vx = item.motionX + SPEED_XZ * dx;
        double vy = item.motionY + SPEED_Y * dy;
        double vz = item.motionZ + SPEED_XZ * dz;

        double absvxz = Math.sqrt(vx * vx + vz * vz);
        double absvy = Math.abs(vy);

        double rationspeedxz = absvxz / MAX_SPEED_XZ;
        if (rationspeedxz > 1) {
            vx /= rationspeedxz;
            vz /= rationspeedxz;
        }

        double rationspeedy = absvy / MAX_SPEED_Y;
        if (rationspeedy > 1) {
            vy /= rationspeedy;
        }

        if (absvxz < 0.2 && absxz < 0.2) {
            item.setDead();
        }

        item.setVelocity(vx, vy, vz);
    }
}
 
Example 13
private static void tryAuraCoreCreation(ItemStack i, EntityPlayer entityPlayer, World world, int x, int y, int z) {
    if(world.isRemote) return;

    List items = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1)
            .expand(EntityAuraCore.CLUSTER_RANGE, EntityAuraCore.CLUSTER_RANGE, EntityAuraCore.CLUSTER_RANGE));
    Iterator it = items.iterator();
    EntityItem itemAuraCore = null;
    while(itemAuraCore == null && it.hasNext()) {
        Object item = it.next();
        if(item != null && item instanceof EntityItem && !((EntityItem) item).isDead) {
            EntityItem entityItem = (EntityItem) item;
            if(entityItem.getEntityItem() != null && entityItem.getEntityItem().getItem() != null
                    && entityItem.getEntityItem().getItem() instanceof ItemAuraCore && !(item instanceof EntityAuraCore)) {
                if(((ItemAuraCore) entityItem.getEntityItem().getItem()).isBlank(entityItem.getEntityItem())) itemAuraCore = entityItem;
            }
        }
    }

    if(itemAuraCore == null) return;

    int meta = world.getBlockMetadata(x, y, z);
    if(meta <= 6) {
        Aspect[] aspects;
        switch (meta) {
            case 0:
                aspects = new Aspect[]{Aspect.AIR};
                break;
            case 1:
                aspects = new Aspect[]{Aspect.FIRE};
                break;
            case 2:
                aspects = new Aspect[]{Aspect.WATER};
                break;
            case 3:
                aspects = new Aspect[]{Aspect.EARTH};
                break;
            case 4:
                aspects = new Aspect[]{Aspect.ORDER};
                break;
            case 5:
                aspects = new Aspect[]{Aspect.ENTROPY};
                break;
            case 6:
                aspects = new Aspect[]{Aspect.AIR, Aspect.FIRE, Aspect.EARTH, Aspect.WATER, Aspect.ORDER, Aspect.ENTROPY};
                break;
            default:
                return;
        }

        if(!ThaumcraftApiHelper.consumeVisFromWandCrafting(i, entityPlayer, (AspectList)RegisteredRecipes.auraCoreRecipes[meta].get(0), true))
            return;


        PacketStartAnimation packet = new PacketStartAnimation(PacketStartAnimation.ID_BURST, x, y, z);
        PacketHandler.INSTANCE.sendToAllAround(packet, new NetworkRegistry.TargetPoint(world.provider.dimensionId, x, y, z, 32.0D));
        world.createExplosion(null, x + 0.5D, y + 0.5D, z + 0.5D, 1.5F, false);
        world.setBlockToAir(x, y, z);

        EntityAuraCore ea =
                new EntityAuraCore(itemAuraCore.worldObj, itemAuraCore.posX, itemAuraCore.posY, itemAuraCore.posZ,
                        itemAuraCore.getEntityItem(), new ChunkCoordinates(x, y, z), aspects);
        ea.age = itemAuraCore.age;
        ea.hoverStart = itemAuraCore.hoverStart;
        ea.motionX = itemAuraCore.motionX;
        ea.motionY = itemAuraCore.motionY;
        ea.motionZ = itemAuraCore.motionZ;
        itemAuraCore.worldObj.spawnEntityInWorld(ea);
        itemAuraCore.setDead();
    }
}
 
Example 14
private void tryVortexUnfinishedResearchNotes() {
    float centerY = yCoord + 0.4F;
    List entityItems = worldObj.selectEntitiesWithinAABB(EntityItem.class,
            AxisAlignedBB.getBoundingBox(xCoord - 0.5, centerY - 0.5, zCoord - 0.5, xCoord + 0.5, centerY + 0.5, zCoord + 0.5).expand(8, 8, 8), new IEntitySelector() {
                @Override
                public boolean isEntityApplicable(Entity e) {
                    return !(e instanceof EntityPermanentItem) && !(e instanceof EntitySpecialItem) &&
                            e instanceof EntityItem && ((EntityItem) e).getEntityItem() != null &&
                            ((EntityItem) e).getEntityItem().getItem() instanceof ItemResearchNotes &&
                            shouldVortexResearchNote(((EntityItem) e).getEntityItem());
                }
            });

    Entity dummy = new EntityItem(worldObj);
    dummy.posX = xCoord + 0.5;
    dummy.posY = centerY + 0.5;
    dummy.posZ = zCoord + 0.5;

    //MC code.
    EntityItem entity = null;
    double d0 = Double.MAX_VALUE;
    for (Object entityItem : entityItems) {
        EntityItem entityIt = (EntityItem) entityItem;
        if (entityIt != dummy) {
            double d1 = dummy.getDistanceSqToEntity(entityIt);
            if (d1 <= d0) {
                entity = entityIt;
                d0 = d1;
            }
        }
    }
    if(entity == null) return;
    if(dummy.getDistanceToEntity(entity) < 1 && !worldObj.isRemote) {
        ItemStack inter = entity.getEntityItem();
        inter.stackSize--;
        this.storedResearchNote = inter.copy();
        this.storedResearchNote.stackSize = 1;

        EntityPermNoClipItem item = new EntityPermNoClipItem(entity.worldObj, xCoord + 0.5F, centerY + 0.3F, zCoord + 0.5F, storedResearchNote, xCoord, yCoord, zCoord);
        entity.worldObj.spawnEntityInWorld(item);
        item.motionX = 0;
        item.motionY = 0;
        item.motionZ = 0;
        item.hoverStart = entity.hoverStart;
        item.age = entity.age;
        item.noClip = true;

        timeSinceLastItemInfo = 0;

        if(inter.stackSize <= 0) entity.setDead();
        entity.noClip = false;
        item.delayBeforeCanPickup = 60;
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        markDirty();
    } else {
        entity.noClip = true;
        applyMovementVectors(entity);
    }
}
 
Example 15
private void tryVortexPossibleItems() {
    TileAuraPylon io = getInputTile();
    if (io == null) return;

    int masterY = yCoord + 1;
    float dst = ((float) (masterY - io.yCoord)) / 2F;
    float yC = masterY - dst;
    List entityItems = worldObj.selectEntitiesWithinAABB(EntityItem.class,
            AxisAlignedBB.getBoundingBox(xCoord - 0.5, yC - 0.5, zCoord - 0.5, xCoord + 0.5, yC + 0.5, zCoord + 0.5).expand(8, 8, 8), new IEntitySelector() {
                @Override
                public boolean isEntityApplicable(Entity e) {
                    return !(e instanceof EntityPermanentItem) && !(e instanceof EntitySpecialItem) &&
                            e instanceof EntityItem && ((EntityItem) e).getEntityItem() != null &&
                            ((EntityItem) e).getEntityItem().getItem() instanceof ItemCrystalEssence &&
                            ((ItemCrystalEssence) ((EntityItem) e).getEntityItem().getItem()).getAspects(((EntityItem) e).getEntityItem()) != null;
                }
            });
    Entity dummy = new EntityItem(worldObj);
    dummy.posX = xCoord + 0.5;
    dummy.posY = yC + 0.5;
    dummy.posZ = zCoord + 0.5;

    //MC code.
    EntityItem entity = null;
    double d0 = Double.MAX_VALUE;
    for (Object entityItem : entityItems) {
        EntityItem entityIt = (EntityItem) entityItem;
        if (entityIt != dummy) {
            double d1 = dummy.getDistanceSqToEntity(entityIt);
            if (d1 <= d0) {
                entity = entityIt;
                d0 = d1;
            }
        }
    }
    if(entity == null) return;
    if(dummy.getDistanceToEntity(entity) < 1 && !worldObj.isRemote) {
        ItemStack inter = entity.getEntityItem();
        inter.stackSize--;
        this.crystalEssentiaStack = inter.copy();
        this.crystalEssentiaStack.stackSize = 1;

        EntityPermNoClipItem item = new EntityPermNoClipItem(entity.worldObj, xCoord + 0.5F, yC + 0.3F, zCoord + 0.5F, crystalEssentiaStack, xCoord, yCoord, zCoord);
        entity.worldObj.spawnEntityInWorld(item);
        item.motionX = 0;
        item.motionY = 0;
        item.motionZ = 0;
        item.hoverStart = entity.hoverStart;
        item.age = entity.age;
        item.noClip = true;

        timeSinceLastItemInfo = 0;

        holdingAspect = ((ItemCrystalEssence) crystalEssentiaStack.getItem()).getAspects(crystalEssentiaStack).getAspects()[0];
        distributeAspectInformation();

        if(inter.stackSize <= 0) entity.setDead();
        entity.noClip = false;
        item.delayBeforeCanPickup = 60;
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        markDirty();
    } else {
        entity.noClip = true;
        applyMovementVectors(entity);
    }
}
 
Example 16
private void updateTrackedItems(){
    if(trackedItemIds != null) {
        trackedItems.clear();
        for(Entity entity : (List<Entity>)worldObj.loadedEntityList) {
            if(trackedItemIds.contains(entity.getUniqueID()) && entity instanceof EntityItem) {
                trackedItems.add((EntityItem)entity);
            }
        }
        trackedItemIds = null;
    }
    Iterator<EntityItem> iterator = trackedItems.iterator();
    while(iterator.hasNext()) {
        EntityItem item = iterator.next();
        if(item.worldObj != worldObj || item.isDead) {
            iterator.remove();
        } else {
            Map<ChunkPosition, ForgeDirection> positions = new HashMap<ChunkPosition, ForgeDirection>();
            double range = 0.2;
            for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                double posX = item.posX + d.offsetX * range;
                double posY = item.posY + d.offsetY * range;
                double posZ = item.posZ + d.offsetZ * range;
                positions.put(new ChunkPosition((int)Math.floor(posX), (int)Math.floor(posY), (int)Math.floor(posZ)), d.getOpposite());
            }
            for(Entry<ChunkPosition, ForgeDirection> entry : positions.entrySet()) {
                ChunkPosition pos = entry.getKey();
                TileEntity te = worldObj.getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
                IInventory inv = IOHelper.getInventoryForTE(te);
                ItemStack remainder = IOHelper.insert(inv, item.getEntityItem(), entry.getValue().ordinal(), false);
                if(remainder != null) {
                    item.setEntityItemStack(remainder);
                } else {
                    item.setDead();
                    iterator.remove();
                    lastInsertingInventory = new ChunkPosition(te.xCoord, te.yCoord, te.zCoord);
                    lastInsertingInventorySide = entry.getValue();
                    break;
                }
            }
        }
    }
}
 
Example 17
/**
 * Tries to first fill the matching stacks in the player's inventory,
 * and then depending on the bag's mode, tries to add the remaining items
 * to the bag's inventory.
 * @param event
 * @return true if all items were handled and further processing of the event should not occur
 */
public static boolean onEntityItemPickupEvent(EntityItemPickupEvent event)
{
    EntityItem entityItem = event.getItem();
    ItemStack stack = entityItem.getItem();
    EntityPlayer player = event.getEntityPlayer();

    if (player.getEntityWorld().isRemote || entityItem.isDead || stack.isEmpty())
    {
        return true;
    }

    ItemStack origStack = ItemStack.EMPTY;
    final int origStackSize = stack.getCount();
    int stackSizeLast = origStackSize;
    boolean ret = false;

    IItemHandler playerInv = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    // Not all the items could fit into existing stacks in the player's inventory, move them directly to the bag
    List<Integer> slots = InventoryUtils.getSlotNumbersOfMatchingItems(playerInv, EnderUtilitiesItems.HANDY_BAG);

    for (int slot : slots)
    {
        ItemStack bagStack = playerInv.getStackInSlot(slot);

        // Bag is not locked
        if (bagStack.isEmpty() == false && bagStack.getItem() == EnderUtilitiesItems.HANDY_BAG && ItemHandyBag.bagIsOpenable(bagStack))
        {
            // Delayed the stack copying until we know if there is a valid bag,
            // so check if the stack was copied already or not.
            if (origStack == ItemStack.EMPTY)
            {
                origStack = stack.copy();
            }

            stack = handleItems(stack, bagStack, player);

            if (stack.isEmpty() || stack.getCount() != stackSizeLast)
            {
                if (stack.isEmpty())
                {
                    entityItem.setDead();
                    event.setCanceled(true);
                    ret = true;
                    break;
                }

                ItemStack pickedUpStack = origStack.copy();
                pickedUpStack.setCount(stackSizeLast - stack.getCount());

                FMLCommonHandler.instance().firePlayerItemPickupEvent(player, entityItem, pickedUpStack);
                player.onItemPickup(entityItem, origStackSize);
            }

            stackSizeLast = stack.getCount();
        }
    }

    // Not everything was handled, update the stack
    if (entityItem.isDead == false && stack.getCount() != origStackSize)
    {
        entityItem.setItem(stack);
    }

    // At least some items were picked up
    if (entityItem.isSilent() == false && (entityItem.isDead || stack.getCount() != origStackSize))
    {
        player.getEntityWorld().playSound(null, player.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.MASTER,
                0.2F, ((itemRand.nextFloat() - itemRand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    }

    return ret;
}
 
Example 18
@Override
public boolean onEntityItemUpdate(EntityItem entityItem){
    MotionProperties motProps = (MotionProperties)entityItem.getExtendedProperties("plasticPlant");
    double oldMotionX = entityItem.motionX;
    double oldMotionY = entityItem.motionY;
    double oldMotionZ = entityItem.motionZ;
    if(motProps != null) {
        oldMotionX = motProps.oldMotionX;
        oldMotionY = motProps.oldMotionY;
        oldMotionZ = motProps.oldMotionZ;
    }

    ItemStack stack = entityItem.getEntityItem();
    int itemDamage = stack.getItemDamage();

    if(motProps == null && (itemDamage % 16 == ItemPlasticPlants.PROPULSION_PLANT_DAMAGE || itemDamage % 16 == ItemPlasticPlants.REPULSION_PLANT_DAMAGE)) {
        motProps = new MotionProperties();
        entityItem.registerExtendedProperties("plasticPlant", motProps);
    }
    if(motProps != null) motProps.update(entityItem);

    boolean isDelayOver = isActive(entityItem) || entityItem.age > 60 && entityItem.delayBeforeCanPickup == 0;
    if(entityItem.onGround || Math.abs(entityItem.motionY) < 0.13D && (itemDamage % 16 == ItemPlasticPlants.HELIUM_PLANT_DAMAGE || itemDamage % 16 == ItemPlasticPlants.SQUID_PLANT_DAMAGE)) {
        if(!handleRepulsionBehaviour(entityItem, oldMotionX, oldMotionY, oldMotionZ)) return false;
        if(!handlePropulsionBehaviour(entityItem, oldMotionX, oldMotionZ)) return false;
        if(!entityItem.worldObj.isRemote) {
            Block blockID = getPlantBlockIDFromSeed(itemDamage % 16);
            int landedBlockX = (int)Math.floor(entityItem.posX);// - 0.5F);
            int landedBlockY = (int)Math.floor(entityItem.posY);
            int landedBlockZ = (int)Math.floor(entityItem.posZ);// - 0.5F);

            boolean canSustain = false;

            canSustain = ((BlockPneumaticPlantBase)blockID).canBlockStay(entityItem.worldObj, landedBlockX, landedBlockY, landedBlockZ);
            if(itemDamage % 16 == ItemPlasticPlants.FIRE_FLOWER_DAMAGE && !canSustain && !isInChamber(entityItem.worldObj.getBlock(landedBlockX, landedBlockY - 1, landedBlockZ)) && net.minecraft.init.Blocks.fire.canPlaceBlockAt(entityItem.worldObj, landedBlockX, landedBlockY, landedBlockZ) && entityItem.worldObj.isAirBlock(landedBlockX, landedBlockY, landedBlockZ)) {
                entityItem.worldObj.setBlock(landedBlockX, landedBlockY, landedBlockZ, net.minecraft.init.Blocks.fire);
            }

            if(canSustain && isDelayOver) {
                if(entityItem.worldObj.isAirBlock(landedBlockX, landedBlockY, landedBlockZ)) {

                    entityItem.worldObj.setBlock(landedBlockX, landedBlockY, landedBlockZ, blockID, itemDamage > 15 || !isActive(entityItem) ? 0 : 7, 3);

                    entityItem.playSound("mob.chicken.plop", 1.0F, (rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F);
                    for(int i = 0; i < 10; i++) {
                        spawnParticle(entityItem.worldObj, "explode", entityItem.posX + rand.nextDouble() - 0.5D, entityItem.posY + rand.nextDouble() - 0.5D, entityItem.posZ + rand.nextDouble() - 0.5D, 0.0D, 0.0D, 0.0D);
                    }
                    if(stack.stackSize == 1) {
                        entityItem.setDead();
                    } else {
                        stack.stackSize--;
                    }
                }
            }
        }
    }

    // when the entity on the ground check whether the block beneath it is
    // dirt, and the block above it is air, if yes, then plant it.
    if(itemDamage % 16 == ItemPlasticPlants.SQUID_PLANT_DAMAGE && entityItem.worldObj.isMaterialInBB(entityItem.boundingBox.contract(0.003D, 0.003D, 0.003D), Material.water)) {
        entityItem.motionY += 0.06D;
    }
    if(itemDamage % 16 == ItemPlasticPlants.HELIUM_PLANT_DAMAGE) {
        entityItem.motionY += 0.08D;
    }
    if(itemDamage % 16 == ItemPlasticPlants.FLYING_FLOWER_DAMAGE) {
        entityItem.motionY += 0.04D;
        if(entityItem.age % 60 == 0) {
            entityItem.motionX += (rand.nextDouble() - 0.5D) * 0.1D;
            entityItem.motionY += (rand.nextDouble() - 0.6D) * 0.1D;
            entityItem.motionZ += (rand.nextDouble() - 0.5D) * 0.1D;
        }
    }
    return false;
}
 
Example 19
@Override
public void onLivingUpdate()
{
    super.onLivingUpdate();

    if (mouthCounter > 0 && ++mouthCounter > 30)
    {
        mouthCounter = 0;
    }

    if (attackCounter > 0 && ++attackCounter > 100)
    {
        attackCounter = 0;
    }

    if ((MoCreatures.isServer()) && !getIsAdult() && (rand.nextInt(250) == 0))
    {
        setEdad(getEdad() + 1);
        if (getEdad() >= 100)
        {
            setAdult(true);
        }
    }
    /**
     * panda bears and cubs will sit down every now and then
     */
    if ((MoCreatures.isServer()) && (getType() == 3 || (!getIsAdult() && getEdad() < 60)) && (rand.nextInt(300) == 0))
    {
        setBearState(2);
    }

    /**
     * Sitting bears will resume on fours stance every now and then
     */
    if ((MoCreatures.isServer()) && (getBearState() == 2) && (rand.nextInt(800) == 0))
    {
        setBearState(0);
    }

    /**
     * Adult non panda bears will stand on hind legs if close to player
     */

    if ((MoCreatures.isServer()) && standingCounter == 0 && getBearState() != 2 && getIsAdult() && getType() != 3 && (rand.nextInt(500) == 0))
    {
        standingCounter = 1;
        EntityPlayer entityplayer1 = worldObj.getClosestPlayerToEntity(this, 8D);
        if (entityplayer1 != null)
        {
            setBearState(1);
        }
    }

    if ((MoCreatures.isServer()) && standingCounter > 0 && ++standingCounter > 50)
    {
        standingCounter = 0;
        setBearState(0);
    }

    if (MoCreatures.isServer() && getType() == 3 && (deathTime == 0) && getBearState() != 2)
    {
        EntityItem entityitem = getClosestItem(this, 12D, Item.reed.itemID, Item.sugar.itemID);
        if (entityitem != null)
        {

            float f = entityitem.getDistanceToEntity(this);
            if (f > 2.0F)
            {
                getMyOwnPath(entityitem, f);
            }
            if ((f < 2.0F) && (entityitem != null) && (deathTime == 0))
            {
                entityitem.setDead();
                worldObj.playSoundAtEntity(this, "eating", 1.0F, 1.0F + ((rand.nextFloat() - rand.nextFloat()) * 0.2F));
                //setTamed(true);
                health = getMaxHealth();
            }

        }
    }
}
 
Example 20
@Override
public void onLivingUpdate()
{
    super.onLivingUpdate();
    // fixes glide issue in SMP
    if (worldObj.isRemote)
    {
        if (ridingEntity != null)
        {
            updateEntityActionState();
        }
        else
        {
            //return; 
            //commenting this fixes the wing movement bug
        }
    }
    //if (!worldObj.isRemote)

    winge = wingb;
    wingd = wingc;
    wingc = (float) (wingc + ((onGround ? -1 : 4) * 0.29999999999999999D));
    if (wingc < 0.0F)
    {
        wingc = 0.0F;
    }
    if (wingc > 1.0F)
    {
        wingc = 1.0F;
    }
    if (!onGround && (wingh < 1.0F))
    {
        wingh = 1.0F;
    }
    wingh = (float) (wingh * 0.90000000000000002D);
    if (!onGround && (motionY < 0.0D))
    {
        motionY *= 0.80000000000000004D;
    }
    wingb += wingh * 2.0F;

    //check added to avoid duplicating behavior on client / server
    if (MoCreatures.isServer())
    {
        EntityLiving entityliving = getBoogey(5D);
        if ((entityliving != null) && !getIsTamed() && !getPreTamed() && canEntityBeSeen(entityliving))
        {
            fleeing = true;
        }
        if (rand.nextInt(200) == 0)
        {
            fleeing = true;
        }
        if (fleeing)
        {
            if (FlyToNextTree())
            {
                fleeing = false;
            }
            int ai[] = ReturnNearestMaterialCoord(this, Material.leaves, Double.valueOf(16D));
            if (ai[0] == -1)
            {
                for (int i = 0; i < 2; i++)
                {
                    WingFlap();
                }

                fleeing = false;
            }
            if (rand.nextInt(50) == 0)
            {
                fleeing = false;
            }
        }
        if (!fleeing)
        {
            EntityItem entityitem = getClosestItem(this, 12D, Item.seeds.itemID, -1);
            if (entityitem != null)
            {
                FlyToNextEntity(entityitem);
                EntityItem entityitem1 = getClosestItem(this, 1.0D, Item.seeds.itemID, -1);
                if ((rand.nextInt(50) == 0) && (entityitem1 != null))
                {
                    entityitem1.setDead();
                    setPreTamed(true);                        
                }
            }
        }
        if (isInsideOfMaterial(Material.water))
        {
            WingFlap();
        }
    }
}