change inventory system
This commit is contained in:
parent
9bd1ac3b45
commit
2d9ea3d654
15 changed files with 349 additions and 245 deletions
|
@ -1,6 +1,9 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.block.tech.BlockChest;
|
||||
import common.collect.Lists;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.tileentity.TileEntityChest;
|
||||
|
@ -22,17 +25,19 @@ public class ContainerChest extends Container
|
|||
int xOffset = this.width < 12 ? 0 : (this.width - 12) * 18 / 2;
|
||||
int yOffset = (this.height - 3) * 18;
|
||||
|
||||
List<SlotCommon> list1 = Lists.newArrayList();
|
||||
for (int j = 0; j < this.height; ++j)
|
||||
{
|
||||
for (int k = 0; k < this.width; ++k)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(chest, k + j * this.width, 8 + k * 18, 18 + j * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list1, chest, k + j * this.width, 8 + k * 18, 18 + j * 18));
|
||||
}
|
||||
}
|
||||
|
||||
List<SlotCommon> list2 = Lists.newArrayList();
|
||||
for (int l = 0; l < player.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18 + xOffset, 85 + (l / 12) * 18 + yOffset));
|
||||
this.addSlotToContainer(new SlotCommon(list2, player, l, 8 + (l % 12) * 18 + xOffset, 85 + (l / 12) * 18 + yOffset));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package common.inventory;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import common.collect.Lists;
|
||||
import common.enchantment.Enchantment;
|
||||
import common.enchantment.EnchantmentHelper;
|
||||
import common.enchantment.RngEnchantment;
|
||||
|
@ -63,9 +64,10 @@ public class ContainerEnchantment extends Container
|
|||
}
|
||||
});
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < playerInv.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInv, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, playerInv, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.collect.Lists;
|
||||
import common.entity.Entity;
|
||||
import common.entity.animal.EntityHorse;
|
||||
import common.entity.npc.EntityNPC;
|
||||
|
@ -32,26 +35,28 @@ public class ContainerEntityInventory extends Container
|
|||
{
|
||||
return super.isItemValid(stack) && horse.canWearArmor() && EntityHorse.isArmorItem(stack.getItem());
|
||||
}
|
||||
public boolean canBeHovered()
|
||||
public boolean canDraw()
|
||||
{
|
||||
return horse.canWearArmor();
|
||||
}
|
||||
});
|
||||
if (horse.isChested())
|
||||
{
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int k = 0; k < i; ++k)
|
||||
{
|
||||
for (int l = 0; l < 5; ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(entityInv, 2 + l + k * 5, 80 + l * 18, 18 + k * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, entityInv, 2 + l + k * 5, 80 + l * 18, 18 + k * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < player.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,133 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.collect.Lists;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.network.IPlayer;
|
||||
import common.village.MerchantRecipe;
|
||||
import common.world.World;
|
||||
|
||||
public class ContainerMerchant extends Container
|
||||
{
|
||||
private 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().getSize());
|
||||
}
|
||||
|
||||
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.isEmpty())
|
||||
{
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
if (itemstack1 != null && itemstack1.isEmpty())
|
||||
{
|
||||
itemstack1 = null;
|
||||
}
|
||||
|
||||
this.theMerchantInventory.setInventorySlotContents(0, itemstack);
|
||||
this.theMerchantInventory.setInventorySlotContents(1, itemstack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doTrade(MerchantRecipe trade, ItemStack firstItem, ItemStack secondItem)
|
||||
{
|
||||
ItemStack itemstack = trade.first();
|
||||
ItemStack itemstack1 = trade.second();
|
||||
|
||||
if (firstItem != null && firstItem.getItem() == itemstack.getItem())
|
||||
{
|
||||
if (itemstack1 != null && secondItem != null && itemstack1.getItem() == secondItem.getItem())
|
||||
{
|
||||
firstItem.decrSize(itemstack.getSize());
|
||||
secondItem.decrSize(itemstack1.getSize());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itemstack1 == null && secondItem == null)
|
||||
{
|
||||
firstItem.decrSize(itemstack.getSize());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private EntityNPC theMerchant;
|
||||
private InventoryMerchant merchantInventory;
|
||||
private final World theWorld;
|
||||
|
@ -28,9 +149,10 @@ public class ContainerMerchant extends Container
|
|||
});
|
||||
this.addSlotToContainer(new SlotMerchantResult(playerInventory, this.merchantInventory, 2, 120, 53));
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < playerInventory.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.collect.Lists;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.item.material.ItemArmor;
|
||||
|
@ -26,14 +29,18 @@ public class ContainerPlayer extends Container {
|
|||
return stack != null && stack.getItem() instanceof ItemArmor armor && armor.getArmorType().canUseInSlot(ContainerPlayer.this.thePlayer, type);
|
||||
}
|
||||
public String getTexture() {
|
||||
return ContainerPlayer.this.thePlayer.hasArmorSlot(type) ? (type.isRing() ? "ring" : type.getName()) : "";
|
||||
return type.isRing() ? "ring" : type.getName();
|
||||
}
|
||||
public boolean canDraw() {
|
||||
return ContainerPlayer.this.thePlayer.hasArmorSlot(type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < player.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import common.block.tech.BlockAnvil;
|
||||
import common.collect.Lists;
|
||||
import common.enchantment.Enchantment;
|
||||
import common.enchantment.EnchantmentHelper;
|
||||
import common.entity.npc.EntityNPC;
|
||||
|
@ -17,6 +19,78 @@ import common.world.World;
|
|||
|
||||
public class ContainerRepair extends Container
|
||||
{
|
||||
private 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];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
for (int i = 0; i < this.stackResult.length; ++i)
|
||||
{
|
||||
this.stackResult[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IInventory outputSlot;
|
||||
private IInventory inputSlots;
|
||||
private World theWorld;
|
||||
|
@ -121,9 +195,10 @@ public class ContainerRepair extends Container
|
|||
}
|
||||
});
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < playerInventory.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.collect.Lists;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.network.IPlayer;
|
||||
|
@ -51,9 +54,10 @@ public class ContainerTile extends Container
|
|||
++output;
|
||||
}
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < player.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18, 112 + (l / 12) * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 112 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.block.tech.BlockWorkbench;
|
||||
import common.collect.Lists;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.util.LocalPos;
|
||||
|
@ -15,8 +18,10 @@ public class ContainerWorkbench extends Container {
|
|||
this.block = block;
|
||||
this.worldObj = worldIn;
|
||||
this.pos = posIn;
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for(int l = 0; l < playerInventory.getInventoryCapacity(); ++l) {
|
||||
this.addSlotToContainer(new Slot(playerInventory, l, 8 + (l % 12) * 18, 30 + 3 * 18 + (l / 12) * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 30 + 3 * 18 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
package common.inventory;
|
||||
|
||||
import common.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];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
for (int i = 0; i < this.stackResult.length; ++i)
|
||||
{
|
||||
this.stackResult[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -118,11 +118,6 @@ public class Slot
|
|||
return this.canStackItems() ? 1000000000 : 1;
|
||||
}
|
||||
|
||||
public String getTexture()
|
||||
{
|
||||
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.
|
||||
|
@ -147,15 +142,6 @@ public class Slot
|
|||
{
|
||||
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;
|
||||
|
@ -168,4 +154,24 @@ public class Slot
|
|||
public boolean canEditItem() {
|
||||
return this.canCheatItem();
|
||||
}
|
||||
|
||||
public int getBackgroundWidth() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getBackgroundHeight() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getTexture() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean canDraw() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canHover() {
|
||||
return this.canDraw();
|
||||
}
|
||||
}
|
||||
|
|
51
common/src/main/java/common/inventory/SlotCommon.java
Normal file
51
common/src/main/java/common/inventory/SlotCommon.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SlotCommon extends Slot {
|
||||
private final List<SlotCommon> list;
|
||||
private final SlotCommon draw;
|
||||
|
||||
private int w;
|
||||
private int h;
|
||||
|
||||
public SlotCommon(List<SlotCommon> list, IInventory inventoryIn, int index, int xPosition, int yPosition) {
|
||||
super(inventoryIn, index, xPosition, yPosition);
|
||||
this.list = list;
|
||||
this.draw = list.isEmpty() ? null : list.getFirst();
|
||||
list.add(this);
|
||||
}
|
||||
|
||||
public String getTexture() {
|
||||
return this.draw == null ? super.getTexture() : null;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
int x1 = Integer.MAX_VALUE;
|
||||
int y1 = Integer.MAX_VALUE;
|
||||
int x2 = Integer.MIN_VALUE;
|
||||
int y2 = Integer.MIN_VALUE;
|
||||
for(SlotCommon slot : this.list) {
|
||||
x1 = Math.min(x1, slot.xDisplayPosition);
|
||||
y1 = Math.min(y1, slot.yDisplayPosition);
|
||||
x2 = Math.max(x2, slot.xDisplayPosition + 18);
|
||||
y2 = Math.max(y2, slot.yDisplayPosition + 18);
|
||||
}
|
||||
this.w = (x2 - x1) / 18;
|
||||
this.h = (y2 - y1) / 18;
|
||||
}
|
||||
|
||||
public int getBackgroundWidth() {
|
||||
if(this.draw != null)
|
||||
return this.draw.getBackgroundWidth();
|
||||
this.init();
|
||||
return this.w;
|
||||
}
|
||||
|
||||
public int getBackgroundHeight() {
|
||||
if(this.draw != null)
|
||||
return this.draw.getBackgroundHeight();
|
||||
this.init();
|
||||
return this.h;
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
package common.inventory;
|
||||
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.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().getSize());
|
||||
}
|
||||
|
||||
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.isEmpty())
|
||||
{
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
if (itemstack1 != null && itemstack1.isEmpty())
|
||||
{
|
||||
itemstack1 = null;
|
||||
}
|
||||
|
||||
this.theMerchantInventory.setInventorySlotContents(0, itemstack);
|
||||
this.theMerchantInventory.setInventorySlotContents(1, itemstack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doTrade(MerchantRecipe trade, ItemStack firstItem, ItemStack secondItem)
|
||||
{
|
||||
ItemStack itemstack = trade.first();
|
||||
ItemStack itemstack1 = trade.second();
|
||||
|
||||
if (firstItem != null && firstItem.getItem() == itemstack.getItem())
|
||||
{
|
||||
if (itemstack1 != null && secondItem != null && itemstack1.getItem() == secondItem.getItem())
|
||||
{
|
||||
firstItem.decrSize(itemstack.getSize());
|
||||
secondItem.decrSize(itemstack1.getSize());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itemstack1 == null && secondItem == null)
|
||||
{
|
||||
firstItem.decrSize(itemstack.getSize());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package common.inventory;
|
||||
|
||||
import common.item.ItemStack;
|
||||
|
||||
public class SlotOutput extends Slot {
|
||||
public SlotOutput(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) {
|
||||
super(inventoryIn, slotIndex, xPosition, yPosition);
|
||||
}
|
||||
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue