improve inventory code
This commit is contained in:
parent
c374f35393
commit
cfcb590574
25 changed files with 144 additions and 184 deletions
|
@ -11,13 +11,9 @@ public class GuiChest extends GuiContainer {
|
|||
public GuiChest(EntityNPC player, IInventory chest, Block block) {
|
||||
super(new ContainerChest(player, chest));
|
||||
this.block = block;
|
||||
if(((ContainerChest)this.inventorySlots).getWidth() > 12)
|
||||
this.xSize += (((ContainerChest)this.inventorySlots).getWidth() - 12) * 18;
|
||||
this.ySize = 37 + 18 * ((player.getInventoryCapacity() + 11) / 12) + ((ContainerChest)this.inventorySlots).getHeight() * 18;
|
||||
}
|
||||
|
||||
public void addElements() {
|
||||
this.label(this.block.getDisplay(), 8, 16);
|
||||
this.label("Inventar", 8, 37 - 8 + ((ContainerChest)this.inventorySlots).getHeight() * 18);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ import client.window.Button;
|
|||
import common.collect.Lists;
|
||||
import common.enchantment.Enchantment;
|
||||
import common.entity.npc.Attribute;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.ItemRegistry;
|
||||
import common.inventory.Container;
|
||||
import common.inventory.ContainerChest;
|
||||
import common.inventory.Slot;
|
||||
import common.item.CheatTab;
|
||||
import common.item.ItemStack;
|
||||
|
@ -40,6 +40,7 @@ import common.packet.CPacketCheat;
|
|||
import common.util.ExtMath;
|
||||
import common.util.Util;
|
||||
import common.util.Color;
|
||||
import common.util.Equipment;
|
||||
|
||||
public abstract class GuiContainer extends Gui
|
||||
{
|
||||
|
@ -63,8 +64,8 @@ public abstract class GuiContainer extends Gui
|
|||
private static CheatTab selectedTab = CheatTab.ALL;
|
||||
|
||||
protected RenderItem itemRender;
|
||||
protected int xSize = 14 + 18 * 12;
|
||||
protected int ySize = 166;
|
||||
protected final int xSize;
|
||||
protected final int ySize;
|
||||
public Container inventorySlots;
|
||||
private Slot theSlot;
|
||||
protected final List<Overlay> drawnOverlays = Lists.<Overlay>newArrayList();
|
||||
|
@ -259,12 +260,8 @@ public abstract class GuiContainer extends Gui
|
|||
{
|
||||
this.inventorySlots = container;
|
||||
this.ignoreMouseUp = true;
|
||||
}
|
||||
|
||||
public GuiContainer(Container container, EntityNPC player)
|
||||
{
|
||||
this(container);
|
||||
this.ySize = 90 + 18 * ((player.getInventoryCapacity() + 11) / 12);
|
||||
this.xSize = (container.getInventoryOffsetX() - 1) * 2 + 18 * 12;
|
||||
this.ySize = container.getInventoryOffsetY() + 6 + 18 * ((Equipment.INVENTORY_SLOTS + 11) / 12);
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
|
@ -277,6 +274,7 @@ public abstract class GuiContainer extends Gui
|
|||
this.initGui();
|
||||
this.addButtons();
|
||||
this.addElements();
|
||||
this.label("Inventar", this.inventorySlots.getInventoryOffsetX(), this.inventorySlots.getInventoryOffsetY() - 2);
|
||||
}
|
||||
|
||||
public void hover(String text, int x, int y) {
|
||||
|
|
|
@ -12,11 +12,9 @@ public class GuiCrafting extends GuiContainer {
|
|||
public GuiCrafting(EntityNPC inv, World world, BlockWorkbench type) {
|
||||
super(new ContainerWorkbench(inv, world, LocalPos.ORIGIN, type));
|
||||
this.type = type;
|
||||
this.ySize = 36 + 18 * ((inv.getInventoryCapacity() + 11) / 12) + 18 * 3;
|
||||
}
|
||||
|
||||
public void addElements() {
|
||||
this.label(this.type.getDisplay(), 8, 16);
|
||||
this.label("Inventar", 8, 36 - 8 + 18 * 3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ public class GuiDevice extends GuiContainer {
|
|||
super(new ContainerTile(player, tile, inv));
|
||||
this.playerInv = player;
|
||||
this.tileInv = tile;
|
||||
this.ySize = 118 + 18 * ((player.getInventoryCapacity() + 11) / 12);
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
|
@ -49,7 +48,6 @@ public class GuiDevice extends GuiContainer {
|
|||
|
||||
public void addElements() {
|
||||
this.header = this.label("", 8, 16);
|
||||
this.label("Inventar", 8, 118 - 8);
|
||||
this.desc = this.display("", 8, 18, 160, 4);
|
||||
this.progress = this.tile.hasProgress() ? this.bar(7, 70, 162, 9) : null;
|
||||
this.temperature = this.tile.hasTemperature() ? this.bar(7, this.progress == null ? 70 : 60, 162, 9) : null;
|
||||
|
|
|
@ -26,7 +26,7 @@ public class GuiEnchant extends GuiContainer implements ButtonCallback {
|
|||
private final Label[] mana = new Label[3];
|
||||
|
||||
public GuiEnchant(EntityNPC inv, World world) {
|
||||
super(new ContainerEnchantment(inv, world), inv);
|
||||
super(new ContainerEnchantment(inv, world));
|
||||
this.enchantment = (ContainerEnchantment)this.inventorySlots;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,6 @@ public class GuiEnchant extends GuiContainer implements ButtonCallback {
|
|||
|
||||
public void addElements() {
|
||||
this.label(Blocks.enchanting_table.getDisplay(), 8, 16);
|
||||
this.label("Inventar", 8, 90 - 8);
|
||||
for(int l = 0; l < 3; ++l) {
|
||||
int i1 = 60;
|
||||
int j1 = i1 + 2;
|
||||
|
|
|
@ -9,12 +9,11 @@ public class GuiEntity extends GuiContainer {
|
|||
private final String title;
|
||||
|
||||
public GuiEntity(EntityNPC player, IInventory entityInv, Entity entity) {
|
||||
super(new ContainerEntityInventory(player, entityInv, entity), player);
|
||||
super(new ContainerEntityInventory(player, entityInv, entity));
|
||||
this.title = entity.getName();
|
||||
}
|
||||
|
||||
public void addElements() {
|
||||
this.label(this.title, 8, 16);
|
||||
this.label("Inventar", 8, 90 - 8);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import common.entity.npc.EntityNPC;
|
|||
|
||||
public class GuiInventory extends GuiContainer {
|
||||
public GuiInventory(EntityNPC player) {
|
||||
super(player.inventoryContainer, player);
|
||||
super(player.inventoryContainer);
|
||||
}
|
||||
|
||||
public void addElements() {
|
||||
|
|
|
@ -24,7 +24,7 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback {
|
|||
private ActButton nextBtn;
|
||||
|
||||
public GuiMerchant(EntityNPC inv, Entity entity, World world) {
|
||||
super(new ContainerMerchant(inv, null, world), inv);
|
||||
super(new ContainerMerchant(inv, null, world));
|
||||
this.title = entity.getName();
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,6 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback {
|
|||
|
||||
public void addElements() {
|
||||
this.label(this.title, 8, 16);
|
||||
this.label("Inventar", 8, 90 - 8);
|
||||
}
|
||||
|
||||
public void drawOverlays() {
|
||||
|
|
|
@ -12,7 +12,7 @@ public class GuiRepair extends GuiContainer {
|
|||
private EntityNPC playerInv;
|
||||
|
||||
public GuiRepair(EntityNPC inv, World world) {
|
||||
super(new ContainerRepair(inv, world), inv);
|
||||
super(new ContainerRepair(inv, world));
|
||||
this.playerInv = inv;
|
||||
this.anvil = (ContainerRepair)this.inventorySlots;
|
||||
}
|
||||
|
@ -32,6 +32,5 @@ public class GuiRepair extends GuiContainer {
|
|||
public void addElements() {
|
||||
this.label("Amboss", 8, 16);
|
||||
this.info = this.label("", 60, 77);
|
||||
this.label("Inventar", 8, 90 - 8);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1132,7 +1132,7 @@ public class ClientPlayer implements IClientPlayer
|
|||
// flag = true; // guicontainercreative.getSelectedTabIndex() != CheatTab.tabInventory.getIndex();
|
||||
// }
|
||||
|
||||
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= Equipment.ARMOR_SLOTS && packetIn.getSlot() < Equipment.ARMOR_SLOTS + entityplayer.getInventoryCapacity())
|
||||
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= Equipment.ARMOR_SLOTS && packetIn.getSlot() < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)
|
||||
{
|
||||
ItemStack itemstack = entityplayer.inventoryContainer.getSlot(packetIn.getSlot()).getStack();
|
||||
|
||||
|
|
|
@ -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,27 +22,25 @@ 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));
|
||||
}
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return this.chestSize;
|
||||
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() {
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
@ -37,15 +37,11 @@ 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));
|
||||
}
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return Equipment.ARMOR_SLOTS;
|
||||
public int getInventoryOffsetY() {
|
||||
return 92;
|
||||
}
|
||||
|
||||
public ItemStack getSingleRecipe(ItemStack stack) {
|
||||
|
@ -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,15 +55,11 @@ 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));
|
||||
}
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return this.tileInv.getSizeInventory();
|
||||
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,14 +20,7 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPlayerInventoryOffset() {
|
||||
return 0;
|
||||
this.addPlayerSlots(playerInventory);
|
||||
}
|
||||
|
||||
public int 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;
|
||||
|
||||
|
|
|
@ -955,11 +955,7 @@ public class Player extends User implements Executor, IPlayer
|
|||
--this.entity.hurtResistance;
|
||||
}
|
||||
|
||||
Container.removeEmptySlots(this.entity, 0, this.entity.getInventoryCapacity());
|
||||
if(this.entity.openContainer instanceof ContainerChest chest)
|
||||
Container.removeEmptySlots(chest.getChestInventory(), 0, chest.getChestInventory().getSizeInventory());
|
||||
else if(this.entity.openContainer instanceof ContainerEntityInventory ent && ent.getEntityInventory() != null)
|
||||
Container.removeEmptySlots(ent.getEntityInventory(), 2, ent.getEntityInventory().getSizeInventory() - 2);
|
||||
this.entity.openContainer.clearStacks();
|
||||
this.entity.openContainer.detectAndSendChanges();
|
||||
// if(!this.worldObj.client)
|
||||
|
||||
|
@ -2953,7 +2949,7 @@ public class Player extends User implements Executor, IPlayer
|
|||
return;
|
||||
slot.putStack(stack);
|
||||
}
|
||||
this.entity.openContainer.resortStacks(this.entity);
|
||||
this.entity.openContainer.resortStacks();
|
||||
this.entity.openContainer.detectAndSendChanges();
|
||||
this.entity.worldObj.playSoundAtEntity(this.entity, SoundEvent.POP, 0.2F);
|
||||
if(amount == 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue