base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,12 @@
package net.minecraft.inventory;
public enum ClickType
{
PICKUP,
QUICK_MOVE,
SWAP,
CLONE,
THROW,
QUICK_CRAFT,
PICKUP_ALL;
}

View File

@@ -0,0 +1,883 @@
package net.minecraft.inventory;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.network.play.server.SPacketSetSlot;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class Container
{
/** the list of all items(stacks) for the corresponding slot */
public NonNullList<ItemStack> inventoryItemStacks = NonNullList.<ItemStack>create();
/** The list of {@link Slots} in this {@code Container}. */
public List<Slot> inventorySlots = Lists.<Slot>newArrayList();
public int windowId;
@SideOnly(Side.CLIENT)
private short transactionID;
/** The current drag mode (0 : evenly split, 1 : one item by slot, 2 : not used ?) */
private int dragMode = -1;
/** The current drag event (0 : start, 1 : add slot : 2 : end) */
private int dragEvent;
/** The list of slots where the itemstack holds will be distributed */
private final Set<Slot> dragSlots = Sets.<Slot>newHashSet();
/** list of all people that need to be notified when this craftinventory changes */
protected List<IContainerListener> listeners = Lists.<IContainerListener>newArrayList();
private final Set<EntityPlayer> playerList = Sets.<EntityPlayer>newHashSet();
/**
* Adds an item slot to this container
*/
protected Slot addSlotToContainer(Slot slotIn)
{
slotIn.slotNumber = this.inventorySlots.size();
this.inventorySlots.add(slotIn);
this.inventoryItemStacks.add(ItemStack.EMPTY);
return slotIn;
}
public void addListener(IContainerListener listener)
{
if (this.listeners.contains(listener))
{
throw new IllegalArgumentException("Listener already listening");
}
else
{
this.listeners.add(listener);
listener.sendAllContents(this, this.getInventory());
this.detectAndSendChanges();
}
}
/**
* returns a list if itemStacks, for each slot.
*/
public NonNullList<ItemStack> getInventory()
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>create();
for (int i = 0; i < this.inventorySlots.size(); ++i)
{
nonnulllist.add(((Slot)this.inventorySlots.get(i)).getStack());
}
return nonnulllist;
}
/**
* Remove the given Listener. Method name is for legacy.
*/
@SideOnly(Side.CLIENT)
public void removeListener(IContainerListener listener)
{
this.listeners.remove(listener);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges()
{
for (int i = 0; i < this.inventorySlots.size(); ++i)
{
ItemStack itemstack = ((Slot)this.inventorySlots.get(i)).getStack();
ItemStack itemstack1 = this.inventoryItemStacks.get(i);
if (!ItemStack.areItemStacksEqual(itemstack1, itemstack))
{
boolean clientStackChanged = !ItemStack.areItemStacksEqualUsingNBTShareTag(itemstack1, itemstack);
itemstack1 = itemstack.isEmpty() ? ItemStack.EMPTY : itemstack.copy();
this.inventoryItemStacks.set(i, itemstack1);
if (clientStackChanged)
for (int j = 0; j < this.listeners.size(); ++j)
{
((IContainerListener)this.listeners.get(j)).sendSlotContents(this, i, itemstack1);
}
}
}
}
/**
* Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
*/
public boolean enchantItem(EntityPlayer playerIn, int id)
{
return false;
}
@Nullable
public Slot getSlotFromInventory(IInventory inv, int slotIn)
{
for (int i = 0; i < this.inventorySlots.size(); ++i)
{
Slot slot = this.inventorySlots.get(i);
if (slot.isHere(inv, slotIn))
{
return slot;
}
}
return null;
}
public Slot getSlot(int slotId)
{
return this.inventorySlots.get(slotId);
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
Slot slot = this.inventorySlots.get(index);
return slot != null ? slot.getStack() : ItemStack.EMPTY;
}
public ItemStack slotClick(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);
}
else if (itemstack11.getCount() <= slot6.getItemStackLimit(itemstack11))
{
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);
slot4.onSwapCraft(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;
}
/**
* Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in
* is null for the initial slot that was double-clicked.
*/
public boolean canMergeSlot(ItemStack stack, Slot slotIn)
{
return true;
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
InventoryPlayer inventoryplayer = playerIn.inventory;
if (!inventoryplayer.getItemStack().isEmpty())
{
playerIn.dropItem(inventoryplayer.getItemStack(), false);
inventoryplayer.setItemStack(ItemStack.EMPTY);
}
}
protected void clearContainer(EntityPlayer playerIn, World worldIn, IInventory inventoryIn)
{
if (!playerIn.isEntityAlive() || playerIn instanceof EntityPlayerMP && ((EntityPlayerMP)playerIn).hasDisconnected())
{
for (int j = 0; j < inventoryIn.getSizeInventory(); ++j)
{
playerIn.dropItem(inventoryIn.removeStackFromSlot(j), false);
}
}
else
{
for (int i = 0; i < inventoryIn.getSizeInventory(); ++i)
{
playerIn.inventory.placeItemBackInInventory(worldIn, inventoryIn.removeStackFromSlot(i));
}
}
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory inventoryIn)
{
this.detectAndSendChanges();
}
/**
* Puts an ItemStack in a slot.
*/
public void putStackInSlot(int slotID, ItemStack stack)
{
this.getSlot(slotID).putStack(stack);
}
@SideOnly(Side.CLIENT)
public void setAll(List<ItemStack> p_190896_1_)
{
for (int i = 0; i < p_190896_1_.size(); ++i)
{
this.getSlot(i).putStack(p_190896_1_.get(i));
}
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
}
/**
* Gets a unique transaction ID. Parameter is unused.
*/
@SideOnly(Side.CLIENT)
public short getNextTransactionID(InventoryPlayer invPlayer)
{
++this.transactionID;
return this.transactionID;
}
/**
* gets whether or not the player can craft in this inventory or not
*/
public boolean getCanCraft(EntityPlayer player)
{
return !this.playerList.contains(player);
}
/**
* sets whether the player can craft in this inventory or not
*/
public void setCanCraft(EntityPlayer player, boolean canCraft)
{
if (canCraft)
{
this.playerList.remove(player);
}
else
{
this.playerList.add(player);
}
}
/**
* Determines whether supplied player can use this container
*/
public abstract boolean canInteractWith(EntityPlayer playerIn);
/**
* Merges provided ItemStack with the first avaliable one in the container/player inventor between minIndex
* (included) and maxIndex (excluded). Args : stack, minIndex, maxIndex, negativDirection. /!\ the Container
* implementation do not check if the item is valid for the slot
*/
protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection)
{
boolean flag = false;
int i = startIndex;
if (reverseDirection)
{
i = endIndex - 1;
}
if (stack.isStackable())
{
while (!stack.isEmpty())
{
if (reverseDirection)
{
if (i < startIndex)
{
break;
}
}
else if (i >= endIndex)
{
break;
}
Slot slot = this.inventorySlots.get(i);
ItemStack itemstack = slot.getStack();
if (!itemstack.isEmpty() && itemstack.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getMetadata() == itemstack.getMetadata()) && ItemStack.areItemStackTagsEqual(stack, itemstack))
{
int j = itemstack.getCount() + stack.getCount();
int maxSize = Math.min(slot.getSlotStackLimit(), stack.getMaxStackSize());
if (j <= maxSize)
{
stack.setCount(0);
itemstack.setCount(j);
slot.onSlotChanged();
flag = true;
}
else if (itemstack.getCount() < maxSize)
{
stack.shrink(maxSize - itemstack.getCount());
itemstack.setCount(maxSize);
slot.onSlotChanged();
flag = true;
}
}
if (reverseDirection)
{
--i;
}
else
{
++i;
}
}
}
if (!stack.isEmpty())
{
if (reverseDirection)
{
i = endIndex - 1;
}
else
{
i = startIndex;
}
while (true)
{
if (reverseDirection)
{
if (i < startIndex)
{
break;
}
}
else if (i >= endIndex)
{
break;
}
Slot slot1 = this.inventorySlots.get(i);
ItemStack itemstack1 = slot1.getStack();
if (itemstack1.isEmpty() && slot1.isItemValid(stack))
{
if (stack.getCount() > slot1.getSlotStackLimit())
{
slot1.putStack(stack.splitStack(slot1.getSlotStackLimit()));
}
else
{
slot1.putStack(stack.splitStack(stack.getCount()));
}
slot1.onSlotChanged();
flag = true;
break;
}
if (reverseDirection)
{
--i;
}
else
{
++i;
}
}
}
return flag;
}
/**
* Extracts the drag mode. Args : eventButton. Return (0 : evenly split, 1 : one item by slot, 2 : not used ?)
*/
public static int extractDragMode(int eventButton)
{
return eventButton >> 2 & 3;
}
/**
* Args : clickedButton, Returns (0 : start drag, 1 : add slot, 2 : end drag)
*/
public static int getDragEvent(int clickedButton)
{
return clickedButton & 3;
}
@SideOnly(Side.CLIENT)
public static int getQuickcraftMask(int p_94534_0_, int p_94534_1_)
{
return p_94534_0_ & 3 | (p_94534_1_ & 3) << 2;
}
public static boolean isValidDragMode(int dragModeIn, EntityPlayer player)
{
if (dragModeIn == 0)
{
return true;
}
else if (dragModeIn == 1)
{
return true;
}
else
{
return dragModeIn == 2 && player.capabilities.isCreativeMode;
}
}
/**
* Reset the drag fields
*/
protected void resetDrag()
{
this.dragEvent = 0;
this.dragSlots.clear();
}
/**
* Checks if it's possible to add the given itemstack to the given slot.
*/
public static boolean canAddItemToSlot(@Nullable Slot slotIn, ItemStack stack, boolean stackSizeMatters)
{
boolean flag = slotIn == null || !slotIn.getHasStack();
if (!flag && stack.isItemEqual(slotIn.getStack()) && ItemStack.areItemStackTagsEqual(slotIn.getStack(), stack))
{
return slotIn.getStack().getCount() + (stackSizeMatters ? 0 : stack.getCount()) <= stack.getMaxStackSize();
}
else
{
return flag;
}
}
/**
* Compute the new stack size, Returns the stack with the new size. Args : dragSlots, dragMode, dragStack,
* slotStackSize
*/
public static void computeStackSize(Set<Slot> dragSlotsIn, int dragModeIn, ItemStack stack, int slotStackSize)
{
switch (dragModeIn)
{
case 0:
stack.setCount(MathHelper.floor((float)stack.getCount() / (float)dragSlotsIn.size()));
break;
case 1:
stack.setCount(1);
break;
case 2:
stack.setCount(stack.getMaxStackSize());
}
stack.grow(slotStackSize);
}
/**
* Returns true if the player can "drag-spilt" items into this slot,. returns true by default. Called to check if
* the slot can be added to a list of Slots to split the held ItemStack across.
*/
public boolean canDragIntoSlot(Slot slotIn)
{
return true;
}
/**
* Like the version that takes an inventory. If the given TileEntity is not an Inventory, 0 is returned instead.
*/
public static int calcRedstone(@Nullable TileEntity te)
{
return te instanceof IInventory ? calcRedstoneFromInventory((IInventory)te) : 0;
}
public static int calcRedstoneFromInventory(@Nullable IInventory inv)
{
if (inv == null)
{
return 0;
}
else
{
int i = 0;
float f = 0.0F;
for (int j = 0; j < inv.getSizeInventory(); ++j)
{
ItemStack itemstack = inv.getStackInSlot(j);
if (!itemstack.isEmpty())
{
f += (float)itemstack.getCount() / (float)Math.min(inv.getInventoryStackLimit(), itemstack.getMaxStackSize());
++i;
}
}
f = f / (float)inv.getSizeInventory();
return MathHelper.floor(f * 14.0F) + (i > 0 ? 1 : 0);
}
}
protected void slotChangedCraftingGrid(World p_192389_1_, EntityPlayer p_192389_2_, InventoryCrafting p_192389_3_, InventoryCraftResult p_192389_4_)
{
if (!p_192389_1_.isRemote)
{
EntityPlayerMP entityplayermp = (EntityPlayerMP)p_192389_2_;
ItemStack itemstack = ItemStack.EMPTY;
IRecipe irecipe = CraftingManager.findMatchingRecipe(p_192389_3_, p_192389_1_);
if (irecipe != null && (irecipe.isDynamic() || !p_192389_1_.getGameRules().getBoolean("doLimitedCrafting") || entityplayermp.getRecipeBook().isUnlocked(irecipe)))
{
p_192389_4_.setRecipeUsed(irecipe);
itemstack = irecipe.getCraftingResult(p_192389_3_);
}
p_192389_4_.setInventorySlotContents(0, itemstack);
entityplayermp.connection.sendPacket(new SPacketSetSlot(this.windowId, 0, itemstack));
}
}
}

