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

The following examples show how to use net.minecraft.entity.item.EntityItem#setItem() . 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
Source File: MetaItem1.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onEntityItemUpdate(EntityItem itemEntity) {
    int damage = itemEntity.getItem().getMetadata();
    if (damage >= this.metaItemOffset || itemEntity.getEntityWorld().isRemote)
        return false;
    Material material = Material.MATERIAL_REGISTRY.getObjectById(damage % 1000);
    OrePrefix prefix = this.orePrefixes[(damage / 1000)];
    if (!purifyMap.containsKey(prefix))
        return false;
    BlockPos blockPos = new BlockPos(itemEntity);
    IBlockState blockState = itemEntity.getEntityWorld().getBlockState(blockPos);
    int waterLevel = blockState.getBlock() instanceof BlockCauldron ?
        blockState.getValue(BlockCauldron.LEVEL) : 0;
    if (waterLevel == 0)
        return false;
    itemEntity.getEntityWorld().setBlockState(blockPos,
        blockState.withProperty(BlockCauldron.LEVEL, waterLevel - 1));
    ItemStack replacementStack = OreDictUnifier.get(purifyMap.get(prefix), material,
        itemEntity.getItem().getCount());
    itemEntity.setItem(replacementStack);
    return false;
}
 
Example 2
Source File: HarvesterTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
private void handleEntity(EntityItem entity, ItemStack itemStack) {
    if (StackHelper.isItemStackEmpty(itemStack)) {
        entity.setDead();
    } else {
        entity.setItem(itemStack);
    }
}
 
Example 3
Source File: MetaTileEntityItemCollector.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void moveItemsInEffectRange() {
    List<EntityItem> itemsInRange = getWorld().getEntitiesWithinAABB(EntityItem.class, areaBoundingBox);
    for (EntityItem entityItem : itemsInRange) {
        double distanceX = (areaCenterPos.getX() + 0.5) - entityItem.posX;
        double distanceZ = (areaCenterPos.getZ() + 0.5) - entityItem.posZ;
        double distance = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ);
        if(!itemFilter.testItemStack(entityItem.getItem())) {
            continue;
        }
        if (distance >= 0.7) {
            if(!entityItem.cannotPickup()) {
                double directionX = distanceX / distance;
                double directionZ = distanceZ / distance;
                entityItem.motionX = directionX * MOTION_MULTIPLIER * getTier();
                entityItem.motionZ = directionZ * MOTION_MULTIPLIER * getTier();
                entityItem.velocityChanged = true;
                entityItem.setPickupDelay(1);
            }
        } else {
            ItemStack itemStack = entityItem.getItem();
            ItemStack remainder = ItemHandlerHelper.insertItemStacked(exportItems, itemStack, false);
            if (remainder.isEmpty()) {
                entityItem.setDead();
            } else if (itemStack.getCount() > remainder.getCount()) {
                entityItem.setItem(remainder);
            }
        }
    }
    if (getTimer() % 5 == 0) {
        pushItemsIntoNearbyHandlers(getFrontFacing());
    }
}
 
Example 4
Source File: EntityFairy.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onDeath(@Nonnull DamageSource cause) {
	if (getIsInvulnerable()) return;

	if (!world.isRemote) {
		FairyData dataFairy = getDataFairy();
		if (dataFairy == null) return;

		if (dataFairy.isDepressed) {

			ItemStack stack = new ItemStack(ModItems.FAIRY_ITEM);
			NBTHelper.setTag(stack, "fairy", dataFairy.serializeNBT());

			world.removeEntity(this);

			EntityItem entityItem = new EntityItem(world);
			entityItem.setPosition(posX, posY, posZ);
			entityItem.setItem(stack);
			entityItem.setPickupDelay(20);
			entityItem.setNoDespawn();

			world.spawnEntity(entityItem);
			return;
		}

		super.onDeath(cause);

		if (getHealth() <= 0)
			PacketHandler.NETWORK.sendToAllAround(new PacketExplode(getPositionVector().add(0, 0.25, 0), dataFairy.primaryColor, dataFairy.secondaryColor, 0.5, 0.5, RandUtil.nextInt(100, 200), 75, 25, true),
					new NetworkRegistry.TargetPoint(world.provider.getDimension(), posX, posY, posZ, 256));
	}
}
 
