use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class ContainerBetterStorage method transferStackInSlot.
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotId) {
ItemStack stack = null;
Slot slot = (Slot) inventorySlots.get(slotId);
// If slot isn't empty and item can be stacked.
if ((slot != null) && slot.getHasStack()) {
ItemStack slotStack = slot.getStack();
stack = slotStack.copy();
if (!mergeItemStack(slotStack, transferStart(slotId), transferEnd(slotId), transferDirection(slotId)))
return null;
if (slotStack.stackSize != 0)
slot.onSlotChanged();
else
slot.putStack(null);
}
return stack;
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class ContainerCraftingStation method slotClick.
@Override
public ItemStack slotClick(int slotId, int button, int special, EntityPlayer player) {
if (!inv.outputIsReal && (inv.currentCrafting != null) && (slotId >= 9) && (slotId < 18) && (inv.output[slotId - 9] != null) && inv.canTake(player) && (special != 3)) {
ItemStack craftingStack = inv.output[slotId - 9];
int amount = craftingStack.stackSize;
// Shift-click: Craft up to one stack of items at once.
if (special == 1) {
ItemStack stack;
int count = 0;
do {
count += amount;
inv.craft(player);
stack = super.slotClick(slotId, button, special, player);
} while (!inv.outputIsReal && (inv.currentCrafting != null) && (inv.output[slotId - 9] != null) && inv.canTake(player) && ((stack == null) || (StackUtils.matches(stack, inv.output[slotId - 9]))) && inv.hasItemRequirements() && (count + amount <= craftingStack.getMaxStackSize()));
return stack;
// Regular clicking: Craft once.
} else if (special < 2) {
ItemStack holding = player.inventory.getItemStack();
if ((holding == null) || (StackUtils.matches(holding, craftingStack) && (holding.stackSize <= holding.getMaxStackSize() - amount)))
inv.craft(player);
// No fancy inventory mechanics in the crafting slots.
} else
return craftingStack;
}
return super.slotClick(slotId, button, special, player);
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class EntityFrienderman method onLivingUpdate.
@Override
public void onLivingUpdate() {
if (worldObj.isRemote) {
super.onLivingUpdate();
return;
}
int x = (int) Math.floor(posX);
int y = (int) (posY + 0.6);
int z = (int) Math.floor(posZ);
GameRules rules = worldObj.getGameRules();
String ruleBefore = rules.getGameRuleStringValue("mobGriefing");
boolean ruleChanged = false;
boolean hasEnderChest = (func_146080_bZ() == Blocks.ender_chest);
boolean hasBackpack = (getEquipmentInSlot(EquipmentSlot.CHEST) != null);
// Temporarily change the blocks which endermen can carry.
// TODO: Make a pull request to Forge which allows us to do this by overriding a method instead.
IdentityHashMap<Block, Boolean> carriable = ReflectionUtils.get(EntityEnderman.class, null, "carriable", "");
ReflectionUtils.set(EntityEnderman.class, null, "carriable", "", friendermanCarriable);
// prevent dropping of enderchests regardless of the gamerule.
if (hasEnderChest) {
if (ruleBefore.equalsIgnoreCase("true")) {
rules.setOrCreateGameRule("mobGriefing", "false");
ruleChanged = true;
}
} else if (hasBackpack && worldObj.isAirBlock(x, y, z)) {
if (ruleBefore.equalsIgnoreCase("false")) {
rules.setOrCreateGameRule("mobGriefing", "true");
ruleChanged = true;
}
}
super.onLivingUpdate();
// Reset carriable blocks and gamerule.
ReflectionUtils.set(EntityEnderman.class, null, "carriable", "", carriable);
if (ruleChanged)
rules.setOrCreateGameRule("mobGriefing", ruleBefore);
// If ender chest was picked up, remove ender backpack and place it on the ground.
if (!hasEnderChest && (func_146080_bZ() == Blocks.ender_chest)) {
setCurrentItemOrArmor(3, null);
worldObj.setBlock(x, y, z, BetterStorageTiles.enderBackpack, RandomUtils.getInt(2, 6), 3);
WorldUtils.get(worldObj, x, y, z, TileEntityBackpack.class).stack = new ItemStack(BetterStorageItems.itemEnderBackpack);
double px = x + 0.5;
double py = y + 0.5;
double pz = z + 0.5;
BetterStorage.networkChannel.sendToAllAround(new PacketBackpackTeleport(px, py, pz, x, y, z), worldObj, px, py, pz, 256);
worldObj.playSoundEffect(px, py, pz, "mob.endermen.portal", 1.0F, 1.0F);
}
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class InventoryBetterStorage method decrStackSize.
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if (stack == null)
return null;
amount = Math.min(amount, stack.stackSize);
if (amount < stack.stackSize) {
stack.stackSize -= amount;
stack = StackUtils.copyStack(stack, amount);
markDirty();
} else
setInventorySlotContents(slot, null);
return stack;
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class InventoryBetterStorage method getStackInSlotOnClosing.
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
if (stack == null)
return null;
setInventorySlotContents(slot, null);
return stack;
}
Aggregations