item slot refactor

This commit is contained in:
Sen 2025-08-01 18:19:14 +02:00
parent c3f9655338
commit 6fb9ded711
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
90 changed files with 1177 additions and 1622 deletions

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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<Attribute, Float> mods = stack.getAttributeModifiers(null);
Map<Attribute, Float> 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);

View file

@ -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();

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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);

View file

@ -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
{

View file

@ -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;
}
}

View file

@ -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<? extends EntityLiving> 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();

View file

@ -26,7 +26,7 @@ public class LayerArmor implements LayerRenderer<EntityNPC>
static {
List<Equipment> 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()]);

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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));
}
}

View file

@ -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);
}
}

View file

@ -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)));
}
}
}

View file

@ -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<Integer, Float> slots = Maps.<Integer, Float>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<Attribute, AttributeInstance> attributes = Maps.<Attribute, AttributeInstance>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<Attribute, Float> modifiers, int slot) {
for(Entry<Attribute, Float> entry : modifiers.entrySet()) {
this.attributes.get(entry.getKey()).removeModifier(slot);
}
}
public void add(Map<Attribute, Float> modifiers, int slot, int amount) {
for(Entry<Attribute, Float> entry : modifiers.entrySet()) {
this.attributes.get(entry.getKey()).applyModifier(slot, entry.getValue() * (float)amount);
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
}
// }

View file

@ -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);
}

View file

@ -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()

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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();

View file

@ -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);

View file

@ -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)

View file

@ -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;

View file

@ -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;
}
/**

View file

@ -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())
{

View file

@ -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)

View file

@ -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)
// {

View file

@ -1,4 +1,4 @@
package common.attributes;
package common.entity.npc;
public enum Attribute {
RADIATION("Strahlung"),

View file

@ -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));

View file

@ -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)
{

File diff suppressed because it is too large Load diff

View file

@ -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;
}

View file

@ -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();

View file

@ -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;

View file

@ -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<CombatEntry> combat = Lists.<CombatEntry>newArrayList();
private final Map<Effect, StatusEffect> effects = Maps.<Effect, StatusEffect>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);
}
// }
}

View file

@ -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)));
}
}

View file

@ -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;

View file

@ -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)

View file

@ -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));
}
}

View file

@ -26,12 +26,12 @@ public class ContainerEnchantment extends Container
public int[] mana;
public Pair<Enchantment, Integer>[] 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);
}
}
}

View file

@ -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));
}
}

View file

@ -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)
{

View file

@ -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);

View file

@ -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);
}
}
}

View file

@ -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<ItemStack> lastStacks = Lists.<ItemStack>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))
{

View file

@ -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);
}
}
}

View file

@ -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));
}
}

View file

@ -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);
}
}
}

View file

@ -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_);
}

View file

@ -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.
*/

View file

@ -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<TagObject> toTag(List<TagObject> 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<TagObject> 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;
}
}
}

View file

@ -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);
}
}
}

View file

@ -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;

View file

@ -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<Attribute, Float> getAttributeModifiers(Equipment slot) {
public Map<Attribute, Float> getAttributeModifiers() {
Map<Attribute, Float> 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<Attribute, Float> getArmorModifiers(Equipment slot) {
Map<Attribute, Float> 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);
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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<String> tooltip)
{
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> 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<Attribute, Float> 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<Attribute, Float> 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<EntityNPC> list = world.<EntityNPC>getEntitiesWithinAABB(EntityNPC.class, axisalignedbb, new Predicate<EntityNPC>() {
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<EntityNPC> list = world.<EntityNPC>getEntitiesWithinAABB(EntityNPC.class, axisalignedbb, new Predicate<EntityNPC>() {
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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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));
}

View file

@ -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)
{

View file

@ -41,7 +41,7 @@ public class SPacketSpawnPlayer implements Packet<IClientPlayer>
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();

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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)

View file

@ -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);
}

View file

@ -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<? extends EntityLiving> 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<? extends EntityLiving> 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<? extends EntityLiving> 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<? extends EntityLiving> getAnimalType() {
return this.animalType;
}
}

View file

@ -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) {

View file

@ -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++;
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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++;
}

View file

@ -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<ItemStack> 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;