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

The following examples show how to use net.minecraft.entity.item.EntityItem#getEntityItem() . 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: ItemEmptyPCB.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@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 2
Source File: TileArcaneDropper.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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
Source File: FarmLogicHelium.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@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 4
Source File: FarmLogicSquid.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@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
Source File: MoCEntityAmbient.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public EntityItem getClosestItem(Entity entity, double d, int i, int j)
{
	double d1 = -1D;
	EntityItem entityitem = null;
	List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(d, d, d));
	for (int k = 0; k < list.size(); k++)
	{
		Entity entity1 = (Entity) list.get(k);
		if (!(entity1 instanceof EntityItem))
		{
			continue;
		}
		EntityItem entityitem1 = (EntityItem) entity1;
		if ((entityitem1.getEntityItem().itemID != i) && (entityitem1.getEntityItem().itemID != j))
		{
			continue;
		}
		double d2 = entityitem1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
		if (((d < 0.0D) || (d2 < (d * d))) && ((d1 == -1D) || (d2 < d1)))
		{
			d1 = d2;
			entityitem = entityitem1;
		}
	}

	return entityitem;
}
 
Example 6
Source File: ComponentExplosive.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public boolean onEntityItemUpdate(EntityItem entityItem, String type) {
	if(type == "onDropped") {
		entityItem.worldObj.newExplosion(entityItem, entityItem.posX, entityItem.posY, entityItem.posZ, 3F, false, true);
		//entityItem.setEntityItemStack(new ItemStack(Block.dirt));
		entityItem.getEntityItem().stackSize--;
		//entityItem.setEntityItemStack();
	}
	return false;
}
 
Example 7
Source File: TileEntityPressureChamberValve.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
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 8
Source File: MoCEntityAquatic.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public EntityItem getClosestFish(Entity entity, double d)
{
    double d1 = -1D;
    EntityItem entityitem = null;
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, 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 entityitem1 = (EntityItem) entity1;
        if ((entityitem1.getEntityItem().itemID != Item.fishRaw.itemID) || !entityitem1.isInWater())
        {
            continue;
        }
        double d2 = entityitem1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
        if (((d < 0.0D) || (d2 < (d * d))) && ((d1 == -1D) || (d2 < d1)))
        {
            d1 = d2;
            entityitem = entityitem1;
        }
    }

    return entityitem;
}
 
Example 9
Source File: MoCEntityAnimal.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public EntityItem getClosestItem(Entity entity, double d, int i, int j)
{
	double d1 = -1D;
	EntityItem entityitem = null;
	List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(d, d, d));
	for (int k = 0; k < list.size(); k++)
	{
		Entity entity1 = (Entity) list.get(k);
		if (!(entity1 instanceof EntityItem))
		{
			continue;
		}
		EntityItem entityitem1 = (EntityItem) entity1;
		if ((entityitem1.getEntityItem().itemID != i) && (entityitem1.getEntityItem().itemID != j))
		{
			continue;
		}
		double d2 = entityitem1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
		if (((d < 0.0D) || (d2 < (d * d))) && ((d1 == -1D) || (d2 < d1)))
		{
			d1 = d2;
			entityitem = entityitem1;
		}
	}

	return entityitem;
}
 
Example 10
Source File: ComponentLight.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public boolean onEntityItemUpdate(EntityItem entityItem, String type) {
	if(type == "onUpdate") {
		World world = entityItem.worldObj;
		NBTTagCompound data = entityItem.getEntityItem().stackTagCompound;
		int lx = data.getInteger("lastLightX");
		int ly = data.getInteger("lastLightY");
		int lz = data.getInteger("lastLightZ");
		//System.out.println("Last: " + lx + "," + ly + "," + lz);
		int nlx = (int) entityItem.posX;
		int nly = (int) entityItem.posY;
		int nlz = (int) entityItem.posZ;
		if(nlx != lx || nly != ly || nlz != lz) {
			int d = (nlx - lx)*(nlx - lx)+(nly - ly)*(nly - ly)+(nlz - lz)*(nlz - lz);
			if(d > 13) {
				if(ly >= 0 && ly < 256 && world.getBlock(nlx, nly, nlz) == BlockLight.instance)
					world.setBlockToAir(lx, ly, lz);
				if(nly >= 0 && nly < 256 && world.isAirBlock(nlx, nly, nlz)) {
					world.setBlock(nlx, nly, nlz, BlockLight.instance);
					data.setInteger("lastLightX",nlx);
					data.setInteger("lastLightY",nly);
					data.setInteger("lastLightZ",nlz);
					//System.out.println("Placed: " + nlx + "," + nly + "," + nlz);
				}
			}
		}
		//entityItem.getEntityItem().stackTagCompound = data;
	}
	else {
		System.out.println("Hmm. " + type);
	}
	return false;
}
 
Example 11
Source File: TileArcaneDropper.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getStackInSlot(int slot) {
    updateInventory();

    if(slot >= items.size()) return null; //Get rekt. nothing here on this slot.

    EntityItem entity = items.get(slot);
    return entity == null || entity.isDead ? null : entity.getEntityItem();
}
 
