From 6fb9ded711ae2f14d431c8a194608240a3a5a668 Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 1 Aug 2025 18:19:14 +0200 Subject: [PATCH] item slot refactor --- client/src/main/java/client/Client.java | 48 +- .../java/client/gui/container/GuiBrewing.java | 6 +- .../java/client/gui/container/GuiChest.java | 7 +- .../client/gui/container/GuiContainer.java | 31 +- .../client/gui/container/GuiCrafting.java | 4 +- .../java/client/gui/container/GuiDevice.java | 7 +- .../client/gui/container/GuiDispenser.java | 4 +- .../java/client/gui/container/GuiEnchant.java | 4 +- .../java/client/gui/container/GuiEntity.java | 6 +- .../java/client/gui/container/GuiFurnace.java | 4 +- .../java/client/gui/container/GuiHopper.java | 4 +- .../client/gui/container/GuiMerchant.java | 4 +- .../java/client/gui/container/GuiRepair.java | 8 +- .../java/client/network/ClientPlayer.java | 37 +- .../java/client/renderer/ItemRenderer.java | 4 +- .../client/renderer/entity/RenderItem.java | 8 +- .../client/renderer/layers/LayerArmor.java | 2 +- .../java/client/util/PlayerController.java | 16 +- .../main/java/common/ai/AIFireballAttack.java | 8 +- .../src/main/java/common/ai/EntityAIBeg.java | 2 +- .../java/common/ai/EntityAIShareItems.java | 9 +- .../java/common/ai/EntityAITakePlace.java | 4 +- .../java/common/attributes/AttributeMap.java | 60 -- common/src/main/java/common/block/Block.java | 2 +- .../block/artificial/BlockFlowerPot.java | 4 +- .../block/artificial/BlockMetalBlock.java | 2 +- .../common/block/natural/BlockMetalOre.java | 2 +- .../java/common/block/tech/BlockAnvil.java | 4 +- .../java/common/block/tech/BlockCauldron.java | 8 +- .../block/tech/BlockEnchantmentTable.java | 4 +- .../common/block/tech/BlockWarpChest.java | 6 +- .../common/block/tech/BlockWorkbench.java | 4 +- .../common/block/tech/InteractionObject.java | 3 +- .../src/main/java/common/effect/Effect.java | 13 +- .../common/enchantment/EnchantmentType.java | 2 +- .../java/common/entity/animal/EntityCat.java | 4 +- .../java/common/entity/animal/EntityCow.java | 8 +- .../common/entity/animal/EntityHorse.java | 12 +- .../common/entity/animal/EntitySheep.java | 2 +- .../java/common/entity/animal/EntityWolf.java | 8 +- .../java/common/entity/item/EntityItem.java | 2 +- .../{attributes => entity/npc}/Attribute.java | 2 +- .../common/entity/npc/EntityCultivator.java | 4 +- .../java/common/entity/npc/EntityHaunter.java | 2 +- .../java/common/entity/npc/EntityNPC.java | 977 +++++++++++++----- .../common/entity/projectile/EntityArrow.java | 2 +- .../common/entity/projectile/EntityDie.java | 2 +- .../common/entity/types/EntityAnimal.java | 6 +- .../common/entity/types/EntityLiving.java | 28 +- .../main/java/common/init/ItemRegistry.java | 2 +- .../main/java/common/inventory/Container.java | 69 +- .../inventory/ContainerBrewingStand.java | 8 +- .../java/common/inventory/ContainerChest.java | 6 +- .../inventory/ContainerEnchantment.java | 8 +- .../inventory/ContainerEntityInventory.java | 6 +- .../common/inventory/ContainerFurnace.java | 4 +- .../common/inventory/ContainerHopper.java | 2 +- .../common/inventory/ContainerMerchant.java | 10 +- .../common/inventory/ContainerPlayer.java | 61 +- .../common/inventory/ContainerRepair.java | 6 +- .../java/common/inventory/ContainerTile.java | 6 +- .../common/inventory/ContainerWorkbench.java | 6 +- .../main/java/common/inventory/IInvBasic.java | 3 - .../java/common/inventory/InventoryBasic.java | 40 - .../common/inventory/InventoryPlayer.java | 712 ------------- .../java/common/inventory/SlotCrafting.java | 4 +- common/src/main/java/common/item/Item.java | 3 +- .../src/main/java/common/item/ItemStack.java | 16 +- .../item/consumable/ItemMilkBottle.java | 3 +- .../common/item/consumable/ItemPotion.java | 4 +- .../common/item/material/ItemAnimalArmor.java | 12 +- .../java/common/item/material/ItemArmor.java | 161 ++- .../java/common/item/material/ItemBottle.java | 4 +- .../java/common/item/material/ItemBucket.java | 6 +- .../java/common/item/material/ItemMetal.java | 3 +- .../main/java/common/item/weapon/ItemBow.java | 6 +- .../java/common/item/weapon/ItemGunBase.java | 4 +- .../common/packet/SPacketSpawnPlayer.java | 2 +- .../tileentity/TileEntityBrewingStand.java | 4 +- .../tileentity/TileEntityDispenser.java | 4 +- .../common/tileentity/TileEntityFurnace.java | 4 +- .../common/tileentity/TileEntityHopper.java | 6 +- .../tileentity/TileEntityInventory.java | 3 +- .../src/main/java/common/util/Equipment.java | 68 +- server/src/main/java/server/Server.java | 4 +- .../server/command/commands/CommandClear.java | 14 +- .../server/command/commands/CommandItem.java | 2 +- .../server/command/commands/CommandMore.java | 7 +- .../command/commands/CommandRepair.java | 7 +- .../src/main/java/server/network/Player.java | 99 +- 90 files changed, 1177 insertions(+), 1622 deletions(-) delete mode 100755 common/src/main/java/common/attributes/AttributeMap.java rename common/src/main/java/common/{attributes => entity/npc}/Attribute.java (91%) delete mode 100755 common/src/main/java/common/inventory/InventoryPlayer.java diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index 758bdbb9..5049fd9c 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -124,7 +124,6 @@ import common.init.ItemRegistry; import common.init.Items; import common.init.Registry; import common.init.SoundEvent; -import common.inventory.InventoryPlayer; import common.item.Item; import common.item.ItemControl; import common.item.ItemStack; @@ -871,9 +870,9 @@ public class Client implements IThreadListener { { if (this.keyBindsHotbar[l].isPressed()) { - if(this.player.inventory.currentItem != l) + if(this.player.getSelectedIndex() != l) this.controller.resetUseCooldown(); - this.player.inventory.currentItem = l; + this.player.setSelectedIndex(l); } } @@ -1065,14 +1064,14 @@ public class Client implements IThreadListener { } } - int selected = this.player.inventory.currentItem; + int selected = this.player.getSelectedIndex(); for(int n = 0; n < 9; n++) { int x = this.fbX / 2 - 180 + n * 40 + 4; int y = this.fbY - 40; Drawing.drawRectBorder(x - 1, y - 1, 36, 36, 0xff6f6f6f, selected == n ? 0xffffffff : 0xff000000, 0xffafafaf, 0xff4f4f4f); } - ItemStack itemstack = this.player.inventory.getCurrentItem(); + ItemStack itemstack = this.player.getHeldItem(); String current = itemstack != null ? itemstack.getItem().getHotbarText(this.player, itemstack) : ""; if(!current.isEmpty()) Drawing.drawTextUpward(current, this.fbX / 2, this.fbY - 60, 0xffffffff); @@ -1211,7 +1210,7 @@ public class Client implements IThreadListener { for(int index = 0; index < 9; ++index) { int xPos = index * 20; - ItemStack itemstack = this.player.inventory.mainInventory[index]; + ItemStack itemstack = this.player.getStackInSlot(index); if(itemstack != null) { GlState.enableDepth(); this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0); @@ -1246,10 +1245,10 @@ public class Client implements IThreadListener { GlState.disableDepth(); if(this.world != null && this.open == null && this.player != null && this.viewEntity == this.player) { for(int index = 0; index < 9; ++index) { - ItemStack itemstack = this.player.inventory.mainInventory[index]; + ItemStack itemstack = this.player.getStackInSlot(index); if(itemstack != null) { GuiContainer.renderItemOverlay(itemstack, - this.fbX / 2 - 180 + 4 + 1 + index * 40, this.fbY - 40 + 1, null, index == this.player.inventory.currentItem ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), 2); + this.fbX / 2 - 180 + 4 + 1 + index * 40, this.fbY - 40 + 1, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), 2); } } } @@ -1367,7 +1366,11 @@ public class Client implements IThreadListener { if(this.zooming) this.zoomLevel = ExtMath.clampf(this.zoomLevel + (dir < 0 ? -0.25f : 0.25f), 2.0f, 16.0f); else if(this.player != null) { - this.player.inventory.changeCurrentItem(dir); + this.player.setSelectedIndex(this.player.getSelectedIndex() - dir); + if(this.player.getSelectedIndex() < 0) + this.player.setSelectedIndex(9 - 1); + else if(this.player.getSelectedIndex() >= 9) + this.player.setSelectedIndex(0); this.controller.resetUseCooldown(); } } @@ -1384,7 +1387,7 @@ public class Client implements IThreadListener { if(this.player != null) { if(this.getNetHandler() != null) this.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_CONTAINER, this.player.openContainer.windowId)); - this.player.inventory.setItemStack(null); + this.player.setMouseItem(null); this.player.openContainer = this.player.inventoryContainer; } if (this.open != null) @@ -1451,13 +1454,13 @@ public class Client implements IThreadListener { } else { - ItemStack itemstack = this.player.inventory.getCurrentItem(); + ItemStack itemstack = this.player.getHeldItem(); if ((this.pointed.type != ObjectType.BLOCK || this.world.getState(this.pointed.block).getBlock() == Blocks.air) && itemstack != null && itemstack.getItem().onAction(itemstack, this.player, this.world, ItemControl.PRIMARY, null)) { this.player.swingItem(); this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.PRIMARY.ordinal())); if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty()) - this.player.inventory.mainInventory[this.player.inventory.currentItem] = null; + this.player.setHeldItem(null); this.leftClickCounter = 10; return; } @@ -1493,7 +1496,7 @@ public class Client implements IThreadListener { { this.rightClickTimer = 4; boolean flag = true; - ItemStack itemstack = this.player.inventory.getCurrentItem(); + ItemStack itemstack = this.player.getHeldItem(); if (itemstack != null && itemstack.getItem() == Items.camera && !this.saving) { @@ -1511,7 +1514,7 @@ public class Client implements IThreadListener { this.player.swingItem(); this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.SECONDARY.ordinal())); if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty()) - this.player.inventory.mainInventory[this.player.inventory.currentItem] = null; + this.player.setHeldItem(null); return; } @@ -1545,7 +1548,7 @@ public class Client implements IThreadListener { if (itemstack.isEmpty()) { - this.player.inventory.mainInventory[this.player.inventory.currentItem] = null; + this.player.setHeldItem(null); } else if (itemstack.getSize() != i) { @@ -1557,7 +1560,7 @@ public class Client implements IThreadListener { if (flag) { - ItemStack itemstack1 = this.player.inventory.getCurrentItem(); + ItemStack itemstack1 = this.player.getHeldItem(); if (itemstack1 != null && this.controller.sendUseItem(this.player, this.world, itemstack1)) { @@ -1574,7 +1577,7 @@ public class Client implements IThreadListener { if(this.player.getHeldItem() != null && this.player.getHeldItem().getItem().onAction(this.player.getHeldItem(), this.player, this.world, ItemControl.TERTIARY, null)) { this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.TERTIARY.ordinal())); if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty()) - this.player.inventory.mainInventory[this.player.inventory.currentItem] = null; + this.player.setHeldItem(null); return; } @@ -1586,12 +1589,13 @@ public class Client implements IThreadListener { if(item == null) return; - InventoryPlayer inventoryplayer = this.player.inventory; - - if(inventoryplayer.setCurrentItem(item)) + int idx = this.player.getInventorySlotContainItem(item); + if(idx >= 0 && idx < 9) { + this.player.setSelectedIndex(idx); this.controller.resetUseCooldown(); + } if(this.itemCheat) { - this.player.client.addToSendQueue(new CPacketCheat(item, -2 - inventoryplayer.currentItem, this.ctrl())); + this.player.client.addToSendQueue(new CPacketCheat(item, -2 - this.player.getSelectedIndex(), this.ctrl())); } } } @@ -1603,7 +1607,7 @@ public class Client implements IThreadListener { if(this.player.getHeldItem() != null && this.player.getHeldItem().getItem().onAction(this.player.getHeldItem(), this.player, this.world, ItemControl.QUARTERNARY, null)) { this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.QUARTERNARY.ordinal())); if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty()) - this.player.inventory.mainInventory[this.player.inventory.currentItem] = null; + this.player.setHeldItem(null); return; } } diff --git a/client/src/main/java/client/gui/container/GuiBrewing.java b/client/src/main/java/client/gui/container/GuiBrewing.java index 2133b29c..e490576b 100755 --- a/client/src/main/java/client/gui/container/GuiBrewing.java +++ b/client/src/main/java/client/gui/container/GuiBrewing.java @@ -3,13 +3,13 @@ package client.gui.container; import common.init.Blocks; import common.inventory.ContainerBrewingStand; import common.inventory.IInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; public class GuiBrewing extends GuiContainer { - private final InventoryPlayer playerInv; + private final EntityNPC playerInv; private final IInventory brewer; - public GuiBrewing(InventoryPlayer player, IInventory brewer) { + public GuiBrewing(EntityNPC player, IInventory brewer) { super(new ContainerBrewingStand(player, brewer)); this.playerInv = player; this.brewer = brewer; diff --git a/client/src/main/java/client/gui/container/GuiChest.java b/client/src/main/java/client/gui/container/GuiChest.java index 512850fa..a033951c 100755 --- a/client/src/main/java/client/gui/container/GuiChest.java +++ b/client/src/main/java/client/gui/container/GuiChest.java @@ -1,16 +1,15 @@ package client.gui.container; -import client.Client; import common.block.Block; import common.inventory.ContainerChest; import common.inventory.IInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; public class GuiChest extends GuiContainer { private final Block block; - public GuiChest(InventoryPlayer inv, IInventory chest, Block block) { - super(new ContainerChest(inv, chest, Client.CLIENT.player)); + public GuiChest(EntityNPC player, IInventory chest, Block block) { + super(new ContainerChest(player, chest)); this.block = block; int i = 222; int j = i - 108; diff --git a/client/src/main/java/client/gui/container/GuiContainer.java b/client/src/main/java/client/gui/container/GuiContainer.java index 4e468b44..ebce6c68 100755 --- a/client/src/main/java/client/gui/container/GuiContainer.java +++ b/client/src/main/java/client/gui/container/GuiContainer.java @@ -26,13 +26,12 @@ import client.renderer.ItemRenderer; import client.renderer.entity.RenderItem; import client.window.Bind; import client.window.Button; -import common.attributes.Attribute; import common.collect.Lists; import common.collect.Sets; import common.enchantment.Enchantment; +import common.entity.npc.Attribute; import common.init.ItemRegistry; import common.inventory.Container; -import common.inventory.InventoryPlayer; import common.inventory.Slot; import common.item.CheatTab; import common.item.ItemStack; @@ -141,7 +140,8 @@ public abstract class GuiContainer extends Gui } } - Map mods = stack.getAttributeModifiers(null); + Map mods = stack.getAttributeModifiers(); + mods.putAll(stack.getArmorModifiers(null)); if(!mods.isEmpty()) { list.add(""); @@ -390,8 +390,7 @@ public abstract class GuiContainer extends Gui ItemRenderer.disableStandardItemLighting(); ItemRenderer.enableGUIStandardItemLighting(); - InventoryPlayer inventoryplayer = this.gm.player.inventory; - ItemStack stack = inventoryplayer.getItemStack(); + ItemStack stack = this.gm.player.getMouseItem(); if(this.gm.itemCheat) stack = stack == null ? this.cheatStack : stack; if(Bind.CRAFT.isDown()) @@ -420,11 +419,11 @@ public abstract class GuiContainer extends Gui this.drawItemStack(stack, mouseX - j2, mouseY - k2, s); } - if (inventoryplayer.getItemStack() == null && this.cheatStack == null && stack != null) + if (this.gm.player.getMouseItem() == null && this.cheatStack == null && stack != null) { this.renderToolTip(stack, mouseX, mouseY); } - else if (inventoryplayer.getItemStack() == null && this.cheatStack == null && this.theSlot != null && this.theSlot.getHasStack()) + else if (this.gm.player.getMouseItem() == null && this.cheatStack == null && this.theSlot != null && this.theSlot.getHasStack()) { ItemStack itemstack1 = this.theSlot.getStack(); this.renderToolTip(itemstack1, mouseX, mouseY); @@ -504,7 +503,7 @@ public abstract class GuiContainer extends Gui int j = slotIn.yDisplayPosition; ItemStack itemstack = slotIn.getStack(); boolean flag = false; - ItemStack itemstack1 = this.gm.player.inventory.getItemStack(); + ItemStack itemstack1 = this.gm.player.getMouseItem(); String s = null; if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && itemstack1 != null) @@ -550,7 +549,7 @@ public abstract class GuiContainer extends Gui private void updateDragSplitting() { - ItemStack itemstack = this.gm.player.inventory.getItemStack(); + ItemStack itemstack = this.gm.player.getMouseItem(); if (itemstack != null && this.dragSplitting) { @@ -607,7 +606,7 @@ public abstract class GuiContainer extends Gui if((mouseButton == 0 || mouseButton == 1 || mouseButton == 2) && this.clickSide(this.gm.mouseX, this.gm.mouseY, -1, this.gm.shift() || mouseButton == 1, this.gm.ctrl() || mouseButton == 2)) return; if(mouseButton == 0) { - if(this.gm.itemCheat && this.gm.player != null && this.gm.player.inventory.getItemStack() == null) { + if(this.gm.itemCheat && this.gm.player != null && this.gm.player.getMouseItem() == null) { for (CheatTab tab : CheatTab.values()) { if (this.isInsideTab(tab, this.gm.mouseX, this.gm.mouseY)) @@ -647,7 +646,7 @@ public abstract class GuiContainer extends Gui { if (!this.dragSplitting) { - if (this.gm.player.inventory.getItemStack() == null) + if (this.gm.player.getMouseItem() == null) { boolean flag2 = l != -999 && this.gm.shift(); int i1 = 0; @@ -695,7 +694,7 @@ public abstract class GuiContainer extends Gui if(this.gm == null || this.cheatStack != null) return; Slot slot = this.getSlotAtPosition(mouseX, mouseY); - ItemStack itemstack = this.gm.player.inventory.getItemStack(); + ItemStack itemstack = this.gm.player.getMouseItem(); if (this.dragSplitting && slot != null && itemstack != null && itemstack.getSize() > this.dragSplittingSlots.size() && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot)) { @@ -772,7 +771,7 @@ public abstract class GuiContainer extends Gui this.handleMouseClick((Slot)null, -999, Container.getDragCode(2, this.dragSplittingLimit), 5); } - else if (this.gm.player.inventory.getItemStack() != null) + else if (this.gm.player.getMouseItem() != null) { boolean flag1 = k != -999 && this.gm.shift(); @@ -785,7 +784,7 @@ public abstract class GuiContainer extends Gui } } - if (this.gm.player.inventory.getItemStack() == null) + if (this.gm.player.getMouseItem() == null) { this.lastClickTime = 0L; } @@ -829,7 +828,7 @@ public abstract class GuiContainer extends Gui public void useHotbar(int slot) { - if (!this.clickSide(this.gm.mouseX, this.gm.mouseY, slot, this.gm.shift(), this.gm.ctrl()) && this.gm != null && this.gm.player != null && this.gm.player.inventory.getItemStack() == null && this.cheatStack == null && this.theSlot != null) + if (!this.clickSide(this.gm.mouseX, this.gm.mouseY, slot, this.gm.shift(), this.gm.ctrl()) && this.gm != null && this.gm.player != null && this.gm.player.getMouseItem() == null && this.cheatStack == null && this.theSlot != null) { this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, slot, 2); } @@ -971,7 +970,7 @@ public abstract class GuiContainer extends Gui } private boolean clickSide(int mouseX, int mouseY, int slot, boolean instant, boolean full) { - if(this.gm.itemCheat && this.isPointInRegion(this.cheatX, this.cheatY, 18 * this.cheatWidth, 18 * this.cheatHeight, mouseX, mouseY) && this.gm.player != null && this.gm.player.inventory.getItemStack() == null && this.cheatStack == null) { + if(this.gm.itemCheat && this.isPointInRegion(this.cheatX, this.cheatY, 18 * this.cheatWidth, 18 * this.cheatHeight, mouseX, mouseY) && this.gm.player != null && this.gm.player.getMouseItem() == null && this.cheatStack == null) { int size = (ITEM_LIST.size() + this.cheatWidth - 1) / this.cheatWidth - this.cheatHeight; int off = (int)((double)(this.currentScroll * (float)size) + 0.5D); diff --git a/client/src/main/java/client/gui/container/GuiCrafting.java b/client/src/main/java/client/gui/container/GuiCrafting.java index 7deee648..578eaf00 100755 --- a/client/src/main/java/client/gui/container/GuiCrafting.java +++ b/client/src/main/java/client/gui/container/GuiCrafting.java @@ -2,14 +2,14 @@ package client.gui.container; import common.block.tech.BlockWorkbench; import common.inventory.ContainerWorkbench; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.util.BlockPos; import common.world.World; public class GuiCrafting extends GuiContainer { private final BlockWorkbench type; - public GuiCrafting(InventoryPlayer inv, World world, BlockWorkbench type) { + public GuiCrafting(EntityNPC inv, World world, BlockWorkbench type) { super(new ContainerWorkbench(inv, world, BlockPos.ORIGIN, type)); this.type = type; this.ySize = 112 + 18 * this.type.getSize(); diff --git a/client/src/main/java/client/gui/container/GuiDevice.java b/client/src/main/java/client/gui/container/GuiDevice.java index d0047f91..59dbe0bf 100755 --- a/client/src/main/java/client/gui/container/GuiDevice.java +++ b/client/src/main/java/client/gui/container/GuiDevice.java @@ -1,10 +1,9 @@ package client.gui.container; -import client.Client; import client.gui.element.Label; import common.inventory.ContainerTile; import common.inventory.IInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.tileentity.Device; public class GuiDevice extends GuiContainer { @@ -16,8 +15,8 @@ public class GuiDevice extends GuiContainer { private Label temp; private Label desc; - public GuiDevice(InventoryPlayer player, IInventory inv, Device tile) { - super(new ContainerTile(player, tile, inv, Client.CLIENT.player)); + public GuiDevice(EntityNPC player, IInventory inv, Device tile) { + super(new ContainerTile(player, tile, inv)); this.playerInv = player; this.tileInv = tile; this.ySize = 153; diff --git a/client/src/main/java/client/gui/container/GuiDispenser.java b/client/src/main/java/client/gui/container/GuiDispenser.java index b97d99f4..a63d4627 100755 --- a/client/src/main/java/client/gui/container/GuiDispenser.java +++ b/client/src/main/java/client/gui/container/GuiDispenser.java @@ -3,12 +3,12 @@ package client.gui.container; import common.block.tech.BlockDispenser; import common.inventory.ContainerDispenser; import common.inventory.IInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; public class GuiDispenser extends GuiContainer { private final BlockDispenser block; - public GuiDispenser(InventoryPlayer playerInv, IInventory dispenser, BlockDispenser block) { + public GuiDispenser(EntityNPC playerInv, IInventory dispenser, BlockDispenser block) { super(new ContainerDispenser(playerInv, dispenser)); this.block = block; } diff --git a/client/src/main/java/client/gui/container/GuiEnchant.java b/client/src/main/java/client/gui/container/GuiEnchant.java index 13447c45..661bbab6 100755 --- a/client/src/main/java/client/gui/container/GuiEnchant.java +++ b/client/src/main/java/client/gui/container/GuiEnchant.java @@ -7,7 +7,7 @@ import client.gui.element.PressType; import common.enchantment.Enchantment; import common.init.Blocks; import common.inventory.ContainerEnchantment; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.rng.Random; import common.util.Pair; import common.util.Color; @@ -25,7 +25,7 @@ public class GuiEnchant extends GuiContainer implements ButtonCallback { private final Label[] labels = new Label[3]; private final Label[] mana = new Label[3]; - public GuiEnchant(InventoryPlayer inv, World world) { + public GuiEnchant(EntityNPC inv, World world) { super(new ContainerEnchantment(inv, world)); this.enchantment = (ContainerEnchantment)this.inventorySlots; } diff --git a/client/src/main/java/client/gui/container/GuiEntity.java b/client/src/main/java/client/gui/container/GuiEntity.java index ac5a1dec..c4a2adb7 100755 --- a/client/src/main/java/client/gui/container/GuiEntity.java +++ b/client/src/main/java/client/gui/container/GuiEntity.java @@ -1,15 +1,15 @@ package client.gui.container; -import client.Client; import common.entity.Entity; +import common.entity.npc.EntityNPC; import common.inventory.ContainerEntityInventory; import common.inventory.IInventory; public class GuiEntity extends GuiContainer { private final String title; - public GuiEntity(IInventory playerInv, IInventory entityInv, Entity entity) { - super(new ContainerEntityInventory(playerInv, entityInv, entity, Client.CLIENT.player)); + public GuiEntity(EntityNPC player, IInventory entityInv, Entity entity) { + super(new ContainerEntityInventory(player, entityInv, entity)); this.title = entity.getName(); } diff --git a/client/src/main/java/client/gui/container/GuiFurnace.java b/client/src/main/java/client/gui/container/GuiFurnace.java index 5393ac85..b201e02f 100755 --- a/client/src/main/java/client/gui/container/GuiFurnace.java +++ b/client/src/main/java/client/gui/container/GuiFurnace.java @@ -3,14 +3,14 @@ package client.gui.container; import common.block.tech.BlockFurnace; import common.inventory.ContainerFurnace; import common.inventory.IInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.tileentity.TileEntityFurnace; public class GuiFurnace extends GuiContainer { private final BlockFurnace block; private final IInventory furnace; - public GuiFurnace(InventoryPlayer playerInv, IInventory furnaceInv, BlockFurnace block) { + public GuiFurnace(EntityNPC playerInv, IInventory furnaceInv, BlockFurnace block) { super(new ContainerFurnace(playerInv, furnaceInv)); this.block = block; this.furnace = furnaceInv; diff --git a/client/src/main/java/client/gui/container/GuiHopper.java b/client/src/main/java/client/gui/container/GuiHopper.java index b3718134..962cc448 100755 --- a/client/src/main/java/client/gui/container/GuiHopper.java +++ b/client/src/main/java/client/gui/container/GuiHopper.java @@ -4,10 +4,10 @@ import client.Client; import common.init.Blocks; import common.inventory.ContainerHopper; import common.inventory.IInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; public class GuiHopper extends GuiContainer { - public GuiHopper(InventoryPlayer playerInv, IInventory hopper) { + public GuiHopper(EntityNPC playerInv, IInventory hopper) { super(new ContainerHopper(playerInv, hopper, Client.CLIENT.player)); this.ySize = 133; } diff --git a/client/src/main/java/client/gui/container/GuiMerchant.java b/client/src/main/java/client/gui/container/GuiMerchant.java index 3204f4b7..847cc6be 100755 --- a/client/src/main/java/client/gui/container/GuiMerchant.java +++ b/client/src/main/java/client/gui/container/GuiMerchant.java @@ -9,7 +9,7 @@ import client.renderer.GlState; import client.renderer.ItemRenderer; import common.entity.Entity; import common.inventory.ContainerMerchant; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.packet.CPacketAction; import common.village.MerchantRecipe; @@ -23,7 +23,7 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback { private ActButton prevBtn; private ActButton nextBtn; - public GuiMerchant(InventoryPlayer inv, Entity entity, World world) { + public GuiMerchant(EntityNPC inv, Entity entity, World world) { super(new ContainerMerchant(inv, null, world)); this.title = entity.getName(); } diff --git a/client/src/main/java/client/gui/container/GuiRepair.java b/client/src/main/java/client/gui/container/GuiRepair.java index 09f396d1..c7633b5c 100755 --- a/client/src/main/java/client/gui/container/GuiRepair.java +++ b/client/src/main/java/client/gui/container/GuiRepair.java @@ -1,17 +1,17 @@ package client.gui.container; import client.gui.element.Label; +import common.entity.npc.EntityNPC; import common.inventory.ContainerRepair; -import common.inventory.InventoryPlayer; import common.util.Color; import common.world.World; public class GuiRepair extends GuiContainer { private ContainerRepair anvil; private Label info; - private InventoryPlayer playerInv; + private EntityNPC playerInv; - public GuiRepair(InventoryPlayer inv, World world) { + public GuiRepair(EntityNPC inv, World world) { super(new ContainerRepair(inv, world)); this.playerInv = inv; this.anvil = (ContainerRepair)this.inventorySlots; @@ -23,7 +23,7 @@ public class GuiRepair extends GuiContainer { this.info.setText(Color.DARK_RED + "Zu teuer!"); else if(this.anvil.maximumCost <= 0 || !this.anvil.getSlot(2).getHasStack()) this.info.setText(""); - else if(!this.anvil.getSlot(2).canTakeStack(this.playerInv.player)) + else if(!this.anvil.getSlot(2).canTakeStack(this.playerInv)) this.info.setText(Color.RED + "Manakosten: " + this.anvil.maximumCost); else this.info.setText(Color.GREEN + "Manakosten: " + this.anvil.maximumCost); diff --git a/client/src/main/java/client/network/ClientPlayer.java b/client/src/main/java/client/network/ClientPlayer.java index 9e9d42f7..89df2f92 100755 --- a/client/src/main/java/client/network/ClientPlayer.java +++ b/client/src/main/java/client/network/ClientPlayer.java @@ -52,7 +52,6 @@ import common.init.Items; import common.init.SoundEvent; import common.inventory.Container; import common.inventory.InventoryBasic; -import common.inventory.InventoryPlayer; import common.inventory.InventoryWarpChest; import common.item.ItemStack; import common.item.material.ItemGrindedBones; @@ -530,11 +529,11 @@ public class ClientPlayer implements IClientPlayer if (i == 0) { - player.inventory.mainInventory[player.inventory.currentItem] = null; + player.setHeldItem(null); } else { - player.inventory.mainInventory[player.inventory.currentItem] = new ItemStack(ItemRegistry.byId(i)); + player.setHeldItem(new ItemStack(ItemRegistry.byId(i))); } player.setPositionAndRotation(x, y, z, yaw, pitch); @@ -588,11 +587,11 @@ public class ClientPlayer implements IClientPlayer { NetHandler.checkThread(packetIn, this, this.gm, this.world); - if (packetIn.getHeldItemHotbarIndex() >= 0 && packetIn.getHeldItemHotbarIndex() < InventoryPlayer.getHotbarSize()) + if (packetIn.getHeldItemHotbarIndex() >= 0 && packetIn.getHeldItemHotbarIndex() < 9) { - if(this.gm.player.inventory.currentItem != packetIn.getHeldItemHotbarIndex()) + if(this.gm.player.getSelectedIndex() != packetIn.getHeldItemHotbarIndex()) this.gm.controller.resetUseCooldown(); - this.gm.player.inventory.currentItem = packetIn.getHeldItemHotbarIndex(); + this.gm.player.setSelectedIndex(packetIn.getHeldItemHotbarIndex()); } } @@ -1117,7 +1116,7 @@ public class ClientPlayer implements IClientPlayer TileEntity tile = this.world.getTileEntity(packet.getTilePos()); if(!(tile instanceof Device dev)) return; - this.gm.show(new GuiDevice(this.gm.player.inventory, new LocalContainer(slots), dev)); + this.gm.show(new GuiDevice(player, new LocalContainer(slots), dev)); } else if (packet.getEntityId() != -1) { @@ -1125,44 +1124,44 @@ public class ClientPlayer implements IClientPlayer if(entity == null) return; if(entity instanceof EntityNPC) - this.gm.show(new GuiMerchant(player.inventory, entity, player.worldObj)); + this.gm.show(new GuiMerchant(player, entity, player.worldObj)); else - this.gm.show(new GuiEntity(player.inventory, new InventoryBasic(slots), entity)); + this.gm.show(new GuiEntity(player, new InventoryBasic(slots), entity)); } else if (block == Blocks.warp_chest) { - this.gm.show(new GuiChest(player.inventory, new InventoryWarpChest(), block)); + this.gm.show(new GuiChest(player, new InventoryWarpChest(), block)); } else if (block == Blocks.enchanting_table) { - this.gm.show(new GuiEnchant(player.inventory, player.worldObj)); + this.gm.show(new GuiEnchant(player, player.worldObj)); } else if (block instanceof BlockAnvil) { - this.gm.show(new GuiRepair(player.inventory, player.worldObj)); + this.gm.show(new GuiRepair(player, player.worldObj)); } else if (block instanceof BlockChest) { - this.gm.show(new GuiChest(player.inventory, new InventoryBasic(slots), block)); + this.gm.show(new GuiChest(player, new InventoryBasic(slots), block)); } else if (block == Blocks.hopper) { - this.gm.show(new GuiHopper(player.inventory, new InventoryBasic(slots))); + this.gm.show(new GuiHopper(player, new InventoryBasic(slots))); } else if (block instanceof BlockFurnace furnace) { - this.gm.show(new GuiFurnace(player.inventory, new LocalContainer(slots), furnace)); + this.gm.show(new GuiFurnace(player, new LocalContainer(slots), furnace)); } else if (block == Blocks.brewing_stand) { - this.gm.show(new GuiBrewing(player.inventory, new LocalContainer(slots))); + this.gm.show(new GuiBrewing(player, new LocalContainer(slots))); } else if (block instanceof BlockDispenser dispenser) { - this.gm.show(new GuiDispenser(player.inventory, new InventoryBasic(slots), dispenser)); + this.gm.show(new GuiDispenser(player, new InventoryBasic(slots), dispenser)); } else if(block instanceof BlockWorkbench bench) { - this.gm.show(new GuiCrafting(player.inventory, player.worldObj, bench)); + this.gm.show(new GuiCrafting(player, player.worldObj, bench)); } else { return; @@ -1180,7 +1179,7 @@ public class ClientPlayer implements IClientPlayer if (packetIn.getWindowId() == -1) { - entityplayer.inventory.setItemStack(packetIn.getStack()); + entityplayer.setMouseItem(packetIn.getStack()); } else { diff --git a/client/src/main/java/client/renderer/ItemRenderer.java b/client/src/main/java/client/renderer/ItemRenderer.java index 6dc4a7dd..6a1a1296 100755 --- a/client/src/main/java/client/renderer/ItemRenderer.java +++ b/client/src/main/java/client/renderer/ItemRenderer.java @@ -40,7 +40,6 @@ public class ItemRenderer private ItemStack itemToRender; private float equippedProgress; private float prevEquippedProgress; - private int equippedItemSlot = -1; private static FloatBuffer setColorBuffer(float r, float g, float b, float a) { @@ -497,7 +496,7 @@ public class ItemRenderer { this.prevEquippedProgress = this.equippedProgress; EntityNPC entityplayer = this.gm.player; - ItemStack itemstack = entityplayer.inventory.getCurrentItem(); + ItemStack itemstack = entityplayer.getHeldItem(); boolean flag = false; if (this.itemToRender != null && itemstack != null) @@ -524,7 +523,6 @@ public class ItemRenderer if (this.equippedProgress < 0.1F) { this.itemToRender = itemstack; - this.equippedItemSlot = entityplayer.inventory.currentItem; } } diff --git a/client/src/main/java/client/renderer/entity/RenderItem.java b/client/src/main/java/client/renderer/entity/RenderItem.java index 32a0f671..bb6412c3 100755 --- a/client/src/main/java/client/renderer/entity/RenderItem.java +++ b/client/src/main/java/client/renderer/entity/RenderItem.java @@ -16,6 +16,7 @@ import client.renderer.layers.LayerArmor; import client.renderer.model.ModelHorse; import client.renderer.texture.TextureManager; import client.renderer.texture.TextureMap; +import common.entity.animal.EntityHorse; import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; import common.item.Item; @@ -145,11 +146,14 @@ public class RenderItem GL11.glTranslatef(0.9f, 0.5f, 0.0f); GL11.glRotatef(180.0f, 0.0f, 1.0f, 0.0f); GL11.glScalef(0.85f, -0.85f, 0.85f); + Class clazz = horseArmor.getArmorType().getAnimalType(); boolean cull = GlState.isCullEnabled(); if(cull) GlState.disableCull(); - this.manager.bindTexture("textures/armor/" + horseArmor.getArmorTexture() + "_horse.png"); - this.horse.render(null, 0, 0, 0, 0, 0, 0.0625F); + if(clazz == EntityHorse.class) { + this.manager.bindTexture("textures/armor/" + horseArmor.getArmorTexture() + "_horse.png"); + this.horse.render(null, 0, 0, 0, 0, 0, 0.0625F); + } if(cull) GlState.enableCull(); GL11.glPopMatrix(); diff --git a/client/src/main/java/client/renderer/layers/LayerArmor.java b/client/src/main/java/client/renderer/layers/LayerArmor.java index db9da379..1202038f 100755 --- a/client/src/main/java/client/renderer/layers/LayerArmor.java +++ b/client/src/main/java/client/renderer/layers/LayerArmor.java @@ -26,7 +26,7 @@ public class LayerArmor implements LayerRenderer static { List list = Lists.newArrayList(); for(Equipment tool : Equipment.values()) { - if(tool.isArmor() && tool.isArmorRendered() && !tool.isAnimalArmor()) + if(tool.isArmor() && tool.isMainArmor() && !tool.isAnimalArmor()) list.add(tool); } SLOTS = list.toArray(new Equipment[list.size()]); diff --git a/client/src/main/java/client/util/PlayerController.java b/client/src/main/java/client/util/PlayerController.java index 8c36ab27..fabe09b0 100755 --- a/client/src/main/java/client/util/PlayerController.java +++ b/client/src/main/java/client/util/PlayerController.java @@ -65,7 +65,7 @@ public class PlayerController { stack.getItem().onBlockDestroyed(stack, world, block, pos, this.gm.player); if(stack.isEmpty()) { - this.gm.player.destroyCurrentEquippedItem(); + this.gm.player.setHeldItem(null); } } @@ -83,7 +83,7 @@ public class PlayerController { this.interacting = true; this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, pos, face)); if(this.gm.player.getHeldItem() != null && this.gm.player.getHeldItem().isEmpty()) - this.gm.player.inventory.mainInventory[this.gm.player.inventory.currentItem] = null; + this.gm.player.setHeldItem(null); return true; } if(!this.hitting || !this.isHitting(pos)) { @@ -200,7 +200,7 @@ public class PlayerController { } private void syncItem() { - int slot = this.gm.player.inventory.currentItem; + int slot = this.gm.player.getSelectedIndex(); if(slot != this.lastSelected) { this.lastSelected = slot; @@ -235,7 +235,7 @@ public class PlayerController { flag = true; } - this.handler.addToSendQueue(new CPacketPlace(pos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2)); + this.handler.addToSendQueue(new CPacketPlace(pos, side.getIndex(), player.getHeldItem(), f, f1, f2)); if(!flag) { if(stack == null) { @@ -255,16 +255,16 @@ public class PlayerController { this.syncItem(); if(this.itemUseCooldown > 0) return false; - this.handler.addToSendQueue(new CPacketPlace(player.inventory.getCurrentItem())); + this.handler.addToSendQueue(new CPacketPlace(player.getHeldItem())); int size = stack.getSize(); this.itemUseCooldown = this.itemUseCooldownMax = stack.getItem().getUseCooldown(stack, world, player); ItemStack changed = stack.getItem().onItemRightClick(stack, world, player); if(changed != stack || changed != null && changed.getSize() != size) { - player.inventory.mainInventory[player.inventory.currentItem] = changed; + player.setHeldItem(changed); if(changed.isEmpty()) { - player.inventory.mainInventory[player.inventory.currentItem] = null; + player.setHeldItem(null); } return true; @@ -293,7 +293,7 @@ public class PlayerController { } public ItemStack windowClick(int window, int slot, int button, int mode, EntityNPC player) { - short id = player.openContainer.getNextTransactionID(player.inventory); + short id = player.openContainer.getNextTransactionID(player); ItemStack stack = player.openContainer.slotClick(slot, button, mode, player); this.handler.addToSendQueue(new CPacketClick(window, slot, button, mode, stack, id)); return stack; diff --git a/common/src/main/java/common/ai/AIFireballAttack.java b/common/src/main/java/common/ai/AIFireballAttack.java index 31751a87..f904504f 100755 --- a/common/src/main/java/common/ai/AIFireballAttack.java +++ b/common/src/main/java/common/ai/AIFireballAttack.java @@ -40,7 +40,7 @@ public class AIFireballAttack extends EntityAIBase public void resetTask() { - this.parentEntity.setItemNoUpdate(null); + this.parentEntity.setHeldNoUpdate(null); } public void updateTask() @@ -56,13 +56,13 @@ public class AIFireballAttack extends EntityAIBase if (this.attackTimer == this.delay) { world.playEffect(1007, new BlockPos(this.parentEntity), 0); - this.parentEntity.setItemNoUpdate(new ItemStack(Items.orb)); + this.parentEntity.setHeldNoUpdate(new ItemStack(Items.orb)); } if (this.attackTimer == this.delay * 2) { this.parentEntity.swingItem(); - this.parentEntity.setItemNoUpdate(null); + this.parentEntity.setHeldNoUpdate(null); double d1 = 1.0D; Vec3 vec3 = this.parentEntity.getLook(1.0F); double d2 = target.posX - (this.parentEntity.posX + vec3.xCoord * d1); @@ -91,6 +91,6 @@ public class AIFireballAttack extends EntityAIBase --this.attackTimer; } - this.parentEntity.setItemNoUpdate(this.attackTimer > this.delay ? new ItemStack(Items.orb) : null); + this.parentEntity.setHeldNoUpdate(this.attackTimer > this.delay ? new ItemStack(Items.orb) : null); } } \ No newline at end of file diff --git a/common/src/main/java/common/ai/EntityAIBeg.java b/common/src/main/java/common/ai/EntityAIBeg.java index 752e455b..d8b36551 100755 --- a/common/src/main/java/common/ai/EntityAIBeg.java +++ b/common/src/main/java/common/ai/EntityAIBeg.java @@ -71,7 +71,7 @@ public class EntityAIBeg extends EntityAIBase */ private boolean hasPlayerGotBoneInHand(EntityNPC player) { - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); return itemstack == null ? false : (!this.theWolf.isTamed() && itemstack.getItem() == Items.bone ? true : this.theWolf.isBreedingItem(itemstack)); } } diff --git a/common/src/main/java/common/ai/EntityAIShareItems.java b/common/src/main/java/common/ai/EntityAIShareItems.java index acb9a079..b4a79afb 100755 --- a/common/src/main/java/common/ai/EntityAIShareItems.java +++ b/common/src/main/java/common/ai/EntityAIShareItems.java @@ -3,7 +3,6 @@ package common.ai; import common.entity.item.EntityItem; import common.entity.npc.EntityNPC; import common.init.Items; -import common.inventory.InventoryBasic; import common.item.Item; import common.item.ItemStack; import common.util.ExtMath; @@ -49,11 +48,9 @@ public class EntityAIShareItems extends EntityAIWatchClosest2 if (this.interactionDelay == 0) { - InventoryBasic inventorybasic = this.entity.getExtendedInventory(); - - for (int i = 0; i < inventorybasic.getSizeInventory(); ++i) + for (int i = 0; i < this.entity.getInventoryCapacity(); ++i) { - ItemStack itemstack = inventorybasic.getStackInSlot(i); + ItemStack itemstack = this.entity.getStackInSlot(i); ItemStack itemstack1 = null; if (itemstack != null) @@ -76,7 +73,7 @@ public class EntityAIShareItems extends EntityAIWatchClosest2 if (itemstack.isEmpty()) { - inventorybasic.setInventorySlotContents(i, (ItemStack)null); + this.entity.setInventorySlotContents(i, (ItemStack)null); } } diff --git a/common/src/main/java/common/ai/EntityAITakePlace.java b/common/src/main/java/common/ai/EntityAITakePlace.java index 12c3f1e8..08fc9140 100755 --- a/common/src/main/java/common/ai/EntityAITakePlace.java +++ b/common/src/main/java/common/ai/EntityAITakePlace.java @@ -85,7 +85,7 @@ public class EntityAITakePlace extends EntityAIBase this.entity.swingItem(); world.setState(blockpos, state, 3); if(stack.decrSize()) - this.entity.setItemNoUpdate(null); + this.entity.setHeldNoUpdate(null); } } else { @@ -102,7 +102,7 @@ public class EntityAITakePlace extends EntityAIBase if(this.entity.getHeldItem() != null) this.entity.getHeldItem().incrSize(); else - this.entity.setItemNoUpdate(new ItemStack(STEALABLE.get(state))); + this.entity.setHeldNoUpdate(new ItemStack(STEALABLE.get(state))); } } } diff --git a/common/src/main/java/common/attributes/AttributeMap.java b/common/src/main/java/common/attributes/AttributeMap.java deleted file mode 100755 index dfa85127..00000000 --- a/common/src/main/java/common/attributes/AttributeMap.java +++ /dev/null @@ -1,60 +0,0 @@ -package common.attributes; - -import java.util.Map; -import java.util.Map.Entry; - -import common.collect.Maps; - -public class AttributeMap { - private class AttributeInstance { - private final Map slots = Maps.newHashMap(); - - private boolean update = true; - private float value; - - public void applyModifier(int slot, float amount) { - this.slots.put(slot, amount); - this.update = true; - } - - public void removeModifier(int slot) { - if(this.slots.remove(slot) != null) - this.update = true; - } - - public float getAttributeValue() { - if(this.update) { - this.value = 0.0f; - for(Float mod : this.slots.values()) { - this.value += mod; - } - this.update = false; - } - return this.value; - } - } - - private final Map attributes = Maps.newHashMap(); - - public AttributeMap() { - for(Attribute attribute : Attribute.values()) { - this.attributes.put(attribute, new AttributeInstance()); - } - } - - public float get(Attribute attribute) { - return this.attributes.get(attribute).getAttributeValue(); - } - - public void remove(Map modifiers, int slot) { - for(Entry entry : modifiers.entrySet()) { - this.attributes.get(entry.getKey()).removeModifier(slot); - } - } - - public void add(Map modifiers, int slot, int amount) { - for(Entry entry : modifiers.entrySet()) { - this.attributes.get(entry.getKey()).applyModifier(slot, entry.getValue() * (float)amount); - } - } -} diff --git a/common/src/main/java/common/block/Block.java b/common/src/main/java/common/block/Block.java index 9df05099..8c577709 100755 --- a/common/src/main/java/common/block/Block.java +++ b/common/src/main/java/common/block/Block.java @@ -13,7 +13,6 @@ import java.util.Set; import java.util.Map.Entry; import java.util.function.Function; -import common.attributes.Attribute; import common.block.artificial.BlockSlab; import common.block.natural.BlockSnow; import common.collect.ImmutableList; @@ -27,6 +26,7 @@ import common.enchantment.EnchantmentHelper; import common.entity.Entity; import common.entity.item.EntityItem; import common.entity.item.EntityXp; +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; import common.init.Blocks; diff --git a/common/src/main/java/common/block/artificial/BlockFlowerPot.java b/common/src/main/java/common/block/artificial/BlockFlowerPot.java index 8db92c57..331f3828 100755 --- a/common/src/main/java/common/block/artificial/BlockFlowerPot.java +++ b/common/src/main/java/common/block/artificial/BlockFlowerPot.java @@ -54,7 +54,7 @@ public class BlockFlowerPot extends Block public boolean onUse(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) { - ItemStack itemstack = playerIn.inventory.getCurrentItem(); + ItemStack itemstack = playerIn.getHeldItem(); if (itemstack != null && itemstack.getItem().getBlock() != null) { @@ -80,7 +80,7 @@ public class BlockFlowerPot extends Block if (itemstack.decrSize()) { - playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, (ItemStack)null); + playerIn.setHeldItem(null); } return true; diff --git a/common/src/main/java/common/block/artificial/BlockMetalBlock.java b/common/src/main/java/common/block/artificial/BlockMetalBlock.java index 3dba770e..6b7db339 100644 --- a/common/src/main/java/common/block/artificial/BlockMetalBlock.java +++ b/common/src/main/java/common/block/artificial/BlockMetalBlock.java @@ -3,10 +3,10 @@ package common.block.artificial; import java.util.List; import java.util.Map; -import common.attributes.Attribute; import common.block.Block; import common.block.Material; import common.block.SoundType; +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.init.MetalType; import common.item.CheatTab; diff --git a/common/src/main/java/common/block/natural/BlockMetalOre.java b/common/src/main/java/common/block/natural/BlockMetalOre.java index 7497d6e8..4b38d930 100644 --- a/common/src/main/java/common/block/natural/BlockMetalOre.java +++ b/common/src/main/java/common/block/natural/BlockMetalOre.java @@ -3,8 +3,8 @@ package common.block.natural; import java.util.List; import java.util.Map; -import common.attributes.Attribute; import common.block.SoundType; +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.init.MetalType; import common.item.ItemStack; diff --git a/common/src/main/java/common/block/tech/BlockAnvil.java b/common/src/main/java/common/block/tech/BlockAnvil.java index 8904383a..7e06be64 100755 --- a/common/src/main/java/common/block/tech/BlockAnvil.java +++ b/common/src/main/java/common/block/tech/BlockAnvil.java @@ -9,7 +9,7 @@ import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; import common.inventory.Container; import common.inventory.ContainerRepair; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.item.CheatTab; import common.model.Model; import common.model.Model.ModelProvider; @@ -142,7 +142,7 @@ public class BlockAnvil extends BlockFalling implements Rotatable this.position = pos; } - public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) + public Container createContainer(EntityNPC playerInventory) { return new ContainerRepair(playerInventory, this.world, this.position); } diff --git a/common/src/main/java/common/block/tech/BlockCauldron.java b/common/src/main/java/common/block/tech/BlockCauldron.java index 9e29fe80..4578c0e9 100755 --- a/common/src/main/java/common/block/tech/BlockCauldron.java +++ b/common/src/main/java/common/block/tech/BlockCauldron.java @@ -88,7 +88,7 @@ public class BlockCauldron extends Block } else { - ItemStack itemstack = playerIn.inventory.getCurrentItem(); + ItemStack itemstack = playerIn.getHeldItem(); if (itemstack == null) { @@ -105,7 +105,7 @@ public class BlockCauldron extends Block { // if (!playerIn.creative) // { - playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.bucket)); + playerIn.setHeldItem(new ItemStack(Items.bucket)); // } // playerIn.triggerAchievement(StatRegistry.cauldronFilledStat); @@ -122,7 +122,7 @@ public class BlockCauldron extends Block // { ItemStack itemstack2 = new ItemStack(Items.water_bottle); - if (!playerIn.inventory.addItemStackToInventory(itemstack2)) + if (!playerIn.addItemStackToInventory(itemstack2)) { worldIn.spawnEntityInWorld(new EntityItem(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.5D, (double)pos.getZ() + 0.5D, itemstack2)); } @@ -135,7 +135,7 @@ public class BlockCauldron extends Block if (itemstack.decrSize()) { - playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, (ItemStack)null); + playerIn.setHeldItem(null); } // } diff --git a/common/src/main/java/common/block/tech/BlockEnchantmentTable.java b/common/src/main/java/common/block/tech/BlockEnchantmentTable.java index ab75d628..b14d1ad2 100755 --- a/common/src/main/java/common/block/tech/BlockEnchantmentTable.java +++ b/common/src/main/java/common/block/tech/BlockEnchantmentTable.java @@ -5,7 +5,7 @@ import common.block.Material; import common.entity.npc.EntityNPC; import common.inventory.Container; import common.inventory.ContainerEnchantment; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.item.CheatTab; import common.model.Model; import common.model.Model.ModelProvider; @@ -69,7 +69,7 @@ public class BlockEnchantmentTable extends Block this.position = pos; } - public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) + public Container createContainer(EntityNPC playerInventory) { return new ContainerEnchantment(playerInventory, this.world, this.position); } diff --git a/common/src/main/java/common/block/tech/BlockWarpChest.java b/common/src/main/java/common/block/tech/BlockWarpChest.java index dd575238..43761d09 100755 --- a/common/src/main/java/common/block/tech/BlockWarpChest.java +++ b/common/src/main/java/common/block/tech/BlockWarpChest.java @@ -8,7 +8,7 @@ import common.entity.types.EntityLiving; import common.init.Items; import common.inventory.Container; import common.inventory.ContainerChest; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.item.CheatTab; import common.item.Item; import common.model.Model; @@ -130,9 +130,9 @@ public class BlockWarpChest extends Block implements Rotatable public class WarpChest implements InteractionObject { - public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) + public Container createContainer(EntityNPC playerInventory) { - return new ContainerChest(playerIn.inventory, playerIn.getWarpChest(), playerIn); + return new ContainerChest(playerInventory, playerInventory.getWarpChest()); } public Block getBlock() diff --git a/common/src/main/java/common/block/tech/BlockWorkbench.java b/common/src/main/java/common/block/tech/BlockWorkbench.java index 49eb7a8a..7cfe9353 100755 --- a/common/src/main/java/common/block/tech/BlockWorkbench.java +++ b/common/src/main/java/common/block/tech/BlockWorkbench.java @@ -5,7 +5,7 @@ import common.block.Material; import common.entity.npc.EntityNPC; import common.inventory.Container; import common.inventory.ContainerWorkbench; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.item.CheatTab; import common.model.Model; import common.model.Model.ModelProvider; @@ -58,7 +58,7 @@ public class BlockWorkbench extends Block this.position = pos; } - public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) + public Container createContainer(EntityNPC playerInventory) { return new ContainerWorkbench(playerInventory, this.world, this.position, BlockWorkbench.this); } diff --git a/common/src/main/java/common/block/tech/InteractionObject.java b/common/src/main/java/common/block/tech/InteractionObject.java index 3b2aea49..73be2c2a 100755 --- a/common/src/main/java/common/block/tech/InteractionObject.java +++ b/common/src/main/java/common/block/tech/InteractionObject.java @@ -3,9 +3,8 @@ package common.block.tech; import common.block.Block; import common.entity.npc.EntityNPC; import common.inventory.Container; -import common.inventory.InventoryPlayer; public interface InteractionObject { - Container createContainer(InventoryPlayer inv, EntityNPC player); + Container createContainer(EntityNPC inv); Block getBlock(); } diff --git a/common/src/main/java/common/effect/Effect.java b/common/src/main/java/common/effect/Effect.java index 52587e46..a7979e4e 100755 --- a/common/src/main/java/common/effect/Effect.java +++ b/common/src/main/java/common/effect/Effect.java @@ -152,7 +152,7 @@ public enum Effect { int k = 40 >> amp; if(k > 0 && duration % k != 0) return; - for(ItemStack stack : npc.inventory.mainInventory) { + for(ItemStack stack : npc.getInventory()) { if(stack != null && !stack.isEmpty()) { if(!stack.isFull()) stack.incrSize(); @@ -162,7 +162,16 @@ public enum Effect { stack.setItemDamage(stack.getItemDamage() - 1); } } - for(ItemStack stack : npc.inventory.armorInventory) { + if(!npc.isPlayer() && npc.getHeldItem() != null && !npc.getHeldItem().isEmpty()) { + ItemStack stack = npc.getHeldItem(); + if(!stack.isFull()) + stack.incrSize(); + if(stack.getRepairCost() > 0) + stack.setRepairCost(stack.getRepairCost() - 1); + if(stack.isItemStackDamageable() && stack.getItemDamage() > 0) + stack.setItemDamage(stack.getItemDamage() - 1); + } + for(ItemStack stack : npc.getArmor()) { if(stack != null && !stack.isEmpty()) { if(!stack.isFull()) stack.incrSize(); diff --git a/common/src/main/java/common/enchantment/EnchantmentType.java b/common/src/main/java/common/enchantment/EnchantmentType.java index bc8471f3..7013cb50 100755 --- a/common/src/main/java/common/enchantment/EnchantmentType.java +++ b/common/src/main/java/common/enchantment/EnchantmentType.java @@ -32,7 +32,7 @@ public enum EnchantmentType } else if (item instanceof ItemArmor armor) { - return this == ARMOR || armor.getArmorType().getEnchantmentType() == this; + return (this == ARMOR && armor.getArmorType().isMainArmor()) || armor.getArmorType().getEnchantmentType() == this; } else if(item instanceof ItemTool tool) { return this == DIGGER || (tool.getToolType().isMelee() && this == WEAPON); diff --git a/common/src/main/java/common/entity/animal/EntityCat.java b/common/src/main/java/common/entity/animal/EntityCat.java index 2593f1c1..75cf3510 100755 --- a/common/src/main/java/common/entity/animal/EntityCat.java +++ b/common/src/main/java/common/entity/animal/EntityCat.java @@ -208,7 +208,7 @@ public class EntityCat extends EntityTameable */ public boolean interact(EntityNPC player) { - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); if (this.isTamed()) { @@ -221,7 +221,7 @@ public class EntityCat extends EntityTameable { if (itemstack.decrSize()) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null); + player.setHeldItem(null); } if (!this.worldObj.client) diff --git a/common/src/main/java/common/entity/animal/EntityCow.java b/common/src/main/java/common/entity/animal/EntityCow.java index da199551..55a561db 100755 --- a/common/src/main/java/common/entity/animal/EntityCow.java +++ b/common/src/main/java/common/entity/animal/EntityCow.java @@ -120,17 +120,17 @@ public class EntityCow extends EntityAnimal */ public boolean interact(EntityNPC player) { - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); if (itemstack != null && itemstack.getItem() == Items.bucket /* && !player.creative */ && !this.isChild()) { if (itemstack.decrSize()) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Items.milk_bucket)); + player.setHeldItem(new ItemStack(Items.milk_bucket)); } - else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.milk_bucket))) + else if (!player.addItemStackToInventory(new ItemStack(Items.milk_bucket))) { - player.dropPlayerItemWithRandomChoice(new ItemStack(Items.milk_bucket), false); + player.dropItem(new ItemStack(Items.milk_bucket), false); } return true; diff --git a/common/src/main/java/common/entity/animal/EntityHorse.java b/common/src/main/java/common/entity/animal/EntityHorse.java index 625e6483..c7a5fd46 100755 --- a/common/src/main/java/common/entity/animal/EntityHorse.java +++ b/common/src/main/java/common/entity/animal/EntityHorse.java @@ -266,7 +266,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic { public ItemAnimalArmor getHorseArmorItem() { Item item = ItemRegistry.byId(this.dataWatcher.getWatchableObjectInt(22)); - return item instanceof ItemAnimalArmor armor ? armor : null; + return item instanceof ItemAnimalArmor armor && armor.getArmorType().getAnimalType() == EntityHorse.class ? armor : null; } public boolean isEatingHaystack() @@ -292,7 +292,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic { @Serverside public void setHorseArmorStack(ItemStack itemStackIn) { - this.dataWatcher.updateObject(22, itemStackIn != null && itemStackIn.getItem() instanceof ItemAnimalArmor armor ? ItemRegistry.getId(armor) : 0); + this.dataWatcher.updateObject(22, itemStackIn != null && itemStackIn.getItem() instanceof ItemAnimalArmor armor && armor.getArmorType().getAnimalType() == EntityHorse.class ? ItemRegistry.getId(armor) : 0); } public void setBreeding(boolean breeding) @@ -765,7 +765,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic { */ public boolean interact(EntityNPC player) { - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); if (itemstack != null && itemstack.getItem() instanceof ItemMobTemplate) { @@ -788,7 +788,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic { if (this.canWearArmor()) { - if (itemstack.getItem() instanceof ItemAnimalArmor) + if (itemstack.getItem() instanceof ItemAnimalArmor armor && armor.getArmorType().getAnimalType() == EntityHorse.class) { if (!this.isTame()) { @@ -909,7 +909,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic { { if (itemstack.decrSize()) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null); + player.setHeldItem(null); } return true; @@ -1718,7 +1718,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic { */ public static boolean isArmorItem(Item p_146085_0_) { - return p_146085_0_ instanceof ItemAnimalArmor; + return p_146085_0_ instanceof ItemAnimalArmor armor && armor.getArmorType().getAnimalType() == EntityHorse.class; } /** diff --git a/common/src/main/java/common/entity/animal/EntitySheep.java b/common/src/main/java/common/entity/animal/EntitySheep.java index 43179d25..34f4c984 100755 --- a/common/src/main/java/common/entity/animal/EntitySheep.java +++ b/common/src/main/java/common/entity/animal/EntitySheep.java @@ -174,7 +174,7 @@ public class EntitySheep extends EntityAnimal */ public boolean interact(EntityNPC player) { - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); if (itemstack != null && itemstack.getItem() instanceof ItemTool tool && tool.getToolType() == Equipment.SHEARS && !this.getSheared() && !this.isChild()) { diff --git a/common/src/main/java/common/entity/animal/EntityWolf.java b/common/src/main/java/common/entity/animal/EntityWolf.java index bfc20a18..3ab3f2b5 100755 --- a/common/src/main/java/common/entity/animal/EntityWolf.java +++ b/common/src/main/java/common/entity/animal/EntityWolf.java @@ -349,7 +349,7 @@ public class EntityWolf extends EntityTameable */ public boolean interact(EntityNPC player) { - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); if (this.isTamed()) { @@ -365,7 +365,7 @@ public class EntityWolf extends EntityTameable if (itemstack.decrSize()) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null); + player.setHeldItem(null); } return true; @@ -381,7 +381,7 @@ public class EntityWolf extends EntityTameable if (itemstack.decrSize()) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null); + player.setHeldItem(null); } return true; @@ -401,7 +401,7 @@ public class EntityWolf extends EntityTameable { if (itemstack.decrSize()) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null); + player.setHeldItem(null); } if (!this.worldObj.client) diff --git a/common/src/main/java/common/entity/item/EntityItem.java b/common/src/main/java/common/entity/item/EntityItem.java index 5c54ace3..fe15a76d 100755 --- a/common/src/main/java/common/entity/item/EntityItem.java +++ b/common/src/main/java/common/entity/item/EntityItem.java @@ -391,7 +391,7 @@ public class EntityItem extends Entity int i = itemstack.getSize(); if (this.delayBeforeCanPickup == 0 // && (this.owner == null || 6000 - this.age <= 200 || this.owner.equals(entityIn.getUser())) - && entityIn.inventory.addItemStackToInventory(itemstack)) + && entityIn.addItemStackToInventory(itemstack)) { // if (itemstack.getItem() == Items.log) // { diff --git a/common/src/main/java/common/attributes/Attribute.java b/common/src/main/java/common/entity/npc/Attribute.java similarity index 91% rename from common/src/main/java/common/attributes/Attribute.java rename to common/src/main/java/common/entity/npc/Attribute.java index 571529a0..5c8c92a5 100755 --- a/common/src/main/java/common/attributes/Attribute.java +++ b/common/src/main/java/common/entity/npc/Attribute.java @@ -1,4 +1,4 @@ -package common.attributes; +package common.entity.npc; public enum Attribute { RADIATION("Strahlung"), diff --git a/common/src/main/java/common/entity/npc/EntityCultivator.java b/common/src/main/java/common/entity/npc/EntityCultivator.java index 5ded0de0..a0d70fd7 100755 --- a/common/src/main/java/common/entity/npc/EntityCultivator.java +++ b/common/src/main/java/common/entity/npc/EntityCultivator.java @@ -39,12 +39,12 @@ public class EntityCultivator extends EntityNPC { public void startExecuting() { super.startExecuting(); - EntityCultivator.this.setItemNoUpdate(new ItemStack(Items.camera)); + EntityCultivator.this.setHeldNoUpdate(new ItemStack(Items.camera)); } public void resetTask() { super.resetTask(); - EntityCultivator.this.setItemNoUpdate(null); + EntityCultivator.this.setHeldNoUpdate(null); } }); this.tasks.addTask(10, new EntityAITakePlace(this)); diff --git a/common/src/main/java/common/entity/npc/EntityHaunter.java b/common/src/main/java/common/entity/npc/EntityHaunter.java index afb1304b..0fb823e0 100755 --- a/common/src/main/java/common/entity/npc/EntityHaunter.java +++ b/common/src/main/java/common/entity/npc/EntityHaunter.java @@ -227,7 +227,7 @@ public class EntityHaunter extends EntityNPC { public boolean interact(EntityNPC player) { - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); if (itemstack != null && itemstack.getItem() == Items.lighter) { diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index 5e83e985..b830422b 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -2,6 +2,8 @@ package common.entity.npc; import java.lang.reflect.InvocationTargetException; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.function.Predicate; import common.ai.AIRangedAttack; @@ -23,6 +25,7 @@ import common.ai.EntityAIWatchClosest2; import common.block.Block; import common.block.artificial.BlockBed; import common.collect.Lists; +import common.collect.Maps; import common.dimension.Dimension; import common.dimension.Space; import common.effect.Effect; @@ -54,8 +57,7 @@ import common.init.TradeRegistry; import common.init.SpeciesRegistry.ModelType; import common.inventory.Container; import common.inventory.ContainerPlayer; -import common.inventory.InventoryBasic; -import common.inventory.InventoryPlayer; +import common.inventory.IInventory; import common.inventory.InventoryWarpChest; import common.item.Item; import common.item.ItemAction; @@ -97,8 +99,36 @@ import common.village.MerchantRecipeList; import common.world.World; import common.world.AWorldServer; -public abstract class EntityNPC extends EntityLiving +public abstract class EntityNPC extends EntityLiving implements IInventory { + private class AttributeInstance { + private final Map slots = Maps.newHashMap(); + + private boolean update = true; + private float value; + + public void applyModifier(int slot, float amount) { + this.slots.put(slot, amount); + this.update = true; + } + + public void removeModifier(int slot) { + if(this.slots.remove(slot) != null) + this.update = true; + } + + public float getAttributeValue() { + if(this.update) { + this.value = 0.0f; + for(Float mod : this.slots.values()) { + this.value += mod; + } + this.update = false; + } + return this.value; + } + } + public static class CharacterTypeData { public final CharacterInfo character; @@ -164,7 +194,8 @@ public abstract class EntityNPC extends EntityLiving }; protected final SpeciesInfo species; - + + private final Map attributes = Maps.newHashMap(); private EntityNPC talkingPlayer; private boolean isWilling; private boolean fleeing; @@ -172,9 +203,11 @@ public abstract class EntityNPC extends EntityLiving protected boolean noPickup; private ItemStack heldItem; private ItemStack prevHeldItem; - private ItemStack[] armor = new ItemStack[Equipment.ARMOR_SLOTS]; - private final ItemStack[] prevArmor = new ItemStack[Equipment.ARMOR_SLOTS]; - private InventoryBasic extraInventory; + 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[36]; + private final ItemStack[] prevItems = new ItemStack[this.items.length]; private int inLove; protected Alignment alignment = Alignment.NEUTRAL; private MerchantRecipeList trades; @@ -185,7 +218,6 @@ public abstract class EntityNPC extends EntityLiving public IClientPlayer client; protected boolean slave; - public InventoryPlayer inventory; protected InventoryWarpChest warpChest; public ContainerPlayer inventoryContainer; public Container openContainer; @@ -213,6 +245,7 @@ public abstract class EntityNPC extends EntityLiving private int lastXPSound; public EntityHook fishEntity; protected int sinceLastAttack; + private int currentItem; private boolean otherPlayerUsing; private int otherPlayerMPPosRotationIncrements; @@ -245,8 +278,10 @@ public abstract class EntityNPC extends EntityLiving public EntityNPC(World worldIn) { super(worldIn); + for(Attribute attribute : Attribute.values()) { + this.attributes.put(attribute, new AttributeInstance()); + } this.species = SpeciesRegistry.CLASSES.get(this.getClass()); - this.extraInventory = new InventoryBasic(8); // this.setCharacter(""); if(this.species != null) this.setSize(this.getSpeciesBaseSize() * this.species.renderer.width / this.species.renderer.height, this.getSpeciesBaseSize()); // /* 0.6F, */ 1.8F); @@ -372,10 +407,9 @@ public abstract class EntityNPC extends EntityLiving private void initPlayer() { - this.inventory = new InventoryPlayer(this); this.warpChest = new InventoryWarpChest(); // this.setHeight(1.8f); - this.inventoryContainer = new ContainerPlayer(this.inventory, !this.worldObj.client, this); + this.inventoryContainer = new ContainerPlayer(this); this.openContainer = this.inventoryContainer; this.setLocationAndAngles(0.5D, 1.0D, 0.5D, 0.0F, 0.0F); this.fireResistance = 20; @@ -628,13 +662,13 @@ public abstract class EntityNPC extends EntityLiving public boolean interact(EntityNPC player) { - ItemStack stack = player.inventory.getCurrentItem(); + ItemStack stack = player.getHeldItem(); boolean flag = stack != null && !(stack.getItem() instanceof ItemTool); if (stack != null && !this.isPlayer() && this.isBreedingItem(stack) && this.getGrowingAge() == 0 && !this.isMating()) { if(stack.decrSize()) - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + player.setHeldItem(null); if (!this.worldObj.client) { this.setIsWillingToMate(true); @@ -646,7 +680,7 @@ public abstract class EntityNPC extends EntityLiving else if (stack != null && !this.isPlayer() && this.isBreedingItem(stack) && this.getGrowingAge() < 0) { if(stack.decrSize()) - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + player.setHeldItem(null); if (!this.worldObj.client) { this.grow(this.rand.range(200, 250)); @@ -947,11 +981,6 @@ public abstract class EntityNPC extends EntityLiving // // super.onStruckByLightning(lightningBolt); // } - - public InventoryBasic getExtendedInventory() - { - return this.extraInventory; - } // protected void updateEquipmentIfNeeded(EntityItem itemEntity) // { @@ -1398,7 +1427,7 @@ public abstract class EntityNPC extends EntityLiving if (this.canPickUpExtraItem(item)) { - ItemStack remain = this.extraInventory.addStack(stack); + ItemStack remain = this.addStack(stack); if (remain == null) { @@ -1630,37 +1659,89 @@ public abstract class EntityNPC extends EntityLiving this.setManaPoints(mana - pts); return mana >= pts; } + + public float getAttribute(Attribute attribute) { + return this.attributes.get(attribute).getAttributeValue(); + } + + private void removeModifiers(Map modifiers, int slot) { + for(Entry entry : modifiers.entrySet()) { + this.attributes.get(entry.getKey()).removeModifier(slot); + } + } + + private void addModifiers(Map modifiers, int slot, int amount) { + for(Entry entry : modifiers.entrySet()) { + this.attributes.get(entry.getKey()).applyModifier(slot, entry.getValue() * (float)amount); + } + } private void updateNpc() { if(!this.worldObj.client) { - ItemStack itemstack2 = this.prevHeldItem; - ItemStack itemstack21 = this.getHeldItem(); - if (!ItemStack.allEquals(itemstack21, itemstack2)) + ItemStack prevHeld = this.prevHeldItem; + ItemStack held = this.getHeldItem(); + if (!ItemStack.allEquals(held, prevHeld)) { - ((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new SPacketEntityEquipment(this.getId(), 0, itemstack21)); - this.prevHeldItem = itemstack21 == null ? null : itemstack21.copy(); + ((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new SPacketEntityEquipment(this.getId(), 0, held)); + + if(!this.isPlayer()) { + if (!ItemStack.allEquals(held, prevHeld)) + { + if (prevHeld != null) + { + this.removeModifiers(prevHeld.getAttributeModifiers(), 0); + } + + if (held != null) + { + this.addModifiers(held.getAttributeModifiers(), 0, held.getSize()); + } + } + } + + this.prevHeldItem = held == null ? null : held.copy(); + } + for (int index = 0; index < this.getInventoryCapacity(); index++) + { + ItemStack last = this.prevItems[index]; + ItemStack current = this.getStackInSlot(index); + + if (!ItemStack.allEquals(current, last)) + { + if (last != null) + { + this.removeModifiers(last.getAttributeModifiers(), index + 1); + } + + if (current != null) + { + this.addModifiers(current.getAttributeModifiers(), index + 1, current.getSize()); + } + + this.prevItems[index] = current == null ? null : current.copy(); + } } for (Equipment slot : Equipment.ARMOR) { - ItemStack itemstack = this.prevArmor[slot.getIndex()]; - ItemStack itemstack1 = this.getArmor(slot); + ItemStack last = this.prevArmor[slot.getIndex()]; + ItemStack current = this.getArmor(slot); - if (!ItemStack.allEquals(itemstack1, itemstack)) + if (!ItemStack.allEquals(current, last)) { - ((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new SPacketEntityEquipment(this.getId(), slot.getIndex() + 1, itemstack1)); + ((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new SPacketEntityEquipment(this.getId(), slot.getIndex() + 1, current)); - if (itemstack != null) + if (last != null) { - this.attributes.remove(itemstack.getAttributeModifiers(slot), -1 - slot.getIndex()); + this.removeModifiers(last.getArmorModifiers(slot), -1 - slot.getIndex()); } - if (itemstack1 != null) + if (current != null) { - this.attributes.add(itemstack1.getAttributeModifiers(slot), -1 - slot.getIndex(), itemstack1.getSize()); + this.addModifiers(current.getArmorModifiers(slot), -1 - slot.getIndex(), current.getSize()); } - this.prevArmor[slot.getIndex()] = itemstack1 == null ? null : itemstack1.copy(); + this.prevArmor[slot.getIndex()] = current == null ? null : current.copy(); } } } @@ -1797,10 +1878,10 @@ public abstract class EntityNPC extends EntityLiving this.lswingAmount += (f - this.lswingAmount) * 0.4F; this.limbSwing += this.lswingAmount; - if (!this.otherPlayerUsing && this.isUsingItem() && this.inventory.mainInventory[this.inventory.currentItem] != null) + if (!this.otherPlayerUsing && this.isUsingItem() && this.getHeldItem() != null) { - ItemStack itemstack = this.inventory.mainInventory[this.inventory.currentItem]; - this.setItemInUse(this.inventory.mainInventory[this.inventory.currentItem], itemstack.getItem().getMaxItemUseDuration(itemstack)); + ItemStack itemstack = this.getHeldItem(); + this.setItemInUse(itemstack, itemstack.getItem().getMaxItemUseDuration(itemstack)); this.otherPlayerUsing = true; } else if (this.otherPlayerUsing && !this.isUsingItem()) @@ -1825,7 +1906,7 @@ public abstract class EntityNPC extends EntityLiving if (this.itemInUse != null) { - ItemStack itemstack = this.inventory.getCurrentItem(); + ItemStack itemstack = this.getHeldItem(); if (itemstack == this.itemInUse) { @@ -1934,16 +2015,7 @@ public abstract class EntityNPC extends EntityLiving this.client.addToSendQueue(new CPacketBreak(c07packetplayerdigging$action, BlockPos.ORIGIN, Facing.DOWN)); return null; } - return this.dropItem(this.inventory.decrStackSize(this.inventory.currentItem, dropAll && this.inventory.getCurrentItem() != null ? this.inventory.getCurrentItem().getSize() : 1), false, true); - } - - /** - * Joins the passed in entity item with the world. Args: entityItem - */ - protected void joinEntityItemWithWorld(EntityItem itemIn) - { - if(this.client == null) - this.worldObj.spawnEntityInWorld(itemIn); + return this.dropItem(this.decrStackSize(this.getSelectedIndex(), dropAll && this.getHeldItem() != null ? this.getHeldItem().getSize() : 1), false, true); } protected void changeSize(float width, float height) { @@ -2685,27 +2757,40 @@ public abstract class EntityNPC extends EntityLiving } } + public int getSelectedIndex() { + return this.currentItem; + } + + public void setSelectedIndex(int index) { + this.currentItem = index; + } + public ItemStack getHeldItem() { - return this.isPlayer() ? this.inventory.getCurrentItem() : this.heldItem; + return this.isPlayer() ? (this.getSelectedIndex() < 9 && this.getSelectedIndex() >= 0 ? this.getStackInSlot(this.getSelectedIndex()) : null) : this.heldItem; } public ItemStack[] getArmor() { - return this.isPlayer() ? this.inventory.armorInventory : this.armor; + return this.armor; + } + + public ItemStack[] getInventory() + { + return this.items; } public ItemStack getArmor(Equipment slot) { - return this.isPlayer() ? this.inventory.armorInventory[slot.getIndex()] : this.armor[slot.getIndex()]; + return this.getArmor()[slot.getIndex()]; } public void setHeldItem(ItemStack stack) { - if(this.slave && this.client == null) { - this.inventory.mainInventory[this.inventory.currentItem] = stack; + if(this.isPlayer()) { + this.setInventorySlotContents(this.getSelectedIndex(), stack); } - else if(!this.isPlayer()) { + else { this.heldItem = stack; if(!this.worldObj.client) this.setCombatTask(); @@ -2714,19 +2799,237 @@ public abstract class EntityNPC extends EntityLiving public void setArmor(Equipment slot, ItemStack stack) { - if(this.isPlayer()) { - this.inventory.armorInventory[slot.getIndex()] = stack; - } - else { - this.armor[slot.getIndex()] = stack; - } + this.getArmor()[slot.getIndex()] = stack; } - public void setItemNoUpdate(ItemStack stack) + public void setHeldNoUpdate(ItemStack stack) { if(!this.isPlayer()) this.heldItem = stack; } + + public void setMouseItem(ItemStack stack) + { + this.mouseItem = stack; + } + + public ItemStack getMouseItem() + { + return this.mouseItem; + } + + public int getInventorySlotContainItem(Item itemIn) + { + for (int i = 0; i < this.getInventoryCapacity(); ++i) + { + if (this.getInventory()[i] != null && this.getInventory()[i].getItem() == itemIn) + { + return i; + } + } + + return -1; + } + + private int storeItemStack(ItemStack itemStackIn) + { + for (int i = 0; i < this.getInventoryCapacity(); ++i) + { + if (this.getInventory()[i] != null && this.getInventory()[i].getItem() == itemStackIn.getItem() && this.getInventory()[i].isStackable() && !this.getInventory()[i].isFull() && this.getInventory()[i].getSize() < this.getInventoryStackLimit() && ItemStack.dataEquals(this.getInventory()[i], itemStackIn)) + { + return i; + } + } + + return -1; + } + + public int getFirstEmptyStack() + { + for (int i = 0; i < this.getInventoryCapacity(); ++i) + { + if (this.getInventory()[i] == null) + { + return i; + } + } + + return -1; + } + + private int storePartialItemStack(ItemStack itemStackIn) + { + Item item = itemStackIn.getItem(); + int i = itemStackIn.getSize(); + int j = this.storeItemStack(itemStackIn); + + if (j < 0) + { + j = this.getFirstEmptyStack(); + } + + if (j < 0) + { + return i; + } + else + { + if (this.getInventory()[j] == null) + { + this.getInventory()[j] = new ItemStack(item, 0); + + this.getInventory()[j].copyData(itemStackIn); + } + + int k = i; + + if (i > this.getInventory()[j].getMaxStackSize() - this.getInventory()[j].getSize()) + { + k = this.getInventory()[j].getMaxStackSize() - this.getInventory()[j].getSize(); + } + + if (k > this.getInventoryStackLimit() - this.getInventory()[j].getSize()) + { + k = this.getInventoryStackLimit() - this.getInventory()[j].getSize(); + } + + if (k == 0) + { + return i; + } + else + { + i = i - k; + this.getInventory()[j].incrSize(k); + return i; + } + } + } + + public boolean consumeInventoryItem(Item itemIn) + { + int i = this.getInventorySlotContainItem(itemIn); + + if (i < 0) + { + return false; + } + else + { + if (this.getInventory()[i].decrSize()) + { + this.getInventory()[i] = null; + } + + return true; + } + } + + public boolean hasItem(Item itemIn) + { + int i = this.getInventorySlotContainItem(itemIn); + return i >= 0; + } + + public boolean addItemStackToInventory(final ItemStack itemStackIn) + { + if (itemStackIn != null && !itemStackIn.isEmpty() && itemStackIn.getItem() != null) + { + if (itemStackIn.isItemDamaged()) + { + int j = this.getFirstEmptyStack(); + + if (j >= 0) + { + this.getInventory()[j] = ItemStack.copy(itemStackIn); + itemStackIn.setSize(0); + return true; + } + else + { + return false; + } + } + else + { + int i; + + while (true) + { + i = itemStackIn.getSize(); + itemStackIn.setSize(this.storePartialItemStack(itemStackIn)); + + if (itemStackIn.isEmpty() || itemStackIn.getSize() >= i) + { + break; + } + } + + return itemStackIn.getSize() < i; + } + } + else + { + return false; + } + } + + public ItemStack addStack(ItemStack stack) + { + ItemStack itemstack = stack.copy(); + for (int i = 0; i < this.getInventoryCapacity(); ++i) + { + ItemStack itemstack1 = this.getInventory()[i]; + + if (itemstack1 == null) + { + this.getInventory()[i] = itemstack; + return null; + } + + if (ItemStack.itemEquals(itemstack1, itemstack)) + { + int j = Math.min(this.getInventoryStackLimit(), itemstack1.getMaxStackSize()); + int k = Math.min(itemstack.getSize(), j - itemstack1.getSize()); + + if (k > 0) + { + itemstack1.incrSize(k); + if (itemstack.decrSize(k)) + { + return null; + } + } + } + } + return itemstack; + } + + public boolean hasItemStack(ItemStack itemStackIn) + { + for (ItemStack stack : this.getArmor()) + { + if (stack != null && stack.itemEquals(itemStackIn)) + { + return true; + } + } + + for (int j = 0; j < this.getInventoryCapacity(); ++j) + { + if (this.getInventory()[j] != null && this.getInventory()[j].itemEquals(itemStackIn)) + { + return true; + } + } + + return false; + } + + public int getInventoryCapacity() + { + return this.getInventory().length; + } // END OTHER @@ -2777,7 +3080,7 @@ public abstract class EntityNPC extends EntityLiving if (this.worldObj.client || (!Vars.keepInventory && Vars.playerDrop)) { - this.inventory.dropAllItems(); + this.clear(); } if (cause != null) @@ -2839,11 +3142,11 @@ public abstract class EntityNPC extends EntityLiving if (itemstack != this.itemInUse || itemstack != null && itemstack.getSize() != i) { - this.inventory.mainInventory[this.inventory.currentItem] = itemstack; + this.setHeldItem(itemstack); if (itemstack.isEmpty()) { - this.inventory.mainInventory[this.inventory.currentItem] = null; + this.setHeldItem(null); } } @@ -3124,81 +3427,69 @@ public abstract class EntityNPC extends EntityLiving p_71044_1_.onCollideWithPlayer(this); } - /** - * Args: itemstack, flag - */ - public EntityItem dropPlayerItemWithRandomChoice(ItemStack itemStackIn, boolean traceItem) + public final EntityItem dropItem(ItemStack itemStackIn, boolean traceItem) { return this.dropItem(itemStackIn, false, traceItem); } public EntityItem dropItem(ItemStack droppedItem, boolean dropAround, boolean traceItem) { - if (droppedItem == null) - { + if(this.worldObj.client || droppedItem == null || droppedItem.isEmpty()) return null; - } - else if (droppedItem.isEmpty()) - { - return null; - } - else - { - if(traceItem && !this.worldObj.client) - this.connection.sendThrowMessage(droppedItem); - - double d0 = this.posY - 0.30000001192092896D + (double)this.getEyeHeight(); - EntityItem entityitem = new EntityItem(this.worldObj, this.posX, d0, this.posZ, droppedItem); - entityitem.setPickupDelay(40); + if(traceItem) + this.connection.sendThrowMessage(droppedItem); + + double d0 = this.posY - 0.30000001192092896D + (double)this.getEyeHeight(); + EntityItem entityitem = new EntityItem(this.worldObj, this.posX, d0, this.posZ, droppedItem); + entityitem.setPickupDelay(40); // if (traceItem) // { // entityitem.setThrower(this.getUser()); // } - if (dropAround) - { - float f = this.rand.floatv() * 0.5F; - float f1 = this.rand.floatv() * (float)Math.PI * 2.0F; - entityitem.motionX = (double)(-ExtMath.sin(f1) * f); - entityitem.motionZ = (double)(ExtMath.cos(f1) * f); - entityitem.motionY = 0.20000000298023224D; - } - else - { - float f2 = 0.3F; - entityitem.motionX = (double)(-ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI) * f2); - entityitem.motionZ = (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI) * f2); - entityitem.motionY = (double)(-ExtMath.sin(this.rotPitch / 180.0F * (float)Math.PI) * f2 + 0.1F); - float f3 = this.rand.floatv() * (float)Math.PI * 2.0F; - f2 = 0.02F * this.rand.floatv(); - entityitem.motionX += Math.cos((double)f3) * (double)f2; - entityitem.motionY += (double)((this.rand.floatv() - this.rand.floatv()) * 0.1F); - entityitem.motionZ += Math.sin((double)f3) * (double)f2; - } + if (dropAround) + { + float f = this.rand.floatv() * 0.5F; + float f1 = this.rand.floatv() * (float)Math.PI * 2.0F; + entityitem.motionX = (double)(-ExtMath.sin(f1) * f); + entityitem.motionZ = (double)(ExtMath.cos(f1) * f); + entityitem.motionY = 0.20000000298023224D; + } + else + { + float f2 = 0.3F; + entityitem.motionX = (double)(-ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI) * f2); + entityitem.motionZ = (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI) * f2); + entityitem.motionY = (double)(-ExtMath.sin(this.rotPitch / 180.0F * (float)Math.PI) * f2 + 0.1F); + float f3 = this.rand.floatv() * (float)Math.PI * 2.0F; + f2 = 0.02F * this.rand.floatv(); + entityitem.motionX += Math.cos((double)f3) * (double)f2; + entityitem.motionY += (double)((this.rand.floatv() - this.rand.floatv()) * 0.1F); + entityitem.motionZ += Math.sin((double)f3) * (double)f2; + } - this.joinEntityItemWithWorld(entityitem); + this.worldObj.spawnEntityInWorld(entityitem); // if (traceItem) // { // this.triggerAchievement(StatRegistry.dropStat); // } - return entityitem; - } + return entityitem; } /** * Block hardness will be further counted in game/block/Block.getPlayerRelativeBlockHardness */ - public float getToolDigEfficiency(Block p_180471_1_) + public float getToolDigEfficiency(Block block) { - float f = this.inventory.getStrVsBlock(p_180471_1_); + float f = this.getHeldItem() != null && this.getHeldItem().getItem() instanceof ItemTool tool && block.getMiningTool() == tool.getToolType() ? tool.getToolMaterial().getEfficiency() : 1.0f; if (f > 1.0F) { int i = EnchantmentHelper.getEfficiencyModifier(this); - ItemStack itemstack = this.inventory.getCurrentItem(); + ItemStack itemstack = this.getHeldItem(); if (i > 0 && itemstack != null) { @@ -3243,12 +3534,11 @@ public abstract class EntityNPC extends EntityLiving return f; } - /** - * Checks if the player has the ability to harvest a block (checks current inventory item for a tool if necessary) - */ - public boolean canHarvestBlock(Block blockToHarvest) + public boolean canHarvestBlock(Block block) { - return this.inventory.canHeldItemHarvest(blockToHarvest); + if(!block.getMaterial().isToolRequired()) + return true; + return this.getHeldItem() != null && this.getHeldItem().getItem() instanceof ItemTool tool && block.getMiningTool() == tool.getToolType() && (!tool.getToolType().isLevelled() || tool.getToolMaterial().getHarvestLevel() >= block.getMiningLevel()); } public int getAttackDamage() { @@ -3264,44 +3554,49 @@ public abstract class EntityNPC extends EntityLiving this.attackDamageBase = value; } - public void readEntity(TagObject tagCompund) + public void readEntity(TagObject tag) { - super.readEntity(tagCompund); + super.readEntity(tag); // if(tagCompund.hasBoolean("CanPickUpLoot")) { // this.setCanPickUpLoot(tagCompund.getBoolean("CanPickUpLoot")); // } - if(!this.isPlayer()) { - if(tagCompund.hasObject("HeldItem")) { - this.heldItem = ItemStack.readFromTag(tagCompund.getObject("HeldItem")); - } - if(tagCompund.hasList("Armor")) { - List nbttaglist = tagCompund.getList("Armor"); - - for(int i = 0; i < this.armor.length; ++i) { - this.armor[i] = i < nbttaglist.size() ? ItemStack.readFromTag(nbttaglist.get(i)) : null; - } - } - } + List list = tag.getList("items"); + this.clear(); + for(int z = 0; z < list.size(); z++) { + TagObject item = list.get(z); + int slot = item.getByte("Slot") & 255; + ItemStack stack = ItemStack.readFromTag(item); + if(stack != null && slot >= 0 && slot < this.getInventoryCapacity()) + this.setInventorySlotContents(slot, stack); + } + if(this.isPlayer()) + this.setSelectedIndex(tag.getInt("selected")); + else + this.setHeldNoUpdate(ItemStack.readFromTag(tag.getObject("held"))); + for(Equipment slot : Equipment.ARMOR) { + this.setArmor(slot, ItemStack.readFromTag(tag.getObject(slot.getName()))); + } + // this.setSpecies(tagCompund.getString("Species")); - this.setChar(tagCompund.getString("Char")); - this.isWilling = tagCompund.getBool("Willing"); - this.setMating(tagCompund.getBool("Mating")); + this.setChar(tag.getString("Char")); + this.isWilling = tag.getBool("Willing"); + this.setMating(tag.getBool("Mating")); Alignment // align; // try { - align = Alignment.getByName(tagCompund.getString("Align")); + align = Alignment.getByName(tag.getString("Align")); // } // catch(IllegalArgumentException e) { // align = this.getNaturalAlign(this.rand); // } this.setAlignment(align); - this.setMaxMana(Math.max(0, tagCompund.getInt("MaxMana"))); - this.setManaPoints(tagCompund.getInt("Mana")); - this.attackDamageBase = tagCompund.getInt("AttackDmg"); + this.setMaxMana(Math.max(0, tag.getInt("MaxMana"))); + this.setManaPoints(tag.getInt("Mana")); + this.attackDamageBase = tag.getInt("AttackDmg"); Enum type = null; - if(tagCompund.hasString("ClassType") && this.species != null && this.species.classEnum != null) { - type = this.species.classnames.get(tagCompund.getString("ClassType")); + if(tag.hasString("ClassType") && this.species != null && this.species.classEnum != null) { + type = this.species.classnames.get(tag.getString("ClassType")); // try { // type = Enum.valueOf(this.species.classEnum, tagCompund.getString("ClassType").toUpperCase()); // } @@ -3310,44 +3605,27 @@ public abstract class EntityNPC extends EntityLiving // } } this.setNpcClass(type); - this.setHeight(tagCompund.hasFloat("Height") ? tagCompund.getFloat("Height") : this.getBaseSize()); + this.setHeight(tag.hasFloat("Height") ? tag.getFloat("Height") : this.getBaseSize()); - if(!this.isPlayer()) { - List nbttaglist = tagCompund.getList("Items"); - - for (int i = 0; i < nbttaglist.size(); ++i) - { - ItemStack itemstack = ItemStack.readFromTag(nbttaglist.get(i)); - - if (itemstack != null) - { - this.extraInventory.addStack(itemstack); - } - } - } - - if(tagCompund.hasList("Offers")) { + if(tag.hasList("Offers")) { this.trades = new MerchantRecipeList(); - this.trades.fromTags(tagCompund.getList("Offers")); + this.trades.fromTags(tag.getList("Offers")); } - this.healTimer = tagCompund.getInt("healTimer"); - if(tagCompund.hasByteArray("Skin")) - this.skin = tagCompund.getByteArray("Skin"); + this.healTimer = tag.getInt("healTimer"); + if(tag.hasByteArray("Skin")) + this.skin = tag.getByteArray("Skin"); // this.setCanPickUpLoot(true); this.setCombatTask(); if(this.isPlayer()) { // this.entityUniqueID = getOfflineUUID(this.user); - List nbttaglist0 = tagCompund.getList("Inventory"); - this.inventory.fromTag(nbttaglist0); - this.inventory.currentItem = tagCompund.getInt("SelectedItemSlot"); // this.sleeping = tagCompund.getBoolean("Sleeping"); // this.sleepTimer = tagCompund.getShort("SleepTimer"); - this.experience = tagCompund.getFloat("XpP"); - this.experienceLevel = tagCompund.getInt("XpLevel"); - this.experienceTotal = tagCompund.getInt("XpTotal"); - this.enchSeed = tagCompund.getInt("EnchSeed"); + this.experience = tag.getFloat("XpP"); + this.experienceLevel = tag.getInt("XpLevel"); + this.experienceTotal = tag.getInt("XpTotal"); + this.enchSeed = tag.getInt("EnchSeed"); if (this.enchSeed == 0) { @@ -3363,36 +3641,36 @@ public abstract class EntityNPC extends EntityLiving // this.wakeUpPlayer(); // } - if (tagCompund.hasInt("SpawnX") && tagCompund.hasInt("SpawnY") && tagCompund.hasInt("SpawnZ") && tagCompund.hasString("SpawnDim")) + if (tag.hasInt("SpawnX") && tag.hasInt("SpawnY") && tag.hasInt("SpawnZ") && tag.hasString("SpawnDim")) { - Dimension dim = DimensionRegistry.getDimension(tagCompund.getString("SpawnDim")); - this.spawnPos = dim == null ? null : new WorldPos(tagCompund.getInt("SpawnX"), tagCompund.getInt("SpawnY"), - tagCompund.getInt("SpawnZ"), dim); + Dimension dim = DimensionRegistry.getDimension(tag.getString("SpawnDim")); + this.spawnPos = dim == null ? null : new WorldPos(tag.getInt("SpawnX"), tag.getInt("SpawnY"), + tag.getInt("SpawnZ"), dim); // this.spawnForced = tagCompund.getBoolean("SpawnForced"); } - if (tagCompund.hasInt("OriginX") && tagCompund.hasInt("OriginY") && tagCompund.hasInt("OriginZ") && tagCompund.hasString("OriginDim")) + if (tag.hasInt("OriginX") && tag.hasInt("OriginY") && tag.hasInt("OriginZ") && tag.hasString("OriginDim")) { - Dimension dim = DimensionRegistry.getDimension(tagCompund.getString("OriginDim")); - this.originPos = dim == null ? new WorldPos(0, 64, 0, Space.INSTANCE) : new WorldPos(tagCompund.getInt("OriginX"), tagCompund.getInt("OriginY"), - tagCompund.getInt("OriginZ"), dim); + Dimension dim = DimensionRegistry.getDimension(tag.getString("OriginDim")); + this.originPos = dim == null ? new WorldPos(0, 64, 0, Space.INSTANCE) : new WorldPos(tag.getInt("OriginX"), tag.getInt("OriginY"), + tag.getInt("OriginZ"), dim); } - this.flying = tagCompund.getBool("flying") && (this.hasEffect(Effect.FLYING) || this.canNaturallyFly()); + this.flying = tag.getBool("flying") && (this.hasEffect(Effect.FLYING) || this.canNaturallyFly()); // if(tagCompund.hasKey("speed", 99)) // this.speed = tagCompund.getFloat("speed"); // this.disableDamagePersist = tagCompund.getBoolean("alwaysInvulnerable"); // this.disableTargetPersist = tagCompund.getBoolean("neverTarget"); // this.allowFlyingPersist = tagCompund.getBoolean("alwaysFly"); - this.noclip = tagCompund.getBool("noClip"); + this.noclip = tag.getBool("noClip"); - if (tagCompund.hasList("WarpItems")) + if (tag.hasList("WarpItems")) { - List nbttaglist1 = tagCompund.getList("WarpItems"); + List nbttaglist1 = tag.getList("WarpItems"); this.warpChest.readTags(nbttaglist1); } - this.movedDistance = tagCompund.getLong("MovedDist"); + this.movedDistance = tag.getLong("MovedDist"); // ModelType // model; // try { @@ -3408,75 +3686,64 @@ public abstract class EntityNPC extends EntityLiving } } - public void writeEntity(TagObject tagCompound) + public void writeEntity(TagObject tag) { - super.writeEntity(tagCompound); + super.writeEntity(tag); // tagCompound.setBoolean("CanPickUpLoot", this.canPickUpLoot()); - if(!this.isPlayer()) { - TagObject held = new TagObject(); - if(this.heldItem != null) { - this.heldItem.writeTags(held); - } - tagCompound.setObject("HeldItem", held); - - List armor = Lists.newArrayList(); - - for(int i = 0; i < this.armor.length; ++i) { + + List list = Lists.newArrayList(); + for(int z = 0; z < this.getInventoryCapacity(); z++) { + if(this.getStackInSlot(z) != null) { TagObject item = new TagObject(); - - if(this.armor[i] != null) { - this.armor[i].writeTags(item); - } - - armor.add(item); + item.setByte("Slot", (byte)z); + this.getStackInSlot(z).writeTags(item); + list.add(item); } - - tagCompound.setList("Armor", armor); - } + } + tag.setList("items", list); + if(this.isPlayer()) { + tag.setInt("held", this.getSelectedIndex()); + } + else { + TagObject item = new TagObject(); + if(this.getHeldItem() != null) + this.getHeldItem().writeTags(item); + tag.setObject("held", item); + } + for(Equipment slot : Equipment.ARMOR) { + TagObject item = new TagObject(); + if(this.getArmor(slot) != null) + this.getArmor(slot).writeTags(item); + tag.setObject(slot.getName(), item); + } + // tagCompound.setString("Species", this.getSpecies()); - tagCompound.setString("Char", this.getChar()); - tagCompound.setBool("Willing", this.isWilling); - tagCompound.setBool("Mating", this.isMating()); - tagCompound.setString("Align", this.alignment.name); - tagCompound.setFloat("Height", this.getHeight()); - tagCompound.setInt("MaxMana", this.getMaxMana()); - tagCompound.setInt("Mana", this.getManaPoints()); - tagCompound.setInt("AttackDmg", this.attackDamageBase); + tag.setString("Char", this.getChar()); + tag.setBool("Willing", this.isWilling); + tag.setBool("Mating", this.isMating()); + tag.setString("Align", this.alignment.name); + tag.setFloat("Height", this.getHeight()); + tag.setInt("MaxMana", this.getMaxMana()); + tag.setInt("Mana", this.getManaPoints()); + tag.setInt("AttackDmg", this.attackDamageBase); Enum type = this.getNpcClass(); if(type != null) - tagCompound.setString("ClassType", this.species.classnames.inverse().get(type)); + tag.setString("ClassType", this.species.classnames.inverse().get(type)); - if(!this.isPlayer()) { - List nbttaglist = Lists.newArrayList(); - - for (int i = 0; i < this.extraInventory.getSizeInventory(); ++i) - { - ItemStack itemstack = this.extraInventory.getStackInSlot(i); - - if (itemstack != null) - { - nbttaglist.add(itemstack.writeTags(new TagObject())); - } - } - - tagCompound.setList("Items", nbttaglist); - } if(this.trades != null) - tagCompound.setList("Offers", this.trades.toTags()); - tagCompound.setInt("healTimer", this.healTimer); + tag.setList("Offers", this.trades.toTags()); + tag.setInt("healTimer", this.healTimer); if(this.skin != null) - tagCompound.setByteArray("Skin", this.skin); + tag.setByteArray("Skin", this.skin); if(this.isPlayer()) { - tagCompound.setList("Inventory", this.inventory.toTag(Lists.newArrayList())); - tagCompound.setInt("SelectedItemSlot", this.inventory.currentItem); // tagCompound.setBoolean("Sleeping", this.sleeping); // tagCompound.setShort("SleepTimer", (short)this.sleepTimer); - tagCompound.setFloat("XpP", this.experience); - tagCompound.setInt("XpLevel", this.experienceLevel); - tagCompound.setInt("XpTotal", this.experienceTotal); - tagCompound.setInt("EnchSeed", this.enchSeed); + tag.setFloat("XpP", this.experience); + tag.setInt("XpLevel", this.experienceLevel); + tag.setInt("XpTotal", this.experienceTotal); + tag.setInt("EnchSeed", this.enchSeed); // tagCompound.setInteger("Score", this.getScore()); // tagCompound.setInteger("Mana", this.getManaPoints()); @@ -3484,10 +3751,10 @@ public abstract class EntityNPC extends EntityLiving { Dimension dim = this.spawnPos.getDimension(); if(dim != null) { - tagCompound.setInt("SpawnX", this.spawnPos.getX()); - tagCompound.setInt("SpawnY", this.spawnPos.getY()); - tagCompound.setInt("SpawnZ", this.spawnPos.getZ()); - tagCompound.setString("SpawnDim", DimensionRegistry.getName(dim)); + tag.setInt("SpawnX", this.spawnPos.getX()); + tag.setInt("SpawnY", this.spawnPos.getY()); + tag.setInt("SpawnZ", this.spawnPos.getZ()); + tag.setString("SpawnDim", DimensionRegistry.getName(dim)); } // tagCompound.setBoolean("SpawnForced", this.spawnForced); } @@ -3496,29 +3763,23 @@ public abstract class EntityNPC extends EntityLiving { Dimension dim = this.originPos.getDimension(); if(dim != null) { - tagCompound.setInt("OriginX", this.originPos.getX()); - tagCompound.setInt("OriginY", this.originPos.getY()); - tagCompound.setInt("OriginZ", this.originPos.getZ()); - tagCompound.setString("OriginDim", DimensionRegistry.getName(dim)); + tag.setInt("OriginX", this.originPos.getX()); + tag.setInt("OriginY", this.originPos.getY()); + tag.setInt("OriginZ", this.originPos.getZ()); + tag.setString("OriginDim", DimensionRegistry.getName(dim)); } } - tagCompound.setBool("flying", this.flying); + tag.setBool("flying", this.flying); // tagCompound.setFloat("speed", this.speed); // tagCompound.setBoolean("alwaysInvulnerable", this.disableDamagePersist); // tagCompound.setBoolean("neverTarget", this.disableTargetPersist); // tagCompound.setBoolean("alwaysFly", this.allowFlyingPersist); - tagCompound.setBool("noClip", this.noclip); + tag.setBool("noClip", this.noclip); - tagCompound.setList("WarpItems", this.warpChest.writeTags()); - ItemStack itemstack = this.inventory.getCurrentItem(); - - if (itemstack != null && itemstack.getItem() != null) - { - tagCompound.setObject("SelectedItem", itemstack.writeTags(new TagObject())); - } + tag.setList("WarpItems", this.warpChest.writeTags()); - tagCompound.setLong("MovedDist", this.movedDistance); + tag.setLong("MovedDist", this.movedDistance); // tagCompound.setString("Model", this.getModel().name); // tagCompound.setInteger("PartFlags", this.getModelParts()); @@ -3526,28 +3787,36 @@ public abstract class EntityNPC extends EntityLiving } } - protected void damageArmor(int p_70675_1_) + protected void damageArmor(int damage) { - if(this.isPlayer()) - this.inventory.damageArmor(p_70675_1_); + if(this.isPlayer()) { + damage = damage / 4; + if (damage < 1) + damage = 1; + for (Equipment slot : Equipment.ARMOR) + { + ItemStack stack = this.getArmor(slot); + if (stack != null && stack.getItem() instanceof ItemArmor) + { + stack.damage(damage, this); + if (stack.isEmpty()) + this.setArmor(slot, null); + } + } + } } public int getTotalArmorValue() { - if(this.isPlayer()) - return this.inventory.getTotalArmorValue(); - int i = 0; - - for (ItemStack itemstack : this.armor) + int value = 0; + for (ItemStack stack : this.getArmor()) { - if (itemstack != null && itemstack.getItem() instanceof ItemArmor) + if (stack != null && stack.getItem() instanceof ItemArmor armor) { - int j = ((ItemArmor)itemstack.getItem()).getArmorValue(); - i += j; + value += armor.getArmorValue(); } } - - return i; + return value; } public boolean interactWith(Entity targetEntity) @@ -3579,7 +3848,7 @@ public abstract class EntityNPC extends EntityLiving { if (itemstack.isEmpty()) // && !this.creative) { - this.destroyCurrentEquippedItem(); + this.setHeldItem(null); } return true; @@ -3594,7 +3863,7 @@ public abstract class EntityNPC extends EntityLiving { if (itemstack.isEmpty()) // && !this.creative) { - this.destroyCurrentEquippedItem(); + this.setHeldItem(null); } // else if (itemstack.stackSize < itemstack1.stackSize && this.creative) // { @@ -3607,14 +3876,6 @@ public abstract class EntityNPC extends EntityLiving // } } - /** - * Destroys the currently equipped item from the player's inventory. - */ - public void destroyCurrentEquippedItem() - { - this.inventory.setInventorySlotContents(this.inventory.currentItem, (ItemStack)null); - } - /** * Returns the Y Offset of this entity. */ @@ -3720,7 +3981,7 @@ public abstract class EntityNPC extends EntityLiving if (itemstack.isEmpty()) { - this.destroyCurrentEquippedItem(); + this.setHeldItem(null); } } @@ -4236,23 +4497,23 @@ public abstract class EntityNPC extends EntityLiving else if(stack.getItem().getWieldType() != null) this.setHeldItem(stack); else - this.extraInventory.addStack(stack); + this.addStack(stack); } } else { + this.clear(); this.setHeldItem(this.pickItem()); for(Equipment slot : Equipment.ARMOR) { this.setArmor(slot, this.pickArmor(slot)); } int items = this.pickItemAmount(); ItemStack stack; - this.extraInventory.clear(); for(int z = 0; z < items; z++) { stack = this.pickLoot(z); if(stack == null) { break; } - this.extraInventory.addStack(stack); + this.addStack(stack); } } } @@ -4351,17 +4612,9 @@ public abstract class EntityNPC extends EntityLiving { this.entityDropItem(itemstack1, 0.0F); } - for (Equipment slot : Equipment.ARMOR) + for (int i = 0; i < this.getSizeInventory(); ++i) { - ItemStack itemstack = this.getArmor(slot); - if (itemstack != null) - { - this.entityDropItem(itemstack, 0.0F); - } - } - for (int i = 0; i < this.extraInventory.getSizeInventory(); ++i) - { - ItemStack itemstack = this.extraInventory.getStackInSlot(i); + ItemStack itemstack = this.getStackInSlot(i); if (itemstack != null) { this.entityDropItem(itemstack, 0.0F); @@ -4486,6 +4739,14 @@ public abstract class EntityNPC extends EntityLiving { } + public float getBaseRadiation() { + return this.getAttribute(Attribute.RADIATION); + } + + public float getRadiationResistance() { + return super.getRadiationResistance() + this.getAttribute(Attribute.RADIATION_RESISTANCE); + } + public EntityType getType() { return EntityType.NPC; } @@ -4521,4 +4782,148 @@ public abstract class EntityNPC extends EntityLiving if(this.connection != null) this.connection.sendPlayerAbilities(); } + + // Inventory + + public ItemStack decrStackSize(int index, int count) + { + ItemStack[] aitemstack = this.getInventory(); + + if (index >= this.getInventoryCapacity()) + { + aitemstack = this.getArmor(); + index -= this.getInventoryCapacity(); + } + + if (aitemstack[index] != null) + { + if (aitemstack[index].getSize() <= count) + { + ItemStack itemstack1 = aitemstack[index]; + aitemstack[index] = null; + return itemstack1; + } + else + { + ItemStack itemstack = aitemstack[index].split(count); + + if (aitemstack[index].isEmpty()) + { + aitemstack[index] = null; + } + + return itemstack; + } + } + else + { + return null; + } + } + + public ItemStack removeStackFromSlot(int index) + { + ItemStack[] aitemstack = this.getInventory(); + + if (index >= this.getInventoryCapacity()) + { + aitemstack = this.getArmor(); + index -= this.getInventoryCapacity(); + } + + if (aitemstack[index] != null) + { + ItemStack itemstack = aitemstack[index]; + aitemstack[index] = null; + return itemstack; + } + else + { + return null; + } + } + + public void setInventorySlotContents(int index, ItemStack stack) + { + ItemStack[] aitemstack = this.getInventory(); + + if (index >= aitemstack.length) + { + index -= aitemstack.length; + aitemstack = this.getArmor(); + } + + aitemstack[index] = stack; + } + + public int getSizeInventory() + { + return this.getInventoryCapacity() + this.getArmor().length; + } + + public ItemStack getStackInSlot(int index) + { + ItemStack[] aitemstack = this.getInventory(); + + if (index >= aitemstack.length) + { + index -= aitemstack.length; + aitemstack = this.getArmor(); + } + + return aitemstack[index]; + } + + public int getInventoryStackLimit() + { + return ItemStack.MAX_SIZE; + } + + public void markDirty() + { + } + + public boolean isUseableByPlayer(EntityNPC player) + { + return this.dead ? false : player.getDistanceSqToEntity(this) <= 64.0D; + } + + public void openInventory(EntityNPC player) + { + } + + public void closeInventory(EntityNPC player) + { + } + + 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.getInventoryCapacity(); ++i) + { + this.getInventory()[i] = null; + } + + for(Equipment slot : Equipment.ARMOR) { + this.setArmor(slot, null); + } + } } diff --git a/common/src/main/java/common/entity/projectile/EntityArrow.java b/common/src/main/java/common/entity/projectile/EntityArrow.java index 2db98436..dad55019 100755 --- a/common/src/main/java/common/entity/projectile/EntityArrow.java +++ b/common/src/main/java/common/entity/projectile/EntityArrow.java @@ -512,7 +512,7 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData { boolean flag = this.canBePickedUp == 1; // || this.canBePickedUp == 2 && entityIn.creative; - if (this.canBePickedUp == 1 && !entityIn.inventory.addItemStackToInventory(new ItemStack(Items.arrow, 1))) + if (this.canBePickedUp == 1 && !entityIn.addItemStackToInventory(new ItemStack(Items.arrow, 1))) { flag = false; } diff --git a/common/src/main/java/common/entity/projectile/EntityDie.java b/common/src/main/java/common/entity/projectile/EntityDie.java index 1bc3fe3d..7f2e3cfe 100755 --- a/common/src/main/java/common/entity/projectile/EntityDie.java +++ b/common/src/main/java/common/entity/projectile/EntityDie.java @@ -125,7 +125,7 @@ public class EntityDie extends EntityThrowable implements IObjectData { if(this.noPickup) this.setDead(); - else if(player.inventory.addItemStackToInventory(this.getStack())) { + else if(player.addItemStackToInventory(this.getStack())) { this.setDead(); player.worldObj.playSoundAtEntity(player, SoundEvent.POP, 0.2F); player.inventoryContainer.detectAndSendChanges(); diff --git a/common/src/main/java/common/entity/types/EntityAnimal.java b/common/src/main/java/common/entity/types/EntityAnimal.java index d19b4640..3cdebd68 100755 --- a/common/src/main/java/common/entity/types/EntityAnimal.java +++ b/common/src/main/java/common/entity/types/EntityAnimal.java @@ -163,14 +163,14 @@ public abstract class EntityAnimal extends EntityLiving */ public boolean interact(EntityNPC player) { - ItemStack stack = player.inventory.getCurrentItem(); + ItemStack stack = player.getHeldItem(); if (stack != null) { if (this.isBreedingItem(stack) && this.getGrowingAge() == 0 && !this.isInLove()) { if(stack.decrSize()) - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + player.setHeldItem(null); this.setInLove(player); return true; } @@ -178,7 +178,7 @@ public abstract class EntityAnimal extends EntityLiving if (this.isChild() && this.isBreedingItem(stack)) { if(stack.decrSize()) - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + player.setHeldItem(null); if(!this.worldObj.client) this.grow((int)((float)(-this.getGrowingAge() / 20) * 0.1F)); return true; diff --git a/common/src/main/java/common/entity/types/EntityLiving.java b/common/src/main/java/common/entity/types/EntityLiving.java index c363d2aa..f727da32 100755 --- a/common/src/main/java/common/entity/types/EntityLiving.java +++ b/common/src/main/java/common/entity/types/EntityLiving.java @@ -13,8 +13,6 @@ import common.ai.EntityJumpHelper; import common.ai.EntityLookHelper; import common.ai.EntityMoveHelper; import common.ai.EntitySenses; -import common.attributes.Attribute; -import common.attributes.AttributeMap; import common.block.Block; import common.block.SoundType; import common.collect.Lists; @@ -66,7 +64,6 @@ import common.world.AWorldServer; public abstract class EntityLiving extends Entity { - protected AttributeMap attributes = new AttributeMap(); private final List combat = Lists.newArrayList(); private final Map effects = Maps.newEnumMap(Effect.class); public int soundTimer; @@ -358,8 +355,8 @@ public abstract class EntityLiving extends Entity if(!this.worldObj.client) { if(!this.firstEffectUpdate && Vars.radiation) { // && // (!(this.isPlayer()) || !((EntityNPCMP)this).creative)) { - float radiation = this.radiation + this.attributes.get(Attribute.RADIATION); - radiation -= 10.0f + this.attributes.get(Attribute.RADIATION_RESISTANCE); + float radiation = this.radiation + this.getBaseRadiation(); + radiation -= this.getRadiationResistance(); // if(this.isPlayer()) // Log.SERVER.info("rad:" + radiation); if(radiation >= 0.0f) { @@ -400,6 +397,14 @@ public abstract class EntityLiving extends Entity // this.target = null; // FIX Creative // } } + + public float getBaseRadiation() { + return 0.0f; + } + + public float getRadiationResistance() { + return 10.0f; + } // /** // * If Animal, checks if the age timer is negative @@ -1358,11 +1363,6 @@ public abstract class EntityLiving extends Entity this.swingFactor = (float)this.swingTimer / (float)i; } - public final AttributeMap getAttributeMap() - { - return this.attributes; - } - // public CreatureType getCreatureType() // { // return CreatureType.UNDEFINED; @@ -2595,11 +2595,11 @@ public abstract class EntityLiving extends Entity this.clearLeashed(true, true); return true; } - ItemStack stack = player.inventory.getCurrentItem(); + ItemStack stack = player.getHeldItem(); if(stack != null && stack.getItem() == Items.lead && this.allowLeashing() && (!(this instanceof EntityTameable tameable) || !tameable.isTamed() || tameable.isOwner(player))) { this.setLeashedTo(player, true); if(stack.decrSize()) - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + player.setHeldItem(null); return true; } return this.interact(player) || super.interactFirst(player); @@ -2998,7 +2998,7 @@ public abstract class EntityLiving extends Entity public boolean interact(EntityNPC player) { - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); if (itemstack != null && itemstack.getItem() instanceof ItemMobTemplate) { @@ -3028,7 +3028,7 @@ public abstract class EntityLiving extends Entity if (itemstack.decrSize()) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null); + player.setHeldItem(null); } // } } diff --git a/common/src/main/java/common/init/ItemRegistry.java b/common/src/main/java/common/init/ItemRegistry.java index 9fcb010d..4d685382 100755 --- a/common/src/main/java/common/init/ItemRegistry.java +++ b/common/src/main/java/common/init/ItemRegistry.java @@ -128,7 +128,7 @@ public abstract class ItemRegistry { private static void registerTools(ToolMaterial material, String name, String prefix) { for(Equipment tool : Equipment.values()) { if(tool.canRegister(material)) - register(name + "_" + tool.getName(), (tool.isArmor() ? (tool.isAnimalArmor() ? new ItemAnimalArmor(material, name) : new ItemArmor(material, name, tool)) : new ItemTool(material, tool)).setDisplay(tool.getDisplay(prefix, prefix == null))); + register(name + "_" + tool.getName(), (tool.isArmor() ? (tool.isAnimalArmor() ? new ItemAnimalArmor(material, name, tool) : new ItemArmor(material, name, tool)) : new ItemTool(material, tool)).setDisplay(tool.getDisplay(prefix, prefix == null))); } } diff --git a/common/src/main/java/common/inventory/Container.java b/common/src/main/java/common/inventory/Container.java index 56ab7bb2..ee358303 100755 --- a/common/src/main/java/common/inventory/Container.java +++ b/common/src/main/java/common/inventory/Container.java @@ -145,7 +145,6 @@ public abstract class Container public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityNPC playerIn) { ItemStack itemstack = null; - InventoryPlayer inventoryplayer = playerIn.inventory; if (mode == 5) { @@ -156,7 +155,7 @@ public abstract class Container { this.resetDrag(); } - else if (inventoryplayer.getItemStack() == null) + else if (playerIn.getMouseItem() == null) { this.resetDrag(); } @@ -178,7 +177,7 @@ public abstract class Container { Slot slot = (Slot)this.inventorySlots.get(slotId); - if (slot != null && canAddItemToSlot(slot, inventoryplayer.getItemStack(), true) && slot.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().getSize() > this.dragSlots.size() && this.canDragIntoSlot(slot)) + if (slot != null && canAddItemToSlot(slot, playerIn.getMouseItem(), true) && slot.isItemValid(playerIn.getMouseItem()) && playerIn.getMouseItem().getSize() > this.dragSlots.size() && this.canDragIntoSlot(slot)) { this.dragSlots.add(slot); } @@ -187,12 +186,12 @@ public abstract class Container { if (!this.dragSlots.isEmpty()) { - ItemStack itemstack3 = inventoryplayer.getItemStack().copy(); - int j = inventoryplayer.getItemStack().getSize(); + ItemStack itemstack3 = playerIn.getMouseItem().copy(); + int j = playerIn.getMouseItem().getSize(); for (Slot slot1 : this.dragSlots) { - if (slot1 != null && canAddItemToSlot(slot1, inventoryplayer.getItemStack(), true) && slot1.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().getSize() >= this.dragSlots.size() && this.canDragIntoSlot(slot1)) + if (slot1 != null && canAddItemToSlot(slot1, playerIn.getMouseItem(), true) && slot1.isItemValid(playerIn.getMouseItem()) && playerIn.getMouseItem().getSize() >= this.dragSlots.size() && this.canDragIntoSlot(slot1)) { ItemStack itemstack1 = itemstack3.copy(); int k = slot1.getHasStack() ? slot1.getStack().getSize() : 0; @@ -220,7 +219,7 @@ public abstract class Container itemstack3 = null; } - inventoryplayer.setItemStack(itemstack3); + playerIn.setMouseItem(itemstack3); } this.resetDrag(); @@ -238,21 +237,21 @@ public abstract class Container { if (slotId == -999) { - if (inventoryplayer.getItemStack() != null) + if (playerIn.getMouseItem() != null) { if (clickedButton == 0) { - playerIn.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack(), true); - inventoryplayer.setItemStack((ItemStack)null); + playerIn.dropItem(playerIn.getMouseItem(), true); + playerIn.setMouseItem((ItemStack)null); } if (clickedButton == 1) { - playerIn.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack().split(1), true); + playerIn.dropItem(playerIn.getMouseItem().split(1), true); - if (inventoryplayer.getItemStack().isEmpty()) + if (playerIn.getMouseItem().isEmpty()) { - inventoryplayer.setItemStack((ItemStack)null); + playerIn.setMouseItem((ItemStack)null); } } } @@ -294,7 +293,7 @@ public abstract class Container if (slot7 != null) { ItemStack itemstack9 = slot7.getStack(); - ItemStack itemstack10 = inventoryplayer.getItemStack(); + ItemStack itemstack10 = playerIn.getMouseItem(); if (itemstack9 != null) { @@ -319,7 +318,7 @@ public abstract class Container if (itemstack10.isEmpty()) { - inventoryplayer.setItemStack((ItemStack)null); + playerIn.setMouseItem((ItemStack)null); } } } @@ -329,14 +328,14 @@ public abstract class Container { int j2 = clickedButton == 0 ? itemstack9.getSize() : (itemstack9.getSize() + 1) / 2; ItemStack itemstack12 = slot7.decrStackSize(j2); - inventoryplayer.setItemStack(itemstack12); + playerIn.setMouseItem(itemstack12); if (itemstack9.isEmpty()) { slot7.putStack((ItemStack)null); } - slot7.onPickupFromSlot(playerIn, inventoryplayer.getItemStack()); + slot7.onPickupFromSlot(playerIn, playerIn.getMouseItem()); } else if (slot7.isItemValid(itemstack10)) { @@ -358,7 +357,7 @@ public abstract class Container if (itemstack10.isEmpty()) { - inventoryplayer.setItemStack((ItemStack)null); + playerIn.setMouseItem((ItemStack)null); } itemstack9.incrSize(i2); @@ -366,7 +365,7 @@ public abstract class Container else if (itemstack10.getSize() <= slot7.getItemStackLimit(itemstack10)) { slot7.putStack(itemstack10); - inventoryplayer.setItemStack(itemstack9); + playerIn.setMouseItem(itemstack9); } } else if (itemstack9.getItem() == itemstack10.getItem() && itemstack10.getMaxStackSize() > 1 && ItemStack.dataEquals(itemstack9, itemstack10)) @@ -383,7 +382,7 @@ public abstract class Container slot7.putStack((ItemStack)null); } - slot7.onPickupFromSlot(playerIn, inventoryplayer.getItemStack()); + slot7.onPickupFromSlot(playerIn, playerIn.getMouseItem()); } } } @@ -398,26 +397,26 @@ public abstract class Container if (slot5.canTakeStack(playerIn)) { - ItemStack itemstack7 = inventoryplayer.getStackInSlot(clickedButton); - boolean flag = itemstack7 == null || slot5.inventory == inventoryplayer && slot5.isItemValid(itemstack7); + ItemStack itemstack7 = playerIn.getStackInSlot(clickedButton); + boolean flag = itemstack7 == null || slot5.inventory == playerIn && slot5.isItemValid(itemstack7); int k1 = -1; if (!flag) { - k1 = inventoryplayer.getFirstEmptyStack(); + k1 = playerIn.getFirstEmptyStack(); flag |= k1 > -1; } if (slot5.getHasStack() && flag) { ItemStack itemstack11 = slot5.getStack(); - inventoryplayer.setInventorySlotContents(clickedButton, itemstack11.copy()); + playerIn.setInventorySlotContents(clickedButton, itemstack11.copy()); - if ((slot5.inventory != inventoryplayer || !slot5.isItemValid(itemstack7)) && itemstack7 != null) + if ((slot5.inventory != playerIn || !slot5.isItemValid(itemstack7)) && itemstack7 != null) { if (k1 > -1) { - inventoryplayer.addItemStackToInventory(itemstack7); + playerIn.addItemStackToInventory(itemstack7); slot5.decrStackSize(itemstack11.getSize()); slot5.putStack((ItemStack)null); slot5.onPickupFromSlot(playerIn, itemstack11); @@ -432,7 +431,7 @@ public abstract class Container } else if (!slot5.getHasStack() && itemstack7 != null && slot5.isItemValid(itemstack7)) { - inventoryplayer.setInventorySlotContents(clickedButton, (ItemStack)null); + playerIn.setInventorySlotContents(clickedButton, (ItemStack)null); slot5.putStack(itemstack7); } } @@ -448,7 +447,7 @@ public abstract class Container // inventoryplayer.setItemStack(itemstack6); // } // } - else if (mode == 4 && inventoryplayer.getItemStack() == null && slotId >= 0) + else if (mode == 4 && playerIn.getMouseItem() == null && slotId >= 0) { Slot slot3 = (Slot)this.inventorySlots.get(slotId); @@ -456,13 +455,13 @@ public abstract class Container { ItemStack itemstack5 = slot3.decrStackSize(clickedButton == 0 ? 1 : slot3.getStack().getSize()); slot3.onPickupFromSlot(playerIn, itemstack5); - playerIn.dropPlayerItemWithRandomChoice(itemstack5, true); + playerIn.dropItem(itemstack5, true); } } else if (mode == 6 && slotId >= 0) { Slot slot2 = (Slot)this.inventorySlots.get(slotId); - ItemStack itemstack4 = inventoryplayer.getItemStack(); + ItemStack itemstack4 = playerIn.getMouseItem(); if (itemstack4 != null && (slot2 == null || !slot2.getHasStack() || !slot2.canTakeStack(playerIn))) { @@ -520,12 +519,10 @@ public abstract class Container */ public void onContainerClosed(EntityNPC playerIn) { - InventoryPlayer inventoryplayer = playerIn.inventory; - - if (inventoryplayer.getItemStack() != null) + if (playerIn.getMouseItem() != null) { - playerIn.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack(), true); - inventoryplayer.setItemStack((ItemStack)null); + playerIn.dropItem(playerIn.getMouseItem(), true); + playerIn.setMouseItem(null); } } @@ -563,7 +560,7 @@ public abstract class Container /** * Gets a unique transaction ID. Parameter is unused. */ - public short getNextTransactionID(InventoryPlayer p_75136_1_) + public short getNextTransactionID(EntityNPC p_75136_1_) { ++this.transactionID; return this.transactionID; diff --git a/common/src/main/java/common/inventory/ContainerBrewingStand.java b/common/src/main/java/common/inventory/ContainerBrewingStand.java index b961e649..956cc127 100755 --- a/common/src/main/java/common/inventory/ContainerBrewingStand.java +++ b/common/src/main/java/common/inventory/ContainerBrewingStand.java @@ -15,12 +15,12 @@ public class ContainerBrewingStand extends Container private final Slot theSlot; private int brewTime; - public ContainerBrewingStand(InventoryPlayer playerInventory, IInventory tileBrewingStandIn) + public ContainerBrewingStand(EntityNPC 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.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory, tileBrewingStandIn, 0, 56, 46)); + this.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory, tileBrewingStandIn, 1, 79, 53)); + this.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory, tileBrewingStandIn, 2, 102, 46)); this.theSlot = this.addSlotToContainer(new ContainerBrewingStand.Ingredient(tileBrewingStandIn, 3, 79, 17)); for (int i = 0; i < 3; ++i) diff --git a/common/src/main/java/common/inventory/ContainerChest.java b/common/src/main/java/common/inventory/ContainerChest.java index 9ffdd6bb..2ab69a00 100755 --- a/common/src/main/java/common/inventory/ContainerChest.java +++ b/common/src/main/java/common/inventory/ContainerChest.java @@ -11,7 +11,7 @@ public class ContainerChest extends Container private final int width; private final int height; - public ContainerChest(IInventory inv, IInventory chest, EntityNPC player) + public ContainerChest(EntityNPC player, IInventory chest) { this.chest = chest; this.chestSize = chest.getSizeInventory(); @@ -34,13 +34,13 @@ public class ContainerChest extends Container { for (int j1 = 0; j1 < 9; ++j1) { - this.addSlotToContainer(new Slot(inv, j1 + l * 9 + 9, 8 + j1 * 18 + xOffset, 103 + l * 18 + yoffset)); + this.addSlotToContainer(new Slot(player, j1 + l * 9 + 9, 8 + j1 * 18 + xOffset, 103 + l * 18 + yoffset)); } } for (int i1 = 0; i1 < 9; ++i1) { - this.addSlotToContainer(new Slot(inv, i1, 8 + i1 * 18 + xOffset, 161 + yoffset)); + this.addSlotToContainer(new Slot(player, i1, 8 + i1 * 18 + xOffset, 161 + yoffset)); } } diff --git a/common/src/main/java/common/inventory/ContainerEnchantment.java b/common/src/main/java/common/inventory/ContainerEnchantment.java index aeeefcdb..d2ad0c3f 100755 --- a/common/src/main/java/common/inventory/ContainerEnchantment.java +++ b/common/src/main/java/common/inventory/ContainerEnchantment.java @@ -26,12 +26,12 @@ public class ContainerEnchantment extends Container public int[] mana; public Pair[] ench; - public ContainerEnchantment(InventoryPlayer playerInv, World worldIn) + public ContainerEnchantment(EntityNPC playerInv, World worldIn) { this(playerInv, worldIn, BlockPos.ORIGIN); } - public ContainerEnchantment(InventoryPlayer playerInv, World worldIn, BlockPos pos) + public ContainerEnchantment(EntityNPC playerInv, World worldIn, BlockPos pos) { this.table = new InventoryBasic(1) { @@ -50,7 +50,7 @@ public class ContainerEnchantment extends Container this.ench = new Pair[] {null, null, null}; this.world = worldIn; this.position = pos; - this.seed = playerInv.player.getEnchSeed(); + this.seed = playerInv.getEnchSeed(); this.addSlotToContainer(new Slot(this.table, 0, 25, 47) { public boolean isItemValid(ItemStack stack) @@ -296,7 +296,7 @@ public class ContainerEnchantment extends Container if (itemstack != null) { - playerIn.dropPlayerItemWithRandomChoice(itemstack, false); + playerIn.dropItem(itemstack, false); } } } diff --git a/common/src/main/java/common/inventory/ContainerEntityInventory.java b/common/src/main/java/common/inventory/ContainerEntityInventory.java index f12b39b4..fbe511c1 100755 --- a/common/src/main/java/common/inventory/ContainerEntityInventory.java +++ b/common/src/main/java/common/inventory/ContainerEntityInventory.java @@ -11,7 +11,7 @@ public class ContainerEntityInventory extends Container private IInventory entityInventory; private Entity entity; - public ContainerEntityInventory(IInventory playerInventory, final IInventory entityInv, final Entity entity, EntityNPC player) + public ContainerEntityInventory(EntityNPC player, final IInventory entityInv, final Entity entity) { this.entityInventory = entityInv; this.entity = entity; @@ -54,13 +54,13 @@ public class ContainerEntityInventory extends Container { for (int k1 = 0; k1 < 9; ++k1) { - this.addSlotToContainer(new Slot(playerInventory, k1 + i1 * 9 + 9, 8 + k1 * 18, 102 + i1 * 18 + j)); + this.addSlotToContainer(new Slot(player, 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)); + this.addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 160 + j)); } } diff --git a/common/src/main/java/common/inventory/ContainerFurnace.java b/common/src/main/java/common/inventory/ContainerFurnace.java index 79ffc12f..348eabc1 100755 --- a/common/src/main/java/common/inventory/ContainerFurnace.java +++ b/common/src/main/java/common/inventory/ContainerFurnace.java @@ -14,12 +14,12 @@ public class ContainerFurnace extends Container private int furnaceBurnTime; private int currentItemBurnTime; - public ContainerFurnace(InventoryPlayer playerInventory, IInventory furnaceInventory) + public ContainerFurnace(EntityNPC 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)); + this.addSlotToContainer(new SlotFurnaceOutput(playerInventory, furnaceInventory, 2, 116, 35)); for (int i = 0; i < 3; ++i) { diff --git a/common/src/main/java/common/inventory/ContainerHopper.java b/common/src/main/java/common/inventory/ContainerHopper.java index ea26801e..47141080 100755 --- a/common/src/main/java/common/inventory/ContainerHopper.java +++ b/common/src/main/java/common/inventory/ContainerHopper.java @@ -7,7 +7,7 @@ public class ContainerHopper extends Container { private final IInventory hopperInventory; - public ContainerHopper(InventoryPlayer playerInventory, IInventory hopperInventoryIn, EntityNPC player) + public ContainerHopper(EntityNPC playerInventory, IInventory hopperInventoryIn, EntityNPC player) { this.hopperInventory = hopperInventoryIn; hopperInventoryIn.openInventory(player); diff --git a/common/src/main/java/common/inventory/ContainerMerchant.java b/common/src/main/java/common/inventory/ContainerMerchant.java index 6d5291fd..6e91d4ab 100755 --- a/common/src/main/java/common/inventory/ContainerMerchant.java +++ b/common/src/main/java/common/inventory/ContainerMerchant.java @@ -11,11 +11,11 @@ public class ContainerMerchant extends Container private InventoryMerchant merchantInventory; private final World theWorld; - public ContainerMerchant(InventoryPlayer playerInventory, EntityNPC merchant, World worldIn) + public ContainerMerchant(EntityNPC playerInventory, EntityNPC merchant, World worldIn) { this.theMerchant = merchant; this.theWorld = worldIn; - this.merchantInventory = new InventoryMerchant(playerInventory.player, merchant); + this.merchantInventory = new InventoryMerchant(playerInventory, merchant); this.addSlotToContainer(new Slot(this.merchantInventory, 0, 36, 53) { public boolean canEditItem() { return false; @@ -26,7 +26,7 @@ public class ContainerMerchant extends Container return false; } }); - this.addSlotToContainer(new SlotMerchantResult(playerInventory.player, this.merchantInventory, 2, 120, 53)); + this.addSlotToContainer(new SlotMerchantResult(playerInventory, this.merchantInventory, 2, 120, 53)); for (int i = 0; i < 3; ++i) { @@ -160,14 +160,14 @@ public class ContainerMerchant extends Container if (itemstack != null) { - playerIn.dropPlayerItemWithRandomChoice(itemstack, false); + playerIn.dropItem(itemstack, false); } itemstack = this.merchantInventory.removeStackFromSlot(1); if (itemstack != null) { - playerIn.dropPlayerItemWithRandomChoice(itemstack, false); + playerIn.dropItem(itemstack, false); } } } diff --git a/common/src/main/java/common/inventory/ContainerPlayer.java b/common/src/main/java/common/inventory/ContainerPlayer.java index bb620df9..faf8c1db 100755 --- a/common/src/main/java/common/inventory/ContainerPlayer.java +++ b/common/src/main/java/common/inventory/ContainerPlayer.java @@ -1,9 +1,5 @@ package common.inventory; -import java.util.List; - -import common.attributes.AttributeMap; -import common.collect.Lists; import common.entity.npc.EntityNPC; import common.init.CraftingRegistry; import common.item.ItemStack; @@ -18,17 +14,12 @@ public class ContainerPlayer extends Container { }, 1, 1); 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 lastStacks = Lists.newArrayList(); - public ContainerPlayer(final InventoryPlayer playerInventory, boolean localWorld, EntityNPC player) + public ContainerPlayer(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)); + this.addSlotToContainer(new SlotCrafting(player, this.craftMatrix, this.craftResult, 0, 144, 36)); for (int i = 0; i < 2; ++i) { @@ -45,7 +36,7 @@ public class ContainerPlayer extends Container { for (Equipment slot : Equipment.ARMOR) { final Equipment type = slot; - this.addSlotToContainer(new Slot(playerInventory, 27 + 9 + slot.getIndex(), 8 + (slot.getIndex() / 4) * 18, 8 + (slot.getIndex() % 4) * 18) + this.addSlotToContainer(new Slot(player, 27 + 9 + slot.getIndex(), 8 + (slot.getIndex() / 4) * 18, 8 + (slot.getIndex() % 4) * 18) { public int getSlotStackLimit() { @@ -62,53 +53,17 @@ public class ContainerPlayer extends Container { { for (int j1 = 0; j1 < 9; ++j1) { - this.addSlotToContainer(new Slot(playerInventory, j1 + (l + 1) * 9, 8 + j1 * 18, 84 + l * 18)); + this.addSlotToContainer(new Slot(player, j1 + (l + 1) * 9, 8 + j1 * 18, 84 + l * 18)); } } for (int i1 = 0; i1 < 9; ++i1) { - this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 142)); + this.addSlotToContainer(new Slot(player, i1, 8 + i1 * 18, 142)); } this.onCraftMatrixChanged(this.craftMatrix); } - - protected Slot addSlotToContainer(Slot slotIn) - { - slotIn = super.addSlotToContainer(slotIn); - if(slotIn.slotNumber >= 5 + Equipment.ARMOR_SLOTS) - 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 >= 5 + Equipment.ARMOR_SLOTS) { - ItemStack current = slot.getStack(); - ItemStack last = (ItemStack)this.lastStacks.get(i - (5 + Equipment.ARMOR_SLOTS)); - - if (!ItemStack.allEquals(last, current)) - { - if (last != null) - { - this.attributes.remove(last.getAttributeModifiers(Equipment.PICKAXE), slot.getIndex()); - } - - if (current != null) - { - this.attributes.add(current.getAttributeModifiers(Equipment.PICKAXE), slot.getIndex(), current.getSize()); - } - - last = current == null ? null : current.copy(); - this.lastStacks.set(i - (5 + Equipment.ARMOR_SLOTS), last); - } - } - } - } /** * Callback for when the crafting matrix is changed. @@ -146,7 +101,7 @@ public class ContainerPlayer extends Container { if (itemstack != null) { - playerIn.dropPlayerItemWithRandomChoice(itemstack, false); + playerIn.dropItem(itemstack, false); } } @@ -194,9 +149,9 @@ public class ContainerPlayer extends Container { return null; } } - else if (itemstack.getItem() instanceof ItemArmor && !((Slot)this.inventorySlots.get(5 + Equipment.ARMOR_SLOTS + ((ItemArmor)itemstack.getItem()).getArmorType().getIndex())).getHasStack()) + else if (itemstack.getItem() instanceof ItemArmor armor && !((Slot)this.inventorySlots.get(5 + armor.getArmorType().getIndex())).getHasStack()) { - int idx = 5 + Equipment.ARMOR_SLOTS + ((ItemArmor)itemstack.getItem()).getArmorType().getIndex(); + int idx = 5 + armor.getArmorType().getIndex(); if (!this.mergeItemStack(itemstack1, idx, idx + 1, false)) { diff --git a/common/src/main/java/common/inventory/ContainerRepair.java b/common/src/main/java/common/inventory/ContainerRepair.java index 6a3c61d7..58ac0247 100755 --- a/common/src/main/java/common/inventory/ContainerRepair.java +++ b/common/src/main/java/common/inventory/ContainerRepair.java @@ -24,12 +24,12 @@ public class ContainerRepair extends Container public int maximumCost; private int materialCost; - public ContainerRepair(InventoryPlayer playerInventory, World worldIn) + public ContainerRepair(EntityNPC playerInventory, World worldIn) { this(playerInventory, worldIn, BlockPos.ORIGIN); } - public ContainerRepair(InventoryPlayer playerInventory, final World worldIn, final BlockPos blockPosIn) + public ContainerRepair(EntityNPC playerInventory, final World worldIn, final BlockPos blockPosIn) { this.outputSlot = new InventoryCraftResult(); this.inputSlots = new InventoryBasic(2) @@ -411,7 +411,7 @@ public class ContainerRepair extends Container if (itemstack != null) { - playerIn.dropPlayerItemWithRandomChoice(itemstack, false); + playerIn.dropItem(itemstack, false); } } } diff --git a/common/src/main/java/common/inventory/ContainerTile.java b/common/src/main/java/common/inventory/ContainerTile.java index c05cb1b8..1106221f 100755 --- a/common/src/main/java/common/inventory/ContainerTile.java +++ b/common/src/main/java/common/inventory/ContainerTile.java @@ -14,7 +14,7 @@ public class ContainerTile extends Container private Status status = Status.OFF; private final int[] resources; - public ContainerTile(InventoryPlayer playerInv, Device tile, IInventory tileInv, EntityNPC player) + public ContainerTile(EntityNPC player, Device tile, IInventory tileInv) { this.tileInv = tileInv; this.tile = tile; @@ -37,13 +37,13 @@ public class ContainerTile extends Container { for (int k = 0; k < 9; ++k) { - this.addSlotToContainer(new Slot(playerInv, k + l * 9 + 9, 8 + k * 18, l * 18 + i)); + this.addSlotToContainer(new Slot(player, 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)); + this.addSlotToContainer(new Slot(player, i1, 8 + i1 * 18, 58 + i)); } } diff --git a/common/src/main/java/common/inventory/ContainerWorkbench.java b/common/src/main/java/common/inventory/ContainerWorkbench.java index d5dcb0ea..5d6b3a89 100755 --- a/common/src/main/java/common/inventory/ContainerWorkbench.java +++ b/common/src/main/java/common/inventory/ContainerWorkbench.java @@ -16,7 +16,7 @@ public class ContainerWorkbench extends Container private final BlockPos pos; private final BlockWorkbench block; - public ContainerWorkbench(InventoryPlayer playerInventory, World worldIn, BlockPos posIn, BlockWorkbench block) + public ContainerWorkbench(EntityNPC playerInventory, World worldIn, BlockPos posIn, BlockWorkbench block) { int size = block.getSize(); this.block = block; @@ -24,7 +24,7 @@ public class ContainerWorkbench extends Container this.pos = posIn; this.craftSlots = size * size; this.craftMatrix = new InventoryCrafting(this, size, size); - this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 134, 17 + ((size - 1) * 18) / 2)); + this.addSlotToContainer(new SlotCrafting(playerInventory, this.craftMatrix, this.craftResult, 0, 134, 17 + ((size - 1) * 18) / 2)); for (int i = 0; i < size; ++i) { @@ -77,7 +77,7 @@ public class ContainerWorkbench extends Container if (itemstack != null) { - playerIn.dropPlayerItemWithRandomChoice(itemstack, false); + playerIn.dropItem(itemstack, false); } } } diff --git a/common/src/main/java/common/inventory/IInvBasic.java b/common/src/main/java/common/inventory/IInvBasic.java index 880e0a27..ef9a980b 100755 --- a/common/src/main/java/common/inventory/IInvBasic.java +++ b/common/src/main/java/common/inventory/IInvBasic.java @@ -2,8 +2,5 @@ package common.inventory; public interface IInvBasic { - /** - * Called by InventoryBasic.onInventoryChanged() on a array that is never filled. - */ void onInventoryChanged(InventoryBasic p_76316_1_); } diff --git a/common/src/main/java/common/inventory/InventoryBasic.java b/common/src/main/java/common/inventory/InventoryBasic.java index 3f69e609..93486692 100755 --- a/common/src/main/java/common/inventory/InventoryBasic.java +++ b/common/src/main/java/common/inventory/InventoryBasic.java @@ -84,46 +84,6 @@ public class InventoryBasic implements IInventory } } - 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.itemEquals(itemstack1, itemstack)) - { - int j = Math.min(this.getInventoryStackLimit(), itemstack1.getMaxStackSize()); - int k = Math.min(itemstack.getSize(), j - itemstack1.getSize()); - - if (k > 0) - { - itemstack1.incrSize(k); - if (itemstack.decrSize(k)) - { - this.markDirty(); - return null; - } - } - } - } - - if (itemstack.getSize() != stack.getSize()) - { - this.markDirty(); - } - - return itemstack; - } - /** * Removes a stack from the given slot and returns it. */ diff --git a/common/src/main/java/common/inventory/InventoryPlayer.java b/common/src/main/java/common/inventory/InventoryPlayer.java deleted file mode 100755 index 2cd19282..00000000 --- a/common/src/main/java/common/inventory/InventoryPlayer.java +++ /dev/null @@ -1,712 +0,0 @@ -package common.inventory; - -import common.block.Block; -import common.entity.npc.EntityNPC; -import common.item.Item; -import common.item.ItemStack; -import common.item.material.ItemArmor; -import common.item.tool.ItemTool; -import common.tags.TagObject; -import common.util.Equipment; - -import java.util.List; - -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[Equipment.ARMOR_SLOTS]; - - /** 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; - } - - /** - * 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].isFull() && this.mainInventory[i].getSize() < this.getInventoryStackLimit() && ItemStack.dataEquals(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) // , boolean p_146030_4_) - { -// ItemStack itemstack = this.getCurrentItem(); - int i = 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.getSize(); - 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); - - this.mainInventory[j].copyData(itemStackIn); - } - - int k = i; - - if (i > this.mainInventory[j].getMaxStackSize() - this.mainInventory[j].getSize()) - { - k = this.mainInventory[j].getMaxStackSize() - this.mainInventory[j].getSize(); - } - - if (k > this.getInventoryStackLimit() - this.mainInventory[j].getSize()) - { - k = this.getInventoryStackLimit() - this.mainInventory[j].getSize(); - } - - if (k == 0) - { - return i; - } - else - { - i = i - k; - this.mainInventory[j].incrSize(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].decrSize()) - { - 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.isEmpty() && itemStackIn.getItem() != null) - { - if (itemStackIn.isItemDamaged()) - { - int j = this.getFirstEmptyStack(); - - if (j >= 0) - { - this.mainInventory[j] = ItemStack.copy(itemStackIn); -// this.mainInventory[j].animationsToGo = 5; - itemStackIn.setSize(0); - return true; - } -// else if (this.player.creative) -// { -// itemStackIn.stackSize = 0; -// return true; -// } - else - { - return false; - } - } - else - { - int i; - - while (true) - { - i = itemStackIn.getSize(); - itemStackIn.setSize(this.storePartialItemStack(itemStackIn)); - - if (itemStackIn.isEmpty() || itemStackIn.getSize() >= i) - { - break; - } - } - -// if (itemStackIn.stackSize == i && this.player.creative) -// { -// itemStackIn.stackSize = 0; -// return true; -// } -// else -// { - return itemStackIn.getSize() < 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].getSize() <= count) - { - ItemStack itemstack1 = aitemstack[index]; - aitemstack[index] = null; - return itemstack1; - } - else - { - ItemStack itemstack = aitemstack[index].split(count); - - if (aitemstack[index].isEmpty()) - { - 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 && this.mainInventory[this.currentItem].getItem() instanceof ItemTool tool && blockIn.getMiningTool() == tool.getToolType()) - { - f *= tool.getToolMaterial().getEfficiency(); - } - - return f; - } - - public List toTag(List list) - { - for (int i = 0; i < this.mainInventory.length; ++i) - { - if (this.mainInventory[i] != null) - { - TagObject tag = new TagObject(); - tag.setByte("Slot", (byte)i); - this.mainInventory[i].writeTags(tag); - list.add(tag); - } - } - - for (int j = 0; j < this.armorInventory.length; ++j) - { - if (this.armorInventory[j] != null) - { - TagObject tag = new TagObject(); - tag.setByte("Slot", (byte)(j + 100)); - this.armorInventory[j].writeTags(tag); - list.add(tag); - } - } - - return list; - } - - public void fromTag(List list) - { - this.mainInventory = new ItemStack[36]; - this.armorInventory = new ItemStack[Equipment.ARMOR_SLOTS]; - - for (int i = 0; i < list.size(); ++i) - { - TagObject tag = list.get(i); - int j = tag.getByte("Slot") & 255; - ItemStack stack = ItemStack.readFromTag(tag); - - if (stack != null) - { - if (j >= 0 && j < this.mainInventory.length) - { - this.mainInventory[j] = stack; - } - - if (j >= 100 && j < this.armorInventory.length + 100) - { - this.armorInventory[j - 100] = stack; - } - } - } - } - - /** - * Returns the number of slots in the inventory. - */ - public int getSizeInventory() - { - return this.mainInventory.length + this.armorInventory.length; - } - - /** - * 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]; - } - - /** - * 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 block) { - if(!block.getMaterial().isToolRequired()) - return true; - ItemStack stack = this.getStackInSlot(this.currentItem); - return stack != null && stack.getItem() instanceof ItemTool tool && block.getMiningTool() == tool.getToolType() && (!tool.getToolType().isLevelled() || tool.getToolMaterial().getHarvestLevel() >= block.getMiningLevel()); - } - - /** - * 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()).getArmorValue(); - 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].damage(damage, this.player); - - if (this.armorInventory[i].isEmpty()) - { - 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].itemEquals(itemStackIn)) - { - return true; - } - } - - for (int j = 0; j < this.mainInventory.length; ++j) - { - if (this.mainInventory[j] != null && this.mainInventory[j].itemEquals(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.copy(playerInventory.mainInventory[i]); - } - - for (int j = 0; j < this.armorInventory.length; ++j) - { - this.armorInventory[j] = ItemStack.copy(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; - } - } -} diff --git a/common/src/main/java/common/inventory/SlotCrafting.java b/common/src/main/java/common/inventory/SlotCrafting.java index 58aa5c10..76ce4621 100755 --- a/common/src/main/java/common/inventory/SlotCrafting.java +++ b/common/src/main/java/common/inventory/SlotCrafting.java @@ -28,9 +28,9 @@ public class SlotCrafting extends Slot { craftMatrix.setInventorySlotContents(i, itemstack1); } - else if (!thePlayer.inventory.addItemStackToInventory(itemstack1)) + else if (!thePlayer.addItemStackToInventory(itemstack1)) { - thePlayer.dropPlayerItemWithRandomChoice(itemstack1, false); + thePlayer.dropItem(itemstack1, false); } } } diff --git a/common/src/main/java/common/item/Item.java b/common/src/main/java/common/item/Item.java index 09e78699..218119a2 100755 --- a/common/src/main/java/common/item/Item.java +++ b/common/src/main/java/common/item/Item.java @@ -2,10 +2,11 @@ package common.item; import java.util.List; import java.util.Map; -import common.attributes.Attribute; + import common.block.Block; import common.block.tech.BlockDispenser; import common.entity.Entity; +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; import common.entity.types.IProjectile; diff --git a/common/src/main/java/common/item/ItemStack.java b/common/src/main/java/common/item/ItemStack.java index a2c22473..592b71d9 100755 --- a/common/src/main/java/common/item/ItemStack.java +++ b/common/src/main/java/common/item/ItemStack.java @@ -5,11 +5,11 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import common.attributes.Attribute; import common.collect.Lists; import common.collect.Maps; import common.enchantment.Enchantment; import common.enchantment.EnchantmentHelper; +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; import common.init.ItemRegistry; @@ -265,10 +265,16 @@ public final class ItemStack { return this.repairCost; } - public Map getAttributeModifiers(Equipment slot) { + public Map getAttributeModifiers() { Map map = Maps.newEnumMap(Attribute.class); - if(slot == null || (slot.isArmor() ? (this.item instanceof ItemArmor armor && armor.getArmorType() == slot) : !(this.item instanceof ItemArmor))) - this.item.getModifiers(map); + this.item.getModifiers(map); + return map; + } + + public Map getArmorModifiers(Equipment slot) { + Map map = Maps.newEnumMap(Attribute.class); + if(this.item instanceof ItemArmor armor && (slot == null || armor.getArmorType() == slot)) + armor.getArmorModifiers(map); return map; } @@ -398,7 +404,7 @@ public final class ItemStack { entity.renderBrokenItemStack(this); this.decrSize(); if(entity != null && entity.isPlayer() && this.isEmpty() && this.item instanceof ItemBow) - ((EntityNPC)entity).destroyCurrentEquippedItem(); + ((EntityNPC)entity).setHeldItem(null); this.setItemDamage(0); } } diff --git a/common/src/main/java/common/item/consumable/ItemMilkBottle.java b/common/src/main/java/common/item/consumable/ItemMilkBottle.java index b21551c6..72c6f8d6 100755 --- a/common/src/main/java/common/item/consumable/ItemMilkBottle.java +++ b/common/src/main/java/common/item/consumable/ItemMilkBottle.java @@ -1,7 +1,8 @@ package common.item.consumable; import java.util.Map; -import common.attributes.Attribute; + +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.item.CheatTab; import common.item.Item; diff --git a/common/src/main/java/common/item/consumable/ItemPotion.java b/common/src/main/java/common/item/consumable/ItemPotion.java index f39cf24f..e4095d0f 100755 --- a/common/src/main/java/common/item/consumable/ItemPotion.java +++ b/common/src/main/java/common/item/consumable/ItemPotion.java @@ -122,7 +122,9 @@ public class ItemPotion extends Item return new ItemStack(Items.bottle); } - playerIn.inventory.addItemStackToInventory(new ItemStack(Items.bottle)); + if (!playerIn.addItemStackToInventory(new ItemStack(Items.bottle))) { + playerIn.dropItem(new ItemStack(Items.bottle), false); + } // } return stack; diff --git a/common/src/main/java/common/item/material/ItemAnimalArmor.java b/common/src/main/java/common/item/material/ItemAnimalArmor.java index c60a3c17..3fcae820 100755 --- a/common/src/main/java/common/item/material/ItemAnimalArmor.java +++ b/common/src/main/java/common/item/material/ItemAnimalArmor.java @@ -13,18 +13,28 @@ import common.util.Equipment; public class ItemAnimalArmor extends Item { private final ToolMaterial material; + private final Equipment type; @Clientside private final String texture; - public ItemAnimalArmor(ToolMaterial material, String texture) { + public ItemAnimalArmor(ToolMaterial material, String texture, Equipment type) { this.material = material; this.texture = texture; + this.type = type; this.setUnstackable(); this.setTab(CheatTab.ARMOR); if(this.material.isMagnetic()) this.setMagnetic(); } + public Equipment getArmorType() { + return this.type; + } + + public ToolMaterial getArmorMaterial() { + return this.material; + } + public int getArmorValue() { return this.material.getDamageReduction(Equipment.CHESTPLATE); } diff --git a/common/src/main/java/common/item/material/ItemArmor.java b/common/src/main/java/common/item/material/ItemArmor.java index 97f473a0..9573a137 100755 --- a/common/src/main/java/common/item/material/ItemArmor.java +++ b/common/src/main/java/common/item/material/ItemArmor.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.Map; import java.util.function.Predicate; -import common.attributes.Attribute; +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.init.ToolMaterial; import common.item.CheatTab; @@ -22,124 +22,103 @@ import common.util.Vec3; import common.world.AWorldServer; import common.world.World; -public class ItemArmor extends Item -{ - private final ToolMaterial material; +public class ItemArmor extends Item { + private final ToolMaterial material; private final Equipment type; @Clientside - private final String texture; + private final String texture; - public ItemArmor(ToolMaterial material, String texture, Equipment armorType) - { - this.material = material; - this.texture = texture; - this.type = armorType; - this.setMaxDamage(material.getDurability(armorType)); - this.setTab(CheatTab.ARMOR); - if(this.material.canBeDyed()) - this.setDefaultColor(this.material.getDefaultColor()); - if(this.material.isMagnetic()) - this.setMagnetic(); - } + public ItemArmor(ToolMaterial material, String texture, Equipment armorType) { + this.material = material; + this.texture = texture; + this.type = armorType; + int dmg = material.getDurability(armorType); + if(dmg <= 0) + this.setUnstackable(); + else + this.setMaxDamage(dmg); + this.setTab(CheatTab.ARMOR); + if(this.material.canBeDyed()) + this.setDefaultColor(this.material.getDefaultColor()); + if(this.material.isMagnetic()) + this.setMagnetic(); + } - /** - * Return the enchantability factor of the item, most of the time is based on material. - */ - public int getItemEnchantability() - { - return this.material.getArmorEnchantability(); - } - - public Equipment getArmorType() { - return this.type; - } + public int getItemEnchantability() { + return this.material.getArmorEnchantability(); + } + + public Equipment getArmorType() { + return this.type; + } + + public ToolMaterial getArmorMaterial() { + return this.material; + } - public ToolMaterial getArmorMaterial() - { - return this.material; - } - public int getArmorValue() { return this.material.getDamageReduction(this.type); } @Clientside - public String getArmorTexture() - { - return this.texture; - } + public String getArmorTexture() { + return this.texture; + } @Clientside - public void addInformation(ItemStack stack, EntityNPC playerIn, List tooltip) - { + public void addInformation(ItemStack stack, EntityNPC playerIn, List tooltip) { if(this.material.getDamageReduction(this.type) > 0) tooltip.add(Color.BLUE + "+" + this.material.getDamageReduction(this.type) + " Rüstungspunkte"); - } + } - /** - * Return whether this item is repairable in an anvil. - */ - public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) - { - return this.material.isRepairItem(repair.getItem()) ? true : super.getIsRepairable(toRepair, repair); - } + public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { + return this.material.isRepairItem(repair.getItem()) ? true : super.getIsRepairable(toRepair, repair); + } - /** - * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer - */ - public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn) - { - ItemStack itemstack = playerIn.getArmor(this.type); + public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn) { + ItemStack itemstack = playerIn.getArmor(this.type); - if (itemstack == null) - { - playerIn.setArmor(this.type, itemStackIn.copy()); - itemStackIn.decrSize(); - } + if(itemstack == null) { + playerIn.setArmor(this.type, itemStackIn.copy()); + itemStackIn.decrSize(); + } - return itemStackIn; - } - -// public boolean canBeDyed() { -// return this.material.canBeDyed(); -// } + return itemStackIn; + } - public void getModifiers(Map map) - { - if(this.material.getRadiationReduction(this.type) > 0.0f) - map.put(Attribute.RADIATION_RESISTANCE, this.material.getRadiationReduction(this.type)); - if(this.material.getMagicReduction(this.type) > 0.0f) - map.put(Attribute.MAGIC_RESISTANCE, this.material.getMagicReduction(this.type)); - } + public void getArmorModifiers(Map map) { + if(this.material.getRadiationReduction(this.type) > 0.0f) + map.put(Attribute.RADIATION_RESISTANCE, this.material.getRadiationReduction(this.type)); + if(this.material.getMagicReduction(this.type) > 0.0f) + map.put(Attribute.MAGIC_RESISTANCE, this.material.getMagicReduction(this.type)); + } @Clientside public boolean hasBuiltinModel() { - return this.type.isArmorRendered(); + return this.type.isMainArmor(); } @Serverside public ItemStack dispenseStack(AWorldServer world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) { - BlockPos pos = blockpos.offset(facing); - int i = pos.getX(); - int j = pos.getY(); - int k = pos.getZ(); - BoundingBox axisalignedbb = new BoundingBox((double)i, (double)j, (double)k, (double)(i + 1), (double)(j + 1), (double)(k + 1)); - List list = world.getEntitiesWithinAABB(EntityNPC.class, axisalignedbb, new Predicate() { + BlockPos pos = blockpos.offset(facing); + int i = pos.getX(); + int j = pos.getY(); + int k = pos.getZ(); + BoundingBox axisalignedbb = new BoundingBox((double)i, (double)j, (double)k, (double)(i + 1), (double)(j + 1), (double)(k + 1)); + List list = world.getEntitiesWithinAABB(EntityNPC.class, axisalignedbb, new Predicate() { public boolean test(EntityNPC entity) { return entity.isEntityAlive() && entity.getArmor(ItemArmor.this.type) == null; } - }); + }); - if (list.size() > 0) - { - EntityNPC entitylivingbase = list.get(0); - entitylivingbase.setArmor(this.type, stack.copy(1)); - stack.decrSize(); - return stack; - } - else - { - return super.dispenseStack(world, source, position, blockpos, facing, stack); - } - } + if(list.size() > 0) { + EntityNPC entitylivingbase = list.get(0); + entitylivingbase.setArmor(this.type, stack.copy(1)); + stack.decrSize(); + return stack; + } + else { + return super.dispenseStack(world, source, position, blockpos, facing, stack); + } + } } diff --git a/common/src/main/java/common/item/material/ItemBottle.java b/common/src/main/java/common/item/material/ItemBottle.java index 007f89cb..43f5700e 100755 --- a/common/src/main/java/common/item/material/ItemBottle.java +++ b/common/src/main/java/common/item/material/ItemBottle.java @@ -53,9 +53,9 @@ public class ItemBottle extends Item return new ItemStack(Items.water_bottle); } - if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.water_bottle))) + if (!playerIn.addItemStackToInventory(new ItemStack(Items.water_bottle))) { - playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.water_bottle), false); + playerIn.dropItem(new ItemStack(Items.water_bottle), false); } } } diff --git a/common/src/main/java/common/item/material/ItemBucket.java b/common/src/main/java/common/item/material/ItemBucket.java index 8f67455b..ef25e5e7 100755 --- a/common/src/main/java/common/item/material/ItemBucket.java +++ b/common/src/main/java/common/item/material/ItemBucket.java @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Queue; import java.util.Set; -import common.attributes.Attribute; import common.block.Block; import common.block.Material; import common.block.liquid.BlockDynamicLiquid; @@ -16,6 +15,7 @@ import common.block.liquid.BlockLiquid; import common.block.liquid.BlockStaticLiquid; import common.collect.Maps; import common.collect.Sets; +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.init.Blocks; import common.init.Items; @@ -249,9 +249,9 @@ public class ItemBucket extends Item } else { - if (!player.inventory.addItemStackToInventory(fullBucket)) + if (!player.addItemStackToInventory(fullBucket)) { - player.dropPlayerItemWithRandomChoice(fullBucket, false); + player.dropItem(fullBucket, false); } return emptyBuckets; diff --git a/common/src/main/java/common/item/material/ItemMetal.java b/common/src/main/java/common/item/material/ItemMetal.java index b55a75f2..4592a3b0 100755 --- a/common/src/main/java/common/item/material/ItemMetal.java +++ b/common/src/main/java/common/item/material/ItemMetal.java @@ -2,7 +2,8 @@ package common.item.material; import java.util.List; import java.util.Map; -import common.attributes.Attribute; + +import common.entity.npc.Attribute; import common.entity.npc.EntityNPC; import common.init.MetalType; import common.item.Item; diff --git a/common/src/main/java/common/item/weapon/ItemBow.java b/common/src/main/java/common/item/weapon/ItemBow.java index 0884e2a2..721d9e7f 100755 --- a/common/src/main/java/common/item/weapon/ItemBow.java +++ b/common/src/main/java/common/item/weapon/ItemBow.java @@ -29,7 +29,7 @@ public class ItemBow extends Item { boolean flag = /* playerIn.creative || */ EnchantmentHelper.getEnchantmentLevel(Enchantment.INFINITY, stack) > 0; - if (flag || playerIn.inventory.hasItem(Items.arrow)) + if (flag || playerIn.hasItem(Items.arrow)) { int i = this.getMaxItemUseDuration(stack) - timeLeft; float f = (float)i / 20.0F; @@ -80,7 +80,7 @@ public class ItemBow extends Item } else { - playerIn.inventory.consumeInventoryItem(Items.arrow); + playerIn.consumeInventoryItem(Items.arrow); } // playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]); @@ -122,7 +122,7 @@ public class ItemBow extends Item */ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn) { - if (/* playerIn.creative || */ playerIn.inventory.hasItem(Items.arrow)) + if (/* playerIn.creative || */ playerIn.hasItem(Items.arrow)) { playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn)); } diff --git a/common/src/main/java/common/item/weapon/ItemGunBase.java b/common/src/main/java/common/item/weapon/ItemGunBase.java index f78ceec6..e2d74359 100755 --- a/common/src/main/java/common/item/weapon/ItemGunBase.java +++ b/common/src/main/java/common/item/weapon/ItemGunBase.java @@ -37,7 +37,7 @@ public abstract class ItemGunBase extends Item if(stack.getItemDamage() >= this.getMaxDamage()) return stack; boolean flag = EnchantmentHelper.getEnchantmentLevel(Enchantment.INFINITY, stack) > 0; - if (flag || player.inventory.hasItem(this.getAmmo())) + if (flag || player.hasItem(this.getAmmo())) { EntityBullet bullet = this.createBullet(world, player); bullet.setDamage(this.getAmmo().getDamage(stack)); @@ -53,7 +53,7 @@ public abstract class ItemGunBase extends Item world.playSoundAtEntity(player, this.getLaunchSound(), 1.0F); if(!flag) - player.inventory.consumeInventoryItem(this.getAmmo()); + player.consumeInventoryItem(this.getAmmo()); if (!world.client) { diff --git a/common/src/main/java/common/packet/SPacketSpawnPlayer.java b/common/src/main/java/common/packet/SPacketSpawnPlayer.java index 4f5e95e8..5631d54f 100755 --- a/common/src/main/java/common/packet/SPacketSpawnPlayer.java +++ b/common/src/main/java/common/packet/SPacketSpawnPlayer.java @@ -41,7 +41,7 @@ public class SPacketSpawnPlayer implements Packet this.z = ExtMath.floord(player.posZ * 32.0D); this.yaw = (byte)((int)(player.rotYaw * 256.0F / 360.0F)); this.pitch = (byte)((int)(player.rotPitch * 256.0F / 360.0F)); - ItemStack itemstack = player.inventory.getCurrentItem(); + ItemStack itemstack = player.getHeldItem(); this.currentItem = itemstack == null ? 0 : ItemRegistry.getId(itemstack.getItem()); this.watcher = player.getDataWatcher(); this.texture = player.getSkin(); diff --git a/common/src/main/java/common/tileentity/TileEntityBrewingStand.java b/common/src/main/java/common/tileentity/TileEntityBrewingStand.java index 5149f76c..136813f5 100755 --- a/common/src/main/java/common/tileentity/TileEntityBrewingStand.java +++ b/common/src/main/java/common/tileentity/TileEntityBrewingStand.java @@ -10,7 +10,7 @@ import common.init.Items; import common.inventory.Container; import common.inventory.ContainerBrewingStand; import common.inventory.ISidedInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.item.Item; import common.item.ItemStack; import common.item.consumable.ItemPotion; @@ -305,7 +305,7 @@ public class TileEntityBrewingStand extends TileEntityInventory implements ITick return true; } - public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) + public Container createContainer(EntityNPC playerInventory) { return new ContainerBrewingStand(playerInventory, this); } diff --git a/common/src/main/java/common/tileentity/TileEntityDispenser.java b/common/src/main/java/common/tileentity/TileEntityDispenser.java index a2a48f9c..1699d59e 100755 --- a/common/src/main/java/common/tileentity/TileEntityDispenser.java +++ b/common/src/main/java/common/tileentity/TileEntityDispenser.java @@ -5,7 +5,7 @@ import common.collect.Lists; import common.entity.npc.EntityNPC; import common.inventory.Container; import common.inventory.ContainerDispenser; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.rng.Random; import common.tags.TagObject; @@ -209,7 +209,7 @@ public class TileEntityDispenser extends TileEntityInventory implements ITickabl return true; } - public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) + public Container createContainer(EntityNPC playerInventory) { return new ContainerDispenser(playerInventory, this); } diff --git a/common/src/main/java/common/tileentity/TileEntityFurnace.java b/common/src/main/java/common/tileentity/TileEntityFurnace.java index a675cb21..241d2014 100755 --- a/common/src/main/java/common/tileentity/TileEntityFurnace.java +++ b/common/src/main/java/common/tileentity/TileEntityFurnace.java @@ -15,7 +15,7 @@ import common.inventory.Container; import common.inventory.ContainerFurnace; import common.inventory.IInventory; import common.inventory.ISidedInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.inventory.SlotFurnaceFuel; import common.item.Item; import common.item.ItemStack; @@ -432,7 +432,7 @@ public class TileEntityFurnace extends TileEntityInventory implements ITickable, return true; } - public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) + public Container createContainer(EntityNPC playerInventory) { return new ContainerFurnace(playerInventory, this); } diff --git a/common/src/main/java/common/tileentity/TileEntityHopper.java b/common/src/main/java/common/tileentity/TileEntityHopper.java index be993f58..8fc00688 100755 --- a/common/src/main/java/common/tileentity/TileEntityHopper.java +++ b/common/src/main/java/common/tileentity/TileEntityHopper.java @@ -15,7 +15,7 @@ import common.inventory.Container; import common.inventory.ContainerHopper; import common.inventory.IInventory; import common.inventory.ISidedInventory; -import common.inventory.InventoryPlayer; +import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.tags.TagObject; import common.util.BlockPos; @@ -702,9 +702,9 @@ public class TileEntityHopper extends TileEntityInventory implements ITickable return this.transferCooldown <= 1; } - public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) + public Container createContainer(EntityNPC playerInventory) { - return new ContainerHopper(playerInventory, this, playerIn); + return new ContainerHopper(playerInventory, this, playerInventory); } public int getField(int id) diff --git a/common/src/main/java/common/tileentity/TileEntityInventory.java b/common/src/main/java/common/tileentity/TileEntityInventory.java index 763de03e..39f29286 100755 --- a/common/src/main/java/common/tileentity/TileEntityInventory.java +++ b/common/src/main/java/common/tileentity/TileEntityInventory.java @@ -3,8 +3,7 @@ package common.tileentity; import common.entity.npc.EntityNPC; import common.inventory.Container; import common.inventory.IInventory; -import common.inventory.InventoryPlayer; public abstract class TileEntityInventory extends TileEntity implements IInventory { - public abstract Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn); + public abstract Container createContainer(EntityNPC player); } diff --git a/common/src/main/java/common/util/Equipment.java b/common/src/main/java/common/util/Equipment.java index f87e8693..0c27f1c9 100644 --- a/common/src/main/java/common/util/Equipment.java +++ b/common/src/main/java/common/util/Equipment.java @@ -1,6 +1,8 @@ package common.util; import common.enchantment.EnchantmentType; +import common.entity.animal.EntityHorse; +import common.entity.types.EntityLiving; import common.init.ToolMaterial; public enum Equipment implements Identifyable, Displayable { @@ -8,13 +10,16 @@ public enum Equipment implements Identifyable, Displayable { AXE("axe", "Axt", ItemType.TOOL, 3, "XX", "X#", " #"), SHOVEL("shovel", "Schaufel", ItemType.TOOL, 1, "X", "#", "#"), SHEARS("shears", "Schere", ItemType.OPTIONAL, " X", "X "), + SWORD("sword", "Schwert", ItemType.MELEE, 4, "X", "X", "#"), + HELMET("helmet", "Helm", "Kappe", 11, 0, EnchantmentType.ARMOR_HEAD, 1.0f, 1.0f, "XXX", "X X"), CHESTPLATE("chestplate", "Brustpanzer", "Jacke", 16, 1, EnchantmentType.ARMOR_TORSO, 1.7f, 1.2f, "X X", "XXX", "XXX"), LEGGINGS("leggings", "Beinschutz", "Hose", 15, 2, EnchantmentType.ARMOR_LEGS, 1.6f, 1.1f, "XXX", "X X", "X X"), BOOTS("boots", "Stiefel", "Stiefel", 13, 3, EnchantmentType.ARMOR_FEET, 1.4f, 1.0f, "X X", "X X"), - HORSE_ARMOR("horse_armor", "Pferderüstung", ItemType.ANIMAL, 16, "X X", "XXX", "XXX"); + HORSE_ARMOR("horse_armor", "Pferderüstung", EntityHorse.class, "X X", "XXX", "XXX"); + public static final int ARMOR_SLOTS; public static final Equipment[] ARMOR; @@ -28,7 +33,8 @@ public enum Equipment implements Identifyable, Displayable { private final float phyResist; private final float magicResist; private final EnchantmentType enchType; - + private final Class animalType; + static { int slots = 0; for(Equipment slot : values()) { @@ -43,33 +49,38 @@ public enum Equipment implements Identifyable, Displayable { } } - private Equipment(String name, String display, String altDisplay, ItemType type, int damage, int index, EnchantmentType ench, float phy, float mag, String ... recipe) { + private Equipment(String name, String display, String alt, ItemType type, int dmg, int index, EnchantmentType ench, float phy, float mag, Class clazz, String... recipe) { this.name = name; this.display = display; - this.altDisplay = altDisplay; + this.altDisplay = alt; this.type = type; - this.damage = damage; + this.damage = dmg; this.recipe = recipe; this.index = index; this.phyResist = phy; this.magicResist = mag; this.enchType = ench; + this.animalType = clazz; } - private Equipment(String name, String display, ItemType type, int damage, String ... recipe) { - this(name, display, null, type, damage, -1, null, 0.0f, 0.0f, recipe); + private Equipment(String name, String display, ItemType type, int damage, String... recipe) { + this(name, display, null, type, damage, -1, null, 0.0f, 0.0f, null, recipe); } - private Equipment(String name, String display, ItemType type, String ... recipe) { + private Equipment(String name, String display, ItemType type, String... recipe) { this(name, display, type, -1, recipe); } - private Equipment(String name, String display, String altDisplay, int damage, int index, EnchantmentType ench, float rad, float mag, String ... recipe) { - this(name, display, altDisplay, ItemType.ARMOR, damage, index, ench, rad, mag, recipe); + private Equipment(String name, String display, Class clazz, String... recipe) { + this(name, display, null, ItemType.ANIMAL, -1, -1, null, 0.0f, 0.0f, clazz, recipe); } - private Equipment(String name, String display, int damage, int index, EnchantmentType ench, float rad, float mag, String ... recipe) { - this(name, display, null, ItemType.AUX, damage, index, ench, rad, mag, recipe); + private Equipment(String name, String display, String altDisplay, int damage, int index, EnchantmentType ench, float phy, float mag, String... recipe) { + this(name, display, altDisplay, ItemType.ARMOR, damage, index, ench, phy, mag, null, recipe); + } + + private Equipment(String name, String display, int damage, int index, EnchantmentType ench, float mag, String... recipe) { + this(name, display, null, ItemType.AUX, damage, index, ench, 0.0f, mag, null, recipe); } public String toString() { @@ -88,47 +99,48 @@ public enum Equipment implements Identifyable, Displayable { String display = alt && this.altDisplay != null ? this.altDisplay : this.display; return prefix == null ? display : prefix + display.toLowerCase(); } - + public boolean canRegister(ToolMaterial material) { - return this.isArmor() ? material.hasArmor() && (!this.isAnimalArmor() || material.hasExtras()) : (this.isMelee() ? material.hasWeapons() : (this.isOptional() ? material.hasExtras() : material.hasTools())); + return this.isArmor() ? material.hasArmor() && (!this.isAnimalArmor() || material.hasExtras()) + : (this.isMelee() ? material.hasWeapons() : (this.isOptional() ? material.hasExtras() : material.hasTools())); } - + public ItemType getType() { return this.type; } - + public boolean isLevelled() { return this.type == ItemType.LEVELLED; } - + public boolean isMelee() { return this.type == ItemType.MELEE; } - + public boolean isOptional() { return this.type == ItemType.OPTIONAL; } - + public boolean isArmor() { return this.type == ItemType.ARMOR || this.type == ItemType.AUX || this.type == ItemType.ANIMAL; } - - public boolean isArmorRendered() { + + public boolean isMainArmor() { return this.type == ItemType.ARMOR || this.type == ItemType.ANIMAL; } - + public boolean isAnimalArmor() { return this.type == ItemType.ANIMAL; } - + public int getDamage() { return this.damage; } - + public String[] getRecipe() { return this.recipe; } - + public int getIndex() { return this.index; } @@ -140,8 +152,12 @@ public enum Equipment implements Identifyable, Displayable { public float getMagicalResistance() { return this.magicResist; } - + public EnchantmentType getEnchantmentType() { return this.enchType; } + + public Class getAnimalType() { + return this.animalType; + } } diff --git a/server/src/main/java/server/Server.java b/server/src/main/java/server/Server.java index c053e4fb..f6dbd865 100755 --- a/server/src/main/java/server/Server.java +++ b/server/src/main/java/server/Server.java @@ -930,7 +930,7 @@ public final class Server implements IThreadListener, Executor { conn.sendPacket(new SPacketServerConfig(vars)); conn.sendPacket(new SPacketDimensions(Dimensions.getDimensionData())); conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, UniverseRegistry.getName(world.dimension), EntityRegistry.getEntityID(player), tag == null)); - conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem)); + conn.sendPacket(new SPacketHeldItemChange(player.getSelectedIndex())); this.sendPacket(new SPacketPlayerListItem(false, conn)); world.spawnEntityInWorld(player); @@ -1206,7 +1206,7 @@ public final class Server implements IThreadListener, Executor { public void syncPlayerInventory(EntityNPC player) { player.connection.sendContainer(player.inventoryContainer, player.inventoryContainer.getInventory()); player.connection.setPlayerHealthUpdated(); - player.connection.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem)); + player.connection.sendPacket(new SPacketHeldItemChange(player.getSelectedIndex())); } private void terminateEndpoint(String message) { diff --git a/server/src/main/java/server/command/commands/CommandClear.java b/server/src/main/java/server/command/commands/CommandClear.java index 6a566058..3ea90f22 100644 --- a/server/src/main/java/server/command/commands/CommandClear.java +++ b/server/src/main/java/server/command/commands/CommandClear.java @@ -4,7 +4,6 @@ import java.util.List; import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; -import common.util.Equipment; import server.command.Command; import server.command.CommandEnvironment; import server.command.Executor; @@ -21,16 +20,11 @@ public class CommandClear extends Command { int done = 0; for(EntityLiving entity : entities) { if(entity instanceof EntityNPC) { - if(entity.isPlayer()) { - ((EntityNPC)entity).inventory.clearItems(); - } - else { - ((EntityNPC)entity).getExtendedInventory().clear(); + ((EntityNPC)entity).clear(); + if(entity.isPlayer()) + ((EntityNPC)entity).setMouseItem(null); + else ((EntityNPC)entity).setHeldItem(null); - for(Equipment slot : Equipment.ARMOR) { - ((EntityNPC)entity).setArmor(slot, null); - } - } exec.log("Inventar von %s gelöscht", entity.getCommandName()); done++; } diff --git a/server/src/main/java/server/command/commands/CommandItem.java b/server/src/main/java/server/command/commands/CommandItem.java index e4a8b820..684acfe8 100644 --- a/server/src/main/java/server/command/commands/CommandItem.java +++ b/server/src/main/java/server/command/commands/CommandItem.java @@ -45,7 +45,7 @@ public class CommandItem extends Command { while(total > 0) { int added = Math.min(total, stack.getMaxStackSize()); ItemStack st = stack.copy(added); - player.inventory.addItemStackToInventory(st); + player.addItemStackToInventory(st); added -= st.getSize(); if(added <= 0) break; diff --git a/server/src/main/java/server/command/commands/CommandMore.java b/server/src/main/java/server/command/commands/CommandMore.java index 2d6dff85..88fb5961 100644 --- a/server/src/main/java/server/command/commands/CommandMore.java +++ b/server/src/main/java/server/command/commands/CommandMore.java @@ -31,11 +31,8 @@ public class CommandMore extends Command { for(EntityNPC player : players) { int add = 0; if(all) { - for(ItemStack item : player.inventory.mainInventory) { - if(item != null) - add += this.addItems(item); - } - for(ItemStack item : player.inventory.armorInventory) { + for(int z = 0; z < player.getSizeInventory(); z++) { + ItemStack item = player.getStackInSlot(z); if(item != null) add += this.addItems(item); } diff --git a/server/src/main/java/server/command/commands/CommandRepair.java b/server/src/main/java/server/command/commands/CommandRepair.java index 23abc7b0..ca84b803 100644 --- a/server/src/main/java/server/command/commands/CommandRepair.java +++ b/server/src/main/java/server/command/commands/CommandRepair.java @@ -38,11 +38,8 @@ public class CommandRepair extends Command { for(EntityNPC player : players) { int rep = 0; if(all) { - for(ItemStack item : player.inventory.mainInventory) { - if(item != null && this.fixItem(item)) - rep++; - } - for(ItemStack item : player.inventory.armorInventory) { + for(int z = 0; z < player.getSizeInventory(); z++) { + ItemStack item = player.getStackInSlot(z); if(item != null && this.fixItem(item)) rep++; } diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index fcf17d0e..f267111b 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -40,7 +40,6 @@ import common.inventory.ContainerMerchant; import common.inventory.ContainerTile; import common.inventory.IInventory; import common.inventory.InventoryBasic; -import common.inventory.InventoryPlayer; import common.inventory.Slot; import common.inventory.SlotCrafting; import common.item.Item; @@ -289,7 +288,15 @@ public class Player extends User implements Executor, IPlayer if (!Vars.keepInventory && Vars.playerDrop) { - this.entity.inventory.dropAllItems(); + for (int i = 0; i < this.entity.getSizeInventory(); ++i) + { + ItemStack stack = this.entity.getStackInSlot(i); + if (stack != null) + { + this.entity.dropItem(stack, true, false); + this.entity.setInventorySlotContents(i, null); + } + } } if(Vars.skullDrop) { ItemStack stack = new ItemStack(Items.skull); @@ -411,11 +418,11 @@ public class Player extends User implements Executor, IPlayer this.currentFormId = this.currentFormId % 100 + 1; } - public void updateHeldItem() + public void updateMouseItem() { if (!this.isChangingQuantityOnly) { - this.sendPacket(new SPacketSetSlot(-1, -1, this.entity.inventory.getItemStack())); + this.sendPacket(new SPacketSetSlot(-1, -1, this.entity.getMouseItem())); } } @@ -447,8 +454,12 @@ public class Player extends User implements Executor, IPlayer { this.lastExperience = -1; this.lastHealth = -1.0F; - if(Vars.keepInventory) - this.entity.inventory.copyInventory(oldPlayer.inventory); + if(Vars.keepInventory) { + for(int z = 0; z < this.entity.getSizeInventory(); z++) { + this.entity.setInventorySlotContents(z, ItemStack.copy(oldPlayer.getStackInSlot(z))); + } + this.entity.setSelectedIndex(oldPlayer.getSelectedIndex()); + } this.entity.experienceLevel = oldPlayer.experienceLevel; this.entity.experienceTotal = oldPlayer.experienceTotal; this.entity.experience = oldPlayer.experience; @@ -665,19 +676,19 @@ public class Player extends User implements Executor, IPlayer this.sendPacket(new SPacketSignEditorOpen(sign.getPos())); return; } - else if(object instanceof EntityNPC npc) { + else if(object instanceof EntityNPC npc && !npc.isPlayer()) { this.getNextWindowId(); - this.entity.openContainer = new ContainerMerchant(this.entity.inventory, npc, this.entity.worldObj); + this.entity.openContainer = new ContainerMerchant(this.entity, npc, this.entity.worldObj); } - else if(object instanceof Entity entity) { + else if(object instanceof Entity entity && !entity.isPlayer()) { InventoryBasic inv = entity.getEntityInventory(); this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), entity.getId(), inv.getSizeInventory())); - this.entity.openContainer = new ContainerEntityInventory(this.entity.inventory, inv, entity, this.entity); + this.entity.openContainer = new ContainerEntityInventory(this.entity, inv, entity); } else if (object instanceof Device device) { this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), device.getPos(), device.getSizeInventory())); - this.entity.openContainer = new ContainerTile(this.entity.inventory, device, device, this.entity); + this.entity.openContainer = new ContainerTile(this.entity, device, device); } else if (object instanceof TileEntityChest chest) { @@ -688,17 +699,17 @@ public class Player extends User implements Executor, IPlayer return; } this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), chest.getBlockType(), chest.getSizeInventory())); - this.entity.openContainer = new ContainerChest(this.entity.inventory, chest, this.entity); + this.entity.openContainer = new ContainerChest(this.entity, chest); } else if (object instanceof TileEntityInventory tile) { this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), tile.getBlockType(), tile.getSizeInventory())); - this.entity.openContainer = tile.createContainer(this.entity.inventory, this.entity); + this.entity.openContainer = tile.createContainer(this.entity); } else if (object instanceof InteractionObject obj) { this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), obj.getBlock(), 0)); - this.entity.openContainer = obj.createContainer(this.entity.inventory, this.entity); + this.entity.openContainer = obj.createContainer(this.entity); } else { return; @@ -707,7 +718,7 @@ public class Player extends User implements Executor, IPlayer this.entity.openContainer.windowId = this.currentWindowId; this.entity.openContainer.onCraftGuiOpened(this); - if(object instanceof EntityNPC npc) { + if(object instanceof EntityNPC npc && !npc.isPlayer()) { IInventory merchant = ((ContainerMerchant)this.entity.openContainer).getMerchantInventory(); this.sendPacket(new SPacketOpenWindow(this.currentWindowId, npc.getId(), merchant.getSizeInventory())); MerchantRecipeList trades = npc.getTrades(this.entity); @@ -807,7 +818,7 @@ public class Player extends User implements Executor, IPlayer public void sendContainer(Container container, List items) { this.sendPacket(new SPacketWindowItems(container.windowId, items)); - this.sendPacket(new SPacketSetSlot(-1, -1, this.entity.inventory.getItemStack())); + this.sendPacket(new SPacketSetSlot(-1, -1, this.entity.getMouseItem())); } public void sendProperty(Container container, int variable, int value) @@ -959,7 +970,6 @@ public class Player extends User implements Executor, IPlayer this.entity.openContainer.detectAndSendChanges(); // if(!this.worldObj.client) - this.entity.inventoryContainer.detectAttributeChanges(); if (/* !this.worldObj.client && */ !this.entity.openContainer.canInteractWith(this.entity)) { @@ -1102,7 +1112,7 @@ public class Player extends User implements Executor, IPlayer if(this.onPlayerInteract(true, pos)) { this.sendPacket(new SPacketBlockChange(this.entity.worldObj, pos)); if(this.entity.getHeldItem() != null && this.entity.getHeldItem().isEmpty()) - this.entity.inventory.mainInventory[this.entity.inventory.currentItem] = null; + this.entity.setHeldItem(null); this.entity.openContainer.detectAndSendChanges(); return; } @@ -1220,7 +1230,7 @@ public class Player extends User implements Executor, IPlayer if (itemstack1.isEmpty()) { - this.entity.destroyCurrentEquippedItem(); + this.entity.setHeldItem(null); } } @@ -1245,11 +1255,11 @@ public class Player extends User implements Executor, IPlayer if (itemstack != stack || itemstack != null && (itemstack.getSize() != i || itemstack.getMaxItemUseDuration() > 0 || itemstack.getItemDamage() != j)) { - this.entity.inventory.mainInventory[this.entity.inventory.currentItem] = itemstack; + this.entity.setHeldItem(itemstack); if (itemstack.isEmpty()) { - this.entity.inventory.mainInventory[this.entity.inventory.currentItem] = null; + this.entity.setHeldItem(null); } if (!this.entity.isUsingItem()) @@ -1265,7 +1275,7 @@ public class Player extends User implements Executor, IPlayer this.sendPacket(new SPacketBlockChange(this.entity.worldObj, pos)); stack.getItem().onItemUse(stack, this.entity, this.entity.worldObj, pos, side, offsetX, offsetY, offsetZ); if(stack.isEmpty()) - this.entity.inventory.mainInventory[this.entity.inventory.currentItem] = null; + this.entity.setHeldItem(null); this.entity.openContainer.detectAndSendChanges(); return false; } @@ -1948,7 +1958,7 @@ public class Player extends User implements Executor, IPlayer if(msg.length() > 30) throw new IllegalArgumentException("Ungültiger Name"); if(packetIn.getArg() == -1) - this.entity.inventoryContainer.renameItem(36 + this.entity.inventory.currentItem, msg); + this.entity.inventoryContainer.renameItem(36 + this.entity.getSelectedIndex(), msg); else this.entity.openContainer.renameItem(packetIn.getArg(), msg); this.entity.openContainer.detectAndSendChanges(); @@ -2320,7 +2330,7 @@ public class Player extends User implements Executor, IPlayer if(this.charEditor) return; WorldServer worldserver = this.getEntityWorld(); // this.serverController.getWorld(this.playerEntity.dimension); - ItemStack itemstack = this.entity.inventory.getCurrentItem(); + ItemStack itemstack = this.entity.getHeldItem(); boolean flag = false; BlockPos blockpos = packetIn.getPosition(); Facing enumfacing = Facing.getFront(packetIn.getPlacedBlockDirection()); @@ -2361,25 +2371,25 @@ public class Player extends User implements Executor, IPlayer this.entity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos.offset(enumfacing))); } - itemstack = this.entity.inventory.getCurrentItem(); + itemstack = this.entity.getHeldItem(); if (itemstack != null && itemstack.isEmpty()) { - this.entity.inventory.mainInventory[this.entity.inventory.currentItem] = null; + this.entity.setHeldItem(null); itemstack = null; } if (itemstack == null || itemstack.getMaxItemUseDuration() == 0) { this.isChangingQuantityOnly = true; - this.entity.inventory.mainInventory[this.entity.inventory.currentItem] = ItemStack.copy(this.entity.inventory.mainInventory[this.entity.inventory.currentItem]); - Slot slot = this.entity.openContainer.getSlotFromInventory(this.entity.inventory, this.entity.inventory.currentItem); + this.entity.setHeldItem(ItemStack.copy(this.entity.getHeldItem())); + Slot slot = this.entity.openContainer.getSlotFromInventory(this.entity, this.entity.getSelectedIndex()); this.entity.openContainer.detectAndSendChanges(); this.isChangingQuantityOnly = false; - if (!ItemStack.allEquals(this.entity.inventory.getCurrentItem(), packetIn.getStack())) + if (!ItemStack.allEquals(this.entity.getHeldItem(), packetIn.getStack())) { - this.sendPacket(new SPacketSetSlot(this.entity.openContainer.windowId, slot.slotNumber, this.entity.inventory.getCurrentItem())); + this.sendPacket(new SPacketSetSlot(this.entity.openContainer.windowId, slot.slotNumber, this.entity.getHeldItem())); } } } @@ -2590,10 +2600,10 @@ public class Player extends User implements Executor, IPlayer break; case SET_ITEMSLOT: - if(packetIn.getAuxData() >= 0 && packetIn.getAuxData() < InventoryPlayer.getHotbarSize()) { - if(packetIn.getAuxData() != this.entity.inventory.currentItem) + if(packetIn.getAuxData() >= 0 && packetIn.getAuxData() < 9) { + if(packetIn.getAuxData() != this.entity.getSelectedIndex()) this.itemUseCooldown = 0; - this.entity.inventory.currentItem = packetIn.getAuxData(); + this.entity.setSelectedIndex(packetIn.getAuxData()); } // else // Log.warn(this.user + " versuchte, einen ungültigen Slot zu wählen"); @@ -2639,7 +2649,7 @@ public class Player extends User implements Executor, IPlayer item.getItem().onAction(item, this.entity, this.entity.worldObj, ItemControl.values()[packetIn.getAuxData() % ItemControl.values().length], null); if(item.isEmpty()) - this.entity.inventory.mainInventory[this.entity.inventory.currentItem] = null; + this.entity.setHeldItem(null); this.entity.openContainer.detectAndSendChanges(); } break; @@ -2686,15 +2696,8 @@ public class Player extends User implements Executor, IPlayer case REPAIR: if(this.isAdmin()) { if(packetIn.getAuxData() != 0) { - for(ItemStack stack : this.entity.inventory.mainInventory) { - if(stack != null) { - stack.setSize(stack.getMaxStackSize()); - stack.setRepairCost(0); - if(stack.getItem().getMaxDamage() > 0) - stack.setItemDamage(0); - } - } - for(ItemStack stack : this.entity.inventory.armorInventory) { + for(int z = 0; z < this.entity.getSizeInventory(); z++) { + ItemStack stack = this.entity.getStackInSlot(z); if(stack != null) { stack.setSize(stack.getMaxStackSize()); stack.setRepairCost(0); @@ -2796,15 +2799,15 @@ public class Player extends User implements Executor, IPlayer break; case CRAFT_ITEM: { - if(this.entity.inventory.getItemStack() == null) { + if(this.entity.getMouseItem() == null) { Slot slot = this.entity.openContainer.getSlot(packetIn.getAuxData()); if(slot != null && slot.canCheatItem() && slot.getHasStack()) { ItemStack stack = this.entity.inventoryContainer.getSingleRecipe(slot.getStack()); if(stack != null) { slot.putStack(this.entity.inventoryContainer.craftSingleRecipe(slot.getStack())); - this.entity.inventory.setItemStack(stack); + this.entity.setMouseItem(stack); this.entity.openContainer.detectAndSendChanges(); - this.updateHeldItem(); + this.updateMouseItem(); } } } @@ -2852,7 +2855,7 @@ public class Player extends User implements Executor, IPlayer this.entity.connection.sendPacket(new SPacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), true)); this.isChangingQuantityOnly = true; this.entity.openContainer.detectAndSendChanges(); - this.updateHeldItem(); + this.updateMouseItem(); this.isChangingQuantityOnly = false; } else @@ -2886,7 +2889,7 @@ public class Player extends User implements Executor, IPlayer if(amount <= 0) return; if(packet.getSlot() == -1) { - this.entity.inventory.addItemStackToInventory(stack); + this.entity.addItemStackToInventory(stack); amount -= stack.getSize(); if(amount <= 0) return;