use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class ProgWidgetDropItem method getWidgetAI.
@Override
public EntityAIBase getWidgetAI(IDroneBase drone, IProgWidget widget) {
return new DroneAIImExBase(drone, (ProgWidgetAreaItemBase) widget) {
private final Set<ChunkPosition> visitedPositions = new HashSet<ChunkPosition>();
@Override
public boolean shouldExecute() {
boolean shouldExecute = false;
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
ItemStack stack = drone.getInventory().getStackInSlot(i);
if (stack != null && widget.isItemValidForFilters(stack)) {
shouldExecute = super.shouldExecute();
break;
}
}
return shouldExecute;
}
@Override
protected boolean moveIntoBlock() {
return true;
}
@Override
protected boolean isValidPosition(ChunkPosition pos) {
//another requirement is that the drone can navigate to this exact block, but that's handled by the pathfinder.
return !visitedPositions.contains(pos);
}
@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
visitedPositions.add(pos);
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
ItemStack stack = drone.getInventory().getStackInSlot(i);
if (stack != null && widget.isItemValidForFilters(stack)) {
if (useCount() && getRemainingCount() < stack.stackSize) {
stack = stack.splitStack(getRemainingCount());
decreaseCount(getRemainingCount());
} else {
decreaseCount(stack.stackSize);
drone.getInventory().setInventorySlotContents(i, null);
}
EntityItem item = new EntityItem(drone.getWorld(), pos.chunkPosX + 0.5, pos.chunkPosY + 0.5, pos.chunkPosZ + 0.5, stack);
if (((IItemDropper) widget).dropStraight()) {
item.motionX = 0;
item.motionY = 0;
item.motionZ = 0;
}
drone.getWorld().spawnEntityInWorld(item);
if (useCount() && getRemainingCount() == 0)
break;
}
}
return false;
}
};
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityAerialInterface method setInventorySlotContents.
@Override
public void setInventorySlotContents(int slot, ItemStack itemStack) {
if (slot < 4) {
inventory[slot] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
itemStack.stackSize = getInventoryStackLimit();
}
} else {
EntityPlayer player = getPlayer();
if (dispenserUpgradeInserted) {
if (itemStack != null) {
int startValue = itemStack.stackSize;
while (itemStack.stackSize > 0) {
ItemStack remainingItem = itemStack.onFoodEaten(player.worldObj, player);
remainingItem = ForgeEventFactory.onItemUseFinish(player, itemStack, 0, remainingItem);
if (remainingItem != null && remainingItem.stackSize > 0 && (remainingItem != itemStack || remainingItem.stackSize != startValue)) {
if (!player.inventory.addItemStackToInventory(remainingItem) && remainingItem.stackSize > 0) {
player.dropPlayerItemWithRandomChoice(remainingItem, false);
}
}
if (itemStack.stackSize == startValue)
break;
}
}
} else {
InventoryPlayer inventoryPlayer = player != null ? player.inventory : null;
if (inventoryPlayer != null) {
inventoryPlayer.setInventorySlotContents(slot - 4, itemStack);
} else if (worldObj != null && !worldObj.isRemote) {
EntityItem item = new EntityItem(worldObj, xCoord, yCoord, zCoord, itemStack);
worldObj.spawnEntityInWorld(item);
}
}
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityAirCannon method writeToNBT.
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setBoolean("redstonePowered", redstonePowered);
tag.setFloat("targetRotationAngle", targetRotationAngle);
tag.setFloat("targetHeightAngle", targetHeightAngle);
tag.setFloat("rotationAngle", rotationAngle);
tag.setFloat("heightAngle", heightAngle);
tag.setInteger("gpsX", gpsX);
tag.setInteger("gpsY", gpsY);
tag.setInteger("gpsZ", gpsZ);
tag.setByte("redstoneMode", (byte) redstoneMode);
tag.setBoolean("targetWithinReach", coordWithinReach);
// Write the ItemStacks in the inventory to NBT
NBTTagList tagList = new NBTTagList();
for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
if (inventory[currentIndex] != null) {
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte) currentIndex);
inventory[currentIndex].writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
tag.setTag("Items", tagList);
tagList = new NBTTagList();
for (EntityItem entity : trackedItems) {
UUID uuid = entity.getUniqueID();
NBTTagCompound t = new NBTTagCompound();
t.setLong("UUIDMost", uuid.getMostSignificantBits());
t.setLong("UUIDLeast", uuid.getLeastSignificantBits());
tagList.appendTag(t);
}
tag.setTag("trackedItems", tagList);
if (lastInsertingInventory != null) {
tag.setInteger("inventoryX", lastInsertingInventory.chunkPosX);
tag.setInteger("inventoryY", lastInsertingInventory.chunkPosY);
tag.setInteger("inventoryZ", lastInsertingInventory.chunkPosZ);
tag.setByte("inventorySide", (byte) lastInsertingInventorySide.ordinal());
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityChargingStation method updateEntity.
@Override
public void updateEntity() {
disCharging = false;
charging = false;
List<IPressurizable> chargingItems = new ArrayList<IPressurizable>();
List<ItemStack> chargedStacks = new ArrayList<ItemStack>();
if (inventory[CHARGE_INVENTORY_INDEX] != null && inventory[CHARGE_INVENTORY_INDEX].getItem() instanceof IPressurizable) {
chargingItems.add((IPressurizable) inventory[CHARGE_INVENTORY_INDEX].getItem());
chargedStacks.add(inventory[CHARGE_INVENTORY_INDEX]);
}
if (this.getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
//creating a new word, 'entities padding'.
List<Entity> entitiesPadding = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 2, zCoord + 1));
for (Entity entity : entitiesPadding) {
if (entity instanceof IPressurizable) {
chargingItems.add((IPressurizable) entity);
chargedStacks.add(null);
} else if (entity instanceof EntityItem) {
ItemStack entityStack = ((EntityItem) entity).getEntityItem();
if (entityStack != null && entityStack.getItem() instanceof IPressurizable) {
chargingItems.add((IPressurizable) entityStack.getItem());
chargedStacks.add(entityStack);
}
} else if (entity instanceof EntityPlayer) {
InventoryPlayer inv = ((EntityPlayer) entity).inventory;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof IPressurizable) {
chargingItems.add((IPressurizable) stack.getItem());
chargedStacks.add(stack);
}
}
}
}
}
int speedMultiplier = (int) getSpeedMultiplierFromUpgrades(getUpgradeSlots());
for (int i = 0; i < PneumaticValues.CHARGING_STATION_CHARGE_RATE * speedMultiplier; i++) {
boolean charged = false;
for (int j = 0; j < chargingItems.size(); j++) {
IPressurizable chargingItem = chargingItems.get(j);
ItemStack chargedItem = chargedStacks.get(j);
if (chargingItem.getPressure(chargedItem) > getPressure(ForgeDirection.UNKNOWN) + 0.01F && chargingItem.getPressure(chargedItem) > 0F) {
if (!worldObj.isRemote) {
chargingItem.addAir(chargedItem, -1);
addAir(1, ForgeDirection.UNKNOWN);
}
disCharging = true;
renderAirProgress -= ANIMATION_AIR_SPEED;
if (renderAirProgress < 0.0F) {
renderAirProgress += 1F;
}
charged = true;
} else if (chargingItem.getPressure(chargedItem) < getPressure(ForgeDirection.UNKNOWN) - 0.01F && chargingItem.getPressure(chargedItem) < chargingItem.maxPressure(chargedItem)) {
// if there is pressure, and the item isn't fully charged yet..
if (!worldObj.isRemote) {
chargingItem.addAir(chargedItem, 1);
addAir(-1, ForgeDirection.UNKNOWN);
}
charging = true;
renderAirProgress += ANIMATION_AIR_SPEED;
if (renderAirProgress > 1.0F) {
renderAirProgress -= 1F;
}
charged = true;
}
}
if (!charged)
break;
}
if (!worldObj.isRemote && oldRedstoneStatus != shouldEmitRedstone()) {
oldRedstoneStatus = shouldEmitRedstone();
updateNeighbours();
}
super.updateEntity();
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class TileEntityProgrammableController method dropItem.
@Override
public void dropItem(ItemStack stack) {
Vec3 pos = getPosition();
worldObj.spawnEntityInWorld(new EntityItem(worldObj, pos.xCoord, pos.yCoord, pos.zCoord, stack));
}
Aggregations