Skip to content

Commit

Permalink
Validate chemicals before voiding
Browse files Browse the repository at this point in the history
Closes #61
  • Loading branch information
ramidzkh committed Jul 7, 2024
1 parent 9d9dd68 commit c6ae0d9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/main/java/me/ramidzkh/mekae2/ae2/MekanismKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,13 @@ public ChemicalStack<?> withAmount(long amount) {
}

public byte getForm() {
if (stack instanceof GasStack) {
return GAS;
} else if (stack instanceof InfusionStack) {
return INFUSION;
} else if (stack instanceof PigmentStack) {
return PIGMENT;
} else if (stack instanceof SlurryStack) {
return SLURRY;
} else {
throw new UnsupportedOperationException();
}
return switch (stack) {
case GasStack ignored -> GAS;
case InfusionStack ignored -> INFUSION;
case PigmentStack ignored -> PIGMENT;
case SlurryStack ignored -> SLURRY;
default -> throw new UnsupportedOperationException();
};
}

@Override
Expand Down Expand Up @@ -141,17 +137,17 @@ protected Component computeDisplayName() {

@Override
public boolean isTagged(TagKey<?> tag) {
if (stack.getChemical() instanceof Gas gas) {
return tag.registry().equals(MekanismAPI.GAS_REGISTRY_NAME) && gas.is((TagKey<Gas>) tag);
} else if (stack.getChemical() instanceof InfuseType infuse) {
return tag.registry().equals(MekanismAPI.INFUSE_TYPE_REGISTRY_NAME) && infuse.is((TagKey<InfuseType>) tag);
} else if (stack.getChemical() instanceof Pigment pigment) {
return tag.registry().equals(MekanismAPI.PIGMENT_REGISTRY_NAME) && pigment.is((TagKey<Pigment>) tag);
} else if (stack.getChemical() instanceof Slurry slurry) {
return tag.registry().equals(MekanismAPI.SLURRY_REGISTRY_NAME) && slurry.is((TagKey<Slurry>) tag);
} else {
throw new UnsupportedOperationException();
}
return switch (stack.getChemical()) {
case Gas gas -> tag.registry().equals(MekanismAPI.GAS_REGISTRY_NAME)
&& gas.is((TagKey<Gas>) tag);
case InfuseType infuse -> tag.registry().equals(MekanismAPI.INFUSE_TYPE_REGISTRY_NAME)
&& infuse.is((TagKey<InfuseType>) tag);
case Pigment pigment -> tag.registry().equals(MekanismAPI.PIGMENT_REGISTRY_NAME)
&& pigment.is((TagKey<Pigment>) tag);
case Slurry slurry -> tag.registry().equals(MekanismAPI.SLURRY_REGISTRY_NAME)
&& slurry.is((TagKey<Slurry>) tag);
default -> throw new UnsupportedOperationException();
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.ramidzkh.mekae2.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import me.ramidzkh.mekae2.ae2.MekanismKey;
import mekanism.api.chemical.attribute.ChemicalAttributeValidator;

import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.stacks.AEKey;

@Mixin(targets = "appeng.blockentity.misc.CondenserMEStorage")
public class CondenserMEStorageMixin {

@Inject(method = "insert", at = @At("HEAD"), cancellable = true)
private void onInsert(AEKey what, long amount, Actionable mode, IActionSource source,
CallbackInfoReturnable<Long> cir) {
if (what instanceof MekanismKey key) {
if (!ChemicalAttributeValidator.DEFAULT.process(key.getStack())) {
cir.setReturnValue(0L);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ displayURL = "https://github.com/AppliedEnergistics/Applied-Mekanistics#readme"
logoFile = "logo.png"
authors = "ramidzkh"

[[mixins]]
config = "appmek.mixins.json"

[[dependencies.appmek]]
modId = "neoforge"
type = "required"
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/appmek.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"required": true,
"minVersion": "0.8.5",
"package": "me.ramidzkh.mekae2.mixin",
"mixins": ["CondenserMEStorageMixin"],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit c6ae0d9

Please sign in to comment.