View File

@@ -0,0 +1,171 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerBeacon extends Container
{
private final IInventory tileBeacon;
/** This beacon's slot where you put in Emerald, Diamond, Gold or Iron Ingot. */
private final ContainerBeacon.BeaconSlot beaconSlot;
public ContainerBeacon(IInventory playerInventory, IInventory tileBeaconIn)
{
this.tileBeacon = tileBeaconIn;
this.beaconSlot = new ContainerBeacon.BeaconSlot(tileBeaconIn, 0, 136, 110);
this.addSlotToContainer(this.beaconSlot);
int i = 36;
int j = 137;
for (int k = 0; k < 3; ++k)
{
for (int l = 0; l < 9; ++l)
{
this.addSlotToContainer(new Slot(playerInventory, l + k * 9 + 9, 36 + l * 18, 137 + k * 18));
}
}
for (int i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(playerInventory, i1, 36 + i1 * 18, 195));
}
}
public void addListener(IContainerListener listener)
{
super.addListener(listener);
listener.sendAllWindowProperties(this, this.tileBeacon);
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
this.tileBeacon.setField(id, data);
}
public IInventory getTileEntity()
{
return this.tileBeacon;
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
if (!playerIn.world.isRemote)
{
ItemStack itemstack = this.beaconSlot.decrStackSize(this.beaconSlot.getSlotStackLimit());
if (!itemstack.isEmpty())
{
playerIn.dropItem(itemstack, false);
}
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.tileBeacon.isUsableByPlayer(playerIn);
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 0)
{
if (!this.mergeItemStack(itemstack1, 1, 37, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (this.mergeItemStack(itemstack1, 0, 1, false)) //Forge Fix Shift Clicking in beacons with stacks larger then 1.
{
return ItemStack.EMPTY;
}
else if (index >= 1 && index < 28)
{
if (!this.mergeItemStack(itemstack1, 28, 37, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 28 && index < 37)
{
if (!this.mergeItemStack(itemstack1, 1, 28, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 1, 37, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
class BeaconSlot extends Slot
{
public BeaconSlot(IInventory inventoryIn, int index, int xIn, int yIn)
{
super(inventoryIn, index, xIn, yIn);
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return stack.getItem().isBeaconPayment(stack);
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the
* case of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
}
}

View File

@@ -0,0 +1,285 @@
package net.minecraft.inventory;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionHelper;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerBrewingStand extends Container
{
private final IInventory tileBrewingStand;
/** Instance of Slot. */
private final Slot slot;
/** Used to cache the brewing time to send changes to ICrafting listeners. */
private int prevBrewTime;
/** Used to cache the fuel remaining in the brewing stand to send changes to ICrafting listeners. */
private int prevFuel;
public ContainerBrewingStand(InventoryPlayer playerInventory, IInventory tileBrewingStandIn)
{
this.tileBrewingStand = tileBrewingStandIn;
this.addSlotToContainer(new ContainerBrewingStand.Potion(tileBrewingStandIn, 0, 56, 51));
this.addSlotToContainer(new ContainerBrewingStand.Potion(tileBrewingStandIn, 1, 79, 58));
this.addSlotToContainer(new ContainerBrewingStand.Potion(tileBrewingStandIn, 2, 102, 51));
this.slot = this.addSlotToContainer(new ContainerBrewingStand.Ingredient(tileBrewingStandIn, 3, 79, 17));
this.addSlotToContainer(new ContainerBrewingStand.Fuel(tileBrewingStandIn, 4, 17, 17));
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
}
}
public void addListener(IContainerListener listener)
{
super.addListener(listener);
listener.sendAllWindowProperties(this, this.tileBrewingStand);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); ++i)
{
IContainerListener icontainerlistener = this.listeners.get(i);
if (this.prevBrewTime != this.tileBrewingStand.getField(0))
{
icontainerlistener.sendWindowProperty(this, 0, this.tileBrewingStand.getField(0));
}
if (this.prevFuel != this.tileBrewingStand.getField(1))
{
icontainerlistener.sendWindowProperty(this, 1, this.tileBrewingStand.getField(1));
}
}
this.prevBrewTime = this.tileBrewingStand.getField(0);
this.prevFuel = this.tileBrewingStand.getField(1);
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
this.tileBrewingStand.setField(id, data);
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.tileBrewingStand.isUsableByPlayer(playerIn);
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if ((index < 0 || index > 2) && index != 3 && index != 4)
{
if (this.slot.isItemValid(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 3, 4, false))
{
return ItemStack.EMPTY;
}
}
else if (ContainerBrewingStand.Potion.canHoldPotion(itemstack) && itemstack.getCount() == 1)
{
if (!this.mergeItemStack(itemstack1, 0, 3, false))
{
return ItemStack.EMPTY;
}
}
else if (ContainerBrewingStand.Fuel.isValidBrewingFuel(itemstack))
{
if (!this.mergeItemStack(itemstack1, 4, 5, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 5 && index < 32)
{
if (!this.mergeItemStack(itemstack1, 32, 41, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 32 && index < 41)
{
if (!this.mergeItemStack(itemstack1, 5, 32, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 5, 41, false))
{
return ItemStack.EMPTY;
}
}
else
{
if (!this.mergeItemStack(itemstack1, 5, 41, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
static class Fuel extends Slot
{
public Fuel(IInventory iInventoryIn, int index, int xPosition, int yPosition)
{
super(iInventoryIn, index, xPosition, yPosition);
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return isValidBrewingFuel(stack);
}
/**
* Returns true if the given ItemStack is usable as a fuel in the brewing stand.
*/
public static boolean isValidBrewingFuel(ItemStack itemStackIn)
{
return itemStackIn.getItem() == Items.BLAZE_POWDER;
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in
* the case of armor slots)
*/
public int getSlotStackLimit()
{
return 64;
}
}
static class Ingredient extends Slot
{
public Ingredient(IInventory iInventoryIn, int index, int xPosition, int yPosition)
{
super(iInventoryIn, index, xPosition, yPosition);
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return net.minecraftforge.common.brewing.BrewingRecipeRegistry.isValidIngredient(stack);
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in
* the case of armor slots)
*/
public int getSlotStackLimit()
{
return 64;
}
}
static class Potion extends Slot
{
public Potion(IInventory p_i47598_1_, int p_i47598_2_, int p_i47598_3_, int p_i47598_4_)
{
super(p_i47598_1_, p_i47598_2_, p_i47598_3_, p_i47598_4_);
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return canHoldPotion(stack);
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in
* the case of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
{
PotionType potiontype = PotionUtils.getPotionFromItem(stack);
if (thePlayer instanceof EntityPlayerMP)
{
net.minecraftforge.event.ForgeEventFactory.onPlayerBrewedPotion(thePlayer, stack);
CriteriaTriggers.BREWED_POTION.trigger((EntityPlayerMP)thePlayer, potiontype);
}
super.onTake(thePlayer, stack);
return stack;
}
/**
* Returns true if this itemstack can be filled with a potion
*/
public static boolean canHoldPotion(ItemStack stack)
{
return net.minecraftforge.common.brewing.BrewingRecipeRegistry.isValidInput(stack);
}
}
}

View File

@@ -0,0 +1,103 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class ContainerChest extends Container
{
private final IInventory lowerChestInventory;
private final int numRows;
public ContainerChest(IInventory playerInventory, IInventory chestInventory, EntityPlayer player)
{
this.lowerChestInventory = chestInventory;
this.numRows = chestInventory.getSizeInventory() / 9;
chestInventory.openInventory(player);
int i = (this.numRows - 4) * 18;
for (int j = 0; j < this.numRows; ++j)
{
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(chestInventory, k + j * 9, 8 + k * 18, 18 + j * 18));
}
}
for (int l = 0; l < 3; ++l)
{
for (int j1 = 0; j1 < 9; ++j1)
{
this.addSlotToContainer(new Slot(playerInventory, j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + i));
}
}
for (int i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 161 + i));
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.lowerChestInventory.isUsableByPlayer(playerIn);
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index < this.numRows * 9)
{
if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
}
return itemstack;
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
this.lowerChestInventory.closeInventory(playerIn);
}
/**
* Return this chest container's lower chest inventory.
*/
public IInventory getLowerChestInventory()
{
return this.lowerChestInventory;
}
}

View File

@@ -0,0 +1,89 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class ContainerDispenser extends Container
{
private final IInventory dispenserInventory;
public ContainerDispenser(IInventory playerInventory, IInventory dispenserInventoryIn)
{
this.dispenserInventory = dispenserInventoryIn;
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
this.addSlotToContainer(new Slot(dispenserInventoryIn, j + i * 3, 62 + j * 18, 17 + i * 18));
}
}
for (int k = 0; k < 3; ++k)
{
for (int i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
}
}
for (int l = 0; l < 9; ++l)
{
this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.dispenserInventory.isUsableByPlayer(playerIn);
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index < 9)
{
if (!this.mergeItemStack(itemstack1, 9, 45, true))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 0, 9, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
}

View File

@@ -0,0 +1,454 @@
package net.minecraft.inventory;
import java.util.List;
import java.util.Random;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerEnchantment extends Container
{
/** SlotEnchantmentTable object with ItemStack to be enchanted */
public IInventory tableInventory;
/** current world (for bookshelf counting) */
private final World worldPointer;
private final BlockPos position;
private final Random rand;
public int xpSeed;
/** 3-member array storing the enchantment levels of each slot */
public int[] enchantLevels;
public int[] enchantClue;
public int[] worldClue;
@SideOnly(Side.CLIENT)
public ContainerEnchantment(InventoryPlayer playerInv, World worldIn)
{
this(playerInv, worldIn, BlockPos.ORIGIN);
}
public ContainerEnchantment(InventoryPlayer playerInv, World worldIn, BlockPos pos)
{
this.tableInventory = new InventoryBasic("Enchant", true, 2)
{
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't
* think it hasn't changed and skip it.
*/
public void markDirty()
{
super.markDirty();
ContainerEnchantment.this.onCraftMatrixChanged(this);
}
};
this.rand = new Random();
this.enchantLevels = new int[3];
this.enchantClue = new int[] { -1, -1, -1};
this.worldClue = new int[] { -1, -1, -1};
this.worldPointer = worldIn;
this.position = pos;
this.xpSeed = playerInv.player.getXPSeed();
this.addSlotToContainer(new Slot(this.tableInventory, 0, 15, 47)
{
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return true;
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in
* the case of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
});
this.addSlotToContainer(new Slot(this.tableInventory, 1, 35, 47)
{
java.util.List<ItemStack> ores = net.minecraftforge.oredict.OreDictionary.getOres("gemLapis");
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
for (ItemStack ore : ores)
if (net.minecraftforge.oredict.OreDictionary.itemMatches(ore, stack, false)) return true;
return false;
}
});
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInv, k, 8 + k * 18, 142));
}
}
protected void broadcastData(IContainerListener crafting)
{
crafting.sendWindowProperty(this, 0, this.enchantLevels[0]);
crafting.sendWindowProperty(this, 1, this.enchantLevels[1]);
crafting.sendWindowProperty(this, 2, this.enchantLevels[2]);
crafting.sendWindowProperty(this, 3, this.xpSeed & -16);
crafting.sendWindowProperty(this, 4, this.enchantClue[0]);
crafting.sendWindowProperty(this, 5, this.enchantClue[1]);
crafting.sendWindowProperty(this, 6, this.enchantClue[2]);
crafting.sendWindowProperty(this, 7, this.worldClue[0]);
crafting.sendWindowProperty(this, 8, this.worldClue[1]);
crafting.sendWindowProperty(this, 9, this.worldClue[2]);
}
public void addListener(IContainerListener listener)
{
super.addListener(listener);
this.broadcastData(listener);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); ++i)
{
IContainerListener icontainerlistener = this.listeners.get(i);
this.broadcastData(icontainerlistener);
}
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
if (id >= 0 && id <= 2)
{
this.enchantLevels[id] = data;
}
else if (id == 3)
{
this.xpSeed = data;
}
else if (id >= 4 && id <= 6)
{
this.enchantClue[id - 4] = data;
}
else if (id >= 7 && id <= 9)
{
this.worldClue[id - 7] = data;
}
else
{
super.updateProgressBar(id, data);
}
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory inventoryIn)
{
if (inventoryIn == this.tableInventory)
{
ItemStack itemstack = inventoryIn.getStackInSlot(0);
if (!itemstack.isEmpty() && itemstack.isItemEnchantable())
{
if (!this.worldPointer.isRemote)
{
int l = 0;
float power = 0;
for (int j = -1; j <= 1; ++j)
{
for (int k = -1; k <= 1; ++k)
{
if ((j != 0 || k != 0) && this.worldPointer.isAirBlock(this.position.add(k, 0, j)) && this.worldPointer.isAirBlock(this.position.add(k, 1, j)))
{
power += net.minecraftforge.common.ForgeHooks.getEnchantPower(worldPointer, position.add(k * 2, 0, j * 2));
power += net.minecraftforge.common.ForgeHooks.getEnchantPower(worldPointer, position.add(k * 2, 1, j * 2));
if (k != 0 && j != 0)
{
power += net.minecraftforge.common.ForgeHooks.getEnchantPower(worldPointer, position.add(k * 2, 0, j));
power += net.minecraftforge.common.ForgeHooks.getEnchantPower(worldPointer, position.add(k * 2, 1, j));
power += net.minecraftforge.common.ForgeHooks.getEnchantPower(worldPointer, position.add(k, 0, j * 2));
power += net.minecraftforge.common.ForgeHooks.getEnchantPower(worldPointer, position.add(k, 1, j * 2));
}
}
}
}
this.rand.setSeed((long)this.xpSeed);
for (int i1 = 0; i1 < 3; ++i1)
{
this.enchantLevels[i1] = EnchantmentHelper.calcItemStackEnchantability(this.rand, i1, (int)power, itemstack);
this.enchantClue[i1] = -1;
this.worldClue[i1] = -1;
if (this.enchantLevels[i1] < i1 + 1)
{
this.enchantLevels[i1] = 0;
}
this.enchantLevels[i1] = net.minecraftforge.event.ForgeEventFactory.onEnchantmentLevelSet(worldPointer, position, i1, (int)power, itemstack, enchantLevels[i1]);
}
for (int j1 = 0; j1 < 3; ++j1)
{
if (this.enchantLevels[j1] > 0)
{
List<EnchantmentData> list = this.getEnchantmentList(itemstack, j1, this.enchantLevels[j1]);
if (list != null && !list.isEmpty())
{
EnchantmentData enchantmentdata = list.get(this.rand.nextInt(list.size()));
this.enchantClue[j1] = Enchantment.getEnchantmentID(enchantmentdata.enchantment);
this.worldClue[j1] = enchantmentdata.enchantmentLevel;
}
}
}
this.detectAndSendChanges();
}
}
else
{
for (int i = 0; i < 3; ++i)
{
this.enchantLevels[i] = 0;
this.enchantClue[i] = -1;
this.worldClue[i] = -1;
}
}
}
}
/**
* Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
*/
public boolean enchantItem(EntityPlayer playerIn, int id)
{
ItemStack itemstack = this.tableInventory.getStackInSlot(0);
ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
int i = id + 1;
if ((itemstack1.isEmpty() || itemstack1.getCount() < i) && !playerIn.capabilities.isCreativeMode)
{
return false;
}
else if (this.enchantLevels[id] > 0 && !itemstack.isEmpty() && (playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id] || playerIn.capabilities.isCreativeMode))
{
if (!this.worldPointer.isRemote)
{
List<EnchantmentData> list = this.getEnchantmentList(itemstack, id, this.enchantLevels[id]);
if (!list.isEmpty())
{
playerIn.onEnchant(itemstack, i);
boolean flag = itemstack.getItem() == Items.BOOK;
if (flag)
{
itemstack = new ItemStack(Items.ENCHANTED_BOOK);
this.tableInventory.setInventorySlotContents(0, itemstack);
}
for (int j = 0; j < list.size(); ++j)
{
EnchantmentData enchantmentdata = list.get(j);
if (flag)
{
ItemEnchantedBook.addEnchantment(itemstack, enchantmentdata);
}
else
{
itemstack.addEnchantment(enchantmentdata.enchantment, enchantmentdata.enchantmentLevel);
}
}
if (!playerIn.capabilities.isCreativeMode)
{
itemstack1.shrink(i);
if (itemstack1.isEmpty())
{
this.tableInventory.setInventorySlotContents(1, ItemStack.EMPTY);
}
}
playerIn.addStat(StatList.ITEM_ENCHANTED);
if (playerIn instanceof EntityPlayerMP)
{
CriteriaTriggers.ENCHANTED_ITEM.trigger((EntityPlayerMP)playerIn, itemstack, i);
}
this.tableInventory.markDirty();
this.xpSeed = playerIn.getXPSeed();
this.onCraftMatrixChanged(this.tableInventory);
this.worldPointer.playSound((EntityPlayer)null, this.position, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 1.0F, this.worldPointer.rand.nextFloat() * 0.1F + 0.9F);
}
}
return true;
}
else
{
return false;
}
}
private List<EnchantmentData> getEnchantmentList(ItemStack stack, int enchantSlot, int level)
{
this.rand.setSeed((long)(this.xpSeed + enchantSlot));
List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(this.rand, stack, level, false);
if (stack.getItem() == Items.BOOK && list.size() > 1)
{
list.remove(this.rand.nextInt(list.size()));
}
return list;
}
@SideOnly(Side.CLIENT)
public int getLapisAmount()
{
ItemStack itemstack = this.tableInventory.getStackInSlot(1);
return itemstack.isEmpty() ? 0 : itemstack.getCount();
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
if (!this.worldPointer.isRemote)
{
this.clearContainer(playerIn, playerIn.world, this.tableInventory);
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
if (this.worldPointer.getBlockState(this.position).getBlock() != Blocks.ENCHANTING_TABLE)
{
return false;
}
else
{
return playerIn.getDistanceSq((double)this.position.getX() + 0.5D, (double)this.position.getY() + 0.5D, (double)this.position.getZ() + 0.5D) <= 64.0D;
}
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 0)
{
if (!this.mergeItemStack(itemstack1, 2, 38, true))
{
return ItemStack.EMPTY;
}
}
else if (index == 1)
{
if (!this.mergeItemStack(itemstack1, 2, 38, true))
{
return ItemStack.EMPTY;
}
}
else if (itemstack1.getItem() == Items.DYE && EnumDyeColor.byDyeDamage(itemstack1.getMetadata()) == EnumDyeColor.BLUE)
{
if (!this.mergeItemStack(itemstack1, 1, 2, true))
{
return ItemStack.EMPTY;
}
}
else
{
if (((Slot)this.inventorySlots.get(0)).getHasStack() || !((Slot)this.inventorySlots.get(0)).isItemValid(itemstack1))
{
return ItemStack.EMPTY;
}
if (itemstack1.hasTagCompound())// Forge: Fix MC-17431
{
((Slot)this.inventorySlots.get(0)).putStack(itemstack1.splitStack(1));
}
else if (!itemstack1.isEmpty())
{
((Slot)this.inventorySlots.get(0)).putStack(new ItemStack(itemstack1.getItem(), 1, itemstack1.getMetadata()));
itemstack1.shrink(1);
}
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
}

View File

@@ -0,0 +1,173 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerFurnace extends Container
{
private final IInventory tileFurnace;
private int cookTime;
private int totalCookTime;
private int furnaceBurnTime;
private int currentItemBurnTime;
public ContainerFurnace(InventoryPlayer playerInventory, IInventory furnaceInventory)
{
this.tileFurnace = furnaceInventory;
this.addSlotToContainer(new Slot(furnaceInventory, 0, 56, 17));
this.addSlotToContainer(new SlotFurnaceFuel(furnaceInventory, 1, 56, 53));
this.addSlotToContainer(new SlotFurnaceOutput(playerInventory.player, furnaceInventory, 2, 116, 35));
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
}
}
public void addListener(IContainerListener listener)
{
super.addListener(listener);
listener.sendAllWindowProperties(this, this.tileFurnace);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); ++i)
{
IContainerListener icontainerlistener = this.listeners.get(i);
if (this.cookTime != this.tileFurnace.getField(2))
{
icontainerlistener.sendWindowProperty(this, 2, this.tileFurnace.getField(2));
}
if (this.furnaceBurnTime != this.tileFurnace.getField(0))
{
icontainerlistener.sendWindowProperty(this, 0, this.tileFurnace.getField(0));
}
if (this.currentItemBurnTime != this.tileFurnace.getField(1))
{
icontainerlistener.sendWindowProperty(this, 1, this.tileFurnace.getField(1));
}
if (this.totalCookTime != this.tileFurnace.getField(3))
{
icontainerlistener.sendWindowProperty(this, 3, this.tileFurnace.getField(3));
}
}
this.cookTime = this.tileFurnace.getField(2);
this.furnaceBurnTime = this.tileFurnace.getField(0);
this.currentItemBurnTime = this.tileFurnace.getField(1);
this.totalCookTime = this.tileFurnace.getField(3);
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
this.tileFurnace.setField(id, data);
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.tileFurnace.isUsableByPlayer(playerIn);
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index != 1 && index != 0)
{
if (!FurnaceRecipes.instance().getSmeltingResult(itemstack1).isEmpty())
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return ItemStack.EMPTY;
}
}
else if (TileEntityFurnace.isItemFuel(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 1, 2, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 3 && index < 30)
{
if (!this.mergeItemStack(itemstack1, 30, 39, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
}

View File

@@ -0,0 +1,91 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public class ContainerHopper extends Container
{
private final IInventory hopperInventory;
public ContainerHopper(InventoryPlayer playerInventory, IInventory hopperInventoryIn, EntityPlayer player)
{
this.hopperInventory = hopperInventoryIn;
hopperInventoryIn.openInventory(player);
int i = 51;
for (int j = 0; j < hopperInventoryIn.getSizeInventory(); ++j)
{
this.addSlotToContainer(new Slot(hopperInventoryIn, j, 44 + j * 18, 20));
}
for (int l = 0; l < 3; ++l)
{
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInventory, k + l * 9 + 9, 8 + k * 18, l * 18 + 51));
}
}
for (int i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 109));
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.hopperInventory.isUsableByPlayer(playerIn);
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index < this.hopperInventory.getSizeInventory())
{
if (!this.mergeItemStack(itemstack1, this.hopperInventory.getSizeInventory(), this.inventorySlots.size(), true))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 0, this.hopperInventory.getSizeInventory(), false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
}
return itemstack;
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
this.hopperInventory.closeInventory(playerIn);
}
}

View File

@@ -0,0 +1,19 @@
package net.minecraft.inventory;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerHorseChest extends InventoryBasic
{
public ContainerHorseChest(String inventoryTitle, int slotCount)
{
super(inventoryTitle, false, slotCount);
}
@SideOnly(Side.CLIENT)
public ContainerHorseChest(ITextComponent inventoryTitle, int slotCount)
{
super(inventoryTitle, slotCount);
}
}

View File

@@ -0,0 +1,164 @@
package net.minecraft.inventory;
import net.minecraft.entity.passive.AbstractChestHorse;
import net.minecraft.entity.passive.AbstractHorse;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerHorseInventory extends Container
{
private final IInventory horseInventory;
private final AbstractHorse horse;
public ContainerHorseInventory(IInventory playerInventory, IInventory horseInventoryIn, final AbstractHorse horse, EntityPlayer player)
{
this.horseInventory = horseInventoryIn;
this.horse = horse;
int i = 3;
horseInventoryIn.openInventory(player);
int j = -18;
this.addSlotToContainer(new Slot(horseInventoryIn, 0, 8, 18)
{
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return stack.getItem() == Items.SADDLE && !this.getHasStack() && horse.canBeSaddled();
}
/**
* Actualy only call when we want to render the white square effect over the slots. Return always True,
* except for the armor slot of the Donkey/Mule (we can't interact with the Undead and Skeleton horses)
*/
@SideOnly(Side.CLIENT)
public boolean isEnabled()
{
return horse.canBeSaddled();
}
});
this.addSlotToContainer(new Slot(horseInventoryIn, 1, 8, 36)
{
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return horse.isArmor(stack);
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in
* the case of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
/**
* Actualy only call when we want to render the white square effect over the slots. Return always True,
* except for the armor slot of the Donkey/Mule (we can't interact with the Undead and Skeleton horses)
*/
@SideOnly(Side.CLIENT)
public boolean isEnabled()
{
return horse.wearsArmor();
}
});
if (horse instanceof AbstractChestHorse && ((AbstractChestHorse)horse).hasChest())
{
for (int k = 0; k < 3; ++k)
{
for (int l = 0; l < ((AbstractChestHorse)horse).getInventoryColumns(); ++l)
{
this.addSlotToContainer(new Slot(horseInventoryIn, 2 + l + k * ((AbstractChestHorse)horse).getInventoryColumns(), 80 + l * 18, 18 + k * 18));
}
}
}
for (int i1 = 0; i1 < 3; ++i1)
{
for (int k1 = 0; k1 < 9; ++k1)
{
this.addSlotToContainer(new Slot(playerInventory, k1 + i1 * 9 + 9, 8 + k1 * 18, 102 + i1 * 18 + -18));
}
}
for (int j1 = 0; j1 < 9; ++j1)
{
this.addSlotToContainer(new Slot(playerInventory, j1, 8 + j1 * 18, 142));
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.horseInventory.isUsableByPlayer(playerIn) && this.horse.isEntityAlive() && this.horse.getDistance(playerIn) < 8.0F;
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index < this.horseInventory.getSizeInventory())
{
if (!this.mergeItemStack(itemstack1, this.horseInventory.getSizeInventory(), this.inventorySlots.size(), true))
{
return ItemStack.EMPTY;
}
}
else if (this.getSlot(1).isItemValid(itemstack1) && !this.getSlot(1).getHasStack())
{
if (!this.mergeItemStack(itemstack1, 1, 2, false))
{
return ItemStack.EMPTY;
}
}
else if (this.getSlot(0).isItemValid(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return ItemStack.EMPTY;
}
}
else if (this.horseInventory.getSizeInventory() <= 2 || !this.mergeItemStack(itemstack1, 2, this.horseInventory.getSizeInventory(), false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
}
return itemstack;
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
this.horseInventory.closeInventory(playerIn);
}
}

View File

@@ -0,0 +1,155 @@
package net.minecraft.inventory;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ContainerMerchant extends Container
{
/** Instance of Merchant. */
private final IMerchant merchant;
private final InventoryMerchant merchantInventory;
/** Instance of World. */
private final World world;
public ContainerMerchant(InventoryPlayer playerInventory, IMerchant merchant, World worldIn)
{
this.merchant = merchant;
this.world = worldIn;
this.merchantInventory = new InventoryMerchant(playerInventory.player, merchant);
this.addSlotToContainer(new Slot(this.merchantInventory, 0, 36, 53));
this.addSlotToContainer(new Slot(this.merchantInventory, 1, 62, 53));
this.addSlotToContainer(new SlotMerchantResult(playerInventory.player, merchant, this.merchantInventory, 2, 120, 53));
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
}
}
public InventoryMerchant getMerchantInventory()
{
return this.merchantInventory;
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory inventoryIn)
{
this.merchantInventory.resetRecipeAndSlots();
super.onCraftMatrixChanged(inventoryIn);
}
public void setCurrentRecipeIndex(int currentRecipeIndex)
{
this.merchantInventory.setCurrentRecipeIndex(currentRecipeIndex);
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.merchant.getCustomer() == playerIn;
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index != 0 && index != 1)
{
if (index >= 3 && index < 30)
{
if (!this.mergeItemStack(itemstack1, 30, 39, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
this.merchant.setCustomer((EntityPlayer)null);
super.onContainerClosed(playerIn);
if (!this.world.isRemote)
{
ItemStack itemstack = this.merchantInventory.removeStackFromSlot(0);
if (!itemstack.isEmpty())
{
playerIn.dropItem(itemstack, false);
}
itemstack = this.merchantInventory.removeStackFromSlot(1);
if (!itemstack.isEmpty())
{
playerIn.dropItem(itemstack, false);
}
}
}
}

View File

@@ -0,0 +1,235 @@
package net.minecraft.inventory;
import javax.annotation.Nullable;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerPlayer extends Container
{
private static final EntityEquipmentSlot[] VALID_EQUIPMENT_SLOTS = new EntityEquipmentSlot[] {EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET};
/** The crafting matrix inventory. */
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
public InventoryCraftResult craftResult = new InventoryCraftResult();
/** Determines if inventory manipulation should be handled. */
public boolean isLocalWorld;
private final EntityPlayer player;
public ContainerPlayer(InventoryPlayer playerInventory, boolean localWorld, EntityPlayer playerIn)
{
this.isLocalWorld = localWorld;
this.player = playerIn;
this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 154, 28));
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 2; ++j)
{
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 98 + j * 18, 18 + i * 18));
}
}
for (int k = 0; k < 4; ++k)
{
final EntityEquipmentSlot entityequipmentslot = VALID_EQUIPMENT_SLOTS[k];
this.addSlotToContainer(new Slot(playerInventory, 36 + (3 - k), 8, 8 + k * 18)
{
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1
* in the case of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace
* fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return stack.getItem().isValidArmor(stack, entityequipmentslot, player);
}
/**
* Return whether this slot's stack can be taken from this slot.
*/
public boolean canTakeStack(EntityPlayer playerIn)
{
ItemStack itemstack = this.getStack();
return !itemstack.isEmpty() && !playerIn.isCreative() && EnchantmentHelper.hasBindingCurse(itemstack) ? false : super.canTakeStack(playerIn);
}
@Nullable
@SideOnly(Side.CLIENT)
public String getSlotTexture()
{
return ItemArmor.EMPTY_SLOT_NAMES[entityequipmentslot.getIndex()];
}
});
}
for (int l = 0; l < 3; ++l)
{
for (int j1 = 0; j1 < 9; ++j1)
{
this.addSlotToContainer(new Slot(playerInventory, j1 + (l + 1) * 9, 8 + j1 * 18, 84 + l * 18));
}
}
for (int i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 142));
}
this.addSlotToContainer(new Slot(playerInventory, 40, 77, 62)
{
@Nullable
@SideOnly(Side.CLIENT)
public String getSlotTexture()
{
return "minecraft:items/empty_armor_slot_shield";
}
});
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory inventoryIn)
{
this.slotChangedCraftingGrid(this.player.world, this.player, this.craftMatrix, this.craftResult);
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
this.craftResult.clear();
if (!playerIn.world.isRemote)
{
this.clearContainer(playerIn, playerIn.world, this.craftMatrix);
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return true;
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack);
if (index == 0)
{
if (!this.mergeItemStack(itemstack1, 9, 45, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index >= 1 && index < 5)
{
if (!this.mergeItemStack(itemstack1, 9, 45, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 5 && index < 9)
{
if (!this.mergeItemStack(itemstack1, 9, 45, false))
{
return ItemStack.EMPTY;
}
}
else if (entityequipmentslot.getSlotType() == EntityEquipmentSlot.Type.ARMOR && !((Slot)this.inventorySlots.get(8 - entityequipmentslot.getIndex())).getHasStack())
{
int i = 8 - entityequipmentslot.getIndex();
if (!this.mergeItemStack(itemstack1, i, i + 1, false))
{
return ItemStack.EMPTY;
}
}
else if (entityequipmentslot == EntityEquipmentSlot.OFFHAND && !((Slot)this.inventorySlots.get(45)).getHasStack())
{
if (!this.mergeItemStack(itemstack1, 45, 46, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 9 && index < 36)
{
if (!this.mergeItemStack(itemstack1, 36, 45, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 36 && index < 45)
{
if (!this.mergeItemStack(itemstack1, 9, 36, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 9, 45, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);
if (index == 0)
{
playerIn.dropItem(itemstack2, false);
}
}
return itemstack;
}
/**
* Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in
* is null for the initial slot that was double-clicked.
*/
public boolean canMergeSlot(ItemStack stack, Slot slotIn)
{
return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn);
}
}

View File

@@ -0,0 +1,508 @@
package net.minecraft.inventory;
import java.util.Map;
import net.minecraft.block.BlockAnvil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ContainerRepair extends Container
{
private static final Logger LOGGER = LogManager.getLogger();
/** Here comes out item you merged and/or renamed. */
private final IInventory outputSlot;
/** The 2slots where you put your items in that you want to merge and/or rename. */
private final IInventory inputSlots;
private final World world;
private final BlockPos selfPosition;
/** The maximum cost of repairing/renaming in the anvil. */
public int maximumCost;
/** determined by damage of input item and stackSize of repair materials */
public int materialCost;
private String repairedItemName;
/** The player that has this container open. */
private final EntityPlayer player;
@SideOnly(Side.CLIENT)
public ContainerRepair(InventoryPlayer playerInventory, World worldIn, EntityPlayer player)
{
this(playerInventory, worldIn, BlockPos.ORIGIN, player);
}
public ContainerRepair(InventoryPlayer playerInventory, final World worldIn, final BlockPos blockPosIn, EntityPlayer player)
{
this.outputSlot = new InventoryCraftResult();
this.inputSlots = new InventoryBasic("Repair", true, 2)
{
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't
* think it hasn't changed and skip it.
*/
public void markDirty()
{
super.markDirty();
ContainerRepair.this.onCraftMatrixChanged(this);
}
};
this.selfPosition = blockPosIn;
this.world = worldIn;
this.player = player;
this.addSlotToContainer(new Slot(this.inputSlots, 0, 27, 47));
this.addSlotToContainer(new Slot(this.inputSlots, 1, 76, 47));
this.addSlotToContainer(new Slot(this.outputSlot, 2, 134, 47)
{
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return false;
}
/**
* Return whether this slot's stack can be taken from this slot.
*/
public boolean canTakeStack(EntityPlayer playerIn)
{
return (playerIn.capabilities.isCreativeMode || playerIn.experienceLevel >= ContainerRepair.this.maximumCost) && ContainerRepair.this.maximumCost > 0 && this.getHasStack();
}
public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
{
if (!thePlayer.capabilities.isCreativeMode)
{
thePlayer.addExperienceLevel(-ContainerRepair.this.maximumCost);
}
float breakChance = net.minecraftforge.common.ForgeHooks.onAnvilRepair(thePlayer, stack, ContainerRepair.this.inputSlots.getStackInSlot(0), ContainerRepair.this.inputSlots.getStackInSlot(1));
ContainerRepair.this.inputSlots.setInventorySlotContents(0, ItemStack.EMPTY);
if (ContainerRepair.this.materialCost > 0)
{
ItemStack itemstack = ContainerRepair.this.inputSlots.getStackInSlot(1);
if (!itemstack.isEmpty() && itemstack.getCount() > ContainerRepair.this.materialCost)
{
itemstack.shrink(ContainerRepair.this.materialCost);
ContainerRepair.this.inputSlots.setInventorySlotContents(1, itemstack);
}
else
{
ContainerRepair.this.inputSlots.setInventorySlotContents(1, ItemStack.EMPTY);
}
}
else
{
ContainerRepair.this.inputSlots.setInventorySlotContents(1, ItemStack.EMPTY);
}
ContainerRepair.this.maximumCost = 0;
IBlockState iblockstate = worldIn.getBlockState(blockPosIn);
if (!thePlayer.capabilities.isCreativeMode && !worldIn.isRemote && iblockstate.getBlock() == Blocks.ANVIL && thePlayer.getRNG().nextFloat() < breakChance)
{
int l = ((Integer)iblockstate.getValue(BlockAnvil.DAMAGE)).intValue();
++l;
if (l > 2)
{
worldIn.setBlockToAir(blockPosIn);
worldIn.playEvent(1029, blockPosIn, 0);
}
else
{
worldIn.setBlockState(blockPosIn, iblockstate.withProperty(BlockAnvil.DAMAGE, Integer.valueOf(l)), 2);
worldIn.playEvent(1030, blockPosIn, 0);
}
}
else if (!worldIn.isRemote)
{
worldIn.playEvent(1030, blockPosIn, 0);
}
return stack;
}
});
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
}
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory inventoryIn)
{
super.onCraftMatrixChanged(inventoryIn);
if (inventoryIn == this.inputSlots)
{
this.updateRepairOutput();
}
}
/**
* called when the Anvil Input Slot changes, calculates the new result and puts it in the output slot
*/
public void updateRepairOutput()
{
ItemStack itemstack = this.inputSlots.getStackInSlot(0);
this.maximumCost = 1;
int i = 0;
int j = 0;
int k = 0;
if (itemstack.isEmpty())
{
this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY);
this.maximumCost = 0;
}
else
{
ItemStack itemstack1 = itemstack.copy();
ItemStack itemstack2 = this.inputSlots.getStackInSlot(1);
Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(itemstack1);
j = j + itemstack.getRepairCost() + (itemstack2.isEmpty() ? 0 : itemstack2.getRepairCost());
this.materialCost = 0;
boolean flag = false;
if (!itemstack2.isEmpty())
{
if (!net.minecraftforge.common.ForgeHooks.onAnvilChange(this, itemstack, itemstack2, outputSlot, repairedItemName, j)) return;
flag = itemstack2.getItem() == Items.ENCHANTED_BOOK && !ItemEnchantedBook.getEnchantments(itemstack2).hasNoTags();
if (itemstack1.isItemStackDamageable() && itemstack1.getItem().getIsRepairable(itemstack, itemstack2))
{
int l2 = Math.min(itemstack1.getItemDamage(), itemstack1.getMaxDamage() / 4);
if (l2 <= 0)
{
this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY);
this.maximumCost = 0;
return;
}
int i3;
for (i3 = 0; l2 > 0 && i3 < itemstack2.getCount(); ++i3)
{
int j3 = itemstack1.getItemDamage() - l2;
itemstack1.setItemDamage(j3);
++i;
l2 = Math.min(itemstack1.getItemDamage(), itemstack1.getMaxDamage() / 4);
}
this.materialCost = i3;
}
else
{
if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.isItemStackDamageable()))
{
this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY);
this.maximumCost = 0;
return;
}
if (itemstack1.isItemStackDamageable() && !flag)
{
int l = itemstack.getMaxDamage() - itemstack.getItemDamage();
int i1 = itemstack2.getMaxDamage() - itemstack2.getItemDamage();
int j1 = i1 + itemstack1.getMaxDamage() * 12 / 100;
int k1 = l + j1;
int l1 = itemstack1.getMaxDamage() - k1;
if (l1 < 0)
{
l1 = 0;
}
if (l1 < itemstack1.getItemDamage()) // vanilla uses metadata here instead of damage.
{
itemstack1.setItemDamage(l1);
i += 2;
}
}
Map<Enchantment, Integer> map1 = EnchantmentHelper.getEnchantments(itemstack2);
boolean flag2 = false;
boolean flag3 = false;
for (Enchantment enchantment1 : map1.keySet())
{
if (enchantment1 != null)
{
int i2 = map.containsKey(enchantment1) ? ((Integer)map.get(enchantment1)).intValue() : 0;
int j2 = ((Integer)map1.get(enchantment1)).intValue();
j2 = i2 == j2 ? j2 + 1 : Math.max(j2, i2);
boolean flag1 = enchantment1.canApply(itemstack);
if (this.player.capabilities.isCreativeMode || itemstack.getItem() == Items.ENCHANTED_BOOK)
{
flag1 = true;
}
for (Enchantment enchantment : map.keySet())
{
if (enchantment != enchantment1 && !enchantment1.isCompatibleWith(enchantment))
{
flag1 = false;
++i;
}
}
if (!flag1)
{
flag3 = true;
}
else
{
flag2 = true;
if (j2 > enchantment1.getMaxLevel())
{
j2 = enchantment1.getMaxLevel();
}
map.put(enchantment1, Integer.valueOf(j2));
int k3 = 0;
switch (enchantment1.getRarity())
{
case COMMON:
k3 = 1;
break;
case UNCOMMON:
k3 = 2;
break;
case RARE:
k3 = 4;
break;
case VERY_RARE:
k3 = 8;
}
if (flag)
{
k3 = Math.max(1, k3 / 2);
}
i += k3 * j2;
if (itemstack.getCount() > 1)
{
i = 40;
}
}
}
}
if (flag3 && !flag2)
{
this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY);
this.maximumCost = 0;
return;
}
}
}
if (StringUtils.isBlank(this.repairedItemName))
{
if (itemstack.hasDisplayName())
{
k = 1;
i += k;
itemstack1.clearCustomName();
}
}
else if (!this.repairedItemName.equals(itemstack.getDisplayName()))
{
k = 1;
i += k;
itemstack1.setStackDisplayName(this.repairedItemName);
}
if (flag && !itemstack1.getItem().isBookEnchantable(itemstack1, itemstack2)) itemstack1 = ItemStack.EMPTY;
this.maximumCost = j + i;
if (i <= 0)
{
itemstack1 = ItemStack.EMPTY;
}
if (k == i && k > 0 && this.maximumCost >= 40)
{
this.maximumCost = 39;
}
if (this.maximumCost >= 40 && !this.player.capabilities.isCreativeMode)
{
itemstack1 = ItemStack.EMPTY;
}
if (!itemstack1.isEmpty())
{
int k2 = itemstack1.getRepairCost();
if (!itemstack2.isEmpty() && k2 < itemstack2.getRepairCost())
{
k2 = itemstack2.getRepairCost();
}
if (k != i || k == 0)
{
k2 = k2 * 2 + 1;
}
itemstack1.setRepairCost(k2);
EnchantmentHelper.setEnchantments(map, itemstack1);
}
this.outputSlot.setInventorySlotContents(0, itemstack1);
this.detectAndSendChanges();
}
}
public void addListener(IContainerListener listener)
{
super.addListener(listener);
listener.sendWindowProperty(this, 0, this.maximumCost);
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
if (id == 0)
{
this.maximumCost = data;
}
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
if (!this.world.isRemote)
{
this.clearContainer(playerIn, this.world, this.inputSlots);
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
if (this.world.getBlockState(this.selfPosition).getBlock() != Blocks.ANVIL)
{
return false;
}
else
{
return playerIn.getDistanceSq((double)this.selfPosition.getX() + 0.5D, (double)this.selfPosition.getY() + 0.5D, (double)this.selfPosition.getZ() + 0.5D) <= 64.0D;
}
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index != 0 && index != 1)
{
if (index >= 3 && index < 39 && !this.mergeItemStack(itemstack1, 0, 2, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
/**
* used by the Anvil GUI to update the Item Name being typed by the player
*/
public void updateItemName(String newName)
{
this.repairedItemName = newName;
if (this.getSlot(2).getHasStack())
{
ItemStack itemstack = this.getSlot(2).getStack();
if (StringUtils.isBlank(newName))
{
itemstack.clearCustomName();
}
else
{
itemstack.setStackDisplayName(this.repairedItemName);
}
}
this.updateRepairOutput();
}
}

View File

@@ -0,0 +1,95 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public class ContainerShulkerBox extends Container
{
private final IInventory inventory;
public ContainerShulkerBox(InventoryPlayer p_i47266_1_, IInventory p_i47266_2_, EntityPlayer p_i47266_3_)
{
this.inventory = p_i47266_2_;
p_i47266_2_.openInventory(p_i47266_3_);
int i = 3;
int j = 9;
for (int k = 0; k < 3; ++k)
{
for (int l = 0; l < 9; ++l)
{
this.addSlotToContainer(new SlotShulkerBox(p_i47266_2_, l + k * 9, 8 + l * 18, 18 + k * 18));
}
}
for (int i1 = 0; i1 < 3; ++i1)
{
for (int k1 = 0; k1 < 9; ++k1)
{
this.addSlotToContainer(new Slot(p_i47266_1_, k1 + i1 * 9 + 9, 8 + k1 * 18, 84 + i1 * 18));
}
}
for (int j1 = 0; j1 < 9; ++j1)
{
this.addSlotToContainer(new Slot(p_i47266_1_, j1, 8 + j1 * 18, 142));
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
return this.inventory.isUsableByPlayer(playerIn);
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index < this.inventory.getSizeInventory())
{
if (!this.mergeItemStack(itemstack1, this.inventory.getSizeInventory(), this.inventorySlots.size(), true))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 0, this.inventory.getSizeInventory(), false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
}
return itemstack;
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
this.inventory.closeInventory(playerIn);
}
}

View File

@@ -0,0 +1,162 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ContainerWorkbench extends Container
{
/** The crafting matrix inventory (3x3). */
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
public InventoryCraftResult craftResult = new InventoryCraftResult();
private final World world;
/** Position of the workbench */
private final BlockPos pos;
private final EntityPlayer player;
public ContainerWorkbench(InventoryPlayer playerInventory, World worldIn, BlockPos posIn)
{
this.world = worldIn;
this.pos = posIn;
this.player = playerInventory.player;
this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35));
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18));
}
}
for (int k = 0; k < 3; ++k)
{
for (int i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
}
}
for (int l = 0; l < 9; ++l)
{
this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
}
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory inventoryIn)
{
this.slotChangedCraftingGrid(this.world, this.player, this.craftMatrix, this.craftResult);
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer playerIn)
{
super.onContainerClosed(playerIn);
if (!this.world.isRemote)
{
this.clearContainer(playerIn, this.world, this.craftMatrix);
}
}
/**
* Determines whether supplied player can use this container
*/
public boolean canInteractWith(EntityPlayer playerIn)
{
if (this.world.getBlockState(this.pos).getBlock() != Blocks.CRAFTING_TABLE)
{
return false;
}
else
{
return playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
}
/**
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
* inventory and the other inventory(s).
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 0)
{
itemstack1.getItem().onCreated(itemstack1, this.world, playerIn);
if (!this.mergeItemStack(itemstack1, 10, 46, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index >= 10 && index < 37)
{
if (!this.mergeItemStack(itemstack1, 37, 46, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 37 && index < 46)
{
if (!this.mergeItemStack(itemstack1, 10, 37, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 10, 46, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);
if (index == 0)
{
playerIn.dropItem(itemstack2, false);
}
}
return itemstack;
}
/**
* Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in
* is null for the initial slot that was double-clicked.
*/
public boolean canMergeSlot(ItemStack stack, Slot slotIn)
{
return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn);
}
}

