Skip to content

Commit

Permalink
Make ChemicalIngredientConverter check the ingredient class (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh authored Nov 5, 2023
1 parent 8a6bb68 commit 6e71ae5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,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) || what.getForm() != form) {
if (!(inv.getKey(tank) instanceof MekanismKey what && what.getForm() == form)) {
return getEmptyStack();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,5 @@ public long push(AEKey what, long amount, Actionable mode) {

return amount - storage.insertChemical(mekanismKey.withAmount(amount),
Action.fromFluidAction(mode.getFluidAction())).getAmount();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.resources.ResourceLocation;

import me.ramidzkh.mekae2.AppliedMekanistics;
import me.ramidzkh.mekae2.ae2.ChemicalIngredientConverter;
import mekanism.api.IMekanismAccess;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package me.ramidzkh.mekae2.ae2;
package me.ramidzkh.mekae2.integration.jei;

import org.jetbrains.annotations.Nullable;

import me.ramidzkh.mekae2.ae2.MekanismKey;
import mekanism.api.chemical.ChemicalStack;
import mezz.jei.api.ingredients.IIngredientType;

Expand All @@ -20,7 +21,7 @@ public IIngredientType<S> getIngredientType() {
@Nullable
@Override
public S getIngredientFromStack(GenericStack stack) {
if (stack.what() instanceof MekanismKey key) {
if (stack.what() instanceof MekanismKey key && type.getIngredientClass().isInstance(key.getStack())) {
return (S) key.withAmount(Math.max(1, stack.amount()));
} else {
return null;
Expand Down
60 changes: 29 additions & 31 deletions src/main/java/me/ramidzkh/mekae2/qio/QioSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,43 @@ public static void initialize() {
public static void onBlockEntityCapability(AttachCapabilitiesEvent<BlockEntity> event) {
var object = event.getObject();

if (object instanceof IQIOComponent) {
if (DASHBOARD.equals(ForgeRegistries.BLOCK_ENTITY_TYPES.getKey(object.getType()))) {
event.addCapability(AppliedMekanistics.id("qio_storage_monitorable"), new ICapabilityProvider() {
@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> capability,
@Nullable Direction arg) {
out: if (capability == STORAGE && arg != null) {
// guess the source...
// if you're trying to qio across a compact machine wall or something, sorry!
var host = GridHelper.getNodeHost(object.getLevel(), object.getBlockPos().relative(arg));
if (object instanceof IQIOComponent
&& DASHBOARD.equals(ForgeRegistries.BLOCK_ENTITY_TYPES.getKey(object.getType()))) {
event.addCapability(AppliedMekanistics.id("qio_storage_monitorable"), new ICapabilityProvider() {
@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> capability, @Nullable Direction arg) {
out: if (capability == STORAGE && arg != null) {
// guess the source...
// if you're trying to qio across a compact machine wall or something, sorry!
var host = GridHelper.getNodeHost(object.getLevel(), object.getBlockPos().relative(arg));

if (host == null) {
break out;
}
if (host == null) {
break out;
}

var source = host.getGridNode(arg.getOpposite());
var source = host.getGridNode(arg.getOpposite());

// I don't know of any full-block nodes which query inventories, but we'll see
if (source == null) {
source = host.getGridNode(null);
}
// I don't know of any full-block nodes which query inventories, but we'll see
if (source == null) {
source = host.getGridNode(null);
}

if (source == null) {
break out;
}
if (source == null) {
break out;
}

var adapter = new QioStorageAdapter<>((BlockEntity & IQIOComponent) object, arg,
source.getOwningPlayerProfileId());
var adapter = new QioStorageAdapter<>((BlockEntity & IQIOComponent) object, arg,
source.getOwningPlayerProfileId());

if (adapter.getFrequency() != null) {
return LazyOptional.of(() -> adapter).cast();
}
if (adapter.getFrequency() != null) {
return LazyOptional.of(() -> adapter).cast();
}

return LazyOptional.empty();
}
});
}

return LazyOptional.empty();
}
});
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/me/ramidzkh/mekae2/util/ChemicalBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
public interface ChemicalBridge {

static <S extends ChemicalStack<?>> S withAmount(S stack, long amount) {
var copy = stack.copy();
var copy = (S) stack.copy();
copy.setAmount(amount);
return (S) copy;
return copy;
}
}

0 comments on commit 6e71ae5

Please sign in to comment.