Skip to content

Commit

Permalink
Fix missing field crash on 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ChloeDawn committed Jan 3, 2021
1 parent 03de18c commit d12f5af
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/dev/sapphic/armorsoundtweak/ArmorSoundTweak.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
Expand Down Expand Up @@ -98,7 +97,7 @@ public void tick(final TickEvent.ClientTickEvent event) {
}

private @Nullable SoundEvent getEquipSound(final SubItem newItem, final SubItem oldItem) {
final Item item = ((newItem.item == Items.AIR) ? oldItem : newItem).item;
final Item item = (newItem.isEmpty() ? oldItem : newItem).item;

if (SOUNDS.armor && (item instanceof ItemArmor)) {
return ((ItemArmor) item).getArmorMaterial().getSoundEvent();
Expand Down Expand Up @@ -140,12 +139,12 @@ private Sounds() {
}

private static final class SubItem {
private static final SubItem EMPTY = new SubItem(Items.AIR, 0);
private static final SubItem EMPTY = new SubItem(null, 0);

private final Item item;
private final @Nullable Item item;
private final int metadata;

private SubItem(final Item item, final int metadata) {
private SubItem(final @Nullable Item item, final int metadata) {
this.item = item;
this.metadata = metadata;
}
Expand All @@ -154,6 +153,10 @@ private SubItem(final ItemStack stack) {
this(stack.getItem(), stack.getMetadata());
}

private boolean isEmpty() {
return this.item == null;
}

private boolean is(final SubItem that) {
return (this == that) || ((this.metadata == that.metadata) && (this.item == that.item));
}
Expand Down

0 comments on commit d12f5af

Please sign in to comment.