Example 5
Source File: ItemUtils.java    From OpenModsLib with 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 6
Source File: RendererCrystallizer.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void render(TileEntity tile, double x,
		double y, double z, float f,  int destroyStage, float a) {
	TileMultiblockMachine multiBlockTile = (TileMultiblockMachine)tile;

	if(!multiBlockTile.canRender())
		return;

	GL11.glPushMatrix();

	//Rotate and move the model into position
	GL11.glTranslated(x+.5f, y, z + 0.5f);
	EnumFacing front = RotatableBlock.getFront(tile.getWorld().getBlockState(tile.getPos())); //tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord));
	GL11.glRotatef((front.getFrontOffsetX() == 1 ? 180 : 0) + front.getFrontOffsetZ()*90f, 0, 1, 0);
	GL11.glTranslated(-.5f, 0, -1.5f);

	if(multiBlockTile.isRunning()) {

		float progress = multiBlockTile.getProgress(0)/(float)multiBlockTile.getTotalProgress(0);

		bindTexture(texture);
		model.renderPart("Hull");

		List<ItemStack> outputList = multiBlockTile.getOutputs();
		if(outputList != null && !outputList.isEmpty()) {
			ItemStack stack = outputList.get(0);
			EntityItem entity = new EntityItem(tile.getWorld());

			entity.setItem(stack);
			entity.hoverStart = 0;

			int rotation = (int)(tile.getWorld().getTotalWorldTime() % 360);
			GL11.glPushMatrix();
			GL11.glTranslatef(0, 1, 0);

			GL11.glPushMatrix();
			GL11.glTranslated(1, 0.2, 0.7);
			GL11.glRotatef(rotation, 0, 1, 0);
			GL11.glScalef(progress, progress, progress);
			zmaster587.libVulpes.render.RenderHelper.renderItem(multiBlockTile, stack, Minecraft.getMinecraft().getRenderItem());
			GL11.glPopMatrix();

			GL11.glPushMatrix();
			GL11.glTranslated(1, 0.2, 1.5);
			GL11.glRotatef(rotation, 0, 1, 0);
			GL11.glScalef(progress, progress, progress);
			zmaster587.libVulpes.render.RenderHelper.renderItem(multiBlockTile, stack, Minecraft.getMinecraft().getRenderItem());
			GL11.glPopMatrix();

			GL11.glPushMatrix();
			GL11.glTranslated(1, 0.2, 2.3);
			GL11.glRotatef(rotation, 0, 1, 0);
			GL11.glScalef(progress, progress, progress);
			zmaster587.libVulpes.render.RenderHelper.renderItem(multiBlockTile, stack, Minecraft.getMinecraft().getRenderItem());
			GL11.glPopMatrix();

			GL11.glPopMatrix();



			GL11.glPushMatrix();
			GL11.glEnable(GL11.GL_BLEND);
			GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );

			int color = Minecraft.getMinecraft().getItemColors().getColorFromItemstack(stack, 0);

			float divisor = 1/255f;

			GL11.glColor4f((color & 0xFF)*divisor*.5f, ((color & 0xFF00) >>> 8)*divisor*.5f,  ((color & 0xFF0000) >>> 16)*divisor*.5f, 0xE4*divisor);
			GL11.glDisable(GL11.GL_TEXTURE_2D);
			GL11.glTranslatef(0, 1.1f, 0);

			//Fill before emptying
			if(progress < 0.05)
				GL11.glScaled(1, 20*progress, 1);
			else
				GL11.glScaled(1, (1.1-(progress*1.111)), 1);

			GL11.glTranslatef(0, -1.1f, 0);
			model.renderPart("Liquid");
		}
		
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		GL11.glDisable(GL11.GL_BLEND);
		GL11.glPopMatrix();

	}
	else {
		bindTexture(texture);
		model.renderPart("Hull");
	}
	GL11.glPopMatrix();
}
 
Example 7
Source File: ItemHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 8
Source File: ItemNullifier.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 nullifier
    List<Integer> slots = InventoryUtils.getSlotNumbersOfMatchingItems(playerInv, EnderUtilitiesItems.NULLIFIER);

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

        // Nullifier is not disabled
        if (nullifierStack.isEmpty() == false && isNullifierEnabled(nullifierStack))
        {
            // 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, nullifierStack, 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;
}