use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityProgrammableController method updateEntity.
@Override
public void updateEntity() {
super.updateEntity();
oldCurX = curX;
oldCurY = curY;
oldCurZ = curZ;
if (PneumaticCraftUtils.distBetween(getPosition(), targetX, targetY, targetZ) <= getSpeed()) {
curX = targetX;
curY = targetY;
curZ = targetZ;
} else {
Vec3 vec = Vec3.createVectorHelper(targetX - curX, targetY - curY, targetZ - curZ).normalize();
curX += vec.xCoord * getSpeed();
curY += vec.yCoord * getSpeed();
curZ += vec.zCoord * getSpeed();
}
if (!worldObj.isRemote) {
getAIManager();
if (worldObj.getTotalWorldTime() % 40 == 0) {
dispenserUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE);
speedUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_SPEED_DAMAGE);
for (int i = getDroneSlots(); i < 36; i++) {
ItemStack stack = getFakePlayer().inventory.getStackInSlot(i);
if (stack != null) {
worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack));
getFakePlayer().inventory.setInventorySlotContents(i, null);
}
}
tank.setCapacity((dispenserUpgrades + 1) * 16000);
if (tank.getFluidAmount() > tank.getCapacity()) {
tank.getFluid().amount = tank.getCapacity();
}
}
for (int i = 0; i < 4; i++) {
getFakePlayer().theItemInWorldManager.updateBlockRemoving();
}
if (getPressure(ForgeDirection.UNKNOWN) >= getMinWorkingPressure()) {
if (!aiManager.isIdling())
addAir(-10, ForgeDirection.UNKNOWN);
aiManager.onUpdateTasks();
}
} else {
if (drone == null || drone.isDead) {
drone = new EntityProgrammableController(worldObj, this);
drone.posX = curX;
drone.posY = curY;
drone.posZ = curZ;
worldObj.spawnEntityInWorld(drone);
}
drone.setPosition(curX, curY, curZ);
// drone.getMoveHelper().setMoveTo(curX, curY, curZ, 0);
/* drone.prevPosX = oldCurX;
drone.prevPosY = oldCurY;
drone.prevPosZ = oldCurZ;*/
//drone.getMoveHelper().setMoveTo(curX, curY, curZ, getSpeed());
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityProgrammer method tryProgramDrone.
private void tryProgramDrone(EntityPlayer player) {
if (inventory[PROGRAM_SLOT] != null) {
if (player == null || !player.capabilities.isCreativeMode) {
List<ItemStack> requiredStacks = getRequiredPuzzleStacks();
for (ItemStack stack : requiredStacks) {
if (!hasEnoughPuzzleStacks(player, stack))
return;
}
for (ItemStack stack : requiredStacks) {
int left = stack.stackSize;
if (player != null) {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
if (PneumaticCraftUtils.areStacksEqual(stack, player.inventory.getStackInSlot(i), true, true, false, false)) {
left -= player.inventory.decrStackSize(i, left).stackSize;
if (left <= 0)
break;
}
}
}
if (left > 0) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
IInventory neighbor = IOHelper.getInventoryForTE(getWorldObj().getTileEntity(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ));
for (int slot : IOHelper.getAccessibleSlotsForInventory(neighbor, d.getOpposite())) {
if (IOHelper.canExtractItemFromInventory(neighbor, stack, slot, d.getOpposite().ordinal())) {
ItemStack neighborStack = neighbor.getStackInSlot(slot);
if (PneumaticCraftUtils.areStacksEqual(neighborStack, stack, true, true, false, false)) {
left -= neighbor.decrStackSize(slot, left).stackSize;
if (left <= 0)
break;
}
}
}
}
}
}
List<ItemStack> returnedStacks = getReturnedPuzzleStacks();
for (ItemStack stack : returnedStacks) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
IInventory neighbor = IOHelper.getInventoryForTE(getWorldObj().getTileEntity(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ));
stack = IOHelper.insert(neighbor, stack, d.getOpposite().ordinal(), false);
if (stack == null)
break;
}
if (player != null && stack != null) {
if (!player.inventory.addItemStackToInventory(stack)) {
player.dropPlayerItemWithRandomChoice(stack.copy(), false);
stack = null;
}
}
if (stack != null) {
worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack));
}
}
}
NBTTagCompound tag = inventory[PROGRAM_SLOT].getTagCompound();
if (tag == null) {
tag = new NBTTagCompound();
inventory[PROGRAM_SLOT].setTagCompound(tag);
}
writeProgWidgetsToNBT(tag);
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityPressureChamberValve method dropInventory.
private void dropInventory(World world, double x, double y, double z) {
IInventory inventory = this;
Random rand = new Random();
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0) {
float dX = rand.nextFloat() * 0.8F - 0.4F;
float dY = rand.nextFloat() * 0.8F - 0.4F;
float dZ = rand.nextFloat() * 0.8F - 0.4F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound()) {
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
// itemStack.stackSize = 0;
}
}
this.inventory = new ItemStack[4];
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityPressureChamberValve method giveOutput.
private void giveOutput(ItemStack[] output, double[] outputPosition) {
for (ItemStack iStack : output) {
if (iStack.getItem() == etchingAcid) {
for (EntityPlayer player : (List<EntityPlayer>) worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord - 32, yCoord - 32, zCoord - 32, xCoord + 32, yCoord + 32, zCoord + 32))) {
AchievementHandler.giveAchievement(player, new ItemStack(etchingAcid));
}
}
EntityItem item = new EntityItem(worldObj, outputPosition[0], outputPosition[1], outputPosition[2], iStack.copy());
worldObj.spawnEntityInWorld(item);
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityLiquidHopper method exportItem.
@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;
}
Aggregations