use of net.minecraft.entity.player.InventoryPlayer 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.player.InventoryPlayer in project PneumaticCraft by MineMaarten.
the class TileEntityProgrammableController method initializeFakePlayer.
private void initializeFakePlayer() {
String playerUUID = null;
String playerName = "Drone";
fakePlayer = new DroneFakePlayer((WorldServer) worldObj, new GameProfile(playerUUID != null ? UUID.fromString(playerUUID) : null, playerName), new FakePlayerItemInWorldManager(worldObj, fakePlayer, this), this);
fakePlayer.playerNetServerHandler = new NetHandlerPlayServer(MinecraftServer.getServer(), new NetworkManager(false), fakePlayer);
fakePlayer.inventory = new InventoryPlayer(fakePlayer) {
private ItemStack oldStack;
@Override
public int getSizeInventory() {
return getDroneSlots();
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
super.setInventorySlotContents(slot, stack);
if (slot == 0) {
if (oldStack != null) {
getFakePlayer().getAttributeMap().removeAttributeModifiers(oldStack.getAttributeModifiers());
}
if (stack != null) {
getFakePlayer().getAttributeMap().applyAttributeModifiers(stack.getAttributeModifiers());
}
oldStack = stack;
}
}
};
}
use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.
the class EnderPlateInventoryTickHandler method onPlayerChargeTick.
@SubscribeEvent
public void onPlayerChargeTick(TickEvent.PlayerTickEvent e) {
time++;
if (time < 20 || e.side != Side.SERVER)
return;
time = 0;
EntityPlayer player = e.player;
InventoryPlayer playerInv = player.inventory;
int crystals = player.worldObj.getEntitiesWithinAABB(EntityEnderCrystal.class, new AxisAlignedBB(player.posX - 4.5, player.posY - 4.5, player.posZ - 4.5, player.posX + 4.5, player.posY + 4.5, player.posZ + 4.5)).size();
if (crystals == 0)
return;
int charge = (int) (ModConfig.enderPlate_crystalChargeRate * Math.log(crystals + 1) / Math.log(2));
for (ItemStack i : playerInv.mainInventory) {
if (i != null && i.getItem() == ModItems.itemEnderPlate) {
if (!ModItems.itemEnderPlate.isActive(i)) {
ModItems.itemEnderPlate.chargeItem(i, charge);
}
}
}
for (ItemStack i : playerInv.offHandInventory) {
if (i != null && i.getItem() == ModItems.itemEnderPlate) {
if (!ModItems.itemEnderPlate.isActive(i)) {
ModItems.itemEnderPlate.chargeItem(i, charge);
}
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project LogisticsPipes by RS485.
the class DummyContainer method superSlotClick.
@Nonnull
public ItemStack superSlotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
ItemStack itemstack = ItemStack.EMPTY;
InventoryPlayer inventoryplayer = player.inventory;
if (clickTypeIn == ClickType.QUICK_CRAFT) {
int j1 = this.dragEvent;
this.dragEvent = getDragEvent(dragType);
if ((j1 != 1 || this.dragEvent != 2) && j1 != this.dragEvent) {
this.resetDrag();
} else if (inventoryplayer.getItemStack().isEmpty()) {
this.resetDrag();
} else if (this.dragEvent == 0) {
this.dragMode = extractDragMode(dragType);
if (isValidDragMode(this.dragMode, player)) {
this.dragEvent = 1;
this.dragSlots.clear();
} else {
this.resetDrag();
}
} else if (this.dragEvent == 1) {
Slot slot7 = this.inventorySlots.get(slotId);
ItemStack itemstack12 = inventoryplayer.getItemStack();
if (slot7 != null && canAddItemToSlot(slot7, itemstack12, true) && slot7.isItemValid(itemstack12) && (this.dragMode == 2 || itemstack12.getCount() > this.dragSlots.size()) && this.canDragIntoSlot(slot7)) {
this.dragSlots.add(slot7);
}
} else if (this.dragEvent == 2) {
if (!this.dragSlots.isEmpty()) {
ItemStack itemstack9 = inventoryplayer.getItemStack().copy();
int k1 = inventoryplayer.getItemStack().getCount();
for (Slot slot8 : this.dragSlots) {
ItemStack itemstack13 = inventoryplayer.getItemStack();
if (slot8 != null && canAddItemToSlot(slot8, itemstack13, true) && slot8.isItemValid(itemstack13) && (this.dragMode == 2 || itemstack13.getCount() >= this.dragSlots.size()) && this.canDragIntoSlot(slot8)) {
ItemStack itemstack14 = itemstack9.copy();
int j3 = slot8.getHasStack() ? slot8.getStack().getCount() : 0;
computeStackSize(this.dragSlots, this.dragMode, itemstack14, j3);
int k3 = Math.min(itemstack14.getMaxStackSize(), slot8.getItemStackLimit(itemstack14));
if (itemstack14.getCount() > k3) {
itemstack14.setCount(k3);
}
k1 -= itemstack14.getCount() - j3;
slot8.putStack(itemstack14);
}
}
itemstack9.setCount(k1);
inventoryplayer.setItemStack(itemstack9);
}
this.resetDrag();
} else {
this.resetDrag();
}
} else if (this.dragEvent != 0) {
this.resetDrag();
} else if ((clickTypeIn == ClickType.PICKUP || clickTypeIn == ClickType.QUICK_MOVE) && (dragType == 0 || dragType == 1)) {
if (slotId == -999) {
if (!inventoryplayer.getItemStack().isEmpty()) {
if (dragType == 0) {
player.dropItem(inventoryplayer.getItemStack(), true);
inventoryplayer.setItemStack(ItemStack.EMPTY);
}
if (dragType == 1) {
player.dropItem(inventoryplayer.getItemStack().splitStack(1), true);
}
}
} else if (clickTypeIn == ClickType.QUICK_MOVE) {
if (slotId < 0) {
return ItemStack.EMPTY;
}
Slot slot5 = this.inventorySlots.get(slotId);
if (slot5 == null || !slot5.canTakeStack(player)) {
return ItemStack.EMPTY;
}
for (ItemStack itemstack7 = this.transferStackInSlot(player, slotId); !itemstack7.isEmpty() && ItemStack.areItemsEqual(slot5.getStack(), itemstack7); itemstack7 = this.transferStackInSlot(player, slotId)) {
itemstack = itemstack7.copy();
}
} else {
if (slotId < 0) {
return ItemStack.EMPTY;
}
Slot slot6 = this.inventorySlots.get(slotId);
if (slot6 != null) {
ItemStack itemstack8 = slot6.getStack();
ItemStack itemstack11 = inventoryplayer.getItemStack();
if (!itemstack8.isEmpty()) {
itemstack = itemstack8.copy();
}
if (itemstack8.isEmpty()) {
if (!itemstack11.isEmpty() && slot6.isItemValid(itemstack11)) {
int i3 = dragType == 0 ? itemstack11.getCount() : 1;
if (i3 > slot6.getItemStackLimit(itemstack11)) {
i3 = slot6.getItemStackLimit(itemstack11);
}
slot6.putStack(itemstack11.splitStack(i3));
}
} else if (slot6.canTakeStack(player)) {
if (itemstack11.isEmpty()) {
if (itemstack8.isEmpty()) {
slot6.putStack(ItemStack.EMPTY);
inventoryplayer.setItemStack(ItemStack.EMPTY);
} else {
int l2 = dragType == 0 ? itemstack8.getCount() : (itemstack8.getCount() + 1) / 2;
inventoryplayer.setItemStack(slot6.decrStackSize(l2));
if (itemstack8.isEmpty()) {
slot6.putStack(ItemStack.EMPTY);
}
slot6.onTake(player, inventoryplayer.getItemStack());
}
} else if (slot6.isItemValid(itemstack11)) {
if (itemstack8.getItem() == itemstack11.getItem() && itemstack8.getMetadata() == itemstack11.getMetadata() && ItemStack.areItemStackTagsEqual(itemstack8, itemstack11)) {
int k2 = dragType == 0 ? itemstack11.getCount() : 1;
if (k2 > slot6.getItemStackLimit(itemstack11) - itemstack8.getCount()) {
k2 = slot6.getItemStackLimit(itemstack11) - itemstack8.getCount();
}
if (k2 > itemstack11.getMaxStackSize() - itemstack8.getCount()) {
k2 = itemstack11.getMaxStackSize() - itemstack8.getCount();
}
itemstack11.shrink(k2);
itemstack8.grow(k2);
// XXX added reinserting of the modified itemStack (Fix ItemIdentifierInventory's disappearing items)
slot6.putStack(itemstack8);
} else if (itemstack11.getCount() <= slot6.getItemStackLimit(itemstack11)) {
// XXX added Slot switching handle method
handleSwitch(slot6, itemstack8, itemstack11, player);
slot6.putStack(itemstack11);
inventoryplayer.setItemStack(itemstack8);
}
} else if (itemstack8.getItem() == itemstack11.getItem() && itemstack11.getMaxStackSize() > 1 && (!itemstack8.getHasSubtypes() || itemstack8.getMetadata() == itemstack11.getMetadata()) && ItemStack.areItemStackTagsEqual(itemstack8, itemstack11) && !itemstack8.isEmpty()) {
int j2 = itemstack8.getCount();
if (j2 + itemstack11.getCount() <= itemstack11.getMaxStackSize()) {
itemstack11.grow(j2);
itemstack8 = slot6.decrStackSize(j2);
if (itemstack8.isEmpty()) {
slot6.putStack(ItemStack.EMPTY);
}
slot6.onTake(player, inventoryplayer.getItemStack());
}
}
}
slot6.onSlotChanged();
}
}
} else if (clickTypeIn == ClickType.SWAP && dragType >= 0 && dragType < 9) {
Slot slot4 = this.inventorySlots.get(slotId);
ItemStack itemstack6 = inventoryplayer.getStackInSlot(dragType);
ItemStack itemstack10 = slot4.getStack();
if (!itemstack6.isEmpty() || !itemstack10.isEmpty()) {
if (itemstack6.isEmpty()) {
if (slot4.canTakeStack(player)) {
inventoryplayer.setInventorySlotContents(dragType, itemstack10);
ReflectionHelper.invokePrivateMethod(Slot.class, slot4, "onSwapCraft", "func_190900_b", new Class[] { int.class }, new Object[] { itemstack10.getCount() });
slot4.putStack(ItemStack.EMPTY);
slot4.onTake(player, itemstack10);
}
} else if (itemstack10.isEmpty()) {
if (slot4.isItemValid(itemstack6)) {
int l1 = slot4.getItemStackLimit(itemstack6);
if (itemstack6.getCount() > l1) {
slot4.putStack(itemstack6.splitStack(l1));
} else {
slot4.putStack(itemstack6);
inventoryplayer.setInventorySlotContents(dragType, ItemStack.EMPTY);
}
}
} else if (slot4.canTakeStack(player) && slot4.isItemValid(itemstack6)) {
int i2 = slot4.getItemStackLimit(itemstack6);
if (itemstack6.getCount() > i2) {
slot4.putStack(itemstack6.splitStack(i2));
slot4.onTake(player, itemstack10);
if (!inventoryplayer.addItemStackToInventory(itemstack10)) {
player.dropItem(itemstack10, true);
}
} else {
slot4.putStack(itemstack6);
inventoryplayer.setInventorySlotContents(dragType, itemstack10);
slot4.onTake(player, itemstack10);
}
}
}
} else if (clickTypeIn == ClickType.CLONE && player.capabilities.isCreativeMode && inventoryplayer.getItemStack().isEmpty() && slotId >= 0) {
Slot slot3 = this.inventorySlots.get(slotId);
if (slot3 != null && slot3.getHasStack()) {
ItemStack itemstack5 = slot3.getStack().copy();
itemstack5.setCount(itemstack5.getMaxStackSize());
inventoryplayer.setItemStack(itemstack5);
}
} else if (clickTypeIn == ClickType.THROW && inventoryplayer.getItemStack().isEmpty() && slotId >= 0) {
Slot slot2 = this.inventorySlots.get(slotId);
if (slot2 != null && slot2.getHasStack() && slot2.canTakeStack(player)) {
ItemStack itemstack4 = slot2.decrStackSize(dragType == 0 ? 1 : slot2.getStack().getCount());
slot2.onTake(player, itemstack4);
player.dropItem(itemstack4, true);
}
} else if (clickTypeIn == ClickType.PICKUP_ALL && slotId >= 0) {
Slot slot = this.inventorySlots.get(slotId);
ItemStack itemstack1 = inventoryplayer.getItemStack();
if (!itemstack1.isEmpty() && (slot == null || !slot.getHasStack() || !slot.canTakeStack(player))) {
int i = dragType == 0 ? 0 : this.inventorySlots.size() - 1;
int j = dragType == 0 ? 1 : -1;
for (int k = 0; k < 2; ++k) {
for (int l = i; l >= 0 && l < this.inventorySlots.size() && itemstack1.getCount() < itemstack1.getMaxStackSize(); l += j) {
Slot slot1 = this.inventorySlots.get(l);
if (slot1.getHasStack() && canAddItemToSlot(slot1, itemstack1, true) && slot1.canTakeStack(player) && this.canMergeSlot(itemstack1, slot1)) {
ItemStack itemstack2 = slot1.getStack();
if (k != 0 || itemstack2.getCount() != itemstack2.getMaxStackSize()) {
int i1 = Math.min(itemstack1.getMaxStackSize() - itemstack1.getCount(), itemstack2.getCount());
ItemStack itemstack3 = slot1.decrStackSize(i1);
itemstack1.grow(i1);
if (itemstack3.isEmpty()) {
slot1.putStack(ItemStack.EMPTY);
}
slot1.onTake(player, itemstack3);
}
}
}
}
}
this.detectAndSendChanges();
}
return itemstack;
}
use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.
the class CCContainerBase method slotClick.
@Override
public ItemStack slotClick(int index, int button, ClickType mode, EntityPlayer player) {
int adder = 0;
InventoryPlayer inventoryplayer = player.inventory;
ItemStack held = inventoryplayer.getItemStack();
if (index >= 0) {
Slot s = getSlot(index);
if (s instanceof SlotFake) {
if (mode == ClickType.THROW) {
if (button == 0)
slotAdd(s, -1);
else
slotAdd(s, -64);
} else if (mode == ClickType.SWAP) {
return null;
} else if ((mode == ClickType.PICKUP || mode == ClickType.PICKUP_ALL) && (button == 0 || button == 1)) {
ItemStack stack = s.getStack();
if (stack != null && held != null && s.isItemValid(held)) {
if (button == 0) {
adder = held.stackSize;
} else if (button == 1) {
adder = 1;
}
slotAdd(s, adder);
} else if (held != null) {
s.putStack(held.copy());
} else if (stack != null && held == null) {
adder = button == 0 ? 1 : -1;
slotAdd(s, adder);
}
} else if ((mode == ClickType.QUICK_MOVE) && (button == 0 || button == 1)) {
adder = button == 0 ? 8 : -8;
slotAdd(s, adder);
}
this.detectAndSendChanges();
return null;
} else if (mode == ClickType.PICKUP_ALL && index >= 0) {
Slot slot2 = (Slot) this.inventorySlots.get(index);
ItemStack itemstack4 = inventoryplayer.getItemStack();
if (itemstack4 != null && (slot2 == null || !slot2.getHasStack() || !slot2.canTakeStack(player))) {
int i1 = button == 0 ? 0 : this.inventorySlots.size() - 1;
int j1 = button == 0 ? 1 : -1;
for (int i3 = 0; i3 < 2; ++i3) {
for (int j3 = i1; j3 >= 0 && j3 < this.inventorySlots.size() && itemstack4.stackSize < itemstack4.getMaxStackSize(); j3 += j1) {
Slot slot8 = (Slot) this.inventorySlots.get(j3);
if (!(slot8 instanceof SlotFake) && slot8.getHasStack() && canAddItemToSlot(slot8, itemstack4, true) && slot8.canTakeStack(player) && this.canMergeSlot(itemstack4, slot8) && (i3 != 0 || slot8.getStack().stackSize != slot8.getStack().getMaxStackSize())) {
int l = Math.min(itemstack4.getMaxStackSize() - itemstack4.stackSize, slot8.getStack().stackSize);
ItemStack itemstack2 = slot8.decrStackSize(l);
itemstack4.stackSize += l;
if (itemstack2.stackSize <= 0) {
slot8.putStack((ItemStack) null);
}
slot8.onPickupFromSlot(player, itemstack2);
}
}
}
}
this.detectAndSendChanges();
return null;
}
}
return super.slotClick(index, button, mode, player);
}
Aggregations