View File

@@ -0,0 +1,65 @@
package net.minecraft.inventory;
public enum EntityEquipmentSlot
{
MAINHAND(EntityEquipmentSlot.Type.HAND, 0, 0, "mainhand"),
OFFHAND(EntityEquipmentSlot.Type.HAND, 1, 5, "offhand"),
FEET(EntityEquipmentSlot.Type.ARMOR, 0, 1, "feet"),
LEGS(EntityEquipmentSlot.Type.ARMOR, 1, 2, "legs"),
CHEST(EntityEquipmentSlot.Type.ARMOR, 2, 3, "chest"),
HEAD(EntityEquipmentSlot.Type.ARMOR, 3, 4, "head");
private final EntityEquipmentSlot.Type slotType;
private final int index;
private final int slotIndex;
private final String name;
private EntityEquipmentSlot(EntityEquipmentSlot.Type slotTypeIn, int indexIn, int slotIndexIn, String nameIn)
{
this.slotType = slotTypeIn;
this.index = indexIn;
this.slotIndex = slotIndexIn;
this.name = nameIn;
}
public EntityEquipmentSlot.Type getSlotType()
{
return this.slotType;
}
public int getIndex()
{
return this.index;
}
/**
* Gets the actual slot index.
*/
public int getSlotIndex()
{
return this.slotIndex;
}
public String getName()
{
return this.name;
}
public static EntityEquipmentSlot fromString(String targetName)
{
for (EntityEquipmentSlot entityequipmentslot : values())
{
if (entityequipmentslot.getName().equals(targetName))
{
return entityequipmentslot;
}
}
throw new IllegalArgumentException("Invalid slot '" + targetName + "'");
}
public static enum Type {
HAND,
ARMOR;
}
}

View File

@@ -0,0 +1,27 @@
package net.minecraft.inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
public interface IContainerListener
{
/**
* update the crafting window inventory with the items in the list
*/
void sendAllContents(Container containerToSend, NonNullList<ItemStack> itemsList);
/**
* Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
* contents of that slot.
*/
void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack);
/**
* Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress,
* and enchanting level. Normally the first int identifies which variable to update, and the second contains the new
* value. Both are truncated to shorts in non-local SMP.
*/
void sendWindowProperty(Container containerIn, int varToUpdate, int newValue);
void sendAllWindowProperties(Container containerIn, IInventory inventory);
}

View File

@@ -0,0 +1,69 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.IWorldNameable;
public interface IInventory extends IWorldNameable
{
/**
* Returns the number of slots in the inventory.
*/
int getSizeInventory();
boolean isEmpty();
/**
* Returns the stack in the given slot.
*/
ItemStack getStackInSlot(int index);
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
ItemStack decrStackSize(int index, int count);
/**
* Removes a stack from the given slot and returns it.
*/
ItemStack removeStackFromSlot(int index);
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
void setInventorySlotContents(int index, ItemStack stack);
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
int getInventoryStackLimit();
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
* hasn't changed and skip it.
*/
void markDirty();
/**
* Don't rename this method to canInteractWith due to conflicts with Container
*/
boolean isUsableByPlayer(EntityPlayer player);
void openInventory(EntityPlayer player);
void closeInventory(EntityPlayer player);
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. For
* guis use Slot.isItemValid
*/
boolean isItemValidForSlot(int index, ItemStack stack);
int getField(int id);
void setField(int id, int value);
int getFieldCount();
void clear();
}

