initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
14
java/src/game/inventory/AnimalChest.java
Executable file
14
java/src/game/inventory/AnimalChest.java
Executable file
|
@ -0,0 +1,14 @@
|
|||
package game.inventory;
|
||||
|
||||
public class AnimalChest extends InventoryBasic
|
||||
{
|
||||
public AnimalChest(String inventoryName, int slotCount)
|
||||
{
|
||||
super(inventoryName, false, slotCount);
|
||||
}
|
||||
|
||||
public AnimalChest(String invTitle, boolean customName, int slotCount)
|
||||
{
|
||||
super(invTitle, customName, slotCount);
|
||||
}
|
||||
}
|
804
java/src/game/inventory/Container.java
Executable file
804
java/src/game/inventory/Container.java
Executable file
|
@ -0,0 +1,804 @@
|
|||
package game.inventory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.collect.Lists;
|
||||
import game.collect.Sets;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.Item;
|
||||
import game.item.ItemStack;
|
||||
import game.tileentity.TileEntity;
|
||||
|
||||
public abstract class Container
|
||||
{
|
||||
public List<ItemStack> inventoryItemStacks = Lists.<ItemStack>newArrayList();
|
||||
public List<Slot> inventorySlots = Lists.<Slot>newArrayList();
|
||||
public int windowId;
|
||||
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;
|
||||
private final Set<Slot> dragSlots = Sets.<Slot>newHashSet();
|
||||
protected List<ICrafting> crafters = Lists.<ICrafting>newArrayList();
|
||||
private Set<EntityNPC> playerList = Sets.<EntityNPC>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)null);
|
||||
return slotIn;
|
||||
}
|
||||
|
||||
public void onCraftGuiOpened(ICrafting listener)
|
||||
{
|
||||
if (this.crafters.contains(listener))
|
||||
{
|
||||
throw new IllegalArgumentException("Listener already listening");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.crafters.add(listener);
|
||||
listener.updateCraftingInventory(this, this.getInventory());
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given Listener. Method name is for legacy.
|
||||
*/
|
||||
public void removeCraftingFromCrafters(ICrafting listeners)
|
||||
{
|
||||
this.crafters.remove(listeners);
|
||||
}
|
||||
|
||||
public List<ItemStack> getInventory()
|
||||
{
|
||||
List<ItemStack> list = Lists.<ItemStack>newArrayList();
|
||||
|
||||
for (int i = 0; i < this.inventorySlots.size(); ++i)
|
||||
{
|
||||
list.add(((Slot)this.inventorySlots.get(i)).getStack());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 current = ((Slot)this.inventorySlots.get(i)).getStack();
|
||||
ItemStack last = (ItemStack)this.inventoryItemStacks.get(i);
|
||||
|
||||
if (!ItemStack.areItemStacksEqual(last, current))
|
||||
{
|
||||
last = current == null ? null : current.copy();
|
||||
this.inventoryItemStacks.set(i, last);
|
||||
|
||||
for (int j = 0; j < this.crafters.size(); ++j)
|
||||
{
|
||||
((ICrafting)this.crafters.get(j)).sendSlotContents(this, i, last);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
|
||||
*/
|
||||
public boolean enchantItem(EntityNPC playerIn, int id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public Slot getSlotFromInventory(IInventory inv, int slotIn)
|
||||
{
|
||||
for (int i = 0; i < this.inventorySlots.size(); ++i)
|
||||
{
|
||||
Slot slot = (Slot)this.inventorySlots.get(i);
|
||||
|
||||
if (slot.isHere(inv, slotIn))
|
||||
{
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Slot getSlot(int slotId)
|
||||
{
|
||||
return (Slot)this.inventorySlots.get(slotId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
Slot slot = (Slot)this.inventorySlots.get(index);
|
||||
return slot != null ? slot.getStack() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles slot click.
|
||||
*/
|
||||
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityNPC playerIn)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
InventoryPlayer inventoryplayer = playerIn.inventory;
|
||||
|
||||
if (mode == 5)
|
||||
{
|
||||
int i = this.dragEvent;
|
||||
this.dragEvent = getDragEvent(clickedButton);
|
||||
|
||||
if ((i != 1 || this.dragEvent != 2) && i != this.dragEvent)
|
||||
{
|
||||
this.resetDrag();
|
||||
}
|
||||
else if (inventoryplayer.getItemStack() == null)
|
||||
{
|
||||
this.resetDrag();
|
||||
}
|
||||
else if (this.dragEvent == 0)
|
||||
{
|
||||
this.dragMode = extractDragMode(clickedButton);
|
||||
|
||||
if (isValidDragMode(this.dragMode, playerIn))
|
||||
{
|
||||
this.dragEvent = 1;
|
||||
this.dragSlots.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.resetDrag();
|
||||
}
|
||||
}
|
||||
else if (this.dragEvent == 1)
|
||||
{
|
||||
Slot slot = (Slot)this.inventorySlots.get(slotId);
|
||||
|
||||
if (slot != null && canAddItemToSlot(slot, inventoryplayer.getItemStack(), true) && slot.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize > this.dragSlots.size() && this.canDragIntoSlot(slot))
|
||||
{
|
||||
this.dragSlots.add(slot);
|
||||
}
|
||||
}
|
||||
else if (this.dragEvent == 2)
|
||||
{
|
||||
if (!this.dragSlots.isEmpty())
|
||||
{
|
||||
ItemStack itemstack3 = inventoryplayer.getItemStack().copy();
|
||||
int j = inventoryplayer.getItemStack().stackSize;
|
||||
|
||||
for (Slot slot1 : this.dragSlots)
|
||||
{
|
||||
if (slot1 != null && canAddItemToSlot(slot1, inventoryplayer.getItemStack(), true) && slot1.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize >= this.dragSlots.size() && this.canDragIntoSlot(slot1))
|
||||
{
|
||||
ItemStack itemstack1 = itemstack3.copy();
|
||||
int k = slot1.getHasStack() ? slot1.getStack().stackSize : 0;
|
||||
computeStackSize(this.dragSlots, this.dragMode, itemstack1, k);
|
||||
|
||||
if (itemstack1.stackSize > itemstack1.getMaxStackSize())
|
||||
{
|
||||
itemstack1.stackSize = itemstack1.getMaxStackSize();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize > slot1.getItemStackLimit(itemstack1))
|
||||
{
|
||||
itemstack1.stackSize = slot1.getItemStackLimit(itemstack1);
|
||||
}
|
||||
|
||||
j -= itemstack1.stackSize - k;
|
||||
slot1.putStack(itemstack1);
|
||||
}
|
||||
}
|
||||
|
||||
itemstack3.stackSize = j;
|
||||
|
||||
if (itemstack3.stackSize <= 0)
|
||||
{
|
||||
itemstack3 = null;
|
||||
}
|
||||
|
||||
inventoryplayer.setItemStack(itemstack3);
|
||||
}
|
||||
|
||||
this.resetDrag();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.resetDrag();
|
||||
}
|
||||
}
|
||||
else if (this.dragEvent != 0)
|
||||
{
|
||||
this.resetDrag();
|
||||
}
|
||||
else if ((mode == 0 || mode == 1) && (clickedButton == 0 || clickedButton == 1))
|
||||
{
|
||||
if (slotId == -999)
|
||||
{
|
||||
if (inventoryplayer.getItemStack() != null)
|
||||
{
|
||||
if (clickedButton == 0)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack(), true);
|
||||
inventoryplayer.setItemStack((ItemStack)null);
|
||||
}
|
||||
|
||||
if (clickedButton == 1)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack().splitStack(1), true);
|
||||
|
||||
if (inventoryplayer.getItemStack().stackSize == 0)
|
||||
{
|
||||
inventoryplayer.setItemStack((ItemStack)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mode == 1)
|
||||
{
|
||||
if (slotId < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Slot slot6 = (Slot)this.inventorySlots.get(slotId);
|
||||
|
||||
if (slot6 != null && slot6.canTakeStack(playerIn))
|
||||
{
|
||||
ItemStack itemstack8 = this.transferStackInSlot(playerIn, slotId);
|
||||
|
||||
if (itemstack8 != null)
|
||||
{
|
||||
Item item = itemstack8.getItem();
|
||||
itemstack = itemstack8.copy();
|
||||
|
||||
if (slot6.getStack() != null && slot6.getStack().getItem() == item)
|
||||
{
|
||||
this.retrySlotClick(slotId, clickedButton, true, playerIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (slotId < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Slot slot7 = (Slot)this.inventorySlots.get(slotId);
|
||||
|
||||
if (slot7 != null)
|
||||
{
|
||||
ItemStack itemstack9 = slot7.getStack();
|
||||
ItemStack itemstack10 = inventoryplayer.getItemStack();
|
||||
|
||||
if (itemstack9 != null)
|
||||
{
|
||||
itemstack = itemstack9.copy();
|
||||
}
|
||||
|
||||
if (itemstack9 == null)
|
||||
{
|
||||
if (itemstack10 != null && slot7.isItemValid(itemstack10))
|
||||
{
|
||||
int k2 = clickedButton == 0 ? itemstack10.stackSize : 1;
|
||||
|
||||
if (k2 > slot7.getItemStackLimit(itemstack10))
|
||||
{
|
||||
k2 = slot7.getItemStackLimit(itemstack10);
|
||||
}
|
||||
|
||||
if (itemstack10.stackSize >= k2)
|
||||
{
|
||||
slot7.putStack(itemstack10.splitStack(k2));
|
||||
}
|
||||
|
||||
if (itemstack10.stackSize == 0)
|
||||
{
|
||||
inventoryplayer.setItemStack((ItemStack)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (slot7.canTakeStack(playerIn))
|
||||
{
|
||||
if (itemstack10 == null)
|
||||
{
|
||||
int j2 = clickedButton == 0 ? itemstack9.stackSize : (itemstack9.stackSize + 1) / 2;
|
||||
ItemStack itemstack12 = slot7.decrStackSize(j2);
|
||||
inventoryplayer.setItemStack(itemstack12);
|
||||
|
||||
if (itemstack9.stackSize == 0)
|
||||
{
|
||||
slot7.putStack((ItemStack)null);
|
||||
}
|
||||
|
||||
slot7.onPickupFromSlot(playerIn, inventoryplayer.getItemStack());
|
||||
}
|
||||
else if (slot7.isItemValid(itemstack10))
|
||||
{
|
||||
if (itemstack9.getItem() == itemstack10.getItem() && itemstack9.getMetadata() == itemstack10.getMetadata() && ItemStack.areItemStackTagsEqual(itemstack9, itemstack10))
|
||||
{
|
||||
int i2 = clickedButton == 0 ? itemstack10.stackSize : 1;
|
||||
|
||||
if (i2 > slot7.getItemStackLimit(itemstack10) - itemstack9.stackSize)
|
||||
{
|
||||
i2 = slot7.getItemStackLimit(itemstack10) - itemstack9.stackSize;
|
||||
}
|
||||
|
||||
if (i2 > itemstack10.getMaxStackSize() - itemstack9.stackSize)
|
||||
{
|
||||
i2 = itemstack10.getMaxStackSize() - itemstack9.stackSize;
|
||||
}
|
||||
|
||||
itemstack10.splitStack(i2);
|
||||
|
||||
if (itemstack10.stackSize == 0)
|
||||
{
|
||||
inventoryplayer.setItemStack((ItemStack)null);
|
||||
}
|
||||
|
||||
itemstack9.stackSize += i2;
|
||||
}
|
||||
else if (itemstack10.stackSize <= slot7.getItemStackLimit(itemstack10))
|
||||
{
|
||||
slot7.putStack(itemstack10);
|
||||
inventoryplayer.setItemStack(itemstack9);
|
||||
}
|
||||
}
|
||||
else if (itemstack9.getItem() == itemstack10.getItem() && itemstack10.getMaxStackSize() > 1 && (!itemstack9.getHasSubtypes() || itemstack9.getMetadata() == itemstack10.getMetadata()) && ItemStack.areItemStackTagsEqual(itemstack9, itemstack10))
|
||||
{
|
||||
int l1 = itemstack9.stackSize;
|
||||
|
||||
if (l1 > 0 && l1 + itemstack10.stackSize <= itemstack10.getMaxStackSize())
|
||||
{
|
||||
itemstack10.stackSize += l1;
|
||||
itemstack9 = slot7.decrStackSize(l1);
|
||||
|
||||
if (itemstack9.stackSize == 0)
|
||||
{
|
||||
slot7.putStack((ItemStack)null);
|
||||
}
|
||||
|
||||
slot7.onPickupFromSlot(playerIn, inventoryplayer.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slot7.onSlotChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mode == 2 && clickedButton >= 0 && clickedButton < 9)
|
||||
{
|
||||
Slot slot5 = (Slot)this.inventorySlots.get(slotId);
|
||||
|
||||
if (slot5.canTakeStack(playerIn))
|
||||
{
|
||||
ItemStack itemstack7 = inventoryplayer.getStackInSlot(clickedButton);
|
||||
boolean flag = itemstack7 == null || slot5.inventory == inventoryplayer && slot5.isItemValid(itemstack7);
|
||||
int k1 = -1;
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
k1 = inventoryplayer.getFirstEmptyStack();
|
||||
flag |= k1 > -1;
|
||||
}
|
||||
|
||||
if (slot5.getHasStack() && flag)
|
||||
{
|
||||
ItemStack itemstack11 = slot5.getStack();
|
||||
inventoryplayer.setInventorySlotContents(clickedButton, itemstack11.copy());
|
||||
|
||||
if ((slot5.inventory != inventoryplayer || !slot5.isItemValid(itemstack7)) && itemstack7 != null)
|
||||
{
|
||||
if (k1 > -1)
|
||||
{
|
||||
inventoryplayer.addItemStackToInventory(itemstack7);
|
||||
slot5.decrStackSize(itemstack11.stackSize);
|
||||
slot5.putStack((ItemStack)null);
|
||||
slot5.onPickupFromSlot(playerIn, itemstack11);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
slot5.decrStackSize(itemstack11.stackSize);
|
||||
slot5.putStack(itemstack7);
|
||||
slot5.onPickupFromSlot(playerIn, itemstack11);
|
||||
}
|
||||
}
|
||||
else if (!slot5.getHasStack() && itemstack7 != null && slot5.isItemValid(itemstack7))
|
||||
{
|
||||
inventoryplayer.setInventorySlotContents(clickedButton, (ItemStack)null);
|
||||
slot5.putStack(itemstack7);
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if (mode == 3 && playerIn.creative && inventoryplayer.getItemStack() == null && slotId >= 0)
|
||||
// {
|
||||
// Slot slot4 = (Slot)this.inventorySlots.get(slotId);
|
||||
//
|
||||
// if (slot4 != null && slot4.getHasStack())
|
||||
// {
|
||||
// ItemStack itemstack6 = slot4.getStack().copy();
|
||||
// itemstack6.stackSize = itemstack6.getMaxStackSize();
|
||||
// inventoryplayer.setItemStack(itemstack6);
|
||||
// }
|
||||
// }
|
||||
else if (mode == 4 && inventoryplayer.getItemStack() == null && slotId >= 0)
|
||||
{
|
||||
Slot slot3 = (Slot)this.inventorySlots.get(slotId);
|
||||
|
||||
if (slot3 != null && slot3.getHasStack() && slot3.canTakeStack(playerIn))
|
||||
{
|
||||
ItemStack itemstack5 = slot3.decrStackSize(clickedButton == 0 ? 1 : slot3.getStack().stackSize);
|
||||
slot3.onPickupFromSlot(playerIn, itemstack5);
|
||||
playerIn.dropPlayerItemWithRandomChoice(itemstack5, true);
|
||||
}
|
||||
}
|
||||
else if (mode == 6 && slotId >= 0)
|
||||
{
|
||||
Slot slot2 = (Slot)this.inventorySlots.get(slotId);
|
||||
ItemStack itemstack4 = inventoryplayer.getItemStack();
|
||||
|
||||
if (itemstack4 != null && (slot2 == null || !slot2.getHasStack() || !slot2.canTakeStack(playerIn)))
|
||||
{
|
||||
int i1 = clickedButton == 0 ? 0 : this.inventorySlots.size() - 1;
|
||||
int j1 = clickedButton == 0 ? 1 : -1;
|
||||
|
||||
for (int l2 = 0; l2 < 2; ++l2)
|
||||
{
|
||||
for (int i3 = i1; i3 >= 0 && i3 < this.inventorySlots.size() && itemstack4.stackSize < itemstack4.getMaxStackSize(); i3 += j1)
|
||||
{
|
||||
Slot slot8 = (Slot)this.inventorySlots.get(i3);
|
||||
|
||||
if (slot8.getHasStack() && canAddItemToSlot(slot8, itemstack4, true) && slot8.canTakeStack(playerIn) && this.canMergeSlot(itemstack4, slot8) && (l2 != 0 || slot8.getStack().stackSize != slot8.getStack().getMaxStackSize()))
|
||||
{
|
||||
int l = Math.min(itemstack4.getMaxStackSize() - itemstack4.stackSize, slot8.getStack().stackSize);
|
||||
ItemStack itemstack2 = slot8.decrStackSize(l);
|
||||
itemstack4.stackSize += l;
|
||||
|
||||
if (itemstack2.stackSize <= 0)
|
||||
{
|
||||
slot8.putStack((ItemStack)null);
|
||||
}
|
||||
|
||||
slot8.onPickupFromSlot(playerIn, itemstack2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retries slotClick() in case of failure
|
||||
*/
|
||||
protected void retrySlotClick(int slotId, int clickedButton, boolean mode, EntityNPC playerIn)
|
||||
{
|
||||
this.slotClick(slotId, clickedButton, 1, playerIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
InventoryPlayer inventoryplayer = playerIn.inventory;
|
||||
|
||||
if (inventoryplayer.getItemStack() != null)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack(), true);
|
||||
inventoryplayer.setItemStack((ItemStack)null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the crafting matrix is changed.
|
||||
*/
|
||||
public void onCraftMatrixChanged(IInventory inventoryIn)
|
||||
{
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* args: slotID, itemStack to put in slot
|
||||
*/
|
||||
public void putStackInSlot(int slotID, ItemStack stack)
|
||||
{
|
||||
this.getSlot(slotID).putStack(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* places itemstacks in first x slots, x being aitemstack.lenght
|
||||
*/
|
||||
public void putStacksInSlots(ItemStack[] p_75131_1_)
|
||||
{
|
||||
for (int i = 0; i < p_75131_1_.length; ++i)
|
||||
{
|
||||
this.getSlot(i).putStack(p_75131_1_[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateProgressBar(int id, int data)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a unique transaction ID. Parameter is unused.
|
||||
*/
|
||||
public short getNextTransactionID(InventoryPlayer p_75136_1_)
|
||||
{
|
||||
++this.transactionID;
|
||||
return this.transactionID;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets whether or not the player can craft in this inventory or not
|
||||
*/
|
||||
public boolean getCanCraft(EntityNPC p_75129_1_)
|
||||
{
|
||||
return !this.playerList.contains(p_75129_1_);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets whether the player can craft in this inventory or not
|
||||
*/
|
||||
public void setCanCraft(EntityNPC p_75128_1_, boolean p_75128_2_)
|
||||
{
|
||||
if (p_75128_2_)
|
||||
{
|
||||
this.playerList.remove(p_75128_1_);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.playerList.add(p_75128_1_);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean canInteractWith(EntityNPC 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.stackSize > 0 && (!reverseDirection && i < endIndex || reverseDirection && i >= startIndex))
|
||||
{
|
||||
Slot slot = (Slot)this.inventorySlots.get(i);
|
||||
ItemStack itemstack = slot.getStack();
|
||||
|
||||
if (itemstack != null && itemstack.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getMetadata() == itemstack.getMetadata()) && ItemStack.areItemStackTagsEqual(stack, itemstack))
|
||||
{
|
||||
int j = itemstack.stackSize + stack.stackSize;
|
||||
|
||||
if (j <= stack.getMaxStackSize())
|
||||
{
|
||||
stack.stackSize = 0;
|
||||
itemstack.stackSize = j;
|
||||
slot.onSlotChanged();
|
||||
flag = true;
|
||||
}
|
||||
else if (itemstack.stackSize < stack.getMaxStackSize())
|
||||
{
|
||||
stack.stackSize -= stack.getMaxStackSize() - itemstack.stackSize;
|
||||
itemstack.stackSize = stack.getMaxStackSize();
|
||||
slot.onSlotChanged();
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reverseDirection)
|
||||
{
|
||||
--i;
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.stackSize > 0)
|
||||
{
|
||||
if (reverseDirection)
|
||||
{
|
||||
i = endIndex - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = startIndex;
|
||||
}
|
||||
|
||||
while (!reverseDirection && i < endIndex || reverseDirection && i >= startIndex)
|
||||
{
|
||||
Slot slot1 = (Slot)this.inventorySlots.get(i);
|
||||
ItemStack itemstack1 = slot1.getStack();
|
||||
|
||||
if (itemstack1 == null && this.canTransfer(slot1, stack))
|
||||
{
|
||||
slot1.putStack(stack.copy());
|
||||
slot1.onSlotChanged();
|
||||
stack.stackSize = 0;
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (reverseDirection)
|
||||
{
|
||||
--i;
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
protected boolean canTransfer(Slot slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the drag mode. Args : eventButton. Return (0 : evenly split, 1 : one item by slot, 2 : not used ?)
|
||||
*/
|
||||
public static int extractDragMode(int p_94529_0_)
|
||||
{
|
||||
return p_94529_0_ >> 2 & 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Args : clickedButton, Returns (0 : start drag, 1 : add slot, 2 : end drag)
|
||||
*/
|
||||
public static int getDragEvent(int p_94532_0_)
|
||||
{
|
||||
return p_94532_0_ & 3;
|
||||
}
|
||||
|
||||
public static int func_94534_d(int p_94534_0_, int p_94534_1_)
|
||||
{
|
||||
return p_94534_0_ & 3 | (p_94534_1_ & 3) << 2;
|
||||
}
|
||||
|
||||
public static boolean isValidDragMode(int dragModeIn, EntityNPC player)
|
||||
{
|
||||
return dragModeIn == 0 ? true : /* ( */ dragModeIn == 1; // ? true : dragModeIn == 2 && player.creative);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(Slot slotIn, ItemStack stack, boolean stackSizeMatters)
|
||||
{
|
||||
boolean flag = slotIn == null || !slotIn.getHasStack();
|
||||
|
||||
if (slotIn != null && slotIn.getHasStack() && stack != null && stack.isItemEqual(slotIn.getStack()) && ItemStack.areItemStackTagsEqual(slotIn.getStack(), stack))
|
||||
{
|
||||
flag |= slotIn.getStack().stackSize + (stackSizeMatters ? 0 : stack.stackSize) <= stack.getMaxStackSize();
|
||||
}
|
||||
|
||||
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> p_94525_0_, int p_94525_1_, ItemStack p_94525_2_, int p_94525_3_)
|
||||
{
|
||||
switch (p_94525_1_)
|
||||
{
|
||||
case 0:
|
||||
p_94525_2_.stackSize = ExtMath.floorf((float)p_94525_2_.stackSize / (float)p_94525_0_.size());
|
||||
break;
|
||||
|
||||
case 1:
|
||||
p_94525_2_.stackSize = 1;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
p_94525_2_.stackSize = p_94525_2_.getItem().getItemStackLimit();
|
||||
}
|
||||
|
||||
p_94525_2_.stackSize += p_94525_3_;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 p_94531_1_)
|
||||
{
|
||||
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(TileEntity te)
|
||||
{
|
||||
return te instanceof IInventory ? calcRedstoneFromInventory((IInventory)te) : 0;
|
||||
}
|
||||
|
||||
public static int calcRedstoneFromInventory(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 != null)
|
||||
{
|
||||
f += (float)itemstack.stackSize / (float)Math.min(inv.getInventoryStackLimit(), itemstack.getMaxStackSize());
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
f = f / (float)inv.getSizeInventory();
|
||||
return ExtMath.floorf(f * 14.0F) + (i > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
204
java/src/game/inventory/ContainerBrewingStand.java
Executable file
204
java/src/game/inventory/ContainerBrewingStand.java
Executable file
|
@ -0,0 +1,204 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Items;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class ContainerBrewingStand extends Container
|
||||
{
|
||||
private IInventory tileBrewingStand;
|
||||
|
||||
/** Instance of Slot. */
|
||||
private final Slot theSlot;
|
||||
private int brewTime;
|
||||
|
||||
public ContainerBrewingStand(InventoryPlayer playerInventory, IInventory tileBrewingStandIn)
|
||||
{
|
||||
this.tileBrewingStand = tileBrewingStandIn;
|
||||
this.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory.player, tileBrewingStandIn, 0, 56, 46));
|
||||
this.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory.player, tileBrewingStandIn, 1, 79, 53));
|
||||
this.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory.player, tileBrewingStandIn, 2, 102, 46));
|
||||
this.theSlot = this.addSlotToContainer(new ContainerBrewingStand.Ingredient(tileBrewingStandIn, 3, 79, 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 onCraftGuiOpened(ICrafting listener)
|
||||
{
|
||||
super.onCraftGuiOpened(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.crafters.size(); ++i)
|
||||
{
|
||||
ICrafting icrafting = (ICrafting)this.crafters.get(i);
|
||||
|
||||
if (this.brewTime != this.tileBrewingStand.getField(0))
|
||||
{
|
||||
icrafting.sendProgressBarUpdate(this, 0, this.tileBrewingStand.getField(0));
|
||||
}
|
||||
}
|
||||
|
||||
this.brewTime = this.tileBrewingStand.getField(0);
|
||||
}
|
||||
|
||||
public void updateProgressBar(int id, int data)
|
||||
{
|
||||
this.tileBrewingStand.setField(id, data);
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.tileBrewingStand.isUseableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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)
|
||||
{
|
||||
if (!this.theSlot.getHasStack() && this.theSlot.isItemValid(itemstack1))
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 3, 4, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (ContainerBrewingStand.Potion.canHoldPotion(itemstack))
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 0, 3, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 4 && index < 31)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 31, 40, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 31 && index < 40)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 4, 31, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 4, 40, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 4, 40, true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
class Ingredient extends Slot
|
||||
{
|
||||
public Ingredient(IInventory inventoryIn, int index, int xPosition, int yPosition)
|
||||
{
|
||||
super(inventoryIn, index, xPosition, yPosition);
|
||||
}
|
||||
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return stack != null ? stack.getItem().isPotionIngredient(stack) : false;
|
||||
}
|
||||
|
||||
public int getSlotStackLimit()
|
||||
{
|
||||
return ItemStack.MAX_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
static class Potion extends Slot
|
||||
{
|
||||
private EntityNPC player;
|
||||
|
||||
public Potion(EntityNPC playerIn, IInventory inventoryIn, int index, int xPosition, int yPosition)
|
||||
{
|
||||
super(inventoryIn, index, xPosition, yPosition);
|
||||
this.player = playerIn;
|
||||
}
|
||||
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return canHoldPotion(stack);
|
||||
}
|
||||
|
||||
public int getSlotStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
|
||||
// {
|
||||
// if (stack.getItem() == Items.potion && stack.getMetadata() > 0)
|
||||
// {
|
||||
// this.player.triggerAchievement(AchievementList.potion);
|
||||
// }
|
||||
//
|
||||
// super.onPickupFromSlot(playerIn, stack);
|
||||
// }
|
||||
|
||||
public static boolean canHoldPotion(ItemStack stack)
|
||||
{
|
||||
return stack != null && (stack.getItem() == Items.potion || stack.getItem() == Items.glass_bottle);
|
||||
}
|
||||
}
|
||||
}
|
99
java/src/game/inventory/ContainerChest.java
Executable file
99
java/src/game/inventory/ContainerChest.java
Executable file
|
@ -0,0 +1,99 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class ContainerChest extends Container
|
||||
{
|
||||
private IInventory lowerChestInventory;
|
||||
private int numRows;
|
||||
|
||||
public ContainerChest(IInventory playerInventory, IInventory chestInventory, EntityNPC 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));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.lowerChestInventory.isUseableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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 null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
this.lowerChestInventory.closeInventory(playerIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this chest container's lower chest inventory.
|
||||
*/
|
||||
public IInventory getLowerChestInventory()
|
||||
{
|
||||
return this.lowerChestInventory;
|
||||
}
|
||||
}
|
85
java/src/game/inventory/ContainerDispenser.java
Executable file
85
java/src/game/inventory/ContainerDispenser.java
Executable file
|
@ -0,0 +1,85 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class ContainerDispenser extends Container
|
||||
{
|
||||
private 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));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.dispenserInventory.isUseableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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 null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 0, 9, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
424
java/src/game/inventory/ContainerEnchantment.java
Executable file
424
java/src/game/inventory/ContainerEnchantment.java
Executable file
|
@ -0,0 +1,424 @@
|
|||
package game.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.enchantment.EnchantmentHelper;
|
||||
import game.enchantment.RngEnchantment;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.init.Items;
|
||||
import game.item.ItemStack;
|
||||
import game.rng.Random;
|
||||
import game.world.BlockPos;
|
||||
import game.world.World;
|
||||
|
||||
public class ContainerEnchantment extends Container
|
||||
{
|
||||
/** SlotEnchantmentTable object with ItemStack to be enchanted */
|
||||
public IInventory tableInventory;
|
||||
|
||||
/** current world (for bookshelf counting) */
|
||||
private World worldPointer;
|
||||
private BlockPos position;
|
||||
private Random rand;
|
||||
public int xpSeed;
|
||||
|
||||
/** 3-member array storing the enchantment levels of each slot */
|
||||
public int[] enchantLevels;
|
||||
public int[] enchantmentIds;
|
||||
|
||||
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, 1)
|
||||
{
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return ItemStack.MAX_SIZE;
|
||||
}
|
||||
public void markDirty()
|
||||
{
|
||||
super.markDirty();
|
||||
ContainerEnchantment.this.onCraftMatrixChanged(this);
|
||||
}
|
||||
};
|
||||
this.rand = new Random();
|
||||
this.enchantLevels = new int[3];
|
||||
this.enchantmentIds = new int[] { -1, -1, -1};
|
||||
this.worldPointer = worldIn;
|
||||
this.position = pos;
|
||||
this.xpSeed = playerInv.player.getXPSeed();
|
||||
this.addSlotToContainer(new Slot(this.tableInventory, 0, 25, 47)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public int getSlotStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
// this.addSlotToContainer(new Slot(this.tableInventory, 1, 35, 47)
|
||||
// {
|
||||
// public boolean isItemValid(ItemStack stack)
|
||||
// {
|
||||
// return stack.getItem() == Items.dye && EnumDyeColor.byDyeDamage(stack.getMetadata()) == EnumDyeColor.BLUE;
|
||||
// }
|
||||
// });
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
public void onCraftGuiOpened(ICrafting listener)
|
||||
{
|
||||
super.onCraftGuiOpened(listener);
|
||||
listener.sendProgressBarUpdate(this, 0, this.enchantLevels[0]);
|
||||
listener.sendProgressBarUpdate(this, 1, this.enchantLevels[1]);
|
||||
listener.sendProgressBarUpdate(this, 2, this.enchantLevels[2]);
|
||||
listener.sendProgressBarUpdate(this, 3, this.xpSeed & -16);
|
||||
listener.sendProgressBarUpdate(this, 4, this.enchantmentIds[0]);
|
||||
listener.sendProgressBarUpdate(this, 5, this.enchantmentIds[1]);
|
||||
listener.sendProgressBarUpdate(this, 6, this.enchantmentIds[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for changes made in the container, sends them to every listener.
|
||||
*/
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < this.crafters.size(); ++i)
|
||||
{
|
||||
ICrafting icrafting = (ICrafting)this.crafters.get(i);
|
||||
icrafting.sendProgressBarUpdate(this, 0, this.enchantLevels[0]);
|
||||
icrafting.sendProgressBarUpdate(this, 1, this.enchantLevels[1]);
|
||||
icrafting.sendProgressBarUpdate(this, 2, this.enchantLevels[2]);
|
||||
icrafting.sendProgressBarUpdate(this, 3, this.xpSeed & -16);
|
||||
icrafting.sendProgressBarUpdate(this, 4, this.enchantmentIds[0]);
|
||||
icrafting.sendProgressBarUpdate(this, 5, this.enchantmentIds[1]);
|
||||
icrafting.sendProgressBarUpdate(this, 6, this.enchantmentIds[2]);
|
||||
}
|
||||
}
|
||||
|
||||
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.enchantmentIds[id - 4] = 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 != null && itemstack.isItemEnchantable())
|
||||
{
|
||||
if (!this.worldPointer.client)
|
||||
{
|
||||
int l = 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)))
|
||||
{
|
||||
if (this.worldPointer.getState(this.position.add(k * 2, 0, j * 2)).getBlock() == Blocks.bookshelf)
|
||||
{
|
||||
++l;
|
||||
}
|
||||
|
||||
if (this.worldPointer.getState(this.position.add(k * 2, 1, j * 2)).getBlock() == Blocks.bookshelf)
|
||||
{
|
||||
++l;
|
||||
}
|
||||
|
||||
if (k != 0 && j != 0)
|
||||
{
|
||||
if (this.worldPointer.getState(this.position.add(k * 2, 0, j)).getBlock() == Blocks.bookshelf)
|
||||
{
|
||||
++l;
|
||||
}
|
||||
|
||||
if (this.worldPointer.getState(this.position.add(k * 2, 1, j)).getBlock() == Blocks.bookshelf)
|
||||
{
|
||||
++l;
|
||||
}
|
||||
|
||||
if (this.worldPointer.getState(this.position.add(k, 0, j * 2)).getBlock() == Blocks.bookshelf)
|
||||
{
|
||||
++l;
|
||||
}
|
||||
|
||||
if (this.worldPointer.getState(this.position.add(k, 1, j * 2)).getBlock() == Blocks.bookshelf)
|
||||
{
|
||||
++l;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.rand.setSeed((long)this.xpSeed);
|
||||
|
||||
for (int i1 = 0; i1 < 3; ++i1)
|
||||
{
|
||||
this.enchantLevels[i1] = EnchantmentHelper.calcItemStackEnchantability(this.rand, i1, l, itemstack);
|
||||
this.enchantmentIds[i1] = -1;
|
||||
|
||||
if (this.enchantLevels[i1] < i1 + 1)
|
||||
{
|
||||
this.enchantLevels[i1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j1 = 0; j1 < 3; ++j1)
|
||||
{
|
||||
if (this.enchantLevels[j1] > 0)
|
||||
{
|
||||
List<RngEnchantment> list = this.func_178148_a(itemstack, j1, this.enchantLevels[j1]);
|
||||
|
||||
if (list != null && !list.isEmpty())
|
||||
{
|
||||
RngEnchantment enchantmentdata = (RngEnchantment)list.get(this.rand.zrange(list.size()));
|
||||
this.enchantmentIds[j1] = enchantmentdata.enchantmentobj.effectId | enchantmentdata.enchantmentLevel << 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
this.enchantLevels[i] = 0;
|
||||
this.enchantmentIds[i] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
|
||||
*/
|
||||
public boolean enchantItem(EntityNPC playerIn, int id)
|
||||
{
|
||||
ItemStack itemstack = this.tableInventory.getStackInSlot(0);
|
||||
// ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
|
||||
int i = id + 1;
|
||||
|
||||
// if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// else
|
||||
if (this.enchantLevels[id] > 0 && itemstack != null && /* ( */ playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id]) // || playerIn.creative))
|
||||
{
|
||||
if (!this.worldPointer.client)
|
||||
{
|
||||
List<RngEnchantment> list = this.func_178148_a(itemstack, id, this.enchantLevels[id]);
|
||||
boolean flag = itemstack.getItem() == Items.book;
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
playerIn.removeExperienceLevel(i);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
itemstack.setItem(Items.enchanted_book);
|
||||
}
|
||||
|
||||
for (int j = 0; j < list.size(); ++j)
|
||||
{
|
||||
RngEnchantment enchantmentdata = (RngEnchantment)list.get(j);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
Items.enchanted_book.addEnchantment(itemstack, enchantmentdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
|
||||
}
|
||||
}
|
||||
|
||||
// if (!playerIn.capabilities.isCreativeMode)
|
||||
// {
|
||||
// itemstack1.stackSize -= i;
|
||||
//
|
||||
// if (itemstack1.stackSize <= 0)
|
||||
// {
|
||||
// this.tableInventory.setInventorySlotContents(1, (ItemStack)null);
|
||||
// }
|
||||
// }
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.enchantedStat);
|
||||
this.tableInventory.markDirty();
|
||||
this.xpSeed = playerIn.getXPSeed();
|
||||
this.onCraftMatrixChanged(this.tableInventory);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<RngEnchantment> func_178148_a(ItemStack stack, int p_178148_2_, int p_178148_3_)
|
||||
{
|
||||
this.rand.setSeed((long)(this.xpSeed + p_178148_2_));
|
||||
List<RngEnchantment> list = EnchantmentHelper.buildEnchantmentList(this.rand, stack, p_178148_3_);
|
||||
|
||||
if (stack.getItem() == Items.book && list != null && list.size() > 1)
|
||||
{
|
||||
list.remove(this.rand.zrange(list.size()));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// public int getLapisAmount()
|
||||
// {
|
||||
// ItemStack itemstack = this.tableInventory.getStackInSlot(1);
|
||||
// return itemstack == null ? 0 : itemstack.stackSize;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
|
||||
if (!this.worldPointer.client)
|
||||
{
|
||||
for (int i = 0; i < this.tableInventory.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = this.tableInventory.removeStackFromSlot(i);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.worldPointer.getState(this.position).getBlock() != Blocks.enchanting_table ? false : playerIn.getDistanceSq((double)this.position.getX() + 0.5D, (double)this.position.getY() + 0.5D, (double)this.position.getZ() + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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 null;
|
||||
}
|
||||
}
|
||||
// else if (index == 1)
|
||||
// {
|
||||
// if (!this.mergeItemStack(itemstack1, 2, 38, true))
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// else if (itemstack1.getItem() == Items.dye && EnumDyeColor.byDyeDamage(itemstack1.getMetadata()) == EnumDyeColor.BLUE)
|
||||
// {
|
||||
// if (!this.mergeItemStack(itemstack1, 1, 2, true))
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
else
|
||||
{
|
||||
if (((Slot)this.inventorySlots.get(0)).getHasStack() || !((Slot)this.inventorySlots.get(0)).isItemValid(itemstack1))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.hasTagCompound() && itemstack1.stackSize == 1)
|
||||
{
|
||||
((Slot)this.inventorySlots.get(0)).putStack(itemstack1.copy());
|
||||
itemstack1.stackSize = 0;
|
||||
}
|
||||
else if (itemstack1.stackSize >= 1)
|
||||
{
|
||||
((Slot)this.inventorySlots.get(0)).putStack(new ItemStack(itemstack1.getItem(), 1, itemstack1.getMetadata()));
|
||||
--itemstack1.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
165
java/src/game/inventory/ContainerFurnace.java
Executable file
165
java/src/game/inventory/ContainerFurnace.java
Executable file
|
@ -0,0 +1,165 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.SmeltingRegistry;
|
||||
import game.item.ItemStack;
|
||||
import game.tileentity.TileEntityFurnace;
|
||||
|
||||
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 onCraftGuiOpened(ICrafting listener)
|
||||
{
|
||||
super.onCraftGuiOpened(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.crafters.size(); ++i)
|
||||
{
|
||||
ICrafting icrafting = (ICrafting)this.crafters.get(i);
|
||||
|
||||
if (this.cookTime != this.tileFurnace.getField(2))
|
||||
{
|
||||
icrafting.sendProgressBarUpdate(this, 2, this.tileFurnace.getField(2));
|
||||
}
|
||||
|
||||
if (this.furnaceBurnTime != this.tileFurnace.getField(0))
|
||||
{
|
||||
icrafting.sendProgressBarUpdate(this, 0, this.tileFurnace.getField(0));
|
||||
}
|
||||
|
||||
if (this.currentItemBurnTime != this.tileFurnace.getField(1))
|
||||
{
|
||||
icrafting.sendProgressBarUpdate(this, 1, this.tileFurnace.getField(1));
|
||||
}
|
||||
|
||||
if (this.totalCookTime != this.tileFurnace.getField(3))
|
||||
{
|
||||
icrafting.sendProgressBarUpdate(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);
|
||||
}
|
||||
|
||||
public void updateProgressBar(int id, int data)
|
||||
{
|
||||
this.tileFurnace.setField(id, data);
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.tileFurnace.isUseableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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 null;
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
}
|
||||
else if (index != 1 && index != 0)
|
||||
{
|
||||
if (SmeltingRegistry.getResult(itemstack1) != null)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 0, 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (TileEntityFurnace.isItemFuel(itemstack1))
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 1, 2, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 3 && index < 30)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 30, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
86
java/src/game/inventory/ContainerHopper.java
Executable file
86
java/src/game/inventory/ContainerHopper.java
Executable file
|
@ -0,0 +1,86 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class ContainerHopper extends Container
|
||||
{
|
||||
private final IInventory hopperInventory;
|
||||
|
||||
public ContainerHopper(InventoryPlayer playerInventory, IInventory hopperInventoryIn, EntityNPC 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 + i));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i1 = 0; i1 < 9; ++i1)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 58 + i));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.hopperInventory.isUseableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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 null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 0, this.hopperInventory.getSizeInventory(), false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
this.hopperInventory.closeInventory(playerIn);
|
||||
}
|
||||
}
|
129
java/src/game/inventory/ContainerHorseInventory.java
Executable file
129
java/src/game/inventory/ContainerHorseInventory.java
Executable file
|
@ -0,0 +1,129 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.animal.EntityHorse;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Items;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class ContainerHorseInventory extends Container
|
||||
{
|
||||
private IInventory horseInventory;
|
||||
private EntityHorse theHorse;
|
||||
|
||||
public ContainerHorseInventory(IInventory playerInventory, final IInventory horseInventoryIn, final EntityHorse horse, EntityNPC player)
|
||||
{
|
||||
this.horseInventory = horseInventoryIn;
|
||||
this.theHorse = horse;
|
||||
int i = 3;
|
||||
horseInventoryIn.openInventory(player);
|
||||
int j = (i - 4) * 18;
|
||||
this.addSlotToContainer(new Slot(horseInventoryIn, 0, 8, 18)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return super.isItemValid(stack) && stack.getItem() == Items.saddle && !this.getHasStack();
|
||||
}
|
||||
});
|
||||
this.addSlotToContainer(new Slot(horseInventoryIn, 1, 8, 36)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return super.isItemValid(stack) && horse.canWearArmor() && EntityHorse.isArmorItem(stack.getItem());
|
||||
}
|
||||
public boolean canBeHovered()
|
||||
{
|
||||
return horse.canWearArmor();
|
||||
}
|
||||
});
|
||||
|
||||
if (horse.isChested())
|
||||
{
|
||||
for (int k = 0; k < i; ++k)
|
||||
{
|
||||
for (int l = 0; l < 5; ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(horseInventoryIn, 2 + l + k * 5, 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 + j));
|
||||
}
|
||||
}
|
||||
|
||||
for (int j1 = 0; j1 < 9; ++j1)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInventory, j1, 8 + j1 * 18, 160 + j));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.horseInventory.isUseableByPlayer(playerIn) && this.theHorse.isEntityAlive() && this.theHorse.getDistanceToEntity(playerIn) < 8.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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 null;
|
||||
}
|
||||
}
|
||||
else if (this.getSlot(1).isItemValid(itemstack1) && !this.getSlot(1).getHasStack())
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 1, 2, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (this.getSlot(0).isItemValid(itemstack1))
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 0, 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (this.horseInventory.getSizeInventory() <= 2 || !this.mergeItemStack(itemstack1, 2, this.horseInventory.getSizeInventory(), false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
this.horseInventory.closeInventory(playerIn);
|
||||
}
|
||||
}
|
59
java/src/game/inventory/ContainerLocalMenu.java
Executable file
59
java/src/game/inventory/ContainerLocalMenu.java
Executable file
|
@ -0,0 +1,59 @@
|
|||
package game.inventory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import game.collect.Maps;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.tileentity.ILockableContainer;
|
||||
import game.tileentity.LockCode;
|
||||
|
||||
public class ContainerLocalMenu extends InventoryBasic implements ILockableContainer
|
||||
{
|
||||
private String guiID;
|
||||
private Map<Integer, Integer> field_174895_b = Maps.<Integer, Integer>newHashMap();
|
||||
|
||||
public ContainerLocalMenu(String id, String title, int slotCount)
|
||||
{
|
||||
super(title, slotCount);
|
||||
this.guiID = id;
|
||||
}
|
||||
|
||||
public int getField(int id)
|
||||
{
|
||||
return this.field_174895_b.containsKey(Integer.valueOf(id)) ? ((Integer)this.field_174895_b.get(Integer.valueOf(id))).intValue() : 0;
|
||||
}
|
||||
|
||||
public void setField(int id, int value)
|
||||
{
|
||||
this.field_174895_b.put(Integer.valueOf(id), Integer.valueOf(value));
|
||||
}
|
||||
|
||||
public int getFieldCount()
|
||||
{
|
||||
return this.field_174895_b.size();
|
||||
}
|
||||
|
||||
public boolean isLocked()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setLockCode(LockCode code)
|
||||
{
|
||||
}
|
||||
|
||||
public LockCode getLockCode()
|
||||
{
|
||||
return LockCode.EMPTY_CODE;
|
||||
}
|
||||
|
||||
public String getGuiID()
|
||||
{
|
||||
return this.guiID;
|
||||
}
|
||||
|
||||
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
138
java/src/game/inventory/ContainerMachine.java
Executable file
138
java/src/game/inventory/ContainerMachine.java
Executable file
|
@ -0,0 +1,138 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
import game.tileentity.TileEntityMachine;
|
||||
import game.tileentity.TileEntityMachine.Status;
|
||||
|
||||
public class ContainerMachine extends Container
|
||||
{
|
||||
private final IInventory machine;
|
||||
private final TileEntityMachine tile;
|
||||
private int temperature;
|
||||
private Status status = Status.OFF;
|
||||
private final int[] resources;
|
||||
|
||||
public ContainerMachine(InventoryPlayer playerInv, TileEntityMachine tile, IInventory machine, EntityNPC player)
|
||||
{
|
||||
this.machine = machine;
|
||||
this.tile = tile;
|
||||
this.resources = new int[tile.getNumResources()];
|
||||
machine.openInventory(player);
|
||||
int i = 71;
|
||||
|
||||
for (int j = 0; j < machine.getSizeInventory(); ++j)
|
||||
{
|
||||
final int index = j;
|
||||
this.addSlotToContainer(new Slot(machine, j, 8 + j * 18, 40) {
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return ContainerMachine.this.tile.isItemValidForSlot(index, stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (int l = 0; l < 3; ++l)
|
||||
{
|
||||
for (int k = 0; k < 9; ++k)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInv, k + l * 9 + 9, 8 + k * 18, l * 18 + i));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i1 = 0; i1 < 9; ++i1)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInv, i1, 8 + i1 * 18, 58 + i));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.machine.isUseableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
protected boolean canTransfer(Slot slot, ItemStack stack) {
|
||||
return slot.isItemValid(stack);
|
||||
}
|
||||
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot)this.inventorySlots.get(index);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (index < this.machine.getSizeInventory())
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, this.machine.getSizeInventory(), this.inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 0, this.machine.getSizeInventory(), false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
this.machine.closeInventory(playerIn);
|
||||
}
|
||||
|
||||
public void onCraftGuiOpened(ICrafting listener)
|
||||
{
|
||||
super.onCraftGuiOpened(listener);
|
||||
// listener.sendAllWindowProperties(this, this.machine);
|
||||
}
|
||||
|
||||
public void updateProgressBar(int id, int data)
|
||||
{
|
||||
if(id == this.resources.length)
|
||||
this.tile.setTemperature(data);
|
||||
else if(id == this.resources.length + 1)
|
||||
this.tile.setStatus(Status.values()[data % Status.values().length]);
|
||||
else
|
||||
this.tile.getResource(id).setValue(data);
|
||||
}
|
||||
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < this.crafters.size(); ++i)
|
||||
{
|
||||
ICrafting icrafting = (ICrafting)this.crafters.get(i);
|
||||
if(this.temperature != this.tile.getTemperature())
|
||||
icrafting.sendProgressBarUpdate(this, this.resources.length, this.tile.getTemperature());
|
||||
if(this.status != this.tile.getStatus())
|
||||
icrafting.sendProgressBarUpdate(this, this.resources.length + 1, this.tile.getStatus().ordinal());
|
||||
for(int z = 0; z < this.resources.length; z++) {
|
||||
if(this.resources[z] != this.tile.getResource(z).getValue())
|
||||
icrafting.sendProgressBarUpdate(this, z, this.tile.getResource(z).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
this.temperature = this.tile.getTemperature();
|
||||
this.status = this.tile.getStatus();
|
||||
for(int z = 0; z < this.resources.length; z++) {
|
||||
this.resources[z] = this.tile.getResource(z).getValue();
|
||||
}
|
||||
}
|
||||
}
|
165
java/src/game/inventory/ContainerMerchant.java
Executable file
165
java/src/game/inventory/ContainerMerchant.java
Executable file
|
@ -0,0 +1,165 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
import game.world.World;
|
||||
|
||||
public class ContainerMerchant extends Container
|
||||
{
|
||||
private EntityNPC theMerchant;
|
||||
private InventoryMerchant merchantInventory;
|
||||
private final World theWorld;
|
||||
|
||||
public ContainerMerchant(InventoryPlayer playerInventory, EntityNPC merchant, World worldIn)
|
||||
{
|
||||
this.theMerchant = merchant;
|
||||
this.theWorld = 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, 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;
|
||||
}
|
||||
|
||||
public void onCraftGuiOpened(ICrafting listener)
|
||||
{
|
||||
super.onCraftGuiOpened(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for changes made in the container, sends them to every listener.
|
||||
*/
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
public void updateProgressBar(int id, int data)
|
||||
{
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.theMerchant == null || this.theMerchant.getTalking() == playerIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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 null;
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
}
|
||||
else if (index != 0 && index != 1)
|
||||
{
|
||||
if (index >= 3 && index < 30)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 30, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
if(this.theMerchant != null)
|
||||
this.theMerchant.setTalking(null);
|
||||
super.onContainerClosed(playerIn);
|
||||
|
||||
if (!this.theWorld.client)
|
||||
{
|
||||
ItemStack itemstack = this.merchantInventory.removeStackFromSlot(0);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
|
||||
itemstack = this.merchantInventory.removeStackFromSlot(1);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
233
java/src/game/inventory/ContainerPlayer.java
Executable file
233
java/src/game/inventory/ContainerPlayer.java
Executable file
|
@ -0,0 +1,233 @@
|
|||
package game.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.entity.attributes.AttributeMap;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.CraftingRegistry;
|
||||
import game.item.ItemArmor;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class ContainerPlayer extends Container
|
||||
{
|
||||
private final InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
|
||||
private final IInventory craftResult = new InventoryCraftResult();
|
||||
private final boolean isLocalWorld;
|
||||
private final EntityNPC thePlayer;
|
||||
private final AttributeMap attributes;
|
||||
private final List<ItemStack> lastStacks = Lists.<ItemStack>newArrayList();
|
||||
|
||||
public ContainerPlayer(final InventoryPlayer playerInventory, boolean localWorld, EntityNPC player)
|
||||
{
|
||||
this.isLocalWorld = localWorld;
|
||||
this.thePlayer = player;
|
||||
this.attributes = player.getAttributeMap();
|
||||
this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 144, 36));
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
for (int j = 0; j < 2; ++j)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 88 + j * 18, 26 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < 4; ++k)
|
||||
{
|
||||
final int k_f = k;
|
||||
this.addSlotToContainer(new Slot(playerInventory, playerInventory.getSizeInventory() - 1 - k, 8, 8 + k * 18)
|
||||
{
|
||||
public int getSlotStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return stack != null && stack.getItem() instanceof ItemArmor && ((ItemArmor)stack.getItem()).armorType == k_f; // : (stack.getItem() != ItemRegistry.getItemFromBlock(Blocks.pumpkin) && stack.getItem() != Items.skull ? false : k_f == 0));
|
||||
}
|
||||
// public String getSlotTexture()
|
||||
// {
|
||||
// return ItemArmor.EMPTY_SLOT_NAMES[k_f];
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
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.onCraftMatrixChanged(this.craftMatrix);
|
||||
}
|
||||
|
||||
protected Slot addSlotToContainer(Slot slotIn)
|
||||
{
|
||||
slotIn = super.addSlotToContainer(slotIn);
|
||||
if(slotIn.slotNumber >= 9)
|
||||
this.lastStacks.add((ItemStack)null);
|
||||
return slotIn;
|
||||
}
|
||||
|
||||
public void detectAttributeChanges()
|
||||
{
|
||||
for (int i = 0; i < this.inventorySlots.size(); ++i)
|
||||
{
|
||||
Slot slot = this.inventorySlots.get(i);
|
||||
if(slot.slotNumber >= 9) {
|
||||
ItemStack current = slot.getStack();
|
||||
ItemStack last = (ItemStack)this.lastStacks.get(i - 9);
|
||||
|
||||
if (!ItemStack.areItemStacksEqual(last, current))
|
||||
{
|
||||
if (last != null)
|
||||
{
|
||||
this.attributes.removeAttributeModifiers(last.getAttributeModifiers(2), slot.getIndex(), last.stackSize);
|
||||
}
|
||||
|
||||
if (current != null)
|
||||
{
|
||||
this.attributes.applyAttributeModifiers(current.getAttributeModifiers(2), slot.getIndex(), current.stackSize);
|
||||
}
|
||||
|
||||
last = current == null ? null : current.copy();
|
||||
this.lastStacks.set(i - 9, last);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the crafting matrix is changed.
|
||||
*/
|
||||
public void onCraftMatrixChanged(IInventory inventoryIn)
|
||||
{
|
||||
this.craftResult.setInventorySlotContents(0, CraftingRegistry.getBasic(this.craftMatrix, this.thePlayer.worldObj));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
}
|
||||
|
||||
this.craftResult.setInventorySlotContents(0, (ItemStack)null);
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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, 9, 45, true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
}
|
||||
else if (index >= 1 && index < 5)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 9, 45, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 5 && index < 9)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 9, 45, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (itemstack.getItem() instanceof ItemArmor && !((Slot)this.inventorySlots.get(5 + ((ItemArmor)itemstack.getItem()).armorType)).getHasStack())
|
||||
{
|
||||
int i = 5 + ((ItemArmor)itemstack.getItem()).armorType;
|
||||
|
||||
if (!this.mergeItemStack(itemstack1, i, i + 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 9 && index < 36)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 36, 45, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 36 && index < 45)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 9, 36, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 9, 45, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
518
java/src/game/inventory/ContainerRepair.java
Executable file
518
java/src/game/inventory/ContainerRepair.java
Executable file
|
@ -0,0 +1,518 @@
|
|||
package game.inventory;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import game.block.BlockAnvil;
|
||||
import game.enchantment.Enchantment;
|
||||
import game.enchantment.EnchantmentHelper;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.init.Config;
|
||||
import game.init.Items;
|
||||
import game.item.ItemStack;
|
||||
import game.world.BlockPos;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ContainerRepair extends Container
|
||||
{
|
||||
/** Here comes out item you merged and/or renamed. */
|
||||
private IInventory outputSlot;
|
||||
|
||||
/**
|
||||
* The 2slots where you put your items in that you want to merge and/or rename.
|
||||
*/
|
||||
private IInventory inputSlots;
|
||||
private World theWorld;
|
||||
private 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 */
|
||||
private int materialCost;
|
||||
// private String repairedItemName;
|
||||
|
||||
/** The player that has this container open. */
|
||||
private final EntityNPC thePlayer;
|
||||
|
||||
public ContainerRepair(InventoryPlayer playerInventory, World worldIn, EntityNPC player)
|
||||
{
|
||||
this(playerInventory, worldIn, BlockPos.ORIGIN, player);
|
||||
}
|
||||
|
||||
public ContainerRepair(InventoryPlayer playerInventory, final World worldIn, final BlockPos blockPosIn, EntityNPC player)
|
||||
{
|
||||
this.outputSlot = new InventoryCraftResult();
|
||||
this.inputSlots = new InventoryBasic("Repair", true, 2)
|
||||
{
|
||||
public void markDirty()
|
||||
{
|
||||
super.markDirty();
|
||||
ContainerRepair.this.onCraftMatrixChanged(this);
|
||||
}
|
||||
};
|
||||
this.selfPosition = blockPosIn;
|
||||
this.theWorld = worldIn;
|
||||
this.thePlayer = 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)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public boolean canTakeStack(EntityNPC playerIn)
|
||||
{
|
||||
return /* (playerIn.creative || */ playerIn.experienceLevel >= ContainerRepair.this.maximumCost /* ) */ && ContainerRepair.this.maximumCost > 0 && this.getHasStack();
|
||||
}
|
||||
public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
playerIn.addExperienceLevel(-ContainerRepair.this.maximumCost);
|
||||
// }
|
||||
|
||||
ContainerRepair.this.inputSlots.setInventorySlotContents(0, (ItemStack)null);
|
||||
|
||||
if (ContainerRepair.this.materialCost > 0)
|
||||
{
|
||||
ItemStack itemstack = ContainerRepair.this.inputSlots.getStackInSlot(1);
|
||||
|
||||
if (itemstack != null && itemstack.stackSize > ContainerRepair.this.materialCost)
|
||||
{
|
||||
itemstack.stackSize -= ContainerRepair.this.materialCost;
|
||||
ContainerRepair.this.inputSlots.setInventorySlotContents(1, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
ContainerRepair.this.inputSlots.setInventorySlotContents(1, (ItemStack)null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ContainerRepair.this.inputSlots.setInventorySlotContents(1, (ItemStack)null);
|
||||
}
|
||||
|
||||
ContainerRepair.this.maximumCost = 0;
|
||||
State iblockstate = worldIn.getState(blockPosIn);
|
||||
|
||||
if (/* !playerIn.creative && */ !worldIn.client && Config.anvilRepairDecay && iblockstate.getBlock() == Blocks.anvil && playerIn.getRNG().floatv() < 0.12F)
|
||||
{
|
||||
int l = ((Integer)iblockstate.getValue(BlockAnvil.DAMAGE)).intValue();
|
||||
++l;
|
||||
|
||||
if (l > 2)
|
||||
{
|
||||
worldIn.setBlockToAir(blockPosIn);
|
||||
worldIn.playAuxSFX(1020, blockPosIn, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setState(blockPosIn, iblockstate.withProperty(BlockAnvil.DAMAGE, Integer.valueOf(l)), 2);
|
||||
worldIn.playAuxSFX(1021, blockPosIn, 0);
|
||||
}
|
||||
}
|
||||
else if (!worldIn.client)
|
||||
{
|
||||
worldIn.playAuxSFX(1021, blockPosIn, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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()
|
||||
{
|
||||
// int i = 0;
|
||||
// int j = 1;
|
||||
// int k = 1;
|
||||
// int l = 1;
|
||||
// int i1 = 2;
|
||||
// int j1 = 1;
|
||||
// int k1 = 1;
|
||||
ItemStack stack = this.inputSlots.getStackInSlot(0);
|
||||
this.maximumCost = 1;
|
||||
int totalCost = 0;
|
||||
int repairCost = 0;
|
||||
int renameCost = 0;
|
||||
|
||||
if (stack == null)
|
||||
{
|
||||
this.outputSlot.setInventorySlotContents(0, (ItemStack)null);
|
||||
this.maximumCost = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack newStack = stack.copy();
|
||||
ItemStack repStack = this.inputSlots.getStackInSlot(1);
|
||||
Map<Integer, Integer> newEnch = EnchantmentHelper.getEnchantments(newStack);
|
||||
boolean isBook = false;
|
||||
repairCost = repairCost + stack.getRepairCost() + (repStack == null ? 0 : repStack.getRepairCost());
|
||||
this.materialCost = 0;
|
||||
|
||||
if (repStack != null)
|
||||
{
|
||||
isBook = repStack.getItem() == Items.enchanted_book && Items.enchanted_book.getEnchantments(repStack).tagCount() > 0;
|
||||
|
||||
if (newStack.isItemStackDamageable() && newStack.getItem().getIsRepairable(stack, repStack))
|
||||
{
|
||||
int damage = Math.min(newStack.getItemDamage(), newStack.getMaxDamage() / 4);
|
||||
|
||||
if (damage <= 0)
|
||||
{
|
||||
this.outputSlot.setInventorySlotContents(0, (ItemStack)null);
|
||||
this.maximumCost = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int cost;
|
||||
|
||||
for (cost = 0; damage > 0 && cost < repStack.stackSize; ++cost)
|
||||
{
|
||||
int j5 = newStack.getItemDamage() - damage;
|
||||
newStack.setItemDamage(j5);
|
||||
++totalCost;
|
||||
damage = Math.min(newStack.getItemDamage(), newStack.getMaxDamage() / 4);
|
||||
}
|
||||
|
||||
this.materialCost = cost;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isBook && (newStack.getItem() != repStack.getItem() || !newStack.isItemStackDamageable()))
|
||||
{
|
||||
this.outputSlot.setInventorySlotContents(0, (ItemStack)null);
|
||||
this.maximumCost = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (newStack.isItemStackDamageable() && !isBook)
|
||||
{
|
||||
int mainDmg = stack.getMaxDamage() - stack.getItemDamage();
|
||||
int repDmg = repStack.getMaxDamage() - repStack.getItemDamage();
|
||||
int repair = repDmg + newStack.getMaxDamage() * 12 / 100;
|
||||
int newDmg = mainDmg + repair;
|
||||
int damage = newStack.getMaxDamage() - newDmg;
|
||||
|
||||
if (damage < 0)
|
||||
{
|
||||
damage = 0;
|
||||
}
|
||||
|
||||
if (damage < newStack.getMetadata())
|
||||
{
|
||||
newStack.setItemDamage(damage);
|
||||
totalCost += 2;
|
||||
}
|
||||
}
|
||||
|
||||
Map<Integer, Integer> ench = EnchantmentHelper.getEnchantments(repStack);
|
||||
Iterator enchs = ench.keySet().iterator();
|
||||
|
||||
while (enchs.hasNext())
|
||||
{
|
||||
int eid = ((Integer)enchs.next()).intValue();
|
||||
Enchantment enchantment = Enchantment.getEnchantmentById(eid);
|
||||
|
||||
if (enchantment != null)
|
||||
{
|
||||
int newLevel = newEnch.containsKey(Integer.valueOf(eid)) ? ((Integer)newEnch.get(Integer.valueOf(eid))).intValue() : 0;
|
||||
int level = ((Integer)ench.get(Integer.valueOf(eid))).intValue();
|
||||
int diff;
|
||||
|
||||
if (newLevel == level)
|
||||
{
|
||||
++level;
|
||||
diff = level;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff = Math.max(level, newLevel);
|
||||
}
|
||||
|
||||
level = diff;
|
||||
boolean applies = enchantment.canApply(stack);
|
||||
|
||||
if (/* this.thePlayer.creative || */ stack.getItem() == Items.enchanted_book)
|
||||
{
|
||||
applies = true;
|
||||
}
|
||||
|
||||
Iterator newEnchs = newEnch.keySet().iterator();
|
||||
|
||||
while (newEnchs.hasNext())
|
||||
{
|
||||
int nEid = ((Integer)newEnchs.next()).intValue();
|
||||
|
||||
if (nEid != eid && !enchantment.canApplyTogether(Enchantment.getEnchantmentById(nEid)))
|
||||
{
|
||||
applies = false;
|
||||
++totalCost;
|
||||
}
|
||||
}
|
||||
|
||||
if (applies)
|
||||
{
|
||||
if (level > enchantment.getMaxLevel())
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
|
||||
newEnch.put(Integer.valueOf(eid), Integer.valueOf(level));
|
||||
int cost = 0;
|
||||
|
||||
switch (enchantment.getWeight())
|
||||
{
|
||||
case 1:
|
||||
cost = 8;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
cost = 4;
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
default:
|
||||
break;
|
||||
|
||||
case 5:
|
||||
cost = 2;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
cost = 1;
|
||||
}
|
||||
|
||||
if (isBook)
|
||||
{
|
||||
cost = Math.max(1, cost / 2);
|
||||
}
|
||||
|
||||
totalCost += cost * level;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (isBlank(this.repairedItemName))
|
||||
// {
|
||||
// if (stack.hasDisplayName())
|
||||
// {
|
||||
// renameCost = 1;
|
||||
// totalCost += renameCost;
|
||||
// newStack.clearCustomName();
|
||||
// }
|
||||
// }
|
||||
// else if (!this.repairedItemName.equals(stack.getDisplayName()))
|
||||
// {
|
||||
// renameCost = 1;
|
||||
// totalCost += renameCost;
|
||||
// newStack.setStackDisplayName(this.repairedItemName);
|
||||
// }
|
||||
|
||||
this.maximumCost = repairCost + totalCost;
|
||||
|
||||
if (totalCost <= 0)
|
||||
{
|
||||
newStack = null;
|
||||
}
|
||||
|
||||
if (renameCost == totalCost && renameCost > 0 && this.maximumCost >= 40)
|
||||
{
|
||||
this.maximumCost = 39;
|
||||
}
|
||||
|
||||
if (/* Config.repairExperience && */ this.maximumCost >= 40) // && !this.thePlayer.creative)
|
||||
{
|
||||
newStack = null;
|
||||
}
|
||||
|
||||
if (newStack != null)
|
||||
{
|
||||
if(!this.theWorld.client && Config.repairXP) {
|
||||
int cost = newStack.getRepairCost();
|
||||
|
||||
if (repStack != null && cost < repStack.getRepairCost())
|
||||
{
|
||||
cost = repStack.getRepairCost();
|
||||
}
|
||||
|
||||
cost = cost * 2 + 1;
|
||||
newStack.setRepairCost(cost);
|
||||
}
|
||||
EnchantmentHelper.setEnchantments(newEnch, newStack);
|
||||
}
|
||||
|
||||
this.outputSlot.setInventorySlotContents(0, newStack);
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public void onCraftGuiOpened(ICrafting listener)
|
||||
{
|
||||
super.onCraftGuiOpened(listener);
|
||||
listener.sendProgressBarUpdate(this, 0, this.maximumCost);
|
||||
}
|
||||
|
||||
public void updateProgressBar(int id, int data)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
this.maximumCost = data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
|
||||
if (!this.theWorld.client)
|
||||
{
|
||||
for (int i = 0; i < this.inputSlots.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = this.inputSlots.removeStackFromSlot(i);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.theWorld.getState(this.selfPosition).getBlock() != Blocks.anvil ? false : playerIn.getDistanceSq((double)this.selfPosition.getX() + 0.5D, (double)this.selfPosition.getY() + 0.5D, (double)this.selfPosition.getZ() + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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 null;
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
}
|
||||
else if (index != 0 && index != 1)
|
||||
{
|
||||
if (index >= 3 && index < 39 && !this.mergeItemStack(itemstack1, 0, 2, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(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 (isBlank(newName))
|
||||
// {
|
||||
// itemstack.clearCustomName();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// itemstack.setStackDisplayName(this.repairedItemName);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// this.updateRepairOutput();
|
||||
// }
|
||||
|
||||
// private static boolean isBlank(String s) {
|
||||
// if(s != null && !s.isEmpty()) {
|
||||
// for(int i = 0; i < s.length(); ++i) {
|
||||
// if(!Character.isWhitespace(s.charAt(i))) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// else {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
}
|
153
java/src/game/inventory/ContainerWorkbench.java
Executable file
153
java/src/game/inventory/ContainerWorkbench.java
Executable file
|
@ -0,0 +1,153 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.init.CraftingRegistry;
|
||||
import game.item.ItemStack;
|
||||
import game.world.BlockPos;
|
||||
import game.world.World;
|
||||
|
||||
public class ContainerWorkbench extends Container
|
||||
{
|
||||
/** The crafting matrix inventory (3x3). */
|
||||
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
|
||||
public IInventory craftResult = new InventoryCraftResult();
|
||||
private World worldObj;
|
||||
|
||||
/** Position of the workbench */
|
||||
private BlockPos pos;
|
||||
|
||||
public ContainerWorkbench(InventoryPlayer playerInventory, World worldIn, BlockPos posIn)
|
||||
{
|
||||
this.worldObj = worldIn;
|
||||
this.pos = posIn;
|
||||
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));
|
||||
}
|
||||
|
||||
this.onCraftMatrixChanged(this.craftMatrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the crafting matrix is changed.
|
||||
*/
|
||||
public void onCraftMatrixChanged(IInventory inventoryIn)
|
||||
{
|
||||
this.craftResult.setInventorySlotContents(0, CraftingRegistry.getMatching(this.craftMatrix, this.worldObj));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
|
||||
if (!this.worldObj.client)
|
||||
{
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.worldObj.getState(this.pos).getBlock() != Blocks.crafting_table ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot 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, 10, 46, true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
}
|
||||
else if (index >= 10 && index < 37)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 37, 46, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= 37 && index < 46)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 10, 37, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 10, 46, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
13
java/src/game/inventory/ICrafting.java
Executable file
13
java/src/game/inventory/ICrafting.java
Executable file
|
@ -0,0 +1,13 @@
|
|||
package game.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.item.ItemStack;
|
||||
|
||||
public interface ICrafting
|
||||
{
|
||||
void updateCraftingInventory(Container containerToSend, List<ItemStack> itemsList);
|
||||
void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack);
|
||||
void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue);
|
||||
void sendAllWindowProperties(Container p_175173_1_, IInventory p_175173_2_);
|
||||
}
|
9
java/src/game/inventory/IInvBasic.java
Executable file
9
java/src/game/inventory/IInvBasic.java
Executable file
|
@ -0,0 +1,9 @@
|
|||
package game.inventory;
|
||||
|
||||
public interface IInvBasic
|
||||
{
|
||||
/**
|
||||
* Called by InventoryBasic.onInventoryChanged() on a array that is never filled.
|
||||
*/
|
||||
void onInventoryChanged(InventoryBasic p_76316_1_);
|
||||
}
|
66
java/src/game/inventory/IInventory.java
Executable file
66
java/src/game/inventory/IInventory.java
Executable file
|
@ -0,0 +1,66 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
import game.tileentity.IWorldNameable;
|
||||
|
||||
public interface IInventory extends IWorldNameable
|
||||
{
|
||||
/**
|
||||
* Returns the number of slots in the inventory.
|
||||
*/
|
||||
int getSizeInventory();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Do not make give this method the name canInteractWith because it clashes with Container
|
||||
*/
|
||||
boolean isUseableByPlayer(EntityNPC player);
|
||||
|
||||
void openInventory(EntityNPC player);
|
||||
|
||||
void closeInventory(EntityNPC player);
|
||||
|
||||
/**
|
||||
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
|
||||
*/
|
||||
boolean isItemValidForSlot(int index, ItemStack stack);
|
||||
|
||||
int getField(int id);
|
||||
|
||||
void setField(int id, int value);
|
||||
|
||||
int getFieldCount();
|
||||
|
||||
void clear();
|
||||
}
|
21
java/src/game/inventory/ISidedInventory.java
Executable file
21
java/src/game/inventory/ISidedInventory.java
Executable file
|
@ -0,0 +1,21 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.item.ItemStack;
|
||||
import game.world.Facing;
|
||||
|
||||
public interface ISidedInventory extends IInventory
|
||||
{
|
||||
int[] getSlotsForFace(Facing side);
|
||||
|
||||
/**
|
||||
* Returns true if automation can insert the given item in the given slot from the given side. Args: slot, item,
|
||||
* side
|
||||
*/
|
||||
boolean canInsertItem(int index, ItemStack itemStackIn, Facing direction);
|
||||
|
||||
/**
|
||||
* Returns true if automation can extract the given item in the given slot from the given side. Args: slot, item,
|
||||
* side
|
||||
*/
|
||||
boolean canExtractItem(int index, ItemStack stack, Facing direction);
|
||||
}
|
287
java/src/game/inventory/InventoryBasic.java
Executable file
287
java/src/game/inventory/InventoryBasic.java
Executable file
|
@ -0,0 +1,287 @@
|
|||
package game.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class InventoryBasic implements IInventory
|
||||
{
|
||||
private String inventoryTitle;
|
||||
private String inventoryComp;
|
||||
private int slotsCount;
|
||||
private ItemStack[] inventoryContents;
|
||||
private List<IInvBasic> changeListeners;
|
||||
private boolean hasCustomName;
|
||||
|
||||
public InventoryBasic(String title, boolean customName, int slotCount)
|
||||
{
|
||||
this.inventoryTitle = title;
|
||||
this.hasCustomName = customName;
|
||||
this.slotsCount = slotCount;
|
||||
this.inventoryContents = new ItemStack[slotCount];
|
||||
}
|
||||
|
||||
public InventoryBasic(String title, int slotCount)
|
||||
{
|
||||
this(title, true, slotCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener that will be notified when any item in this inventory is modified.
|
||||
*
|
||||
* @param listener the listener to add
|
||||
*/
|
||||
public void addInventoryChangeListener(IInvBasic listener)
|
||||
{
|
||||
if (this.changeListeners == null)
|
||||
{
|
||||
this.changeListeners = Lists.<IInvBasic>newArrayList();
|
||||
}
|
||||
|
||||
this.changeListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes the specified IInvBasic from receiving further change notices
|
||||
*
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public void removeInventoryChangeListener(IInvBasic listener)
|
||||
{
|
||||
this.changeListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stack in the given slot.
|
||||
*/
|
||||
public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
return index >= 0 && index < this.inventoryContents.length ? this.inventoryContents[index] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (this.inventoryContents[index] != null)
|
||||
{
|
||||
if (this.inventoryContents[index].stackSize <= count)
|
||||
{
|
||||
ItemStack itemstack1 = this.inventoryContents[index];
|
||||
this.inventoryContents[index] = null;
|
||||
this.markDirty();
|
||||
return itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = this.inventoryContents[index].splitStack(count);
|
||||
|
||||
if (this.inventoryContents[index].stackSize == 0)
|
||||
{
|
||||
this.inventoryContents[index] = null;
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack addStack(ItemStack stack)
|
||||
{
|
||||
ItemStack itemstack = stack.copy();
|
||||
|
||||
for (int i = 0; i < this.slotsCount; ++i)
|
||||
{
|
||||
ItemStack itemstack1 = this.getStackInSlot(i);
|
||||
|
||||
if (itemstack1 == null)
|
||||
{
|
||||
this.setInventorySlotContents(i, itemstack);
|
||||
this.markDirty();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ItemStack.areItemsEqual(itemstack1, itemstack))
|
||||
{
|
||||
int j = Math.min(this.getInventoryStackLimit(), itemstack1.getMaxStackSize());
|
||||
int k = Math.min(itemstack.stackSize, j - itemstack1.stackSize);
|
||||
|
||||
if (k > 0)
|
||||
{
|
||||
itemstack1.stackSize += k;
|
||||
itemstack.stackSize -= k;
|
||||
|
||||
if (itemstack.stackSize <= 0)
|
||||
{
|
||||
this.markDirty();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itemstack.stackSize != stack.stackSize)
|
||||
{
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a stack from the given slot and returns it.
|
||||
*/
|
||||
public ItemStack removeStackFromSlot(int index)
|
||||
{
|
||||
if (this.inventoryContents[index] != null)
|
||||
{
|
||||
ItemStack itemstack = this.inventoryContents[index];
|
||||
this.inventoryContents[index] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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[index] = stack;
|
||||
|
||||
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
|
||||
{
|
||||
stack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of slots in the inventory.
|
||||
*/
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.slotsCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
// }
|
||||
|
||||
public void setCustomName(String inventoryCompIn)
|
||||
{
|
||||
this.hasCustomName = true;
|
||||
this.inventoryComp = inventoryCompIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted ChatComponent that will be used for the sender's username in chat
|
||||
*/
|
||||
public String getCommandName()
|
||||
{
|
||||
return this.inventoryComp != null ? this.inventoryComp : this.getName();
|
||||
// ((TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
|
||||
*/
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return ItemStack.MAX_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
((IInvBasic)this.changeListeners.get(i)).onInventoryChanged(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not make give this method the name canInteractWith because it clashes with Container
|
||||
*/
|
||||
public boolean isUseableByPlayer(EntityNPC player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void openInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
public void closeInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
|
||||
*/
|
||||
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()
|
||||
{
|
||||
for (int i = 0; i < this.inventoryContents.length; ++i)
|
||||
{
|
||||
this.inventoryContents[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
154
java/src/game/inventory/InventoryCraftResult.java
Executable file
154
java/src/game/inventory/InventoryCraftResult.java
Executable file
|
@ -0,0 +1,154 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class InventoryCraftResult implements IInventory
|
||||
{
|
||||
/** A list of one item containing the result of the crafting formula */
|
||||
private ItemStack[] stackResult = new ItemStack[1];
|
||||
|
||||
/**
|
||||
* Returns the number of slots in the inventory.
|
||||
*/
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stack in the given slot.
|
||||
*/
|
||||
public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
return this.stackResult[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 String getCommandName()
|
||||
{
|
||||
return this.getName(); // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (this.stackResult[0] != null)
|
||||
{
|
||||
ItemStack itemstack = this.stackResult[0];
|
||||
this.stackResult[0] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a stack from the given slot and returns it.
|
||||
*/
|
||||
public ItemStack removeStackFromSlot(int index)
|
||||
{
|
||||
if (this.stackResult[0] != null)
|
||||
{
|
||||
ItemStack itemstack = this.stackResult[0];
|
||||
this.stackResult[0] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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[0] = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
|
||||
*/
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return ItemStack.MAX_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not make give this method the name canInteractWith because it clashes with Container
|
||||
*/
|
||||
public boolean isUseableByPlayer(EntityNPC player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void openInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
public void closeInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
|
||||
*/
|
||||
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()
|
||||
{
|
||||
for (int i = 0; i < this.stackResult.length; ++i)
|
||||
{
|
||||
this.stackResult[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
207
java/src/game/inventory/InventoryCrafting.java
Executable file
207
java/src/game/inventory/InventoryCrafting.java
Executable file
|
@ -0,0 +1,207 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class InventoryCrafting implements IInventory
|
||||
{
|
||||
/** List of the stacks in the crafting matrix. */
|
||||
private final 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.
|
||||
*/
|
||||
private final Container eventHandler;
|
||||
|
||||
public InventoryCrafting(Container eventHandlerIn, int width, int height)
|
||||
{
|
||||
int i = width * height;
|
||||
this.stackList = new ItemStack[i];
|
||||
this.eventHandler = eventHandlerIn;
|
||||
this.inventoryWidth = width;
|
||||
this.inventoryHeight = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of slots in the inventory.
|
||||
*/
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.stackList.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stack in the given slot.
|
||||
*/
|
||||
public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
return index >= this.getSizeInventory() ? null : this.stackList[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the itemstack in the slot specified (Top left is 0, 0). Args: row, column
|
||||
*/
|
||||
public ItemStack getStackInRowAndColumn(int row, int column)
|
||||
{
|
||||
return row >= 0 && row < this.inventoryWidth && column >= 0 && column <= this.inventoryHeight ? this.getStackInSlot(row + column * this.inventoryWidth) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this object. For players this returns their username
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "Handwerk";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 String getCommandName()
|
||||
{
|
||||
return this.getName(); // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a stack from the given slot and returns it.
|
||||
*/
|
||||
public ItemStack removeStackFromSlot(int index)
|
||||
{
|
||||
if (this.stackList[index] != null)
|
||||
{
|
||||
ItemStack itemstack = this.stackList[index];
|
||||
this.stackList[index] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (this.stackList[index] != null)
|
||||
{
|
||||
if (this.stackList[index].stackSize <= count)
|
||||
{
|
||||
ItemStack itemstack1 = this.stackList[index];
|
||||
this.stackList[index] = null;
|
||||
this.eventHandler.onCraftMatrixChanged(this);
|
||||
return itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = this.stackList[index].splitStack(count);
|
||||
|
||||
if (this.stackList[index].stackSize == 0)
|
||||
{
|
||||
this.stackList[index] = null;
|
||||
}
|
||||
|
||||
this.eventHandler.onCraftMatrixChanged(this);
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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[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 ItemStack.MAX_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not make give this method the name canInteractWith because it clashes with Container
|
||||
*/
|
||||
public boolean isUseableByPlayer(EntityNPC player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void openInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
public void closeInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
|
||||
*/
|
||||
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()
|
||||
{
|
||||
for (int i = 0; i < this.stackList.length; ++i)
|
||||
{
|
||||
this.stackList[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return this.inventoryHeight;
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return this.inventoryWidth;
|
||||
}
|
||||
}
|
68
java/src/game/inventory/InventoryHelper.java
Executable file
68
java/src/game/inventory/InventoryHelper.java
Executable file
|
@ -0,0 +1,68 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.entity.item.EntityItem;
|
||||
import game.item.ItemStack;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.rng.Random;
|
||||
import game.world.BlockPos;
|
||||
import game.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 != null)
|
||||
{
|
||||
spawnItemStack(worldIn, x, y, z, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void spawnItemStack(World worldIn, double x, double y, double z, ItemStack stack) // fixed: large sizes
|
||||
{
|
||||
float f = RANDOM.floatv() * 0.8F + 0.1F;
|
||||
float f1 = RANDOM.floatv() * 0.8F + 0.1F;
|
||||
float f2 = RANDOM.floatv() * 0.8F + 0.1F;
|
||||
|
||||
while (stack.stackSize > 0)
|
||||
{
|
||||
int i = stack.stackSize > 64 ? stack.stackSize : (RANDOM.zrange(21) + 10);
|
||||
|
||||
if (i > stack.stackSize)
|
||||
{
|
||||
i = stack.stackSize;
|
||||
}
|
||||
|
||||
stack.stackSize -= i;
|
||||
EntityItem entityitem = new EntityItem(worldIn, x + (double)f, y + (double)f1, z + (double)f2, new ItemStack(stack.getItem(), i, stack.getMetadata()));
|
||||
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
|
||||
}
|
||||
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = RANDOM.gaussian() * (double)f3;
|
||||
entityitem.motionY = RANDOM.gaussian() * (double)f3 + 0.20000000298023224D;
|
||||
entityitem.motionZ = RANDOM.gaussian() * (double)f3;
|
||||
worldIn.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
217
java/src/game/inventory/InventoryLargeChest.java
Executable file
217
java/src/game/inventory/InventoryLargeChest.java
Executable file
|
@ -0,0 +1,217 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
import game.tileentity.ILockableContainer;
|
||||
import game.tileentity.LockCode;
|
||||
import game.tileentity.TileEntityChest;
|
||||
|
||||
public class InventoryLargeChest implements ILockableContainer
|
||||
{
|
||||
/** Name of the chest. */
|
||||
private String name;
|
||||
|
||||
/** Inventory object corresponding to double chest upper part */
|
||||
private TileEntityChest upperChest;
|
||||
|
||||
/** Inventory object corresponding to double chest lower part */
|
||||
private TileEntityChest lowerChest;
|
||||
|
||||
public InventoryLargeChest(String nameIn, TileEntityChest upperChestIn, TileEntityChest 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
return this.upperChest.hasCustomName() ? this.upperChest.getName() : (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 String getCommandName()
|
||||
{
|
||||
return this.getName(); // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not make give this method the name canInteractWith because it clashes with Container
|
||||
*/
|
||||
public boolean isUseableByPlayer(EntityNPC player)
|
||||
{
|
||||
return this.upperChest.isUseableByPlayer(player) && this.lowerChest.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
public void openInventory(EntityNPC player)
|
||||
{
|
||||
this.upperChest.openInventory(player);
|
||||
this.lowerChest.openInventory(player);
|
||||
}
|
||||
|
||||
public void closeInventory(EntityNPC 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.
|
||||
*/
|
||||
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, EntityNPC playerIn)
|
||||
{
|
||||
return new ContainerChest(playerInventory, this, playerIn);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.upperChest.clear();
|
||||
this.lowerChest.clear();
|
||||
}
|
||||
}
|
291
java/src/game/inventory/InventoryMerchant.java
Executable file
291
java/src/game/inventory/InventoryMerchant.java
Executable file
|
@ -0,0 +1,291 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
import game.village.MerchantRecipe;
|
||||
import game.village.MerchantRecipeList;
|
||||
|
||||
public class InventoryMerchant implements IInventory
|
||||
{
|
||||
private final EntityNPC theMerchant;
|
||||
private MerchantRecipeList recipeList;
|
||||
private ItemStack[] theInventory = new ItemStack[3];
|
||||
private final EntityNPC thePlayer;
|
||||
private MerchantRecipe currentRecipe;
|
||||
private int currentRecipeIndex;
|
||||
|
||||
public InventoryMerchant(EntityNPC thePlayerIn, EntityNPC theMerchantIn)
|
||||
{
|
||||
this.thePlayer = thePlayerIn;
|
||||
this.theMerchant = theMerchantIn;
|
||||
}
|
||||
|
||||
public void setRecipes(MerchantRecipeList recipes)
|
||||
{
|
||||
this.recipeList = recipes;
|
||||
}
|
||||
|
||||
public MerchantRecipeList getRecipes()
|
||||
{
|
||||
return this.recipeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of slots in the inventory.
|
||||
*/
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.theInventory.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stack in the given slot.
|
||||
*/
|
||||
public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
return this.theInventory[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)
|
||||
{
|
||||
if (this.theInventory[index] != null)
|
||||
{
|
||||
if (index == 2)
|
||||
{
|
||||
ItemStack itemstack2 = this.theInventory[index];
|
||||
this.theInventory[index] = null;
|
||||
return itemstack2;
|
||||
}
|
||||
else if (this.theInventory[index].stackSize <= count)
|
||||
{
|
||||
ItemStack itemstack1 = this.theInventory[index];
|
||||
this.theInventory[index] = null;
|
||||
|
||||
if (this.inventoryResetNeededOnSlotChange(index))
|
||||
{
|
||||
this.resetRecipeAndSlots();
|
||||
}
|
||||
|
||||
return itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = this.theInventory[index].splitStack(count);
|
||||
|
||||
if (this.theInventory[index].stackSize == 0)
|
||||
{
|
||||
this.theInventory[index] = null;
|
||||
}
|
||||
|
||||
if (this.inventoryResetNeededOnSlotChange(index))
|
||||
{
|
||||
this.resetRecipeAndSlots();
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if par1 slot has changed, does resetRecipeAndSlots need to be called?
|
||||
*/
|
||||
private boolean inventoryResetNeededOnSlotChange(int p_70469_1_)
|
||||
{
|
||||
return p_70469_1_ == 0 || p_70469_1_ == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a stack from the given slot and returns it.
|
||||
*/
|
||||
public ItemStack removeStackFromSlot(int index)
|
||||
{
|
||||
if (this.theInventory[index] != null)
|
||||
{
|
||||
ItemStack itemstack = this.theInventory[index];
|
||||
this.theInventory[index] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.theInventory[index] = stack;
|
||||
|
||||
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
|
||||
{
|
||||
stack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
if (this.inventoryResetNeededOnSlotChange(index))
|
||||
{
|
||||
this.resetRecipeAndSlots();
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the name of this object. For players this returns their username
|
||||
// */
|
||||
// public String getName()
|
||||
// {
|
||||
// return "entity.NPC.name";
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 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 String getCommandName()
|
||||
{
|
||||
return "NSC"; // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new Translation(this.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
|
||||
*/
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return ItemStack.MAX_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not make give this method the name canInteractWith because it clashes with Container
|
||||
*/
|
||||
public boolean isUseableByPlayer(EntityNPC player)
|
||||
{
|
||||
return this.theMerchant == null || this.theMerchant.getTalking() == player;
|
||||
}
|
||||
|
||||
public void openInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
public void closeInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
|
||||
*/
|
||||
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.theInventory[0];
|
||||
ItemStack itemstack1 = this.theInventory[1];
|
||||
|
||||
if (itemstack == null)
|
||||
{
|
||||
itemstack = itemstack1;
|
||||
itemstack1 = null;
|
||||
}
|
||||
|
||||
if (itemstack == null)
|
||||
{
|
||||
this.setInventorySlotContents(2, (ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
MerchantRecipeList merchantrecipelist = this.theMerchant == null ? this.recipeList : this.theMerchant.getTrades(this.thePlayer);
|
||||
|
||||
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 != null)
|
||||
{
|
||||
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)null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setInventorySlotContents(2, (ItemStack)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if(this.theMerchant != null)
|
||||
// this.theMerchant.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()
|
||||
{
|
||||
for (int i = 0; i < this.theInventory.length; ++i)
|
||||
{
|
||||
this.theInventory[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
776
java/src/game/inventory/InventoryPlayer.java
Executable file
776
java/src/game/inventory/InventoryPlayer.java
Executable file
|
@ -0,0 +1,776 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.block.Block;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.Item;
|
||||
import game.item.ItemArmor;
|
||||
import game.item.ItemStack;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagList;
|
||||
|
||||
public class InventoryPlayer implements IInventory
|
||||
{
|
||||
/**
|
||||
* An array of 36 item stacks indicating the main player inventory (including the visible bar).
|
||||
*/
|
||||
public ItemStack[] mainInventory = new ItemStack[36];
|
||||
|
||||
/** An array of 4 item stacks containing the currently worn armor pieces. */
|
||||
public ItemStack[] armorInventory = new ItemStack[4];
|
||||
|
||||
/** The index of the currently held item (0-8). */
|
||||
public int currentItem;
|
||||
|
||||
/** The player whose inventory this is. */
|
||||
public EntityNPC player;
|
||||
private ItemStack itemStack;
|
||||
|
||||
/**
|
||||
* Set true whenever the inventory changes. Nothing sets it false so you will have to write your own code to check
|
||||
* it and reset the value.
|
||||
*/
|
||||
public boolean inventoryChanged;
|
||||
|
||||
public InventoryPlayer(EntityNPC playerIn)
|
||||
{
|
||||
this.player = playerIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item stack currently held by the player.
|
||||
*/
|
||||
public ItemStack getCurrentItem()
|
||||
{
|
||||
return this.currentItem < 9 && this.currentItem >= 0 ? this.mainInventory[this.currentItem] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the player hotbar inventory
|
||||
*/
|
||||
public static int getHotbarSize()
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
|
||||
private int getInventorySlotContainItem(Item itemIn)
|
||||
{
|
||||
for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
{
|
||||
if (this.mainInventory[i] != null && this.mainInventory[i].getItem() == itemIn)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int getInventorySlotContainItemAndDamage(Item itemIn, int metadataIn)
|
||||
{
|
||||
for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
{
|
||||
if (this.mainInventory[i] != null && this.mainInventory[i].getItem() == itemIn && this.mainInventory[i].getMetadata() == metadataIn)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* stores an itemstack in the users inventory
|
||||
*/
|
||||
private int storeItemStack(ItemStack itemStackIn)
|
||||
{
|
||||
for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
{
|
||||
if (this.mainInventory[i] != null && this.mainInventory[i].getItem() == itemStackIn.getItem() && this.mainInventory[i].isStackable() && this.mainInventory[i].stackSize < this.mainInventory[i].getMaxStackSize() && this.mainInventory[i].stackSize < this.getInventoryStackLimit() && (!this.mainInventory[i].getHasSubtypes() || this.mainInventory[i].getMetadata() == itemStackIn.getMetadata()) && ItemStack.areItemStackTagsEqual(this.mainInventory[i], itemStackIn))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first item stack that is empty.
|
||||
*/
|
||||
public int getFirstEmptyStack()
|
||||
{
|
||||
for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
{
|
||||
if (this.mainInventory[i] == null)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean setCurrentItem(Item itemIn, int metadataIn, boolean isMetaSpecific) // , boolean p_146030_4_)
|
||||
{
|
||||
// ItemStack itemstack = this.getCurrentItem();
|
||||
int i = isMetaSpecific ? this.getInventorySlotContainItemAndDamage(itemIn, metadataIn) : this.getInventorySlotContainItem(itemIn);
|
||||
|
||||
if (i >= 0 && i < 9)
|
||||
{
|
||||
this.currentItem = i;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// else if (p_146030_4_ && itemIn != null)
|
||||
// {
|
||||
// int j = this.getFirstEmptyStack();
|
||||
//
|
||||
// if (j >= 0 && j < 9)
|
||||
// {
|
||||
// this.currentItem = j;
|
||||
// }
|
||||
//
|
||||
// if (itemstack == null || !itemstack.isItemEnchantable() || this.getInventorySlotContainItemAndDamage(itemstack.getItem(), itemstack.getItemDamage()) != this.currentItem)
|
||||
// {
|
||||
// int k = this.getInventorySlotContainItemAndDamage(itemIn, metadataIn);
|
||||
// int l;
|
||||
//
|
||||
// if (k >= 0)
|
||||
// {
|
||||
// l = this.mainInventory[k].stackSize;
|
||||
// this.mainInventory[k] = this.mainInventory[this.currentItem];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// l = 1;
|
||||
// }
|
||||
//
|
||||
// this.mainInventory[this.currentItem] = new ItemStack(itemIn, l, metadataIn);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch the current item to the next one or the previous one
|
||||
*
|
||||
* @param direction Direction to switch (1, 0, -1). 1 (any > 0) to select item left of current (decreasing
|
||||
* currentItem index), -1 (any < 0) to select item right of current (increasing currentItem index). 0 has no effect.
|
||||
*/
|
||||
public void changeCurrentItem(int direction)
|
||||
{
|
||||
// if (direction > 0)
|
||||
// {
|
||||
// direction = 1;
|
||||
// }
|
||||
//
|
||||
// if (direction < 0)
|
||||
// {
|
||||
// direction = -1;
|
||||
// }
|
||||
|
||||
for (this.currentItem -= direction; this.currentItem < 0; this.currentItem += 9)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
while (this.currentItem >= 9)
|
||||
{
|
||||
this.currentItem -= 9;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearItems() {
|
||||
for(int z = 0; z < this.mainInventory.length; z++) {
|
||||
this.mainInventory[z] = null;
|
||||
}
|
||||
for(int z = 0; z < this.armorInventory.length; z++) {
|
||||
this.armorInventory[z] = null;
|
||||
}
|
||||
this.itemStack = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function stores as many items of an ItemStack as possible in a matching slot and returns the quantity of
|
||||
* left over items.
|
||||
*/
|
||||
private int storePartialItemStack(ItemStack itemStackIn)
|
||||
{
|
||||
Item item = itemStackIn.getItem();
|
||||
int i = itemStackIn.stackSize;
|
||||
int j = this.storeItemStack(itemStackIn);
|
||||
|
||||
if (j < 0)
|
||||
{
|
||||
j = this.getFirstEmptyStack();
|
||||
}
|
||||
|
||||
if (j < 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.mainInventory[j] == null)
|
||||
{
|
||||
this.mainInventory[j] = new ItemStack(item, 0, itemStackIn.getMetadata());
|
||||
|
||||
if (itemStackIn.hasTagCompound())
|
||||
{
|
||||
this.mainInventory[j].setTagCompound((NBTTagCompound)itemStackIn.getTagCompound().copy());
|
||||
}
|
||||
}
|
||||
|
||||
int k = i;
|
||||
|
||||
if (i > this.mainInventory[j].getMaxStackSize() - this.mainInventory[j].stackSize)
|
||||
{
|
||||
k = this.mainInventory[j].getMaxStackSize() - this.mainInventory[j].stackSize;
|
||||
}
|
||||
|
||||
if (k > this.getInventoryStackLimit() - this.mainInventory[j].stackSize)
|
||||
{
|
||||
k = this.getInventoryStackLimit() - this.mainInventory[j].stackSize;
|
||||
}
|
||||
|
||||
if (k == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = i - k;
|
||||
this.mainInventory[j].stackSize += k;
|
||||
// this.mainInventory[j].animationsToGo = 5;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the number of animations remaining. Only called on client side. This is used to handle the animation of
|
||||
* receiving a block.
|
||||
*/
|
||||
// public void decrementAnimations()
|
||||
// {
|
||||
// for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
// {
|
||||
// if (this.mainInventory[i] != null)
|
||||
// {
|
||||
// this.mainInventory[i].updateAnimation(this.player.worldObj, this.player, i, this.currentItem == i);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* removed one item of specified Item from inventory (if it is in a stack, the stack size will reduce with 1)
|
||||
*/
|
||||
public boolean consumeInventoryItem(Item itemIn)
|
||||
{
|
||||
int i = this.getInventorySlotContainItem(itemIn);
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (--this.mainInventory[i].stackSize <= 0)
|
||||
{
|
||||
this.mainInventory[i] = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a specified Item is inside the inventory
|
||||
*/
|
||||
public boolean hasItem(Item itemIn)
|
||||
{
|
||||
int i = this.getInventorySlotContainItem(itemIn);
|
||||
return i >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the item stack to the inventory, returns false if it is impossible.
|
||||
*/
|
||||
public boolean addItemStackToInventory(final ItemStack itemStackIn)
|
||||
{
|
||||
if (itemStackIn != null && itemStackIn.stackSize != 0 && itemStackIn.getItem() != null)
|
||||
{
|
||||
if (itemStackIn.isItemDamaged())
|
||||
{
|
||||
int j = this.getFirstEmptyStack();
|
||||
|
||||
if (j >= 0)
|
||||
{
|
||||
this.mainInventory[j] = ItemStack.copyItemStack(itemStackIn);
|
||||
// this.mainInventory[j].animationsToGo = 5;
|
||||
itemStackIn.stackSize = 0;
|
||||
return true;
|
||||
}
|
||||
// else if (this.player.creative)
|
||||
// {
|
||||
// itemStackIn.stackSize = 0;
|
||||
// return true;
|
||||
// }
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
while (true)
|
||||
{
|
||||
i = itemStackIn.stackSize;
|
||||
itemStackIn.stackSize = this.storePartialItemStack(itemStackIn);
|
||||
|
||||
if (itemStackIn.stackSize <= 0 || itemStackIn.stackSize >= i)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if (itemStackIn.stackSize == i && this.player.creative)
|
||||
// {
|
||||
// itemStackIn.stackSize = 0;
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
return itemStackIn.stackSize < i;
|
||||
// }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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[] aitemstack = this.mainInventory;
|
||||
|
||||
if (index >= this.mainInventory.length)
|
||||
{
|
||||
aitemstack = this.armorInventory;
|
||||
index -= this.mainInventory.length;
|
||||
}
|
||||
|
||||
if (aitemstack[index] != null)
|
||||
{
|
||||
if (aitemstack[index].stackSize <= count)
|
||||
{
|
||||
ItemStack itemstack1 = aitemstack[index];
|
||||
aitemstack[index] = null;
|
||||
return itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = aitemstack[index].splitStack(count);
|
||||
|
||||
if (aitemstack[index].stackSize == 0)
|
||||
{
|
||||
aitemstack[index] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a stack from the given slot and returns it.
|
||||
*/
|
||||
public ItemStack removeStackFromSlot(int index)
|
||||
{
|
||||
ItemStack[] aitemstack = this.mainInventory;
|
||||
|
||||
if (index >= this.mainInventory.length)
|
||||
{
|
||||
aitemstack = this.armorInventory;
|
||||
index -= this.mainInventory.length;
|
||||
}
|
||||
|
||||
if (aitemstack[index] != null)
|
||||
{
|
||||
ItemStack itemstack = aitemstack[index];
|
||||
aitemstack[index] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
ItemStack[] aitemstack = this.mainInventory;
|
||||
|
||||
if (index >= aitemstack.length)
|
||||
{
|
||||
index -= aitemstack.length;
|
||||
aitemstack = this.armorInventory;
|
||||
}
|
||||
|
||||
aitemstack[index] = stack;
|
||||
}
|
||||
|
||||
public float getStrVsBlock(Block blockIn)
|
||||
{
|
||||
float f = 1.0F;
|
||||
|
||||
if (this.mainInventory[this.currentItem] != null)
|
||||
{
|
||||
f *= this.mainInventory[this.currentItem].getStrVsBlock(blockIn);
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the inventory out as a list of compound tags. This is where the slot indices are used (+100 for armor, +80
|
||||
* for crafting).
|
||||
*
|
||||
* @param nbtTagListIn List to append tags to
|
||||
*/
|
||||
public NBTTagList writeToNBT(NBTTagList nbtTagListIn)
|
||||
{
|
||||
for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
{
|
||||
if (this.mainInventory[i] != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setByte("Slot", (byte)i);
|
||||
this.mainInventory[i].writeToNBT(nbttagcompound);
|
||||
nbtTagListIn.appendTag(nbttagcompound);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < this.armorInventory.length; ++j)
|
||||
{
|
||||
if (this.armorInventory[j] != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte)(j + 100));
|
||||
this.armorInventory[j].writeToNBT(nbttagcompound1);
|
||||
nbtTagListIn.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
return nbtTagListIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads from the given tag list and fills the slots in the inventory with the correct items.
|
||||
*
|
||||
* @param nbtTagListIn tagList to read from
|
||||
*/
|
||||
public void readFromNBT(NBTTagList nbtTagListIn)
|
||||
{
|
||||
this.mainInventory = new ItemStack[36];
|
||||
this.armorInventory = new ItemStack[4];
|
||||
|
||||
for (int i = 0; i < nbtTagListIn.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = nbtTagListIn.getCompoundTagAt(i);
|
||||
int j = nbttagcompound.getByte("Slot") & 255;
|
||||
ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
if (j >= 0 && j < this.mainInventory.length)
|
||||
{
|
||||
this.mainInventory[j] = itemstack;
|
||||
}
|
||||
|
||||
if (j >= 100 && j < this.armorInventory.length + 100)
|
||||
{
|
||||
this.armorInventory[j - 100] = itemstack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of slots in the inventory.
|
||||
*/
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.mainInventory.length + 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stack in the given slot.
|
||||
*/
|
||||
public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
ItemStack[] aitemstack = this.mainInventory;
|
||||
|
||||
if (index >= aitemstack.length)
|
||||
{
|
||||
index -= aitemstack.length;
|
||||
aitemstack = this.armorInventory;
|
||||
}
|
||||
|
||||
return aitemstack[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this object. For players this returns their username
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "Inventar";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 String getCommandName()
|
||||
{
|
||||
return this.getName(); //(TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
|
||||
*/
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return ItemStack.MAX_SIZE;
|
||||
}
|
||||
|
||||
public boolean canHeldItemHarvest(Block blockIn)
|
||||
{
|
||||
if (blockIn.getMaterial().isToolNotRequired())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = this.getStackInSlot(this.currentItem);
|
||||
return itemstack != null ? itemstack.canHarvestBlock(blockIn) : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a player armor item (as itemstack) contained in specified armor slot.
|
||||
*
|
||||
* @param slotIn the slot index requested
|
||||
*/
|
||||
public ItemStack armorItemInSlot(int slotIn)
|
||||
{
|
||||
return this.armorInventory[slotIn];
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the damage values and maximum damage values of each armor item, returns the current armor value.
|
||||
*/
|
||||
public int getTotalArmorValue()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (int j = 0; j < this.armorInventory.length; ++j)
|
||||
{
|
||||
if (this.armorInventory[j] != null && this.armorInventory[j].getItem() instanceof ItemArmor)
|
||||
{
|
||||
int k = ((ItemArmor)this.armorInventory[j].getItem()).damageReduceAmount;
|
||||
i += k;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages armor in each slot by the specified amount.
|
||||
*/
|
||||
public void damageArmor(int damage)
|
||||
{
|
||||
damage = damage / 4;
|
||||
|
||||
if (damage < 1)
|
||||
{
|
||||
damage = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.armorInventory.length; ++i)
|
||||
{
|
||||
if (this.armorInventory[i] != null && this.armorInventory[i].getItem() instanceof ItemArmor)
|
||||
{
|
||||
this.armorInventory[i].damageItem(damage, this.player);
|
||||
|
||||
if (this.armorInventory[i].stackSize == 0)
|
||||
{
|
||||
this.armorInventory[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop all armor and main inventory items.
|
||||
*/
|
||||
public void dropAllItems()
|
||||
{
|
||||
for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
{
|
||||
if (this.mainInventory[i] != null)
|
||||
{
|
||||
this.player.dropItem(this.mainInventory[i], true, false);
|
||||
this.mainInventory[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < this.armorInventory.length; ++j)
|
||||
{
|
||||
if (this.armorInventory[j] != null)
|
||||
{
|
||||
this.player.dropItem(this.armorInventory[j], true, false);
|
||||
this.armorInventory[j] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.inventoryChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the stack helds by mouse, used in GUI/Container
|
||||
*/
|
||||
public void setItemStack(ItemStack itemStackIn)
|
||||
{
|
||||
this.itemStack = itemStackIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stack helds by mouse, used in GUI and Containers
|
||||
*/
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not make give this method the name canInteractWith because it clashes with Container
|
||||
*/
|
||||
public boolean isUseableByPlayer(EntityNPC player)
|
||||
{
|
||||
return this.player.dead ? false : player.getDistanceSqToEntity(this.player) <= 64.0D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the specified ItemStack exists in the inventory.
|
||||
*/
|
||||
public boolean hasItemStack(ItemStack itemStackIn)
|
||||
{
|
||||
for (int i = 0; i < this.armorInventory.length; ++i)
|
||||
{
|
||||
if (this.armorInventory[i] != null && this.armorInventory[i].isItemEqual(itemStackIn))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < this.mainInventory.length; ++j)
|
||||
{
|
||||
if (this.mainInventory[j] != null && this.mainInventory[j].isItemEqual(itemStackIn))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void openInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
public void closeInventory(EntityNPC player)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
|
||||
*/
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the ItemStack contents from another InventoryPlayer instance
|
||||
*/
|
||||
public void copyInventory(InventoryPlayer playerInventory)
|
||||
{
|
||||
for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
{
|
||||
this.mainInventory[i] = ItemStack.copyItemStack(playerInventory.mainInventory[i]);
|
||||
}
|
||||
|
||||
for (int j = 0; j < this.armorInventory.length; ++j)
|
||||
{
|
||||
this.armorInventory[j] = ItemStack.copyItemStack(playerInventory.armorInventory[j]);
|
||||
}
|
||||
|
||||
this.currentItem = playerInventory.currentItem;
|
||||
}
|
||||
|
||||
public int getField(int id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setField(int id, int value)
|
||||
{
|
||||
}
|
||||
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
for (int i = 0; i < this.mainInventory.length; ++i)
|
||||
{
|
||||
this.mainInventory[i] = null;
|
||||
}
|
||||
|
||||
for (int j = 0; j < this.armorInventory.length; ++j)
|
||||
{
|
||||
this.armorInventory[j] = null;
|
||||
}
|
||||
}
|
||||
}
|
88
java/src/game/inventory/InventoryWarpChest.java
Executable file
88
java/src/game/inventory/InventoryWarpChest.java
Executable file
|
@ -0,0 +1,88 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.item.ItemStack;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagList;
|
||||
import game.world.BlockPos;
|
||||
|
||||
public class InventoryWarpChest extends InventoryBasic
|
||||
{
|
||||
private BlockPos associatedChest;
|
||||
|
||||
public InventoryWarpChest()
|
||||
{
|
||||
super("Warptruhe", false, 27);
|
||||
}
|
||||
|
||||
public void setChestTileEntity(BlockPos chestTileEntity)
|
||||
{
|
||||
this.associatedChest = chestTileEntity;
|
||||
}
|
||||
|
||||
public void loadInventoryFromNBT(NBTTagList p_70486_1_)
|
||||
{
|
||||
for (int i = 0; i < this.getSizeInventory(); ++i)
|
||||
{
|
||||
this.setInventorySlotContents(i, (ItemStack)null);
|
||||
}
|
||||
|
||||
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, ItemStack.loadItemStackFromNBT(nbttagcompound));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagList saveInventoryToNBT()
|
||||
{
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < this.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = this.getStackInSlot(i);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setByte("Slot", (byte)i);
|
||||
itemstack.writeToNBT(nbttagcompound);
|
||||
nbttaglist.appendTag(nbttagcompound);
|
||||
}
|
||||
}
|
||||
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public boolean isUseableByPlayer(EntityNPC player)
|
||||
{
|
||||
return (this.associatedChest == null || (player.worldObj.getState(this.associatedChest).getBlock() == Blocks.warp_chest && player.getDistanceSq((double)this.associatedChest.getX() + 0.5D, (double)this.associatedChest.getY() + 0.5D, (double)this.associatedChest.getZ() + 0.5D) <= 64.0D)) && super.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
// public void openInventory(EntityNPC player)
|
||||
// {
|
||||
// if (this.associatedChest != null)
|
||||
// {
|
||||
// this.associatedChest.openChest();
|
||||
// }
|
||||
//
|
||||
// super.openInventory(player);
|
||||
// }
|
||||
|
||||
public void closeInventory(EntityNPC player)
|
||||
{
|
||||
// if (this.associatedChest != null)
|
||||
// {
|
||||
// this.associatedChest.closeChest();
|
||||
// }
|
||||
|
||||
super.closeInventory(player);
|
||||
this.associatedChest = null;
|
||||
}
|
||||
}
|
167
java/src/game/inventory/Slot.java
Executable file
167
java/src/game/inventory/Slot.java
Executable file
|
@ -0,0 +1,167 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
|
||||
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 xDisplayPosition;
|
||||
|
||||
/** display position of the inventory slot on the screen y axis */
|
||||
public int yDisplayPosition;
|
||||
|
||||
public Slot(IInventory inventoryIn, int index, int xPosition, int yPosition)
|
||||
{
|
||||
this.inventory = inventoryIn;
|
||||
this.slotIndex = index;
|
||||
this.xDisplayPosition = xPosition;
|
||||
this.yDisplayPosition = yPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* if par2 has more items than par1, onCrafting(item,countIncrease) is called
|
||||
*/
|
||||
public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_)
|
||||
{
|
||||
if (p_75220_1_ != null && p_75220_2_ != null)
|
||||
{
|
||||
if (p_75220_1_.getItem() == p_75220_2_.getItem())
|
||||
{
|
||||
int i = p_75220_2_.stackSize - p_75220_1_.stackSize;
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
this.onCrafting(p_75220_1_, 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)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
|
||||
*/
|
||||
protected void onCrafting(ItemStack stack)
|
||||
{
|
||||
}
|
||||
|
||||
public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
|
||||
{
|
||||
this.onSlotChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
||||
*/
|
||||
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() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
// public String getSlotTexture()
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 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(EntityNPC 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)
|
||||
*/
|
||||
public boolean canBeHovered()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return this.slotIndex;
|
||||
}
|
||||
}
|
155
java/src/game/inventory/SlotCrafting.java
Executable file
155
java/src/game/inventory/SlotCrafting.java
Executable file
|
@ -0,0 +1,155 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.CraftingRegistry;
|
||||
import game.item.ItemStack;
|
||||
|
||||
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. */
|
||||
private final EntityNPC thePlayer;
|
||||
|
||||
/**
|
||||
* The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.
|
||||
*/
|
||||
private int amountCrafted;
|
||||
|
||||
public SlotCrafting(EntityNPC player, InventoryCrafting craftingInventory, IInventory p_i45790_3_, int slotIndex, int xPosition, int yPosition)
|
||||
{
|
||||
super(p_i45790_3_, slotIndex, xPosition, yPosition);
|
||||
this.thePlayer = player;
|
||||
this.craftMatrix = craftingInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
||||
*/
|
||||
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().stackSize);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.thePlayer.worldObj, this.thePlayer, this.amountCrafted);
|
||||
// }
|
||||
|
||||
this.amountCrafted = 0;
|
||||
|
||||
// if (stack.getItem() == ItemRegistry.getItemFromBlock(Blocks.crafting_table))
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.buildWorkBench);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() instanceof ItemPickaxe)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.buildPickaxe);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() == ItemRegistry.getItemFromBlock(Blocks.furnace))
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.buildFurnace);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() instanceof ItemHoe)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.buildHoe);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() == Items.bread)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.makeBread);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() == Items.cake)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.bakeCake);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() instanceof ItemPickaxe && ((ItemPickaxe)stack.getItem()).getToolMaterial() != ToolMaterial.WOOD)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.buildBetterPickaxe);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() instanceof ItemSword)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.buildSword);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() == ItemRegistry.getItemFromBlock(Blocks.enchanting_table))
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.enchantments);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() == ItemRegistry.getItemFromBlock(Blocks.bookshelf))
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.bookcase);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() == Items.golden_apple && stack.getMetadata() == 1)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.overpowered);
|
||||
// }
|
||||
}
|
||||
|
||||
public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
|
||||
{
|
||||
this.onCrafting(stack);
|
||||
ItemStack[] aitemstack = CraftingRegistry.getRequired(this.craftMatrix, playerIn.worldObj);
|
||||
|
||||
for (int i = 0; i < aitemstack.length; ++i)
|
||||
{
|
||||
ItemStack itemstack = this.craftMatrix.getStackInSlot(i);
|
||||
ItemStack itemstack1 = aitemstack[i];
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
this.craftMatrix.decrStackSize(i, 1);
|
||||
}
|
||||
|
||||
if (itemstack1 != null)
|
||||
{
|
||||
if (this.craftMatrix.getStackInSlot(i) == null)
|
||||
{
|
||||
this.craftMatrix.setInventorySlotContents(i, itemstack1);
|
||||
}
|
||||
else if (!this.thePlayer.inventory.addItemStackToInventory(itemstack1))
|
||||
{
|
||||
this.thePlayer.dropPlayerItemWithRandomChoice(itemstack1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
java/src/game/inventory/SlotFurnaceFuel.java
Executable file
31
java/src/game/inventory/SlotFurnaceFuel.java
Executable file
|
@ -0,0 +1,31 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.init.Items;
|
||||
import game.item.ItemStack;
|
||||
import game.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 a valid item for this slot. Always true beside for the armor slots.
|
||||
*/
|
||||
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 != null && stack.getItem() != null && stack.getItem() == Items.bucket;
|
||||
}
|
||||
}
|
108
java/src/game/inventory/SlotFurnaceOutput.java
Executable file
108
java/src/game/inventory/SlotFurnaceOutput.java
Executable file
|
@ -0,0 +1,108 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.entity.item.EntityXp;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Config;
|
||||
import game.init.SmeltingRegistry;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class SlotFurnaceOutput extends Slot
|
||||
{
|
||||
/** The player that is using the GUI where this slot resides. */
|
||||
private EntityNPC thePlayer;
|
||||
private int smelted;
|
||||
|
||||
public SlotFurnaceOutput(EntityNPC player, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
|
||||
{
|
||||
super(inventoryIn, slotIndex, xPosition, yPosition);
|
||||
this.thePlayer = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
||||
*/
|
||||
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.smelted += Math.min(amount, this.getStack().stackSize);
|
||||
}
|
||||
|
||||
return super.decrStackSize(amount);
|
||||
}
|
||||
|
||||
public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
|
||||
{
|
||||
this.onCrafting(stack);
|
||||
super.onPickupFromSlot(playerIn, 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.smelted += 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.thePlayer.worldObj, this.thePlayer, this.smelted);
|
||||
|
||||
if (!this.thePlayer.worldObj.client && Config.smeltingXP)
|
||||
{
|
||||
int xp = this.smelted;
|
||||
float smeltXp = SmeltingRegistry.getExperience(stack);
|
||||
|
||||
if (smeltXp == 0.0F)
|
||||
{
|
||||
xp = 0;
|
||||
}
|
||||
else if (smeltXp < 1.0F)
|
||||
{
|
||||
int mxp = ExtMath.floorf((float)xp * smeltXp);
|
||||
|
||||
if (mxp < ExtMath.ceilf((float)xp * smeltXp) && Math.random() < (double)((float)xp * smeltXp - (float)mxp))
|
||||
{
|
||||
++mxp;
|
||||
}
|
||||
|
||||
xp = mxp;
|
||||
}
|
||||
|
||||
while (xp > 0)
|
||||
{
|
||||
int split = EntityXp.getXPSplit(xp);
|
||||
xp -= split;
|
||||
this.thePlayer.worldObj.spawnEntityInWorld(new EntityXp(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, split));
|
||||
}
|
||||
}
|
||||
|
||||
this.smelted = 0;
|
||||
|
||||
// if (stack.getItem() == Items.iron_ingot)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.acquireIron);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() == Items.cooked_fish)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.cookFish);
|
||||
// }
|
||||
}
|
||||
}
|
118
java/src/game/inventory/SlotMerchantResult.java
Executable file
118
java/src/game/inventory/SlotMerchantResult.java
Executable file
|
@ -0,0 +1,118 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
import game.village.MerchantRecipe;
|
||||
|
||||
public class SlotMerchantResult extends Slot
|
||||
{
|
||||
private final InventoryMerchant theMerchantInventory;
|
||||
private EntityNPC thePlayer;
|
||||
private int traded;
|
||||
// private final EntityVillager theMerchant;
|
||||
|
||||
public SlotMerchantResult(EntityNPC player, InventoryMerchant merchantInventory, int slotIndex, int xPosition, int yPosition)
|
||||
{
|
||||
super(merchantInventory, slotIndex, xPosition, yPosition);
|
||||
this.thePlayer = player;
|
||||
// this.theMerchant = merchant;
|
||||
this.theMerchantInventory = merchantInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
||||
*/
|
||||
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.traded += Math.min(amount, this.getStack().stackSize);
|
||||
}
|
||||
|
||||
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.traded += 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.thePlayer.worldObj, this.thePlayer, this.traded);
|
||||
this.traded = 0;
|
||||
}
|
||||
|
||||
public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
|
||||
{
|
||||
this.onCrafting(stack);
|
||||
MerchantRecipe merchantrecipe = this.theMerchantInventory.getCurrentRecipe();
|
||||
|
||||
if (merchantrecipe != null)
|
||||
{
|
||||
ItemStack itemstack = this.theMerchantInventory.getStackInSlot(0);
|
||||
ItemStack itemstack1 = this.theMerchantInventory.getStackInSlot(1);
|
||||
|
||||
if (this.doTrade(merchantrecipe, itemstack, itemstack1) || this.doTrade(merchantrecipe, itemstack1, itemstack))
|
||||
{
|
||||
// if(this.theMerchant != null)
|
||||
// this.theMerchant.useRecipe(merchantrecipe);
|
||||
// playerIn.triggerAchievement(StatRegistry.timesTradedWithNpcStat);
|
||||
|
||||
if (itemstack != null && itemstack.stackSize <= 0)
|
||||
{
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
if (itemstack1 != null && itemstack1.stackSize <= 0)
|
||||
{
|
||||
itemstack1 = null;
|
||||
}
|
||||
|
||||
this.theMerchantInventory.setInventorySlotContents(0, itemstack);
|
||||
this.theMerchantInventory.setInventorySlotContents(1, itemstack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doTrade(MerchantRecipe trade, ItemStack firstItem, ItemStack secondItem)
|
||||
{
|
||||
ItemStack itemstack = trade.getItemToBuy();
|
||||
ItemStack itemstack1 = trade.getSecondItemToBuy();
|
||||
|
||||
if (firstItem != null && firstItem.getItem() == itemstack.getItem())
|
||||
{
|
||||
if (itemstack1 != null && secondItem != null && itemstack1.getItem() == secondItem.getItem())
|
||||
{
|
||||
firstItem.stackSize -= itemstack.stackSize;
|
||||
secondItem.stackSize -= itemstack1.stackSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itemstack1 == null && secondItem == null)
|
||||
{
|
||||
firstItem.stackSize -= itemstack.stackSize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue