add item deselect
This commit is contained in:
parent
f123a599a2
commit
ac65a43bbc
20 changed files with 84 additions and 78 deletions
|
@ -452,7 +452,7 @@ public class Client implements IThreadListener {
|
||||||
private final List<ChunkClient> chunkListing = Lists.<ChunkClient>newArrayList();
|
private final List<ChunkClient> chunkListing = Lists.<ChunkClient>newArrayList();
|
||||||
private final Set<Long> emptyChunkListing = Sets.<Long>newHashSet();
|
private final Set<Long> emptyChunkListing = Sets.<Long>newHashSet();
|
||||||
private final Set<Long> nextEmptyChunkListing = Sets.<Long>newHashSet();
|
private final Set<Long> nextEmptyChunkListing = Sets.<Long>newHashSet();
|
||||||
private final int[] lastSelection = new int[ItemCategory.values().length];
|
public final int[] lastSelection = new int[ItemCategory.values().length];
|
||||||
|
|
||||||
private boolean primary;
|
private boolean primary;
|
||||||
private boolean secondary;
|
private boolean secondary;
|
||||||
|
@ -573,9 +573,9 @@ public class Client implements IThreadListener {
|
||||||
public LocalPos pointedLiquid;
|
public LocalPos pointedLiquid;
|
||||||
public DisplayMode vidMode;
|
public DisplayMode vidMode;
|
||||||
public String dimensionName;
|
public String dimensionName;
|
||||||
|
public ItemCategory itemSelection = ItemCategory.USEABLE;
|
||||||
private ChunkClient emptyChunk;
|
private ChunkClient emptyChunk;
|
||||||
private ChunkClient outsideChunk;
|
private ChunkClient outsideChunk;
|
||||||
private ItemCategory itemSelection = ItemCategory.USEABLE;
|
|
||||||
|
|
||||||
private List<Entity> entities;
|
private List<Entity> entities;
|
||||||
private List<Entity> unloaded;
|
private List<Entity> unloaded;
|
||||||
|
@ -1557,6 +1557,8 @@ public class Client implements IThreadListener {
|
||||||
private void select(int dir) {
|
private void select(int dir) {
|
||||||
int last = this.player.getSelectedIndex();
|
int last = this.player.getSelectedIndex();
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
if(last < 0)
|
||||||
|
this.player.setSelectedIndex(0);
|
||||||
do {
|
do {
|
||||||
this.player.setSelectedIndex(this.player.getSelectedIndex() + dir);
|
this.player.setSelectedIndex(this.player.getSelectedIndex() + dir);
|
||||||
if(this.player.getSelectedIndex() < 0)
|
if(this.player.getSelectedIndex() < 0)
|
||||||
|
@ -1574,9 +1576,10 @@ public class Client implements IThreadListener {
|
||||||
|
|
||||||
private void category(int dir) {
|
private void category(int dir) {
|
||||||
ItemCategory last = this.itemSelection;
|
ItemCategory last = this.itemSelection;
|
||||||
this.lastSelection[last.ordinal()] = this.player.getSelectedIndex();
|
this.lastSelection[last.ordinal()] = this.player.getSelectedIndex() >= 0 ? this.player.getSelectedIndex() : 0;
|
||||||
int total;
|
int total;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
boolean any = false;
|
||||||
do {
|
do {
|
||||||
this.itemSelection = ItemCategory.values()[(ItemCategory.values().length + this.itemSelection.ordinal() + dir) % ItemCategory.values().length];
|
this.itemSelection = ItemCategory.values()[(ItemCategory.values().length + this.itemSelection.ordinal() + dir) % ItemCategory.values().length];
|
||||||
total = 0;
|
total = 0;
|
||||||
|
@ -1584,6 +1587,7 @@ public class Client implements IThreadListener {
|
||||||
if(this.player.getStackInSlot(z) != null && this.player.getStackInSlot(z).getItem().getCategory() == this.itemSelection)
|
if(this.player.getStackInSlot(z) != null && this.player.getStackInSlot(z).getItem().getCategory() == this.itemSelection)
|
||||||
++total;
|
++total;
|
||||||
}
|
}
|
||||||
|
any |= total > 0;
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
while(total <= 0 && n < ItemCategory.values().length);
|
while(total <= 0 && n < ItemCategory.values().length);
|
||||||
|
@ -1592,6 +1596,9 @@ public class Client implements IThreadListener {
|
||||||
this.controller.resetUseCooldown();
|
this.controller.resetUseCooldown();
|
||||||
this.player.setSelectedIndex(Math.min(this.lastSelection[this.itemSelection.ordinal()], this.player.getHotbarSize() - 1));
|
this.player.setSelectedIndex(Math.min(this.lastSelection[this.itemSelection.ordinal()], this.player.getHotbarSize() - 1));
|
||||||
}
|
}
|
||||||
|
else if(!any) {
|
||||||
|
this.player.setSelectedIndex(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveCamera(float x, float y) {
|
public void moveCamera(float x, float y) {
|
||||||
|
@ -1679,7 +1686,7 @@ public class Client implements IThreadListener {
|
||||||
this.player.swingItem();
|
this.player.swingItem();
|
||||||
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.PRIMARY.ordinal()));
|
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.PRIMARY.ordinal()));
|
||||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||||
this.player.setHeldItem(null);
|
this.player.clearHeldItem();
|
||||||
this.leftClickCounter = 10;
|
this.leftClickCounter = 10;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1733,7 +1740,7 @@ public class Client implements IThreadListener {
|
||||||
this.player.swingItem();
|
this.player.swingItem();
|
||||||
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.SECONDARY.ordinal()));
|
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.SECONDARY.ordinal()));
|
||||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||||
this.player.setHeldItem(null);
|
this.player.clearHeldItem();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1767,7 +1774,7 @@ public class Client implements IThreadListener {
|
||||||
|
|
||||||
if (itemstack.isEmpty())
|
if (itemstack.isEmpty())
|
||||||
{
|
{
|
||||||
this.player.setHeldItem(null);
|
this.player.clearHeldItem();
|
||||||
}
|
}
|
||||||
else if (itemstack.getSize() != i)
|
else if (itemstack.getSize() != i)
|
||||||
{
|
{
|
||||||
|
@ -1796,7 +1803,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)) {
|
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()));
|
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.TERTIARY.ordinal()));
|
||||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||||
this.player.setHeldItem(null);
|
this.player.clearHeldItem();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1813,7 +1820,7 @@ public class Client implements IThreadListener {
|
||||||
this.player.setSelectedIndex(idx);
|
this.player.setSelectedIndex(idx);
|
||||||
this.controller.resetUseCooldown();
|
this.controller.resetUseCooldown();
|
||||||
}
|
}
|
||||||
if(this.itemCheat) {
|
if(this.itemCheat && this.player.getSelectedIndex() >= 0) {
|
||||||
this.player.client.addToSendQueue(new CPacketCheat(item, -2 - this.player.getSelectedIndex(), this.ctrl()));
|
this.player.client.addToSendQueue(new CPacketCheat(item, -2 - this.player.getSelectedIndex(), this.ctrl()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1826,7 +1833,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)) {
|
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()));
|
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.QUARTERNARY.ordinal()));
|
||||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||||
this.player.setHeldItem(null);
|
this.player.clearHeldItem();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,7 +510,7 @@ public class ClientPlayer implements IClientPlayer
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -568,11 +568,15 @@ public class ClientPlayer implements IClientPlayer
|
||||||
{
|
{
|
||||||
NetHandler.checkThread(packetIn, this, this.gm, this.world);
|
NetHandler.checkThread(packetIn, this, this.gm, this.world);
|
||||||
|
|
||||||
if (packetIn.getHeldItemHotbarIndex() >= 0 && packetIn.getHeldItemHotbarIndex() < this.gm.player.getHotbarSize())
|
if (packetIn.getHeldItemHotbarIndex() >= -1 && packetIn.getHeldItemHotbarIndex() < this.gm.player.getHotbarSize())
|
||||||
{
|
{
|
||||||
if(this.gm.player.getSelectedIndex() != packetIn.getHeldItemHotbarIndex())
|
if(this.gm.player.getSelectedIndex() != packetIn.getHeldItemHotbarIndex())
|
||||||
this.gm.controller.resetUseCooldown();
|
this.gm.controller.resetUseCooldown();
|
||||||
this.gm.player.setSelectedIndex(packetIn.getHeldItemHotbarIndex());
|
this.gm.player.setSelectedIndex(packetIn.getHeldItemHotbarIndex());
|
||||||
|
if(this.gm.player.getHeldItem() != null && this.gm.player.getHeldItem().getItem().getCategory() != null) {
|
||||||
|
this.gm.itemSelection = this.gm.player.getHeldItem().getItem().getCategory();
|
||||||
|
this.gm.lastSelection[this.gm.itemSelection.ordinal()] = this.gm.player.getSelectedIndex();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class PlayerController {
|
||||||
stack.getItem().onBlockDestroyed(stack, world, block, pos, this.gm.player);
|
stack.getItem().onBlockDestroyed(stack, world, block, pos, this.gm.player);
|
||||||
|
|
||||||
if(stack.isEmpty()) {
|
if(stack.isEmpty()) {
|
||||||
this.gm.player.setHeldItem(null);
|
this.gm.player.clearHeldItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class PlayerController {
|
||||||
this.interacting = true;
|
this.interacting = true;
|
||||||
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, pos, face));
|
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, pos, face));
|
||||||
if(this.gm.player.getHeldItem() != null && this.gm.player.getHeldItem().isEmpty())
|
if(this.gm.player.getHeldItem() != null && this.gm.player.getHeldItem().isEmpty())
|
||||||
this.gm.player.setHeldItem(null);
|
this.gm.player.clearHeldItem();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(!this.hitting || !this.isHitting(pos)) {
|
if(!this.hitting || !this.isHitting(pos)) {
|
||||||
|
@ -260,7 +260,7 @@ public class PlayerController {
|
||||||
player.setHeldItem(changed);
|
player.setHeldItem(changed);
|
||||||
|
|
||||||
if(changed.isEmpty()) {
|
if(changed.isEmpty()) {
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class BlockFlowerPot extends Block
|
||||||
|
|
||||||
if (itemstack.decrSize())
|
if (itemstack.decrSize())
|
||||||
{
|
{
|
||||||
playerIn.setHeldItem(null);
|
playerIn.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class BlockCauldron extends Block
|
||||||
|
|
||||||
if (itemstack.decrSize())
|
if (itemstack.decrSize())
|
||||||
{
|
{
|
||||||
playerIn.setHeldItem(null);
|
playerIn.clearHeldItem();
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,7 @@ public class EntityCat extends EntityTameable
|
||||||
{
|
{
|
||||||
if (itemstack.decrSize())
|
if (itemstack.decrSize())
|
||||||
{
|
{
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.worldObj.client)
|
if (!this.worldObj.client)
|
||||||
|
|
|
@ -906,7 +906,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic {
|
||||||
{
|
{
|
||||||
if (itemstack.decrSize())
|
if (itemstack.decrSize())
|
||||||
{
|
{
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -270,7 +270,7 @@ public class EntityWolf extends EntityTameable
|
||||||
|
|
||||||
if (itemstack.decrSize())
|
if (itemstack.decrSize())
|
||||||
{
|
{
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -286,7 +286,7 @@ public class EntityWolf extends EntityTameable
|
||||||
|
|
||||||
if (itemstack.decrSize())
|
if (itemstack.decrSize())
|
||||||
{
|
{
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -306,7 +306,7 @@ public class EntityWolf extends EntityTameable
|
||||||
{
|
{
|
||||||
if (itemstack.decrSize())
|
if (itemstack.decrSize())
|
||||||
{
|
{
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.worldObj.client)
|
if (!this.worldObj.client)
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class EntityMage extends EntityNPC
|
||||||
{
|
{
|
||||||
this.drinking = false;
|
this.drinking = false;
|
||||||
ItemStack itemstack = this.getHeldItem();
|
ItemStack itemstack = this.getHeldItem();
|
||||||
this.setHeldItem(null);
|
this.clearHeldItem();
|
||||||
|
|
||||||
if (itemstack != null && itemstack.getItem() instanceof ItemPotion potion)
|
if (itemstack != null && itemstack.getItem() instanceof ItemPotion potion)
|
||||||
{
|
{
|
||||||
|
@ -115,7 +115,7 @@ public class EntityMage extends EntityNPC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.setHeldItem(null);
|
this.clearHeldItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,6 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
private boolean fleeing;
|
private boolean fleeing;
|
||||||
private boolean playing;
|
private boolean playing;
|
||||||
protected boolean noPickup;
|
protected boolean noPickup;
|
||||||
private ItemStack heldItem;
|
|
||||||
private ItemStack prevHeldItem;
|
private ItemStack prevHeldItem;
|
||||||
private ItemStack mouseItem;
|
private ItemStack mouseItem;
|
||||||
private final ItemStack[] armor = new ItemStack[Equipment.ARMOR_SLOTS];
|
private final ItemStack[] armor = new ItemStack[Equipment.ARMOR_SLOTS];
|
||||||
|
@ -672,7 +671,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
if (stack != null && !this.isPlayer() && this.isBreedingItem(stack) && this.getGrowingAge() == 0 && !this.isMating())
|
if (stack != null && !this.isPlayer() && this.isBreedingItem(stack) && this.getGrowingAge() == 0 && !this.isMating())
|
||||||
{
|
{
|
||||||
if(stack.decrSize())
|
if(stack.decrSize())
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
if (!this.worldObj.client)
|
if (!this.worldObj.client)
|
||||||
{
|
{
|
||||||
this.setIsWillingToMate(true);
|
this.setIsWillingToMate(true);
|
||||||
|
@ -684,7 +683,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
else if (stack != null && !this.isPlayer() && this.isBreedingItem(stack) && this.getGrowingAge() < 0)
|
else if (stack != null && !this.isPlayer() && this.isBreedingItem(stack) && this.getGrowingAge() < 0)
|
||||||
{
|
{
|
||||||
if(stack.decrSize())
|
if(stack.decrSize())
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
if (!this.worldObj.client)
|
if (!this.worldObj.client)
|
||||||
{
|
{
|
||||||
this.grow(this.rand.range(200, 250));
|
this.grow(this.rand.range(200, 250));
|
||||||
|
@ -1741,6 +1740,8 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
*/
|
*/
|
||||||
public EntityItem dropOneItem(boolean dropAll)
|
public EntityItem dropOneItem(boolean dropAll)
|
||||||
{
|
{
|
||||||
|
if(this.getSelectedIndex() < 0)
|
||||||
|
return null;
|
||||||
if(this.client != null) {
|
if(this.client != null) {
|
||||||
CPacketBreak.Action c07packetplayerdigging$action = dropAll ? CPacketBreak.Action.DROP_ALL_ITEMS : CPacketBreak.Action.DROP_ITEM;
|
CPacketBreak.Action c07packetplayerdigging$action = dropAll ? CPacketBreak.Action.DROP_ALL_ITEMS : CPacketBreak.Action.DROP_ITEM;
|
||||||
this.client.addToSendQueue(new CPacketBreak(c07packetplayerdigging$action, LocalPos.ORIGIN, Facing.DOWN));
|
this.client.addToSendQueue(new CPacketBreak(c07packetplayerdigging$action, LocalPos.ORIGIN, Facing.DOWN));
|
||||||
|
@ -2497,7 +2498,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
|
|
||||||
public ItemStack getHeldItem()
|
public ItemStack getHeldItem()
|
||||||
{
|
{
|
||||||
return this.isPlayer() || this.dummy ? (this.getSelectedIndex() < this.getHotbarSize() && this.getSelectedIndex() >= 0 ? this.getStackInSlot(this.getSelectedIndex()) : null) : this.heldItem;
|
return this.getSelectedIndex() < this.getHotbarSize() && this.getSelectedIndex() >= 0 ? this.getStackInSlot(this.getSelectedIndex()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getArmor()
|
public ItemStack[] getArmor()
|
||||||
|
@ -2517,14 +2518,17 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
|
|
||||||
public void setHeldItem(ItemStack stack)
|
public void setHeldItem(ItemStack stack)
|
||||||
{
|
{
|
||||||
if(this.isPlayer() || this.dummy) {
|
if(!this.isPlayer() && !this.dummy)
|
||||||
this.setInventorySlotContents(this.getSelectedIndex(), stack);
|
this.setSelectedIndex(0);
|
||||||
}
|
if(this.getSelectedIndex() >= 0)
|
||||||
else {
|
this.setInventorySlotContents(this.getSelectedIndex(), stack);
|
||||||
this.heldItem = stack;
|
if(!this.isPlayer() && !this.dummy && !this.worldObj.client)
|
||||||
if(!this.worldObj.client)
|
this.setCombatTask();
|
||||||
this.setCombatTask();
|
}
|
||||||
}
|
|
||||||
|
public final void clearHeldItem()
|
||||||
|
{
|
||||||
|
this.setHeldItem(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArmor(Equipment slot, ItemStack stack)
|
public void setArmor(Equipment slot, ItemStack stack)
|
||||||
|
@ -2534,8 +2538,10 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
|
|
||||||
public void setHeldNoUpdate(ItemStack stack)
|
public void setHeldNoUpdate(ItemStack stack)
|
||||||
{
|
{
|
||||||
if(!this.isPlayer())
|
if(!this.isPlayer() && !this.dummy) {
|
||||||
this.heldItem = stack;
|
this.setSelectedIndex(0);
|
||||||
|
this.setInventorySlotContents(this.getSelectedIndex(), stack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMouseItem(ItemStack stack)
|
public void setMouseItem(ItemStack stack)
|
||||||
|
@ -2874,7 +2880,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
|
|
||||||
if (itemstack.isEmpty())
|
if (itemstack.isEmpty())
|
||||||
{
|
{
|
||||||
this.setHeldItem(null);
|
this.clearHeldItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3294,17 +3300,13 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
|
|
||||||
List<TagObject> list = tag.getList("items");
|
List<TagObject> list = tag.getList("items");
|
||||||
this.clear();
|
this.clear();
|
||||||
for(int z = 0; z < list.size(); z++) {
|
for(int z = 0; z < list.size() && z < this.getInventoryCapacity(); z++) {
|
||||||
TagObject item = list.get(z);
|
TagObject item = list.get(z);
|
||||||
int slot = item.getByte("Slot") & 255;
|
|
||||||
ItemStack stack = ItemStack.readFromTag(item);
|
ItemStack stack = ItemStack.readFromTag(item);
|
||||||
if(stack != null && slot >= 0 && slot < this.getInventoryCapacity())
|
if(stack != null)
|
||||||
this.setInventorySlotContents(slot, stack);
|
this.setInventorySlotContents(z, stack);
|
||||||
}
|
}
|
||||||
if(this.isPlayer())
|
this.setSelectedIndex(this.isPlayer() || this.dummy ? tag.getInt("selected") : 0);
|
||||||
this.setSelectedIndex(tag.getInt("selected"));
|
|
||||||
else
|
|
||||||
this.setHeldNoUpdate(ItemStack.readFromTag(tag.getObject("held")));
|
|
||||||
for(Equipment slot : Equipment.ARMOR) {
|
for(Equipment slot : Equipment.ARMOR) {
|
||||||
this.setArmor(slot, ItemStack.readFromTag(tag.getObject(slot.getName())));
|
this.setArmor(slot, ItemStack.readFromTag(tag.getObject(slot.getName())));
|
||||||
}
|
}
|
||||||
|
@ -3426,21 +3428,13 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
for(int z = 0; z < this.getInventoryCapacity(); z++) {
|
for(int z = 0; z < this.getInventoryCapacity(); z++) {
|
||||||
if(this.getStackInSlot(z) != null) {
|
if(this.getStackInSlot(z) != null) {
|
||||||
TagObject item = new TagObject();
|
TagObject item = new TagObject();
|
||||||
item.setByte("Slot", (byte)z);
|
|
||||||
this.getStackInSlot(z).writeTags(item);
|
this.getStackInSlot(z).writeTags(item);
|
||||||
list.add(item);
|
list.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tag.setList("items", list);
|
tag.setList("items", list);
|
||||||
if(this.isPlayer()) {
|
if(this.isPlayer() || this.dummy)
|
||||||
tag.setInt("selected", this.getSelectedIndex());
|
tag.setInt("selected", this.getSelectedIndex());
|
||||||
}
|
|
||||||
else {
|
|
||||||
TagObject item = new TagObject();
|
|
||||||
if(this.getHeldItem() != null)
|
|
||||||
this.getHeldItem().writeTags(item);
|
|
||||||
tag.setObject("held", item);
|
|
||||||
}
|
|
||||||
for(Equipment slot : Equipment.ARMOR) {
|
for(Equipment slot : Equipment.ARMOR) {
|
||||||
TagObject item = new TagObject();
|
TagObject item = new TagObject();
|
||||||
if(this.getArmor(slot) != null)
|
if(this.getArmor(slot) != null)
|
||||||
|
@ -3578,7 +3572,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
{
|
{
|
||||||
if (itemstack.isEmpty()) // && !this.creative)
|
if (itemstack.isEmpty()) // && !this.creative)
|
||||||
{
|
{
|
||||||
this.setHeldItem(null);
|
this.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -3593,7 +3587,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
{
|
{
|
||||||
if (itemstack.isEmpty()) // && !this.creative)
|
if (itemstack.isEmpty()) // && !this.creative)
|
||||||
{
|
{
|
||||||
this.setHeldItem(null);
|
this.clearHeldItem();
|
||||||
}
|
}
|
||||||
// else if (itemstack.stackSize < itemstack1.stackSize && this.creative)
|
// else if (itemstack.stackSize < itemstack1.stackSize && this.creative)
|
||||||
// {
|
// {
|
||||||
|
@ -3701,7 +3695,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
||||||
|
|
||||||
if (itemstack.isEmpty())
|
if (itemstack.isEmpty())
|
||||||
{
|
{
|
||||||
this.setHeldItem(null);
|
this.clearHeldItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ public abstract class EntityAnimal extends EntityLiving
|
||||||
if (this.isBreedingItem(stack) && this.getGrowingAge() == 0 && !this.isInLove())
|
if (this.isBreedingItem(stack) && this.getGrowingAge() == 0 && !this.isInLove())
|
||||||
{
|
{
|
||||||
if(stack.decrSize())
|
if(stack.decrSize())
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
this.setInLove(player);
|
this.setInLove(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ public abstract class EntityAnimal extends EntityLiving
|
||||||
if (this.isChild() && this.isBreedingItem(stack))
|
if (this.isChild() && this.isBreedingItem(stack))
|
||||||
{
|
{
|
||||||
if(stack.decrSize())
|
if(stack.decrSize())
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
if(!this.worldObj.client)
|
if(!this.worldObj.client)
|
||||||
this.grow((int)((float)(-this.getGrowingAge() / 20) * 0.1F));
|
this.grow((int)((float)(-this.getGrowingAge() / 20) * 0.1F));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2678,7 +2678,7 @@ public abstract class EntityLiving extends Entity
|
||||||
if(stack != null && stack.getItem() == Items.lead && this.allowLeashing() && (!(this instanceof EntityTameable tameable) || !tameable.isTamed() || tameable.isOwner(player))) {
|
if(stack != null && stack.getItem() == Items.lead && this.allowLeashing() && (!(this instanceof EntityTameable tameable) || !tameable.isTamed() || tameable.isOwner(player))) {
|
||||||
this.setLeashedTo(player, true);
|
this.setLeashedTo(player, true);
|
||||||
if(stack.decrSize())
|
if(stack.decrSize())
|
||||||
player.setHeldItem(null);
|
player.clearHeldItem();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return this.interact(player) || super.interactFirst(player);
|
return this.interact(player) || super.interactFirst(player);
|
||||||
|
|
|
@ -7,7 +7,6 @@ import common.collect.Lists;
|
||||||
import common.entity.npc.EntityNPC;
|
import common.entity.npc.EntityNPC;
|
||||||
import common.item.ItemStack;
|
import common.item.ItemStack;
|
||||||
import common.tileentity.TileEntityChest;
|
import common.tileentity.TileEntityChest;
|
||||||
import common.util.Equipment;
|
|
||||||
|
|
||||||
public class ContainerChest extends Container
|
public class ContainerChest extends Container
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,6 @@ import common.item.ItemStack;
|
||||||
import common.item.material.ItemEnchantedBook;
|
import common.item.material.ItemEnchantedBook;
|
||||||
import common.network.IPlayer;
|
import common.network.IPlayer;
|
||||||
import common.rng.Random;
|
import common.rng.Random;
|
||||||
import common.util.Equipment;
|
|
||||||
import common.util.LocalPos;
|
import common.util.LocalPos;
|
||||||
import common.util.Pair;
|
import common.util.Pair;
|
||||||
import common.world.World;
|
import common.world.World;
|
||||||
|
|
|
@ -8,7 +8,6 @@ import common.entity.animal.EntityHorse;
|
||||||
import common.entity.npc.EntityNPC;
|
import common.entity.npc.EntityNPC;
|
||||||
import common.init.Items;
|
import common.init.Items;
|
||||||
import common.item.ItemStack;
|
import common.item.ItemStack;
|
||||||
import common.util.Equipment;
|
|
||||||
|
|
||||||
public class ContainerEntityInventory extends Container
|
public class ContainerEntityInventory extends Container
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,6 @@ import common.collect.Lists;
|
||||||
import common.entity.npc.EntityNPC;
|
import common.entity.npc.EntityNPC;
|
||||||
import common.item.ItemStack;
|
import common.item.ItemStack;
|
||||||
import common.network.IPlayer;
|
import common.network.IPlayer;
|
||||||
import common.util.Equipment;
|
|
||||||
import common.village.MerchantRecipe;
|
import common.village.MerchantRecipe;
|
||||||
import common.world.World;
|
import common.world.World;
|
||||||
|
|
||||||
|
|
|
@ -421,7 +421,7 @@ public final class ItemStack {
|
||||||
entity.renderBrokenItemStack(this);
|
entity.renderBrokenItemStack(this);
|
||||||
this.decrSize();
|
this.decrSize();
|
||||||
if(entity != null && entity.isPlayer() && this.isEmpty() && this.item instanceof ItemBow)
|
if(entity != null && entity.isPlayer() && this.isEmpty() && this.item instanceof ItemBow)
|
||||||
((EntityNPC)entity).setHeldItem(null);
|
((EntityNPC)entity).clearHeldItem();
|
||||||
this.setItemDamage(0);
|
this.setItemDamage(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import common.util.Equipment;
|
||||||
import common.util.Serverside;
|
import common.util.Serverside;
|
||||||
import common.util.Vec3;
|
import common.util.Vec3;
|
||||||
import common.world.AWorldServer;
|
import common.world.AWorldServer;
|
||||||
import common.world.World;
|
|
||||||
|
|
||||||
public class ItemArmor extends Item {
|
public class ItemArmor extends Item {
|
||||||
private final ToolMaterial material;
|
private final ToolMaterial material;
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class CommandClear extends Command {
|
||||||
if(entity.isPlayer())
|
if(entity.isPlayer())
|
||||||
((EntityNPC)entity).setMouseItem(null);
|
((EntityNPC)entity).setMouseItem(null);
|
||||||
else
|
else
|
||||||
((EntityNPC)entity).setHeldItem(null);
|
((EntityNPC)entity).clearHeldItem();
|
||||||
exec.log("Inventar von %s gelöscht", entity.getRawName());
|
exec.log("Inventar von %s gelöscht", entity.getRawName());
|
||||||
done++;
|
done++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1108,7 +1108,7 @@ public class Player extends User implements Executor, IPlayer
|
||||||
if(this.onPlayerInteract(true, pos)) {
|
if(this.onPlayerInteract(true, pos)) {
|
||||||
this.sendPacket(new SPacketBlockChange(this.entity.worldObj, pos));
|
this.sendPacket(new SPacketBlockChange(this.entity.worldObj, pos));
|
||||||
if(this.entity.getHeldItem() != null && this.entity.getHeldItem().isEmpty())
|
if(this.entity.getHeldItem() != null && this.entity.getHeldItem().isEmpty())
|
||||||
this.entity.setHeldItem(null);
|
this.entity.clearHeldItem();
|
||||||
this.entity.openContainer.detectAndSendChanges();
|
this.entity.openContainer.detectAndSendChanges();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1223,7 +1223,7 @@ public class Player extends User implements Executor, IPlayer
|
||||||
|
|
||||||
if (itemstack1.isEmpty())
|
if (itemstack1.isEmpty())
|
||||||
{
|
{
|
||||||
this.entity.setHeldItem(null);
|
this.entity.clearHeldItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1252,7 +1252,7 @@ public class Player extends User implements Executor, IPlayer
|
||||||
|
|
||||||
if (itemstack.isEmpty())
|
if (itemstack.isEmpty())
|
||||||
{
|
{
|
||||||
this.entity.setHeldItem(null);
|
this.entity.clearHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.entity.isUsingItem())
|
if (!this.entity.isUsingItem())
|
||||||
|
@ -1268,7 +1268,7 @@ public class Player extends User implements Executor, IPlayer
|
||||||
this.sendPacket(new SPacketBlockChange(this.entity.worldObj, pos));
|
this.sendPacket(new SPacketBlockChange(this.entity.worldObj, pos));
|
||||||
stack.getItem().onItemUse(stack, this.entity, this.entity.worldObj, pos, side, offsetX, offsetY, offsetZ);
|
stack.getItem().onItemUse(stack, this.entity, this.entity.worldObj, pos, side, offsetX, offsetY, offsetZ);
|
||||||
if(stack.isEmpty())
|
if(stack.isEmpty())
|
||||||
this.entity.setHeldItem(null);
|
this.entity.clearHeldItem();
|
||||||
this.entity.openContainer.detectAndSendChanges();
|
this.entity.openContainer.detectAndSendChanges();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1950,10 +1950,13 @@ public class Player extends User implements Executor, IPlayer
|
||||||
case ITEM:
|
case ITEM:
|
||||||
if(msg.length() > 30)
|
if(msg.length() > 30)
|
||||||
throw new IllegalArgumentException("Ungültiger Name");
|
throw new IllegalArgumentException("Ungültiger Name");
|
||||||
if(packetIn.getArg() == -1)
|
if(packetIn.getArg() == -1) {
|
||||||
this.entity.inventoryContainer.renameItem(Equipment.ARMOR_SLOTS + this.entity.getSelectedIndex(), msg);
|
if(this.entity.getSelectedIndex() >= 0)
|
||||||
else
|
this.entity.inventoryContainer.renameItem(Equipment.ARMOR_SLOTS + this.entity.getSelectedIndex(), msg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
this.entity.openContainer.renameItem(packetIn.getArg(), msg);
|
this.entity.openContainer.renameItem(packetIn.getArg(), msg);
|
||||||
|
}
|
||||||
this.entity.openContainer.detectAndSendChanges();
|
this.entity.openContainer.detectAndSendChanges();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2379,11 +2382,14 @@ public class Player extends User implements Executor, IPlayer
|
||||||
this.entity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos.offset(enumfacing)));
|
this.entity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos.offset(enumfacing)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.entity.getSelectedIndex() < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
itemstack = this.entity.getHeldItem();
|
itemstack = this.entity.getHeldItem();
|
||||||
|
|
||||||
if (itemstack != null && itemstack.isEmpty())
|
if (itemstack != null && itemstack.isEmpty())
|
||||||
{
|
{
|
||||||
this.entity.setHeldItem(null);
|
this.entity.clearHeldItem();
|
||||||
itemstack = null;
|
itemstack = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2608,7 +2614,7 @@ public class Player extends User implements Executor, IPlayer
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SET_ITEMSLOT:
|
case SET_ITEMSLOT:
|
||||||
if(packetIn.getAuxData() >= 0 && packetIn.getAuxData() < this.entity.getHotbarSize()) {
|
if(packetIn.getAuxData() >= -1 && packetIn.getAuxData() < this.entity.getHotbarSize()) {
|
||||||
if(packetIn.getAuxData() != this.entity.getSelectedIndex())
|
if(packetIn.getAuxData() != this.entity.getSelectedIndex())
|
||||||
this.itemUseCooldown = 0;
|
this.itemUseCooldown = 0;
|
||||||
this.entity.setSelectedIndex(packetIn.getAuxData());
|
this.entity.setSelectedIndex(packetIn.getAuxData());
|
||||||
|
@ -2657,7 +2663,7 @@ public class Player extends User implements Executor, IPlayer
|
||||||
item.getItem().onAction(item, this.entity, this.entity.worldObj,
|
item.getItem().onAction(item, this.entity, this.entity.worldObj,
|
||||||
ItemControl.values()[packetIn.getAuxData() % ItemControl.values().length], null);
|
ItemControl.values()[packetIn.getAuxData() % ItemControl.values().length], null);
|
||||||
if(item.isEmpty())
|
if(item.isEmpty())
|
||||||
this.entity.setHeldItem(null);
|
this.entity.clearHeldItem();
|
||||||
this.entity.openContainer.detectAndSendChanges();
|
this.entity.openContainer.detectAndSendChanges();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue