Skip to content

Commit 165daf2

Browse files
committed
Similar to vanilla call Entity#onEquipItem when a player sets an item in an armor slot or the offhand slot. This makes putting items in the armor slots play the equip sound
1 parent c595211 commit 165daf2

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/main/java/mekanism/common/inventory/container/MekanismContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected void addArmorSlots(@NotNull Inventory inv, int x, int y, int offhandOf
231231
y += 18;
232232
}
233233
if (offhandOffset != -1) {
234-
addSlot(new OffhandSlot(inv, 40, x, y + offhandOffset));
234+
addSlot(new OffhandSlot(inv, 40, x, y + offhandOffset, inv.player));
235235
}
236236
}
237237

src/main/java/mekanism/common/inventory/container/ModuleTweakerContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public boolean mayPlace(@NotNull ItemStack stack) {
4949
}
5050
});
5151
}
52-
addSlot(new OffhandSlot(inv, 40, 8, 16 + 18 * 4) {
52+
addSlot(new OffhandSlot(inv, 40, 8, 16 + 18 * 4, inv.player) {
5353
@Override
5454
public boolean mayPickup(@NotNull Player player) {
5555
return false;

src/main/java/mekanism/common/inventory/container/slot/ArmorSlot.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ public class ArmorSlot extends InsertableSlot {
1616
InventoryMenu.EMPTY_ARMOR_SLOT_CHESTPLATE, InventoryMenu.EMPTY_ARMOR_SLOT_HELMET};
1717

1818
private final EquipmentSlot slotType;
19+
private final Player owner;
1920

2021
public ArmorSlot(Inventory inventory, int index, int x, int y, EquipmentSlot slotType) {
2122
super(inventory, index, x, y);
2223
this.slotType = slotType;
24+
this.owner = inventory.player;
2325
setBackground(InventoryMenu.BLOCK_ATLAS, ARMOR_SLOT_TEXTURES[this.slotType.getIndex()]);
2426
}
2527

28+
@Override
29+
public void setByPlayer(@NotNull ItemStack newStack, @NotNull ItemStack oldStack) {
30+
this.owner.onEquipItem(slotType, oldStack, newStack);
31+
super.setByPlayer(newStack, oldStack);
32+
}
33+
2634
@Override
2735
public int getMaxStackSize() {
2836
return 1;
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package mekanism.common.inventory.container.slot;
22

33
import net.minecraft.world.Container;
4+
import net.minecraft.world.entity.EquipmentSlot;
5+
import net.minecraft.world.entity.player.Player;
46
import net.minecraft.world.inventory.InventoryMenu;
7+
import net.minecraft.world.item.ItemStack;
8+
import org.jetbrains.annotations.NotNull;
59

610
public class OffhandSlot extends InsertableSlot {
711

8-
public OffhandSlot(Container inventory, int index, int x, int y) {
12+
private final Player owner;
13+
14+
public OffhandSlot(Container inventory, int index, int x, int y, Player owner) {
915
super(inventory, index, x, y);
16+
this.owner = owner;
1017
setBackground(InventoryMenu.BLOCK_ATLAS, InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD);
1118
}
19+
20+
@Override
21+
public void setByPlayer(@NotNull ItemStack newStack, @NotNull ItemStack oldStack) {
22+
this.owner.onEquipItem(EquipmentSlot.OFFHAND, oldStack, newStack);
23+
super.setByPlayer(newStack, oldStack);
24+
}
1225
}

0 commit comments

Comments
 (0)