From c5d7ba48e1ae90baac256f2a9bfd478c022a1517 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Sat, 25 Jun 2022 18:35:01 +0200 Subject: [PATCH] Fix AppliedEnergistics/Applied-Energistics-2#6396: slurry in interface crash; also add empty/fill sounds --- .../ae2/ChemicalContainerItemStrategy.java | 4 ++++ .../mekae2/ae2/GenericStackChemicalStorage.java | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/ramidzkh/mekae2/ae2/ChemicalContainerItemStrategy.java b/src/main/java/me/ramidzkh/mekae2/ae2/ChemicalContainerItemStrategy.java index 50f630f..47e0a44 100644 --- a/src/main/java/me/ramidzkh/mekae2/ae2/ChemicalContainerItemStrategy.java +++ b/src/main/java/me/ramidzkh/mekae2/ae2/ChemicalContainerItemStrategy.java @@ -5,6 +5,8 @@ import org.jetbrains.annotations.Nullable; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; @@ -115,10 +117,12 @@ public long insert(Context context, MekanismKey what, long amount, Actionable mo @Override public void playFillSound(Player player, MekanismKey what) { + player.playNotifySound(SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 1.0F, 1.0F); } @Override public void playEmptySound(Player player, MekanismKey what) { + player.playNotifySound(SoundEvents.BUCKET_EMPTY, SoundSource.PLAYERS, 1.0F, 1.0F); } @Override diff --git a/src/main/java/me/ramidzkh/mekae2/ae2/GenericStackChemicalStorage.java b/src/main/java/me/ramidzkh/mekae2/ae2/GenericStackChemicalStorage.java index 224aa15..e637487 100644 --- a/src/main/java/me/ramidzkh/mekae2/ae2/GenericStackChemicalStorage.java +++ b/src/main/java/me/ramidzkh/mekae2/ae2/GenericStackChemicalStorage.java @@ -21,13 +21,16 @@ import appeng.api.behaviors.GenericInternalInventory; import appeng.api.config.Actionable; +@SuppressWarnings("UnstableApiUsage") public abstract sealed class GenericStackChemicalStorage, S extends ChemicalStack> implements IChemicalHandler { private final GenericInternalInventory inv; + private final byte form; - private GenericStackChemicalStorage(GenericInternalInventory inv) { + private GenericStackChemicalStorage(GenericInternalInventory inv, byte form) { this.inv = inv; + this.form = form; } @Override @@ -37,7 +40,7 @@ public int getTanks() { @Override public S getChemicalInTank(int tank) { - if (inv.getKey(tank)instanceof MekanismKey what) { + if (inv.getKey(tank)instanceof MekanismKey what && what.getForm() == form) { return (S) ChemicalBridge.withAmount(what.getStack(), inv.getAmount(tank)); } @@ -80,7 +83,7 @@ public S insertChemical(int tank, S stack, Action action) { @Override public S extractChemical(int tank, long amount, Action action) { - if (!(inv.getKey(tank)instanceof MekanismKey what)) { + if (!(inv.getKey(tank)instanceof MekanismKey what) || what.getForm() != form) { return getEmptyStack(); } @@ -95,28 +98,28 @@ public S extractChemical(int tank, long amount, Action action) { public static final class OfGas extends GenericStackChemicalStorage implements IGasHandler { public OfGas(GenericInternalInventory inv) { - super(inv); + super(inv, MekanismKey.GAS); } } public static final class OfInfusion extends GenericStackChemicalStorage implements IInfusionHandler { public OfInfusion(GenericInternalInventory inv) { - super(inv); + super(inv, MekanismKey.INFUSION); } } public static final class OfPigment extends GenericStackChemicalStorage implements IPigmentHandler { public OfPigment(GenericInternalInventory inv) { - super(inv); + super(inv, MekanismKey.PIGMENT); } } public static final class OfSlurry extends GenericStackChemicalStorage implements ISlurryHandler { public OfSlurry(GenericInternalInventory inv) { - super(inv); + super(inv, MekanismKey.SLURRY); } } }