Example 12
Source File: RenderAutoChisel.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float scale) {

	// Render Blocks
	TileEntityAutoChisel autoChisel = (TileEntityAutoChisel) tile;
	EntityItem item = autoChisel.getItemForRendering(TileEntityAutoChisel.TARGET);

	rand.setSeed(tile.xCoord + tile.yCoord + tile.zCoord);
	rand.nextBoolean();

	float max = 0.35f;

	if (!Minecraft.getMinecraft().isGamePaused()) {
		autoChisel.xRot += (rand.nextFloat() * max) - (max / 2);
		autoChisel.yRot += (rand.nextFloat() * max) - (max / 2);
		autoChisel.zRot += (rand.nextFloat() * max) - (max / 2);
	}

	if (item != null) {
		glPushMatrix();
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glTranslated(x + 0.5, y + 1.5, z + 0.5);
		glRotatef(autoChisel.xRot, 1, 0, 0);
		glRotatef(autoChisel.yRot, 0, 1, 0);
		glRotatef(autoChisel.zRot, 0, 0, 1);
		glEnable(GL_BLEND);
		glDepthMask(false);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
		renderItem.doRender(item, 0, 0, 0, 0, 0);
		glPopMatrix();
		glPopAttrib();
	}

	item = autoChisel.getItemForRendering(TileEntityAutoChisel.BASE);
	if (item != null) {
		glPushMatrix();
		glTranslated(x + 0.35, y + 0.934, z + 0.5);
		item.getEntityItem().stackSize = autoChisel.getLastBase() == null ? 1 : autoChisel.getLastBase().stackSize;
		renderItem.doRender(item, 0, 0, 0, 0, 0);
		glPopMatrix();
	}

	GameSettings settings = Minecraft.getMinecraft().gameSettings;
	item = autoChisel.getItemForRendering(TileEntityAutoChisel.CHISEL);
	if (item != null) {
		glPushMatrix();
		glTranslated(x + 0.7, y + 1.01, z + 0.5);
		float rot = autoChisel.chiselRot == 0 ? 0 : autoChisel.chiseling ? autoChisel.chiselRot + (TileEntityAutoChisel.rotAmnt * scale) : autoChisel.chiselRot
				- (TileEntityAutoChisel.rotAmnt * scale);
		glRotatef(rot, 0, 0, 1);
		glTranslated(-0.12, 0, 0);
		glScalef(0.9f, 0.9f, 0.9f);
		boolean was = settings.fancyGraphics;
		settings.fancyGraphics = true;
		renderItem.doRender(item, 0, 0, 0, 0, 0);
		settings.fancyGraphics = was;
		glPopMatrix();
	}
}
 
Example 13
Source File: WItem.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public static ItemStack getItemStack(EntityItem entityItem)
{
	return entityItem.getEntityItem();
}
 
Example 14
Source File: EventHandlerGolem.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 15
Source File: TileAuraPylon.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
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
Source File: TileKnowledgeBook.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 17
Source File: ItemPlasticPlants.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@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 18
Source File: TileEntityLiquidHopper.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@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 19
Source File: WandHandler.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 20
Source File: SkullFireSwordDropFix.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent( priority = EventPriority.LOWEST )
public void onLivingDrops( LivingDropsEvent event )
{
  try
  {
    if( mSkullFireSword == null ) {
        return;
    }

    // MainRegistry.Logger.info( "SkullFireSwordDropFix::onLivingDrops" );
    if( event.recentlyHit && isValidSkeletonEntity( event.entityLiving ) && event.source.getEntity() instanceof EntityPlayer)
    {
      EntityPlayer player = (EntityPlayer) event.source.getEntity();
      if( player.getHeldItem() != null && player.getHeldItem().getItem() == mSkullFireSword.getItem())
      {
        // MainRegistry.Logger.info( "SkullFireSwordDropFix::Perform DropAction" );

        if( event.drops.isEmpty() ) {
            dropWitherHeadsInWorld(event, new ItemStack(Items.skull, 1, 1));
        } else
        {
          int skulls = 0;
          for( int i = 0; i < event.drops.size(); i++ )
          {
            EntityItem drop = event.drops.get( i );
            ItemStack stack = drop.getEntityItem();
            if( stack.getItem() == Items.skull )
            {
              if( stack.getItemDamage() == 1 ) {
                  dropWitherHeadsInWorld(event, new ItemStack(Items.skull, skulls + 1, 1));
              } else if( stack.getItemDamage() == 0 ) {
                  dropWitherHeadsInWorld(event, new ItemStack(Items.skull, 1, 1));
              }
            }
          }
          if( skulls == 0 ) {
              dropWitherHeadsInWorld(event, new ItemStack(Items.skull, 1, 1));
          }
        }
      }
    }
  }
  catch( Exception e )
  {
    e.printStackTrace();
  }
}