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

The following examples show how to use net.minecraft.entity.item.EntityItem#setEntityItemStack() . 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
public void renderChopperSeeds(EntityChopperSeeds entity, double x, double y, double z, float var1, float partialTicks){
    float scaleFactor = 0.7F;
    GL11.glPushMatrix(); // start
    GL11.glTranslatef((float)x, (float)y, (float)z); // size
    // GL11.glScalef(1.0F, -1F, -1F);
    GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);
    EntityItem ghostEntityItem = new EntityItem(entity.worldObj);
    ghostEntityItem.hoverStart = 0.0F;
    ghostEntityItem.setEntityItemStack(iStack);
    double radius = 0.25D;
    for(int i = 0; i < 4; i++) {
        GL11.glPushMatrix();
        GL11.glTranslated(Math.sin(0.5D * Math.PI * i + (entity.ticksExisted + partialTicks) * 0.4D) * radius, 0, Math.cos(0.5D * Math.PI * i + (entity.ticksExisted + partialTicks) * 0.4D) * radius);
        itemRenderer.doRender(ghostEntityItem, 0, 0, 0, 0, 0);
        GL11.glPopMatrix();
    }
    GL11.glPopMatrix();
}
 
Example 2
@Override
@Optional.Method(modid = ModIds.FMP)
public void removeTube(TileEntity te){
    if(te instanceof TileMultipart) {
        PartPressureTube tube = FMP.getMultiPart((TileMultipart)te, PartPressureTube.class);
        if(tube != null) {
            List<ItemStack> drops = BlockPressureTube.getModuleDrops(tube.getTube());
            for(ItemStack drop : drops) {
                EntityItem entity = new EntityItem(te.getWorldObj(), te.xCoord + 0.5, te.yCoord + 0.5, te.zCoord + 0.5);
                entity.setEntityItemStack(drop);
                te.getWorldObj().spawnEntityInWorld(entity);
            }
            ((TileMultipart)te).remPart(tube);
        }
    } else {
        super.removeTube(te);
    }
}
 
Example 3
@Override
public boolean onEntityItemUpdate(EntityItem entityItem){
    super.onEntityItemUpdate(entityItem);
    ItemStack stack = entityItem.getEntityItem();
    if(Fluids.areFluidsEqual(FluidRegistry.lookupFluidForBlock(entityItem.worldObj.getBlock((int)Math.floor(entityItem.posX), (int)Math.floor(entityItem.posY), (int)Math.floor(entityItem.posZ))), Fluids.etchingAcid)) {
        if(!stack.hasTagCompound()) {
            stack.setTagCompound(new NBTTagCompound());
        }
        int etchProgress = stack.getTagCompound().getInteger("etchProgress");
        if(etchProgress < 100) {
            if(entityItem.ticksExisted % (TileEntityConstants.PCB_ETCH_TIME / 5) == 0) stack.getTagCompound().setInteger("etchProgress", etchProgress + 1);
        } else {
            entityItem.setEntityItemStack(new ItemStack(rand.nextInt(100) >= stack.getItemDamage() ? Itemss.unassembledPCB : Itemss.failedPCB));
        }
    }
    return false;
}
 
Example 4
Source Project: bartworks   File: BW_MetaGenerated_Items.java    License: MIT License 5 votes vote down vote up
public boolean onEntityItemUpdate(EntityItem aItemEntity) {
    if (this.orePrefixes == OrePrefixes.dustImpure || this.orePrefixes == OrePrefixes.dustPure || this.orePrefixes == OrePrefixes.crushed) {
        int aDamage = aItemEntity.getEntityItem().getItemDamage();
        if ((aDamage >= 0) && (!aItemEntity.worldObj.isRemote)) {
            Werkstoff aMaterial = werkstoffHashMap.get((short) aDamage);
            if ((aMaterial != null) && (aMaterial != Werkstoff.default_null_Werkstoff)) {
                int tX = MathHelper.floor_double(aItemEntity.posX);
                int tY = MathHelper.floor_double(aItemEntity.posY);
                int tZ = MathHelper.floor_double(aItemEntity.posZ);
                Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ);
                byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
                if ((this.orePrefixes == OrePrefixes.dustImpure) || (this.orePrefixes == OrePrefixes.dustPure)) {
                    if ((tBlock == Blocks.cauldron) && (tMetaData > 0)) {
                        aItemEntity.setEntityItemStack(WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dust, aMaterial, aItemEntity.getEntityItem().stackSize));
                        aItemEntity.worldObj.setBlockMetadataWithNotify(tX, tY, tZ, tMetaData - 1, 3);
                        return true;
                    }
                } else {
                    if ((tBlock == Blocks.cauldron) && (tMetaData > 0)) {
                        aItemEntity.setEntityItemStack(WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedPurified, aMaterial, aItemEntity.getEntityItem().stackSize));
                        aItemEntity.worldObj.setBlockMetadataWithNotify(tX, tY, tZ, tMetaData - 1, 3);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 5
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void on(EntityJoinWorldEvent event) {
    if(!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase) {
        EntityGolemBase golem = (EntityGolemBase) event.entity;
        ExtendedGolemProperties props = (ExtendedGolemProperties) golem.getExtendedProperties(Gadomancy.MODID);
        if(props != null) {
            props.setWrapperIfNeeded();
        }
    }

    if (event.entity instanceof EntityItem) {
        EntityItem item = (EntityItem) event.entity;
        ItemStack stack = item.getEntityItem();

        if (stack.getItem() == ConfigItems.itemGolemPlacer) {
            AdditionalGolemType type = GadomancyApi.getAdditionalGolemType(EnumGolemType.getType(stack.getItemDamage()));
            if (type != null) {
                ItemStack fakePlacer = new ItemStack(type.getPlacerItem());
                fakePlacer.setTagCompound(stack.getTagCompound());
                fakePlacer.setItemDamage(stack.getItemDamage());

                item.setEntityItemStack(fakePlacer);
            }
        }
    }

    if(!event.world.isRemote && event.entity instanceof EntityLivingBase) {
        if(((EntityLivingBase) event.entity).isPotionActive(RegisteredPotions.ACHROMATIC)) {
            ((DataAchromatic) SyncDataHolder.getDataServer("AchromaticData")).handleApplication((EntityLivingBase) event.entity);
        }
    }
}
 
Example 6
@Override
public void renderStatic(float size, TileEntity te){
    renderModel(size);
    if(te instanceof TileEntityChargingStation) {
        TileEntityChargingStation tile = (TileEntityChargingStation)te;
        if(tile.getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
            RenderManager.instance.renderEngine.bindTexture(Textures.MODEL_CHARGING_STATION_PAD);
            chargePad.renderModel(size);
        }
        if(tile.getStackInSlot(TileEntityChargingStation.CHARGE_INVENTORY_INDEX) != null) {
            float scaleFactor = 0.7F;

            EntityItem ghostEntityItem = new EntityItem(tile.getWorldObj());
            ghostEntityItem.hoverStart = 0.0F;
            ghostEntityItem.setEntityItemStack(tile.getStackInSlot(TileEntityChargingStation.CHARGE_INVENTORY_INDEX));

            GL11.glTranslated(0, 1, 0);
            GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);
            GL11.glScalef(1.0F, -1F, -1F);

            boolean fancySetting = RenderManager.instance.options.fancyGraphics;
            RenderManager.instance.options.fancyGraphics = true;
            customRenderItem.doRender(ghostEntityItem, 0, 0, 0, 0, 0);
            RenderManager.instance.options.fancyGraphics = fancySetting;
        }
    }
}
 
Example 7
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta){
    List<ItemStack> drops = getModuleDrops((TileEntityPressureTube)world.getTileEntity(x, y, z));
    for(ItemStack drop : drops) {
        EntityItem entity = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5);
        entity.setEntityItemStack(drop);
        world.spawnEntityInWorld(entity);
    }
    super.breakBlock(world, x, y, z, block, meta);
}
 