View File

@@ -0,0 +1,9 @@
package net.minecraft.inventory;
public interface IInventoryChangedListener
{
/**
* Called by InventoryBasic.onInventoryChanged() on a array that is never filled.
*/
void onInventoryChanged(IInventory invBasic);
}

View File

@@ -0,0 +1,19 @@
package net.minecraft.inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
public interface ISidedInventory extends IInventory
{
int[] getSlotsForFace(EnumFacing side);
/**
* Returns true if automation can insert the given item in the given slot from the given side.
*/
boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction);
/**
* Returns true if automation can extract the given item in the given slot from the given side.
*/
boolean canExtractItem(int index, ItemStack stack, EnumFacing direction);
}

View File

@@ -0,0 +1,276 @@
package net.minecraft.inventory;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class InventoryBasic implements IInventory
{
private String inventoryTitle;
private final int slotsCount;
private final NonNullList<ItemStack> inventoryContents;
/** Listeners notified when any item in this inventory is changed. */
private List<IInventoryChangedListener> changeListeners;
private boolean hasCustomName;
public InventoryBasic(String title, boolean customName, int slotCount)
{
this.inventoryTitle = title;
this.hasCustomName = customName;
this.slotsCount = slotCount;
this.inventoryContents = NonNullList.<ItemStack>withSize(slotCount, ItemStack.EMPTY);
}
@SideOnly(Side.CLIENT)
public InventoryBasic(ITextComponent title, int slotCount)
{
this(title.getUnformattedText(), true, slotCount);
}
/**
* Add a listener that will be notified when any item in this inventory is modified.
*/
public void addInventoryChangeListener(IInventoryChangedListener listener)
{
if (this.changeListeners == null)
{
this.changeListeners = Lists.<IInventoryChangedListener>newArrayList();
}
this.changeListeners.add(listener);
}
/**
* removes the specified IInvBasic from receiving further change notices
*/
public void removeInventoryChangeListener(IInventoryChangedListener listener)
{
this.changeListeners.remove(listener);
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return index >= 0 && index < this.inventoryContents.size() ? (ItemStack)this.inventoryContents.get(index) : ItemStack.EMPTY;
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
ItemStack itemstack = ItemStackHelper.getAndSplit(this.inventoryContents, index, count);
if (!itemstack.isEmpty())
{
this.markDirty();
}
return itemstack;
}
public ItemStack addItem(ItemStack stack)
{
ItemStack itemstack = stack.copy();
for (int i = 0; i < this.slotsCount; ++i)
{
ItemStack itemstack1 = this.getStackInSlot(i);
if (itemstack1.isEmpty())
{
this.setInventorySlotContents(i, itemstack);
this.markDirty();
return ItemStack.EMPTY;
}
if (ItemStack.areItemsEqual(itemstack1, itemstack))
{
int j = Math.min(this.getInventoryStackLimit(), itemstack1.getMaxStackSize());
int k = Math.min(itemstack.getCount(), j - itemstack1.getCount());
if (k > 0)
{
itemstack1.grow(k);
itemstack.shrink(k);
if (itemstack.isEmpty())
{
this.markDirty();
return ItemStack.EMPTY;
}
}
}
}
if (itemstack.getCount() != stack.getCount())
{
this.markDirty();
}
return itemstack;
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
ItemStack itemstack = this.inventoryContents.get(index);
if (itemstack.isEmpty())
{
return ItemStack.EMPTY;
}
else
{
this.inventoryContents.set(index, ItemStack.EMPTY);
return itemstack;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
this.inventoryContents.set(index, stack);
if (!stack.isEmpty() && stack.getCount() > this.getInventoryStackLimit())
{
stack.setCount(this.getInventoryStackLimit());
}
this.markDirty();
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.slotsCount;
}
public boolean isEmpty()
{
for (ItemStack itemstack : this.inventoryContents)
{
if (!itemstack.isEmpty())
{
return false;
}
}
return true;
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.inventoryTitle;
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.hasCustomName;
}
/**
* Sets the name of this inventory. This is displayed to the client on opening.
*/
public void setCustomName(String inventoryTitleIn)
{
this.hasCustomName = true;
this.inventoryTitle = inventoryTitleIn;
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public ITextComponent getDisplayName()
{
return (ITextComponent)(this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName(), new Object[0]));
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
* hasn't changed and skip it.
*/
public void markDirty()
{
if (this.changeListeners != null)
{
for (int i = 0; i < this.changeListeners.size(); ++i)
{
((IInventoryChangedListener)this.changeListeners.get(i)).onInventoryChanged(this);
}
}
}
/**
* Don't rename this method to canInteractWith due to conflicts with Container
*/
public boolean isUsableByPlayer(EntityPlayer player)
{
return true;
}
public void openInventory(EntityPlayer player)
{
}
public void closeInventory(EntityPlayer player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. For
* guis use Slot.isItemValid
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
public int getField(int id)
{
return 0;
}
public void setField(int id, int value)
{
}
public int getFieldCount()
{
return 0;
}
public void clear()
{
this.inventoryContents.clear();
}
}

View File

@@ -0,0 +1,165 @@
package net.minecraft.inventory;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
public class InventoryCraftResult implements IInventory
{
/** A list of one item containing the result of the crafting formula */
private final NonNullList<ItemStack> stackResult = NonNullList.<ItemStack>withSize(1, ItemStack.EMPTY);
private IRecipe recipeUsed;
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return 1;
}
public boolean isEmpty()
{
for (ItemStack itemstack : this.stackResult)
{
if (!itemstack.isEmpty())
{
return false;
}
}
return true;
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return this.stackResult.get(0);
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return "Result";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return false;
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public ITextComponent getDisplayName()
{
return (ITextComponent)(this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName(), new Object[0]));
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
return ItemStackHelper.getAndRemove(this.stackResult, 0);
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
return ItemStackHelper.getAndRemove(this.stackResult, 0);
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
this.stackResult.set(0, stack);
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
* hasn't changed and skip it.
*/
public void markDirty()
{
}
/**
* Don't rename this method to canInteractWith due to conflicts with Container
*/
public boolean isUsableByPlayer(EntityPlayer player)
{
return true;
}
public void openInventory(EntityPlayer player)
{
}
public void closeInventory(EntityPlayer player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. For
* guis use Slot.isItemValid
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
public int getField(int id)
{
return 0;
}
public void setField(int id, int value)
{
}
public int getFieldCount()
{
return 0;
}
public void clear()
{
this.stackResult.clear();
}
public void setRecipeUsed(@Nullable IRecipe p_193056_1_)
{
this.recipeUsed = p_193056_1_;
}
@Nullable
public IRecipe getRecipeUsed()
{
return this.recipeUsed;
}
}

View File

@@ -0,0 +1,199 @@
package net.minecraft.inventory;
import net.minecraft.client.util.RecipeItemHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
public class InventoryCrafting implements IInventory
{
/** List of the stacks in the crafting matrix. */
private final NonNullList<ItemStack> stackList;
/** the width of the crafting inventory */
private final int inventoryWidth;
private final int inventoryHeight;
/** Class containing the callbacks for the events on_GUIClosed and on_CraftMaxtrixChanged. */
public final Container eventHandler;
public InventoryCrafting(Container eventHandlerIn, int width, int height)
{
this.stackList = NonNullList.<ItemStack>withSize(width * height, ItemStack.EMPTY);
this.eventHandler = eventHandlerIn;
this.inventoryWidth = width;
this.inventoryHeight = height;
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.stackList.size();
}
public boolean isEmpty()
{
for (ItemStack itemstack : this.stackList)
{
if (!itemstack.isEmpty())
{
return false;
}
}
return true;
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return index >= this.getSizeInventory() ? ItemStack.EMPTY : (ItemStack)this.stackList.get(index);
}
/**
* Gets the ItemStack in the slot specified.
*/
public ItemStack getStackInRowAndColumn(int row, int column)
{
return row >= 0 && row < this.inventoryWidth && column >= 0 && column <= this.inventoryHeight ? this.getStackInSlot(row + column * this.inventoryWidth) : ItemStack.EMPTY;
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return "container.crafting";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return false;
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public ITextComponent getDisplayName()
{
return (ITextComponent)(this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName(), new Object[0]));
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
return ItemStackHelper.getAndRemove(this.stackList, index);
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
ItemStack itemstack = ItemStackHelper.getAndSplit(this.stackList, index, count);
if (!itemstack.isEmpty())
{
this.eventHandler.onCraftMatrixChanged(this);
}
return itemstack;
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
this.stackList.set(index, stack);
this.eventHandler.onCraftMatrixChanged(this);
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
* hasn't changed and skip it.
*/
public void markDirty()
{
}
/**
* Don't rename this method to canInteractWith due to conflicts with Container
*/
public boolean isUsableByPlayer(EntityPlayer player)
{
return true;
}
public void openInventory(EntityPlayer player)
{
}
public void closeInventory(EntityPlayer player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. For
* guis use Slot.isItemValid
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
public int getField(int id)
{
return 0;
}
public void setField(int id, int value)
{
}
public int getFieldCount()
{
return 0;
}
public void clear()
{
this.stackList.clear();
}
public int getHeight()
{
return this.inventoryHeight;
}
public int getWidth()
{
return this.inventoryWidth;
}
public void fillStackedContents(RecipeItemHelper helper)
{
for (ItemStack itemstack : this.stackList)
{
helper.accountStack(itemstack);
}
}
}

View File

@@ -0,0 +1,90 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntityEnderChest;
public class InventoryEnderChest extends InventoryBasic
{
private TileEntityEnderChest associatedChest;
public InventoryEnderChest()
{
super("container.enderchest", false, 27);
}
public void setChestTileEntity(TileEntityEnderChest chestTileEntity)
{
this.associatedChest = chestTileEntity;
}
public void loadInventoryFromNBT(NBTTagList p_70486_1_)
{
for (int i = 0; i < this.getSizeInventory(); ++i)
{
this.setInventorySlotContents(i, ItemStack.EMPTY);
}
for (int k = 0; k < p_70486_1_.tagCount(); ++k)
{
NBTTagCompound nbttagcompound = p_70486_1_.getCompoundTagAt(k);
int j = nbttagcompound.getByte("Slot") & 255;
if (j >= 0 && j < this.getSizeInventory())
{
this.setInventorySlotContents(j, new ItemStack(nbttagcompound));
}
}
}
public NBTTagList saveInventoryToNBT()
{
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.getSizeInventory(); ++i)
{
ItemStack itemstack = this.getStackInSlot(i);
if (!itemstack.isEmpty())
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
itemstack.writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
return nbttaglist;
}
/**
* Don't rename this method to canInteractWith due to conflicts with Container
*/
public boolean isUsableByPlayer(EntityPlayer player)
{
return this.associatedChest != null && !this.associatedChest.canBeUsed(player) ? false : super.isUsableByPlayer(player);
}
public void openInventory(EntityPlayer player)
{
if (this.associatedChest != null)
{
this.associatedChest.openChest();
}
super.openInventory(player);
}
public void closeInventory(EntityPlayer player)
{
if (this.associatedChest != null)
{
this.associatedChest.closeChest();
}
super.closeInventory(player);
this.associatedChest = null;
}
}

View File

@@ -0,0 +1,53 @@
package net.minecraft.inventory;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class InventoryHelper
{
private static final Random RANDOM = new Random();
public static void dropInventoryItems(World worldIn, BlockPos pos, IInventory inventory)
{
dropInventoryItems(worldIn, (double)pos.getX(), (double)pos.getY(), (double)pos.getZ(), inventory);
}
public static void dropInventoryItems(World worldIn, Entity entityAt, IInventory inventory)
{
dropInventoryItems(worldIn, entityAt.posX, entityAt.posY, entityAt.posZ, inventory);
}
private static void dropInventoryItems(World worldIn, double x, double y, double z, IInventory inventory)
{
for (int i = 0; i < inventory.getSizeInventory(); ++i)
{
ItemStack itemstack = inventory.getStackInSlot(i);
if (!itemstack.isEmpty())
{
spawnItemStack(worldIn, x, y, z, itemstack);
}
}
}
public static void spawnItemStack(World worldIn, double x, double y, double z, ItemStack stack)
{
float f = RANDOM.nextFloat() * 0.8F + 0.1F;
float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;
while (!stack.isEmpty())
{
EntityItem entityitem = new EntityItem(worldIn, x + (double)f, y + (double)f1, z + (double)f2, stack.splitStack(RANDOM.nextInt(21) + 10));
float f3 = 0.05F;
entityitem.motionX = RANDOM.nextGaussian() * 0.05000000074505806D;
entityitem.motionY = RANDOM.nextGaussian() * 0.05000000074505806D + 0.20000000298023224D;
entityitem.motionZ = RANDOM.nextGaussian() * 0.05000000074505806D;
worldIn.spawnEntity(entityitem);
}
}
}

View File

@@ -0,0 +1,231 @@
package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.ILockableContainer;
import net.minecraft.world.LockCode;
public class InventoryLargeChest implements ILockableContainer
{
/** Name of the chest. */
private final String name;
/** Inventory object corresponding to double chest upper part */
private final ILockableContainer upperChest;
/** Inventory object corresponding to double chest lower part */
private final ILockableContainer lowerChest;
public InventoryLargeChest(String nameIn, ILockableContainer upperChestIn, ILockableContainer lowerChestIn)
{
this.name = nameIn;
if (upperChestIn == null)
{
upperChestIn = lowerChestIn;
}
if (lowerChestIn == null)
{
lowerChestIn = upperChestIn;
}
this.upperChest = upperChestIn;
this.lowerChest = lowerChestIn;
if (upperChestIn.isLocked())
{
lowerChestIn.setLockCode(upperChestIn.getLockCode());
}
else if (lowerChestIn.isLocked())
{
upperChestIn.setLockCode(lowerChestIn.getLockCode());
}
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.upperChest.getSizeInventory() + this.lowerChest.getSizeInventory();
}
public boolean isEmpty()
{
return this.upperChest.isEmpty() && this.lowerChest.isEmpty();
}
/**
* Return whether the given inventory is part of this large chest.
*/
public boolean isPartOfLargeChest(IInventory inventoryIn)
{
return this.upperChest == inventoryIn || this.lowerChest == inventoryIn;
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
if (this.upperChest.hasCustomName())
{
return this.upperChest.getName();
}
else
{
return this.lowerChest.hasCustomName() ? this.lowerChest.getName() : this.name;
}
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.upperChest.hasCustomName() || this.lowerChest.hasCustomName();
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public ITextComponent getDisplayName()
{
return (ITextComponent)(this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName(), new Object[0]));
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return index >= this.upperChest.getSizeInventory() ? this.lowerChest.getStackInSlot(index - this.upperChest.getSizeInventory()) : this.upperChest.getStackInSlot(index);
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
return index >= this.upperChest.getSizeInventory() ? this.lowerChest.decrStackSize(index - this.upperChest.getSizeInventory(), count) : this.upperChest.decrStackSize(index, count);
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
return index >= this.upperChest.getSizeInventory() ? this.lowerChest.removeStackFromSlot(index - this.upperChest.getSizeInventory()) : this.upperChest.removeStackFromSlot(index);
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
if (index >= this.upperChest.getSizeInventory())
{
this.lowerChest.setInventorySlotContents(index - this.upperChest.getSizeInventory(), stack);
}
else
{
this.upperChest.setInventorySlotContents(index, stack);
}
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return this.upperChest.getInventoryStackLimit();
}
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
* hasn't changed and skip it.
*/
public void markDirty()
{
this.upperChest.markDirty();
this.lowerChest.markDirty();
}
/**
* Don't rename this method to canInteractWith due to conflicts with Container
*/
public boolean isUsableByPlayer(EntityPlayer player)
{
return this.upperChest.isUsableByPlayer(player) && this.lowerChest.isUsableByPlayer(player);
}
public void openInventory(EntityPlayer player)
{
this.upperChest.openInventory(player);
this.lowerChest.openInventory(player);
}
public void closeInventory(EntityPlayer player)
{
this.upperChest.closeInventory(player);
this.lowerChest.closeInventory(player);
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. For
* guis use Slot.isItemValid
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
public int getField(int id)
{
return 0;
}
public void setField(int id, int value)
{
}
public int getFieldCount()
{
return 0;
}
public boolean isLocked()
{
return this.upperChest.isLocked() || this.lowerChest.isLocked();
}
public void setLockCode(LockCode code)
{
this.upperChest.setLockCode(code);
this.lowerChest.setLockCode(code);
}
public LockCode getLockCode()
{
return this.upperChest.getLockCode();
}
public String getGuiID()
{
return this.upperChest.getGuiID();
}
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{
return new ContainerChest(playerInventory, this, playerIn);
}
public void clear()
{
this.upperChest.clear();
this.lowerChest.clear();
}
}

View File

@@ -0,0 +1,262 @@
package net.minecraft.inventory;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
public class InventoryMerchant implements IInventory
{
private final IMerchant merchant;
private final NonNullList<ItemStack> slots = NonNullList.<ItemStack>withSize(3, ItemStack.EMPTY);
private final EntityPlayer player;
private MerchantRecipe currentRecipe;
private int currentRecipeIndex;
public InventoryMerchant(EntityPlayer thePlayerIn, IMerchant theMerchantIn)
{
this.player = thePlayerIn;
this.merchant = theMerchantIn;
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.slots.size();
}
public boolean isEmpty()
{
for (ItemStack itemstack : this.slots)
{
if (!itemstack.isEmpty())
{
return false;
}
}
return true;
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return this.slots.get(index);
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
ItemStack itemstack = this.slots.get(index);
if (index == 2 && !itemstack.isEmpty())
{
return ItemStackHelper.getAndSplit(this.slots, index, itemstack.getCount());
}
else
{
ItemStack itemstack1 = ItemStackHelper.getAndSplit(this.slots, index, count);
if (!itemstack1.isEmpty() && this.inventoryResetNeededOnSlotChange(index))
{
this.resetRecipeAndSlots();
}
return itemstack1;
}
}
/**
* if par1 slot has changed, does resetRecipeAndSlots need to be called?
*/
private boolean inventoryResetNeededOnSlotChange(int slotIn)
{
return slotIn == 0 || slotIn == 1;
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
return ItemStackHelper.getAndRemove(this.slots, index);
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
this.slots.set(index, stack);
if (!stack.isEmpty() && stack.getCount() > this.getInventoryStackLimit())
{
stack.setCount(this.getInventoryStackLimit());
}
if (this.inventoryResetNeededOnSlotChange(index))
{
this.resetRecipeAndSlots();
}
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return "mob.villager";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return false;
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public ITextComponent getDisplayName()
{
return (ITextComponent)(this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName(), new Object[0]));
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
* Don't rename this method to canInteractWith due to conflicts with Container
*/
public boolean isUsableByPlayer(EntityPlayer player)
{
return this.merchant.getCustomer() == player;
}
public void openInventory(EntityPlayer player)
{
}
public void closeInventory(EntityPlayer player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. For
* guis use Slot.isItemValid
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
* hasn't changed and skip it.
*/
public void markDirty()
{
this.resetRecipeAndSlots();
}
public void resetRecipeAndSlots()
{
this.currentRecipe = null;
ItemStack itemstack = this.slots.get(0);
ItemStack itemstack1 = this.slots.get(1);
if (itemstack.isEmpty())
{
itemstack = itemstack1;
itemstack1 = ItemStack.EMPTY;
}
if (itemstack.isEmpty())
{
this.setInventorySlotContents(2, ItemStack.EMPTY);
}
else
{
MerchantRecipeList merchantrecipelist = this.merchant.getRecipes(this.player);
if (merchantrecipelist != null)
{
MerchantRecipe merchantrecipe = merchantrecipelist.canRecipeBeUsed(itemstack, itemstack1, this.currentRecipeIndex);
if (merchantrecipe != null && !merchantrecipe.isRecipeDisabled())
{
this.currentRecipe = merchantrecipe;
this.setInventorySlotContents(2, merchantrecipe.getItemToSell().copy());
}
else if (!itemstack1.isEmpty())
{
merchantrecipe = merchantrecipelist.canRecipeBeUsed(itemstack1, itemstack, this.currentRecipeIndex);
if (merchantrecipe != null && !merchantrecipe.isRecipeDisabled())
{
this.currentRecipe = merchantrecipe;
this.setInventorySlotContents(2, merchantrecipe.getItemToSell().copy());
}
else
{
this.setInventorySlotContents(2, ItemStack.EMPTY);
}
}
else
{
this.setInventorySlotContents(2, ItemStack.EMPTY);
}
}
this.merchant.verifySellingItem(this.getStackInSlot(2));
}
}
public MerchantRecipe getCurrentRecipe()
{
return this.currentRecipe;
}
public void setCurrentRecipeIndex(int currentRecipeIndexIn)
{
this.currentRecipeIndex = currentRecipeIndexIn;
this.resetRecipeAndSlots();
}
public int getField(int id)
{
return 0;
}
public void setField(int id, int value)
{
}
public int getFieldCount()
{
return 0;
}
public void clear()
{
this.slots.clear();
}
}

View File

@@ -0,0 +1,66 @@
package net.minecraft.inventory;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.NonNullList;
public class ItemStackHelper
{
public static ItemStack getAndSplit(List<ItemStack> stacks, int index, int amount)
{
return index >= 0 && index < stacks.size() && !((ItemStack)stacks.get(index)).isEmpty() && amount > 0 ? ((ItemStack)stacks.get(index)).splitStack(amount) : ItemStack.EMPTY;
}
public static ItemStack getAndRemove(List<ItemStack> stacks, int index)
{
return index >= 0 && index < stacks.size() ? (ItemStack)stacks.set(index, ItemStack.EMPTY) : ItemStack.EMPTY;
}
public static NBTTagCompound saveAllItems(NBTTagCompound tag, NonNullList<ItemStack> list)
{
return saveAllItems(tag, list, true);
}
public static NBTTagCompound saveAllItems(NBTTagCompound tag, NonNullList<ItemStack> list, boolean saveEmpty)
{
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < list.size(); ++i)
{
ItemStack itemstack = list.get(i);
if (!itemstack.isEmpty())
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
itemstack.writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
if (!nbttaglist.hasNoTags() || saveEmpty)
{
tag.setTag("Items", nbttaglist);
}
return tag;
}
public static void loadAllItems(NBTTagCompound tag, NonNullList<ItemStack> list)
{
NBTTagList nbttaglist = tag.getTagList("Items", 10);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot") & 255;
if (j >= 0 && j < list.size())
{
list.set(j, new ItemStack(nbttagcompound));
}
}
}
}

View File

@@ -0,0 +1,234 @@
package net.minecraft.inventory;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class Slot
{
/** The index of the slot in the inventory. */
private final int slotIndex;
/** The inventory we want to extract a slot from. */
public final IInventory inventory;
/** the id of the slot(also the index in the inventory arraylist) */
public int slotNumber;
/** display position of the inventory slot on the screen x axis */
public int xPos;
/** display position of the inventory slot on the screen y axis */
public int yPos;
public Slot(IInventory inventoryIn, int index, int xPosition, int yPosition)
{
this.inventory = inventoryIn;
this.slotIndex = index;
this.xPos = xPosition;
this.yPos = yPosition;
}
/**
* if par2 has more items than par1, onCrafting(item,countIncrease) is called
*/
public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_)
{
int i = p_75220_2_.getCount() - p_75220_1_.getCount();
if (i > 0)
{
this.onCrafting(p_75220_2_, i);
}
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
* internal count then calls onCrafting(item).
*/
protected void onCrafting(ItemStack stack, int amount)
{
}
protected void onSwapCraft(int p_190900_1_)
{
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
*/
protected void onCrafting(ItemStack stack)
{
}
public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
{
this.onSlotChanged();
return stack;
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return true;
}
/**
* Helper fnct to get the stack in the slot.
*/
public ItemStack getStack()
{
return this.inventory.getStackInSlot(this.slotIndex);
}
/**
* Returns if this slot contains a stack.
*/
public boolean getHasStack()
{
return !this.getStack().isEmpty();
}
/**
* Helper method to put a stack in the slot.
*/
public void putStack(ItemStack stack)
{
this.inventory.setInventorySlotContents(this.slotIndex, stack);
this.onSlotChanged();
}
/**
* Called when the stack in a Slot changes
*/
public void onSlotChanged()
{
this.inventory.markDirty();
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the case
* of armor slots)
*/
public int getSlotStackLimit()
{
return this.inventory.getInventoryStackLimit();
}
public int getItemStackLimit(ItemStack stack)
{
return this.getSlotStackLimit();
}
@Nullable
@SideOnly(Side.CLIENT)
public String getSlotTexture()
{
return backgroundName;
}
/**
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
* stack.
*/
public ItemStack decrStackSize(int amount)
{
return this.inventory.decrStackSize(this.slotIndex, amount);
}
/**
* returns true if the slot exists in the given inventory and location
*/
public boolean isHere(IInventory inv, int slotIn)
{
return inv == this.inventory && slotIn == this.slotIndex;
}
/**
* Return whether this slot's stack can be taken from this slot.
*/
public boolean canTakeStack(EntityPlayer playerIn)
{
return true;
}
/**
* Actualy only call when we want to render the white square effect over the slots. Return always True, except for
* the armor slot of the Donkey/Mule (we can't interact with the Undead and Skeleton horses)
*/
@SideOnly(Side.CLIENT)
public boolean isEnabled()
{
return true;
}
/*========================================= FORGE START =====================================*/
protected String backgroundName = null;
protected net.minecraft.util.ResourceLocation backgroundLocation = null;
protected Object backgroundMap;
/**
* Gets the path of the texture file to use for the background image of this slot when drawing the GUI.
* @return The resource location for the background image
*/
@SideOnly(Side.CLIENT)
public net.minecraft.util.ResourceLocation getBackgroundLocation()
{
return (backgroundLocation == null ? net.minecraft.client.renderer.texture.TextureMap.LOCATION_BLOCKS_TEXTURE : backgroundLocation);
}
/**
* Sets the texture file to use for the background image of the slot when it's empty.
* @param texture the resourcelocation for the texture
*/
@SideOnly(Side.CLIENT)
public void setBackgroundLocation(net.minecraft.util.ResourceLocation texture)
{
this.backgroundLocation = texture;
}
/**
* Sets which icon index to use as the background image of the slot when it's empty.
* @param name The icon to use, null for none
*/
public void setBackgroundName(@Nullable String name)
{
this.backgroundName = name;
}
@Nullable
@SideOnly(Side.CLIENT)
public net.minecraft.client.renderer.texture.TextureAtlasSprite getBackgroundSprite()
{
String name = getSlotTexture();
return name == null ? null : getBackgroundMap().getAtlasSprite(name);
}
@SideOnly(Side.CLIENT)
protected net.minecraft.client.renderer.texture.TextureMap getBackgroundMap()
{
if (backgroundMap == null) backgroundMap = net.minecraft.client.Minecraft.getMinecraft().getTextureMapBlocks();
return (net.minecraft.client.renderer.texture.TextureMap)backgroundMap;
}
/**
* Retrieves the index in the inventory for this slot, this value should typically not
* be used, but can be useful for some occasions.
*
* @return Index in associated inventory for this slot.
*/
public int getSlotIndex()
{
return slotIndex;
}
/**
* Checks if the other slot is in the same inventory, by comparing the inventory reference.
* @param other
* @return true if the other slot is in the same inventory
*/
public boolean isSameInventory(Slot other)
{
return this.inventory == other.inventory;
}
/*========================================= FORGE END =====================================*/
}

View File

@@ -0,0 +1,123 @@
package net.minecraft.inventory;
import com.google.common.collect.Lists;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
public class SlotCrafting extends Slot
{
/** The craft matrix inventory linked to this result slot. */
private final InventoryCrafting craftMatrix;
/** The player that is using the GUI where this slot resides. */
public final EntityPlayer player;
/** The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. */
private int amountCrafted;
public SlotCrafting(EntityPlayer player, InventoryCrafting craftingInventory, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
{
super(inventoryIn, slotIndex, xPosition, yPosition);
this.player = player;
this.craftMatrix = craftingInventory;
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return false;
}
/**
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
* stack.
*/
public ItemStack decrStackSize(int amount)
{
if (this.getHasStack())
{
this.amountCrafted += Math.min(amount, this.getStack().getCount());
}
return super.decrStackSize(amount);
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
* internal count then calls onCrafting(item).
*/
protected void onCrafting(ItemStack stack, int amount)
{
this.amountCrafted += amount;
this.onCrafting(stack);
}
protected void onSwapCraft(int p_190900_1_)
{
this.amountCrafted += p_190900_1_;
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
*/
protected void onCrafting(ItemStack stack)
{
if (this.amountCrafted > 0)
{
stack.onCrafting(this.player.world, this.player, this.amountCrafted);
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(this.player, stack, craftMatrix);
}
this.amountCrafted = 0;
InventoryCraftResult inventorycraftresult = (InventoryCraftResult)this.inventory;
IRecipe irecipe = inventorycraftresult.getRecipeUsed();
if (irecipe != null && !irecipe.isDynamic())
{
this.player.unlockRecipes(Lists.newArrayList(irecipe));
inventorycraftresult.setRecipeUsed((IRecipe)null);
}
}
public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
{
this.onCrafting(stack);
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(thePlayer);
NonNullList<ItemStack> nonnulllist = CraftingManager.getRemainingItems(this.craftMatrix, thePlayer.world);
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = this.craftMatrix.getStackInSlot(i);
ItemStack itemstack1 = nonnulllist.get(i);
if (!itemstack.isEmpty())
{
this.craftMatrix.decrStackSize(i, 1);
itemstack = this.craftMatrix.getStackInSlot(i);
}
if (!itemstack1.isEmpty())
{
if (itemstack.isEmpty())
{
this.craftMatrix.setInventorySlotContents(i, itemstack1);
}
else if (ItemStack.areItemsEqual(itemstack, itemstack1) && ItemStack.areItemStackTagsEqual(itemstack, itemstack1))
{
itemstack1.grow(itemstack.getCount());
this.craftMatrix.setInventorySlotContents(i, itemstack1);
}
else if (!this.player.inventory.addItemStackToInventory(itemstack1))
{
this.player.dropItem(itemstack1, false);
}
}
}
return stack;
}
}

View File

@@ -0,0 +1,31 @@
package net.minecraft.inventory;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
public class SlotFurnaceFuel extends Slot
{
public SlotFurnaceFuel(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
{
super(inventoryIn, slotIndex, xPosition, yPosition);
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return TileEntityFurnace.isItemFuel(stack) || isBucket(stack);
}
public int getItemStackLimit(ItemStack stack)
{
return isBucket(stack) ? 1 : super.getItemStackLimit(stack);
}
public static boolean isBucket(ItemStack stack)
{
return stack.getItem() == Items.BUCKET;
}
}

View File

@@ -0,0 +1,99 @@
package net.minecraft.inventory;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.math.MathHelper;
public class SlotFurnaceOutput extends Slot
{
/** The player that is using the GUI where this slot resides. */
private final EntityPlayer player;
private int removeCount;
public SlotFurnaceOutput(EntityPlayer player, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
{
super(inventoryIn, slotIndex, xPosition, yPosition);
this.player = player;
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return false;
}
/**
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
* stack.
*/
public ItemStack decrStackSize(int amount)
{
if (this.getHasStack())
{
this.removeCount += Math.min(amount, this.getStack().getCount());
}
return super.decrStackSize(amount);
}
public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
{
this.onCrafting(stack);
super.onTake(thePlayer, stack);
return stack;
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
* internal count then calls onCrafting(item).
*/
protected void onCrafting(ItemStack stack, int amount)
{
this.removeCount += amount;
this.onCrafting(stack);
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
*/
protected void onCrafting(ItemStack stack)
{
stack.onCrafting(this.player.world, this.player, this.removeCount);
if (!this.player.world.isRemote)
{
int i = this.removeCount;
float f = FurnaceRecipes.instance().getSmeltingExperience(stack);
if (f == 0.0F)
{
i = 0;
}
else if (f < 1.0F)
{
int j = MathHelper.floor((float)i * f);
if (j < MathHelper.ceil((float)i * f) && Math.random() < (double)((float)i * f - (float)j))
{
++j;
}
i = j;
}
while (i > 0)
{
int k = EntityXPOrb.getXPSplit(i);
i -= k;
this.player.world.spawnEntity(new EntityXPOrb(this.player.world, this.player.posX, this.player.posY + 0.5D, this.player.posZ + 0.5D, k));
}
}
this.removeCount = 0;
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack);
}
}

View File

@@ -0,0 +1,113 @@
package net.minecraft.inventory;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.village.MerchantRecipe;
public class SlotMerchantResult extends Slot
{
/** Merchant's inventory. */
private final InventoryMerchant merchantInventory;
/** The Player whos trying to buy/sell stuff. */
private final EntityPlayer player;
private int removeCount;
/** "Instance" of the Merchant. */
private final IMerchant merchant;
public SlotMerchantResult(EntityPlayer player, IMerchant merchant, InventoryMerchant merchantInventory, int slotIndex, int xPosition, int yPosition)
{
super(merchantInventory, slotIndex, xPosition, yPosition);
this.player = player;
this.merchant = merchant;
this.merchantInventory = merchantInventory;
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return false;
}
/**
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
* stack.
*/
public ItemStack decrStackSize(int amount)
{
if (this.getHasStack())
{
this.removeCount += Math.min(amount, this.getStack().getCount());
}
return super.decrStackSize(amount);
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
* internal count then calls onCrafting(item).
*/
protected void onCrafting(ItemStack stack, int amount)
{
this.removeCount += amount;
this.onCrafting(stack);
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
*/
protected void onCrafting(ItemStack stack)
{
stack.onCrafting(this.player.world, this.player, this.removeCount);
this.removeCount = 0;
}
public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
{
this.onCrafting(stack);
MerchantRecipe merchantrecipe = this.merchantInventory.getCurrentRecipe();
if (merchantrecipe != null)
{
ItemStack itemstack = this.merchantInventory.getStackInSlot(0);
ItemStack itemstack1 = this.merchantInventory.getStackInSlot(1);
if (this.doTrade(merchantrecipe, itemstack, itemstack1) || this.doTrade(merchantrecipe, itemstack1, itemstack))
{
this.merchant.useRecipe(merchantrecipe);
thePlayer.addStat(StatList.TRADED_WITH_VILLAGER);
this.merchantInventory.setInventorySlotContents(0, itemstack);
this.merchantInventory.setInventorySlotContents(1, itemstack1);
}
}
return stack;
}
private boolean doTrade(MerchantRecipe trade, ItemStack firstItem, ItemStack secondItem)
{
ItemStack itemstack = trade.getItemToBuy();
ItemStack itemstack1 = trade.getSecondItemToBuy();
if (firstItem.getItem() == itemstack.getItem() && firstItem.getCount() >= itemstack.getCount())
{
if (!itemstack1.isEmpty() && !secondItem.isEmpty() && itemstack1.getItem() == secondItem.getItem() && secondItem.getCount() >= itemstack1.getCount())
{
firstItem.shrink(itemstack.getCount());
secondItem.shrink(itemstack1.getCount());
return true;
}
if (itemstack1.isEmpty() && secondItem.isEmpty())
{
firstItem.shrink(itemstack.getCount());
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,21 @@
package net.minecraft.inventory;
import net.minecraft.block.Block;
import net.minecraft.block.BlockShulkerBox;
import net.minecraft.item.ItemStack;
public class SlotShulkerBox extends Slot
{
public SlotShulkerBox(IInventory p_i47265_1_, int slotIndexIn, int xPosition, int yPosition)
{
super(p_i47265_1_, slotIndexIn, xPosition, yPosition);
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean isItemValid(ItemStack stack)
{
return !(Block.getBlockFromItem(stack.getItem()) instanceof BlockShulkerBox);
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.inventory;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;