use of net.minecraft.entity.player.InventoryPlayer in project ImmersiveEngineering by BluSunrize.
the class ContainerIEBase method slotClick.
@Nonnull
@Override
public ItemStack slotClick(int id, int button, ClickType clickType, EntityPlayer player) {
Slot slot = id < 0 ? null : this.inventorySlots.get(id);
if (!(slot instanceof IESlot.Ghost))
return super.slotClick(id, button, clickType, player);
// Spooky Ghost Slots!!!!
ItemStack stack = ItemStack.EMPTY;
ItemStack stackSlot = slot.getStack();
if (!stackSlot.isEmpty())
stack = stackSlot.copy();
if (button == 2)
slot.putStack(ItemStack.EMPTY);
else if (button == 0 || button == 1) {
InventoryPlayer playerInv = player.inventory;
ItemStack stackHeld = playerInv.getItemStack();
if (stackSlot.isEmpty()) {
if (!stackHeld.isEmpty() && slot.isItemValid(stackHeld)) {
slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
}
} else if (stackHeld.isEmpty()) {
slot.putStack(ItemStack.EMPTY);
} else if (slot.isItemValid(stackHeld)) {
slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
}
} else if (button == 5) {
InventoryPlayer playerInv = player.inventory;
ItemStack stackHeld = playerInv.getItemStack();
if (!slot.getHasStack()) {
slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
}
}
return stack;
}
use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.
the class ChargeTickHandler method onPlayerSunlightChargeTick.
@SubscribeEvent
public void onPlayerSunlightChargeTick(TickEvent.PlayerTickEvent e) {
time++;
if (time < 20 || e.side != Side.SERVER)
return;
time = 0;
EntityPlayer player = e.player;
InventoryPlayer playerInv = player.inventory;
if (player.worldObj.isDaytime() && !player.worldObj.isRaining() && Helper.canEntitySeeSky(player)) {
// BAUBLES SUNLIGHT
IBaublesItemHandler baublesInv = player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null);
for (int i = 0; i < baublesInv.getSlots(); i++) {
ItemStack stack = baublesInv.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
if (sitem.isSunlightChargeable(stack, BAUBLES_SLOTS[i])) {
sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, BAUBLES_SLOTS[i]) * 20);
}
}
}
// MAIN
for (int i = 0; i < playerInv.mainInventory.length; i++) {
ItemStack stack = playerInv.mainInventory[i];
if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
if (sitem.isSunlightChargeable(stack, i)) {
sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, i) * 20);
}
}
}
// ARMOR
for (int i = 0; i < playerInv.armorInventory.length; i++) {
ItemStack stack = playerInv.armorInventory[i];
if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
if (sitem.isSunlightChargeable(stack, ARMOR_SLOTS[i])) {
sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, ARMOR_SLOTS[i]) * 20);
}
}
}
// OFFHAND
for (ItemStack stack : playerInv.offHandInventory) {
if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
if (sitem.isSunlightChargeable(stack, OFFHAND_SLOTS[0])) {
sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, OFFHAND_SLOTS[0]) * 20);
}
}
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.
the class ContainerTransmutationTome method onContainerClosed.
@Override
public void onContainerClosed(EntityPlayer playerIn) {
if (player.worldObj.isRemote)
return;
InventoryPlayer inventoryplayer = playerIn.inventory;
if (inventoryplayer.getItemStack() != null) {
playerIn.dropItem(inventoryplayer.getItemStack(), false);
inventoryplayer.setItemStack((ItemStack) null);
}
if (handler.getStackInSlot(0) != null) {
playerIn.dropItem(handler.getStackInSlot(0), false);
handler.setStackInSlot(0, null);
}
if (handler.getStackInSlot(1) != null) {
playerIn.dropItem(handler.getStackInSlot(1), false);
handler.setStackInSlot(1, null);
}
if (out.getStackInSlot(0) != null) {
playerIn.dropItem(out.getStackInSlot(0), false);
out.setStackInSlot(0, null);
}
}
use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.
the class PlayerInventoryTickHandler method onPlayerInventoryTick.
@SubscribeEvent
public void onPlayerInventoryTick(TickEvent.PlayerTickEvent e) {
EntityPlayer player = e.player;
InventoryPlayer playerInv = player.inventory;
// MAIN
for (int i = 0; i < playerInv.mainInventory.length; i++) {
ItemStack stack = playerInv.mainInventory[i];
if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, i, player);
;
}
}
// ARMOR
for (int i = 0; i < playerInv.armorInventory.length; i++) {
ItemStack stack = playerInv.armorInventory[i];
if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, ARMOR_SLOTS[i], player);
;
}
}
// OFFHAND
for (ItemStack stack : playerInv.offHandInventory) {
if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, OFFHAND_SLOTS[0], player);
;
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project LogisticsPipes by RS485.
the class DummyContainer method slotClick.
/**
* Clone/clear itemstacks for items
*/
@Nonnull
@Override
public ItemStack slotClick(int slotId, int mouseButton, @Nonnull ClickType shiftMode, @Nonnull EntityPlayer player) {
lastClicked = System.currentTimeMillis();
if (slotId < 0) {
return superSlotClick(slotId, mouseButton, shiftMode, player);
}
Slot slot = inventorySlots.get(slotId);
// debug dump
if (LogisticsPipes.isDEBUG() && slot != null) {
ItemStack stack = slot.getStack();
if (!stack.isEmpty()) {
ItemIdentifier.get(stack).debugDumpData(player.world.isRemote);
}
}
if (slot == null)
return ItemStack.EMPTY;
if ((!(slot instanceof DummySlot) && !(slot instanceof UnmodifiableSlot) && !(slot instanceof FluidSlot) && !(slot instanceof ColorSlot) && !(slot instanceof HandelableSlot))) {
ItemStack stack1 = superSlotClick(slotId, mouseButton, shiftMode, player);
ItemStack stack2 = slot.getStack();
if (!stack2.isEmpty() && stack2.getItem() instanceof ItemModule) {
if (player instanceof EntityPlayerMP && MainProxy.isServer(player.world)) {
((EntityPlayerMP) player).sendSlotContents(this, slotId, stack2);
}
}
return stack1;
}
InventoryPlayer inventoryplayer = player.inventory;
ItemStack currentlyEquippedStack = inventoryplayer.getItemStack();
// we get a leftclick *and* a doubleclick message if there's a doubleclick with no item on the pointer, filter it out
if (currentlyEquippedStack.isEmpty() && shiftMode == ClickType.PICKUP_ALL) {
return currentlyEquippedStack;
}
if (slot instanceof HandelableSlot) {
overrideMCAntiSend = true;
if (currentlyEquippedStack.isEmpty()) {
inventoryplayer.setItemStack(((HandelableSlot) slot).getProvidedStack());
return ItemStack.EMPTY;
}
return currentlyEquippedStack;
}
if (slot instanceof UnmodifiableSlot) {
return currentlyEquippedStack;
}
handleDummyClick(slot, slotId, currentlyEquippedStack, mouseButton, shiftMode, player);
return currentlyEquippedStack;
}
Aggregations