Example 8
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) {
	final TileEntitySelector selector = (TileEntitySelector)tileEntity;
	final Orientation orientation = selector.getOrientation();

	GL11.glPushMatrix();
	GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
	TransformProvider.instance.multMatrix(orientation);
	GL11.glTranslated(-0.5, 0.501, -0.5); // 0.001 offset for 2d items in fast mode

	final int gridSize = selector.getGridSize();

	renderer.setRenderManager(RenderManager.instance);

	for (ItemSlot slot : selector.getSlots(gridSize)) {
		ItemStack stack = selector.getSlot(slot.slot);
		if (stack != null) {
			EntityItem display = selector.getDisplayEntity();

			GL11.glPushMatrix();
			GL11.glTranslated(slot.x, 0, slot.y + 0.03); // 0.03, since items are rendered off-center
			GL11.glRotated(-90, 1, 0, 0);
			final double scale = slot.size * 5;
			GL11.glScaled(scale, scale, scale);
			display.setEntityItemStack(stack);
			RenderItem.renderInFrame = true;
			renderer.doRender(display, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
			GL11.glPopMatrix();
		}
	}

	RenderItem.renderInFrame = false;

	GL11.glPopMatrix();
}
 
Example 9
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void on(PlaySoundAtEntityEvent event) {
    if(!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase
            && event.name.equals("thaumcraft:zap") && event.volume == 0.5F && event.pitch == 1.0F) {
        EntityGolemBase golem = (EntityGolemBase) event.entity;
        if(markedGolems.containsKey(golem)) {
            EntityPlayer player = markedGolems.get(golem);
            markedGolems.remove(golem);

            AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);

            boolean movedPlacer = false;
            boolean movedCore = core == null || !player.isSneaking();

            for(EntityItem entityItem : golem.capturedDrops) {
                ItemStack item = entityItem.getEntityItem();

                if(!movedCore && item.getItem() == ConfigItems.itemGolemCore) {
                    entityItem.setEntityItemStack(core.getItem());
                }

                if(!movedPlacer && item.getItem() instanceof ItemGolemPlacer
                        || item.getItem() instanceof ItemAdditionalGolemPlacer) {
                    //move persistent data to item
                    NBTTagCompound persistent = (NBTTagCompound) NBTHelper.getPersistentData(golem).copy();
                    if(player.isSneaking()) {
                        persistent.removeTag("Core");
                    }
                    NBTHelper.getData(item).setTag(Gadomancy.MODID, persistent);
                    event.entity.setDead();
                    entityItem.setEntityItemStack(item);

                    MinecraftForge.EVENT_BUS.post(new GolemDropPlacerEvent(player, entityItem, golem));

                    movedPlacer = true;
                }
                event.entity.worldObj.spawnEntityInWorld(entityItem);
            }
            golem.capturedDrops.clear();
            golem.captureDrops = false;
        }
    }
}
 
Example 10
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 11
Source Project: Artifacts   File: TileEntitySword.java    License: MIT License 4 votes vote down vote up
public TileEntitySword() {
	itemEnt = new EntityItem(worldObj);
	contents[0] = new ItemStack(ItemFakeSwordRenderable.wood);
	itemEnt.setEntityItemStack(contents[0]);
}