improve inventory code
This commit is contained in:
parent
c374f35393
commit
cfcb590574
25 changed files with 144 additions and 184 deletions
|
@ -5,6 +5,7 @@ import common.entity.npc.EntityNPC;
|
|||
import common.init.Items;
|
||||
import common.item.Item;
|
||||
import common.item.ItemStack;
|
||||
import common.util.Equipment;
|
||||
import common.util.ExtMath;
|
||||
|
||||
public class EntityAIShareItems extends EntityAIWatchClosest2
|
||||
|
@ -48,7 +49,7 @@ public class EntityAIShareItems extends EntityAIWatchClosest2
|
|||
|
||||
if (this.interactionDelay == 0)
|
||||
{
|
||||
for (int i = 0; i < this.entity.getInventoryCapacity(); ++i)
|
||||
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
|
||||
{
|
||||
ItemStack itemstack = this.entity.getStackInSlot(i);
|
||||
ItemStack itemstack1 = null;
|
||||
|
|
|
@ -203,7 +203,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
private ItemStack mouseItem;
|
||||
private final ItemStack[] armor = new ItemStack[Equipment.ARMOR_SLOTS];
|
||||
private final ItemStack[] prevArmor = new ItemStack[this.armor.length];
|
||||
private final ItemStack[] items = new ItemStack[this.getInventoryCapacity()];
|
||||
private final ItemStack[] items = new ItemStack[Equipment.INVENTORY_SLOTS];
|
||||
private final ItemStack[] prevItems = new ItemStack[this.items.length];
|
||||
private int inLove;
|
||||
protected Alignment alignment = Alignment.NEUTRAL;
|
||||
|
@ -1430,7 +1430,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
|
||||
this.prevHeldItem = held == null ? null : held.copy();
|
||||
}
|
||||
for (int index = 0; index < this.getInventoryCapacity(); index++)
|
||||
for (int index = 0; index < Equipment.INVENTORY_SLOTS; index++)
|
||||
{
|
||||
ItemStack last = this.prevItems[index];
|
||||
ItemStack current = this.getStackInSlot(index);
|
||||
|
@ -2485,7 +2485,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
}
|
||||
|
||||
public int getHotbarSize() {
|
||||
return this.getInventoryCapacity();
|
||||
return Equipment.INVENTORY_SLOTS;
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
|
@ -2556,7 +2556,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
|
||||
public int getInventorySlotContainItem(Item itemIn)
|
||||
{
|
||||
for (int i = 0; i < this.getInventoryCapacity(); ++i)
|
||||
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
|
||||
{
|
||||
if (this.getInventory()[i] != null && this.getInventory()[i].getItem() == itemIn)
|
||||
{
|
||||
|
@ -2569,7 +2569,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
|
||||
private int storeItemStack(ItemStack itemStackIn)
|
||||
{
|
||||
for (int i = 0; i < this.getInventoryCapacity(); ++i)
|
||||
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
|
||||
{
|
||||
if (this.getInventory()[i] != null && this.getInventory()[i].getItem() == itemStackIn.getItem() && this.getInventory()[i].isStackable() && !this.getInventory()[i].isFull() && ItemStack.dataEquals(this.getInventory()[i], itemStackIn))
|
||||
{
|
||||
|
@ -2582,7 +2582,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
|
||||
public int getFirstEmptyStack()
|
||||
{
|
||||
for (int i = 0; i < this.getInventoryCapacity(); ++i)
|
||||
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
|
||||
{
|
||||
if (this.getInventory()[i] == null)
|
||||
{
|
||||
|
@ -2708,7 +2708,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
public ItemStack addStack(ItemStack stack)
|
||||
{
|
||||
ItemStack itemstack = stack.copy();
|
||||
for (int i = 0; i < this.getInventoryCapacity(); ++i)
|
||||
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
|
||||
{
|
||||
ItemStack itemstack1 = this.getInventory()[i];
|
||||
|
||||
|
@ -2746,7 +2746,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < this.getInventoryCapacity(); ++j)
|
||||
for (int j = 0; j < Equipment.INVENTORY_SLOTS; ++j)
|
||||
{
|
||||
if (this.getInventory()[j] != null && this.getInventory()[j].itemEquals(itemStackIn))
|
||||
{
|
||||
|
@ -3300,7 +3300,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
|
||||
List<TagObject> list = tag.getList("items");
|
||||
this.clear();
|
||||
for(int z = 0; z < list.size() && z < this.getInventoryCapacity(); z++) {
|
||||
for(int z = 0; z < list.size() && z < Equipment.INVENTORY_SLOTS; z++) {
|
||||
TagObject item = list.get(z);
|
||||
ItemStack stack = ItemStack.readFromTag(item);
|
||||
if(stack != null)
|
||||
|
@ -3425,7 +3425,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
// tagCompound.setBoolean("CanPickUpLoot", this.canPickUpLoot());
|
||||
|
||||
List<TagObject> list = Lists.newArrayList();
|
||||
for(int z = 0; z < this.getInventoryCapacity(); z++) {
|
||||
for(int z = 0; z < Equipment.INVENTORY_SLOTS; z++) {
|
||||
if(this.getStackInSlot(z) != null) {
|
||||
TagObject item = new TagObject();
|
||||
this.getStackInSlot(z).writeTags(item);
|
||||
|
@ -4505,10 +4505,10 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
{
|
||||
ItemStack[] aitemstack = this.getInventory();
|
||||
|
||||
if (index >= this.getInventoryCapacity())
|
||||
if (index >= Equipment.INVENTORY_SLOTS)
|
||||
{
|
||||
aitemstack = this.getArmor();
|
||||
index -= this.getInventoryCapacity();
|
||||
index -= Equipment.INVENTORY_SLOTS;
|
||||
}
|
||||
|
||||
if (aitemstack[index] != null)
|
||||
|
@ -4541,10 +4541,10 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
{
|
||||
ItemStack[] aitemstack = this.getInventory();
|
||||
|
||||
if (index >= this.getInventoryCapacity())
|
||||
if (index >= Equipment.INVENTORY_SLOTS)
|
||||
{
|
||||
aitemstack = this.getArmor();
|
||||
index -= this.getInventoryCapacity();
|
||||
index -= Equipment.INVENTORY_SLOTS;
|
||||
}
|
||||
|
||||
if (aitemstack[index] != null)
|
||||
|
@ -4574,7 +4574,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.getInventoryCapacity() + this.getArmor().length;
|
||||
return Equipment.INVENTORY_SLOTS + this.getArmor().length;
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlot(int index)
|
||||
|
@ -4597,7 +4597,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
|
||||
public void clear()
|
||||
{
|
||||
for (int i = 0; i < this.getInventoryCapacity(); ++i)
|
||||
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
|
||||
{
|
||||
this.getInventory()[i] = null;
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ public abstract class CraftingRegistry
|
|||
if(input != null) {
|
||||
for(ItemStack stack : recipe.getRequiredItems()) {
|
||||
int amount = stack.getSize();
|
||||
int size = input instanceof EntityNPC entity ? entity.getInventoryCapacity() : input.getSizeInventory();
|
||||
int size = input instanceof EntityNPC entity ? Equipment.INVENTORY_SLOTS : input.getSizeInventory();
|
||||
for(int z = 0; z < size && amount > 0; z++) {
|
||||
ItemStack current = input.getStackInSlot(z);
|
||||
if(current != null && stack.itemEquals(current) && stack.dataEquals(current)) {
|
||||
|
@ -321,7 +321,7 @@ public abstract class CraftingRegistry
|
|||
if(output != null && (!allowDrop || !(output instanceof EntityNPC))) {
|
||||
for(ItemStack stack : recipe.getCraftedItems()) {
|
||||
int amount = stack.getSize();
|
||||
int size = output instanceof EntityNPC entity ? entity.getInventoryCapacity() : output.getSizeInventory();
|
||||
int size = output instanceof EntityNPC entity ? Equipment.INVENTORY_SLOTS : output.getSizeInventory();
|
||||
for(int z = 0; z < size && amount > 0; z++) {
|
||||
ItemStack current = output.getStackInSlot(z);
|
||||
if(current == null) {
|
||||
|
@ -369,7 +369,7 @@ public abstract class CraftingRegistry
|
|||
private static void swapItems(IInventory input, IInventory output, IRecipe recipe) {
|
||||
for(ItemStack stack : recipe.getRequiredItems()) {
|
||||
int amount = stack.getSize();
|
||||
int size = input instanceof EntityNPC entity ? entity.getInventoryCapacity() : input.getSizeInventory();
|
||||
int size = input instanceof EntityNPC entity ? Equipment.INVENTORY_SLOTS : input.getSizeInventory();
|
||||
for(int z = 0; z < size && amount > 0; z++) {
|
||||
ItemStack current = input.getStackInSlot(z);
|
||||
if(current != null && stack.itemEquals(current) && stack.dataEquals(current)) {
|
||||
|
@ -383,7 +383,7 @@ public abstract class CraftingRegistry
|
|||
}
|
||||
for(ItemStack stack : recipe.getCraftedItems()) {
|
||||
int amount = stack.getSize();
|
||||
int size = output instanceof EntityNPC entity ? entity.getInventoryCapacity() : output.getSizeInventory();
|
||||
int size = output instanceof EntityNPC entity ? Equipment.INVENTORY_SLOTS : output.getSizeInventory();
|
||||
for(int z = 0; z < size && amount > 0; z++) {
|
||||
ItemStack current = output.getStackInSlot(z);
|
||||
if(current == null) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import common.entity.npc.EntityNPC;
|
|||
import common.item.Item;
|
||||
import common.item.ItemStack;
|
||||
import common.network.IPlayer;
|
||||
import common.util.Equipment;
|
||||
|
||||
public abstract class Container
|
||||
{
|
||||
|
@ -16,12 +17,32 @@ public abstract class Container
|
|||
public List<Slot> inventorySlots = Lists.<Slot>newArrayList();
|
||||
public int windowId;
|
||||
private short transactionID;
|
||||
protected int offset;
|
||||
protected List<IPlayer> crafters = Lists.<IPlayer>newArrayList();
|
||||
private Set<EntityNPC> playerList = Sets.<EntityNPC>newHashSet();
|
||||
|
||||
/**
|
||||
* Adds an item slot to this container
|
||||
*/
|
||||
public int getInventoryOffsetX() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
public int getInventoryOffsetY() {
|
||||
return 84;
|
||||
}
|
||||
|
||||
public final int getPlayerInventoryOffset() {
|
||||
return this.offset;
|
||||
}
|
||||
|
||||
protected void addPlayerSlots(EntityNPC player) {
|
||||
this.offset = this.inventorySlots.size();
|
||||
int x = this.getInventoryOffsetX();
|
||||
int y = this.getInventoryOffsetY();
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for(int z = 0; z < Equipment.INVENTORY_SLOTS; ++z) {
|
||||
this.addSlotToContainer(new SlotCommon(list, player, z, x + (z % 12) * 18, y + (z / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
protected Slot addSlotToContainer(Slot slotIn)
|
||||
{
|
||||
slotIn.slotNumber = this.inventorySlots.size();
|
||||
|
@ -39,9 +60,7 @@ public abstract class Container
|
|||
else
|
||||
{
|
||||
this.crafters.add(listener);
|
||||
EntityNPC entity = listener.getPresentEntity();
|
||||
if(entity != null)
|
||||
this.resortStacks(entity);
|
||||
this.resortStacks();
|
||||
listener.sendContainer(this, this.getInventory());
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
|
@ -400,7 +419,7 @@ public abstract class Container
|
|||
this.detectAndSendChanges();
|
||||
}
|
||||
|
||||
this.resortStacks(playerIn);
|
||||
this.resortStacks();
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
@ -420,13 +439,50 @@ public abstract class Container
|
|||
}
|
||||
}
|
||||
|
||||
public void resortStacks(EntityNPC player) {
|
||||
if(this.canMergeStacks())
|
||||
this.reorganize(this.getMergeOffset(), this.getMergeSize());
|
||||
this.reorganize(this.getPlayerInventoryOffset(), player.getInventoryCapacity());
|
||||
private void removeEmptySlots(int offset, int size) {
|
||||
int lastFull = Integer.MIN_VALUE;
|
||||
int firstEmpty = Integer.MAX_VALUE;
|
||||
for(int z = 0; z < size; z++) {
|
||||
ItemStack stack = this.inventorySlots.get(offset + z).getStack();
|
||||
if(stack == null && z < firstEmpty)
|
||||
firstEmpty = z;
|
||||
else if(stack != null && z > lastFull)
|
||||
lastFull = z;
|
||||
}
|
||||
if(firstEmpty > lastFull)
|
||||
return;
|
||||
for(int z = 0; z < size; z++) {
|
||||
ItemStack stack = this.inventorySlots.get(offset + z).getStack();
|
||||
if(stack == null) {
|
||||
int shift = -1;
|
||||
for(int n = 1; z + n < size; n++) {
|
||||
ItemStack next = this.inventorySlots.get(offset + z + n).getStack();
|
||||
if(next == null) {
|
||||
if(shift >= 0)
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if(shift < 0)
|
||||
shift = n;
|
||||
this.inventorySlots.get(offset + z + n).putStack(null);
|
||||
this.inventorySlots.get(offset + z + n - shift).putStack(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int getPlayerInventoryOffset();
|
||||
public void resortStacks() {
|
||||
if(this.canMergeStacks())
|
||||
this.reorganize(this.getMergeOffset(), this.getMergeSize());
|
||||
this.reorganize(this.offset, Equipment.INVENTORY_SLOTS);
|
||||
}
|
||||
|
||||
public void clearStacks() {
|
||||
if(this.canMergeStacks())
|
||||
this.removeEmptySlots(this.getMergeOffset(), this.getMergeSize());
|
||||
this.removeEmptySlots(this.offset, Equipment.INVENTORY_SLOTS);
|
||||
}
|
||||
|
||||
protected boolean canMergeStacks() {
|
||||
return false;
|
||||
|
@ -610,37 +666,4 @@ public abstract class Container
|
|||
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static void removeEmptySlots(IInventory inv, int offset, int size) {
|
||||
int lastFull = Integer.MIN_VALUE;
|
||||
int firstEmpty = Integer.MAX_VALUE;
|
||||
for(int z = 0; z < size; z++) {
|
||||
ItemStack stack = inv.getStackInSlot(offset + z);
|
||||
if(stack == null && z < firstEmpty)
|
||||
firstEmpty = z;
|
||||
else if(stack != null && z > lastFull)
|
||||
lastFull = z;
|
||||
}
|
||||
if(firstEmpty > lastFull)
|
||||
return;
|
||||
for(int z = 0; z < size; z++) {
|
||||
ItemStack stack = inv.getStackInSlot(offset + z);
|
||||
if(stack == null) {
|
||||
int shift = -1;
|
||||
for(int n = 1; z + n < size; n++) {
|
||||
ItemStack next = inv.getStackInSlot(offset + z + n);
|
||||
if(next == null) {
|
||||
if(shift >= 0)
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if(shift < 0)
|
||||
shift = n;
|
||||
inv.setInventorySlotContents(offset + z + n, null);
|
||||
inv.setInventorySlotContents(offset + z + n - shift, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,28 +22,26 @@ public class ContainerChest extends Container
|
|||
BlockChest block = BlockChest.getChest(this.chestSize);
|
||||
this.width = block.getInventoryWidth();
|
||||
this.height = block.getInventoryHeight();
|
||||
int xOffset = this.width < 12 ? 0 : (this.width - 12) * 18 / 2;
|
||||
int yOffset = (this.height - 3) * 18;
|
||||
|
||||
List<SlotCommon> list1 = Lists.newArrayList();
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int j = 0; j < this.height; ++j)
|
||||
{
|
||||
for (int k = 0; k < this.width; ++k)
|
||||
{
|
||||
this.addSlotToContainer(new SlotCommon(list1, chest, k + j * this.width, 8 + k * 18, 18 + j * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, 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 SlotCommon(list2, player, l, 8 + (l % 12) * 18 + xOffset, 85 + (l / 12) * 18 + yOffset));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return this.chestSize;
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
public int getInventoryOffsetX() {
|
||||
return 8 + (this.width < 12 ? 0 : (this.width - 12) * 18 / 2);
|
||||
}
|
||||
|
||||
public int getInventoryOffsetY() {
|
||||
return 85 + (this.height - 3) * 18;
|
||||
}
|
||||
|
||||
protected boolean canMergeStacks() {
|
||||
return true;
|
||||
|
|
|
@ -13,6 +13,7 @@ import common.item.ItemStack;
|
|||
import common.item.material.ItemEnchantedBook;
|
||||
import common.network.IPlayer;
|
||||
import common.rng.Random;
|
||||
import common.util.Equipment;
|
||||
import common.util.LocalPos;
|
||||
import common.util.Pair;
|
||||
import common.world.World;
|
||||
|
@ -64,15 +65,7 @@ public class ContainerEnchantment extends Container
|
|||
}
|
||||
});
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < playerInv.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new SlotCommon(list, playerInv, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return 1;
|
||||
this.addPlayerSlots(playerInv);
|
||||
}
|
||||
|
||||
public static int encodeData(Pair<Enchantment, Integer> data) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import common.entity.animal.EntityHorse;
|
|||
import common.entity.npc.EntityNPC;
|
||||
import common.init.Items;
|
||||
import common.item.ItemStack;
|
||||
import common.util.Equipment;
|
||||
|
||||
public class ContainerEntityInventory extends Container
|
||||
{
|
||||
|
@ -51,19 +52,7 @@ public class ContainerEntityInventory extends Container
|
|||
}
|
||||
}
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < player.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return this.entity instanceof EntityHorse horse && horse.isChested() ? (horse.isChested() ? this.entityInventory.getSizeInventory() : 2) : 0;
|
||||
}
|
||||
|
||||
public IInventory getEntityInventory() {
|
||||
return this.entity instanceof EntityHorse horse && horse.isChested() ? this.entityInventory : null;
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
protected boolean canMergeStacks() {
|
||||
|
|
|
@ -6,6 +6,7 @@ import common.collect.Lists;
|
|||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.network.IPlayer;
|
||||
import common.util.Equipment;
|
||||
import common.village.MerchantRecipe;
|
||||
import common.world.World;
|
||||
|
||||
|
@ -149,15 +150,7 @@ 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 SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return 3;
|
||||
this.addPlayerSlots(playerInventory);
|
||||
}
|
||||
|
||||
public InventoryMerchant getMerchantInventory()
|
||||
|
|
|
@ -18,7 +18,7 @@ public class ContainerPlayer extends Container {
|
|||
for (Equipment slot : Equipment.ARMOR)
|
||||
{
|
||||
final Equipment type = slot;
|
||||
this.addSlotToContainer(new Slot(player, player.getInventoryCapacity() + slot.getIndex(), 8 + (slot.getIndex() / 4) * 18, 8 + (slot.getIndex() % 4) * 18)
|
||||
this.addSlotToContainer(new Slot(player, Equipment.INVENTORY_SLOTS + slot.getIndex(), 8 + (slot.getIndex() / 4) * 18, 8 + (slot.getIndex() % 4) * 18)
|
||||
{
|
||||
public boolean canStackItems()
|
||||
{
|
||||
|
@ -36,17 +36,13 @@ public class ContainerPlayer extends Container {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < player.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return Equipment.ARMOR_SLOTS;
|
||||
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
public int getInventoryOffsetY() {
|
||||
return 92;
|
||||
}
|
||||
|
||||
public ItemStack getSingleRecipe(ItemStack stack) {
|
||||
return null;
|
||||
|
@ -90,7 +86,7 @@ public class ContainerPlayer extends Container {
|
|||
|
||||
if (index >= 0 && index < Equipment.ARMOR_SLOTS)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity()))
|
||||
if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -102,11 +98,11 @@ public class ContainerPlayer extends Container {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= Equipment.ARMOR_SLOTS && index < Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity())
|
||||
else if (index >= Equipment.ARMOR_SLOTS && index < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity()))
|
||||
else if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import common.entity.npc.EntityNPC;
|
|||
import common.item.ItemStack;
|
||||
import common.item.material.ItemEnchantedBook;
|
||||
import common.network.IPlayer;
|
||||
import common.util.Equipment;
|
||||
import common.util.LocalPos;
|
||||
import common.vars.Vars;
|
||||
import common.world.State;
|
||||
|
@ -195,15 +196,7 @@ public class ContainerRepair extends Container
|
|||
}
|
||||
});
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < playerInventory.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return 3;
|
||||
this.addPlayerSlots(playerInventory);
|
||||
}
|
||||
|
||||
private void onChanged(IInventory inventoryIn)
|
||||
|
|
|
@ -8,6 +8,7 @@ import common.item.ItemStack;
|
|||
import common.network.IPlayer;
|
||||
import common.tileentity.Device;
|
||||
import common.tileentity.Device.Status;
|
||||
import common.util.Equipment;
|
||||
|
||||
public class ContainerTile extends Container
|
||||
{
|
||||
|
@ -54,16 +55,12 @@ public class ContainerTile extends Container
|
|||
++output;
|
||||
}
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for (int l = 0; l < player.getInventoryCapacity(); ++l)
|
||||
{
|
||||
this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 112 + (l / 12) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return this.tileInv.getSizeInventory();
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
public int getInventoryOffsetY() {
|
||||
return 112;
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ import common.block.tech.BlockWorkbench;
|
|||
import common.collect.Lists;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.util.Equipment;
|
||||
import common.util.LocalPos;
|
||||
import common.world.World;
|
||||
|
||||
|
@ -19,15 +20,8 @@ public class ContainerWorkbench extends Container {
|
|||
this.worldObj = worldIn;
|
||||
this.pos = posIn;
|
||||
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for(int l = 0; l < playerInventory.getInventoryCapacity(); ++l) {
|
||||
this.addSlotToContainer(new SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 30 + 3 * 18 + (l / 12) * 18));
|
||||
}
|
||||
this.addPlayerSlots(playerInventory);
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getTier() {
|
||||
return this.block.getTier();
|
||||
|
|
|
@ -86,7 +86,7 @@ public class Slot
|
|||
/**
|
||||
* Returns if this slot contains a stack.
|
||||
*/
|
||||
public boolean getHasStack()
|
||||
public final boolean getHasStack()
|
||||
{
|
||||
return this.getStack() != null;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public enum Equipment implements Identifyable, Displayable {
|
|||
|
||||
HORSE_ARMOR("horse_armor", "Pferderüstung", EntityHorse.class, 8, 0);
|
||||
|
||||
public static final int INVENTORY_SLOTS = 64;
|
||||
public static final int ARMOR_SLOTS;
|
||||
public static final Equipment[] ARMOR;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue