Skip to content

Commit

Permalink
Block damaged items duplication (#1488)
Browse files Browse the repository at this point in the history
* Block damaged items duplication

* Update Player.java
  • Loading branch information
PetteriM1 committed Aug 5, 2021
1 parent 35ef92e commit d063058
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3070,7 +3070,11 @@ public void onCompletion(Server server) {
//TODO: Implement adventure mode checks
if ((i = this.level.useItemOn(blockVector.asVector3(), i, face, useItemData.clickPos.x, useItemData.clickPos.y, useItemData.clickPos.z, this)) != null) {
if (!i.equals(oldItem) || i.getCount() != oldItem.getCount()) {
inventory.setItemInHand(i);
if (oldItem.getId() == i.getId() || i.getId() == 0) {
inventory.setItemInHand(i);
} else {
server.getLogger().debug("Tried to set item " + i.getId() + " but " + this.username + " had item " + oldItem.getId() + " in their hand slot");
}
inventory.sendHeldItem(this.getViewers().values());
}
break packetswitch;
Expand Down Expand Up @@ -3104,7 +3108,11 @@ public void onCompletion(Server server) {
if (this.isSurvival()) {
this.getFoodData().updateFoodExpLevel(0.025);
if (!i.equals(oldItem) || i.getCount() != oldItem.getCount()) {
inventory.setItemInHand(i);
if (oldItem.getId() == i.getId() || i.getId() == 0) {
inventory.setItemInHand(i);
} else {
server.getLogger().debug("Tried to set item " + i.getId() + " but " + this.username + " had item " + oldItem.getId() + " in their hand slot");
}
inventory.sendHeldItem(this.getViewers().values());
}
}
Expand Down Expand Up @@ -3147,7 +3155,11 @@ public void onCompletion(Server server) {

if (item.onClickAir(this, directionVector)) {
if (!this.isCreative()) {
this.inventory.setItemInHand(item);
if (item.getId() == 0 || this.inventory.getItemInHand().getId() == item.getId()) {
this.inventory.setItemInHand(item);
} else {
server.getLogger().debug("Tried to set item " + item.getId() + " but " + this.username + " had item " + this.inventory.getItemInHand().getId() + " in their hand slot");
}
}

if (!this.isUsingItem()) {
Expand Down Expand Up @@ -3208,7 +3220,11 @@ public void onCompletion(Server server) {
}
}

this.inventory.setItemInHand(item);
if (item.getId() == 0 || this.inventory.getItemInHand().getId() == item.getId()) {
this.inventory.setItemInHand(item);
} else {
server.getLogger().debug("Tried to set item " + item.getId() + " but " + this.username + " had item " + this.inventory.getItemInHand().getId() + " in their hand slot");
}
}
break;
case InventoryTransactionPacket.USE_ITEM_ON_ENTITY_ACTION_ATTACK:
Expand Down Expand Up @@ -3250,9 +3266,13 @@ public void onCompletion(Server server) {

if (item.isTool() && (this.isSurvival() || this.isAdventure())) {
if (item.useOn(target) && item.getDamage() >= item.getMaxDurability()) {
this.inventory.setItemInHand(new ItemBlock(Block.get(BlockID.AIR)));
this.inventory.setItemInHand(Item.get(0));
} else {
this.inventory.setItemInHand(item);
if (item.getId() == 0 || this.inventory.getItemInHand().getId() == item.getId()) {
this.inventory.setItemInHand(item);
} else {
server.getLogger().debug("Tried to set item " + item.getId() + " but " + this.username + " had item " + this.inventory.getItemInHand().getId() + " in their hand slot");
}
}
}
return;
Expand Down

0 comments on commit d063058

Please sign in to comment.