Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ChemicalIngredientConverter check the ingredient class #48

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}