Skip to content

Commit

Permalink
Move IngredientConverters registration into onRuntimeAvailable
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh committed Nov 3, 2023
1 parent 03be790 commit 4f0d321
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package me.ramidzkh.mekae2.ae2.stack;

import java.util.Map;

import org.jetbrains.annotations.Nullable;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;

import me.ramidzkh.mekae2.MekCapabilities;
import me.ramidzkh.mekae2.ae2.MekanismKey;
import mekanism.api.chemical.IChemicalHandler;

import appeng.api.behaviors.ExternalStorageStrategy;
Expand All @@ -18,17 +15,17 @@

public class MekanismExternalStorageStrategy implements ExternalStorageStrategy {

private final Map<Byte, BlockApiCache<? extends IChemicalHandler>> lookups;
private final BlockApiCache<? extends IChemicalHandler>[] lookups;
private final Direction fromSide;

public MekanismExternalStorageStrategy(ServerLevel level,
BlockPos fromPos,
Direction fromSide) {
this.lookups = Map.of(
MekanismKey.GAS, BlockApiCache.create(MekCapabilities.GAS_HANDLER_CAPABILITY, level, fromPos),
MekanismKey.INFUSION, BlockApiCache.create(MekCapabilities.INFUSION_HANDLER_CAPABILITY, level, fromPos),
MekanismKey.PIGMENT, BlockApiCache.create(MekCapabilities.PIGMENT_HANDLER_CAPABILITY, level, fromPos),
MekanismKey.SLURRY, BlockApiCache.create(MekCapabilities.SLURRY_HANDLER_CAPABILITY, level, fromPos));
this.lookups = new BlockApiCache[] {
BlockApiCache.create(MekCapabilities.GAS_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.INFUSION_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.PIGMENT_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.SLURRY_HANDLER_CAPABILITY, level, fromPos) };
this.fromSide = fromSide;
}

Expand All @@ -38,14 +35,14 @@ public MEStorage createWrapper(boolean extractableOnly, Runnable injectOrExtract
var handlers = new IChemicalHandler[4];
var empty = true;

for (var entry : lookups.entrySet()) {
var storage = entry.getValue().find(fromSide);
for (int i = 0; i < 4; i++) {
var storage = lookups[i].find(fromSide);

if (storage == null) {
continue;
}

handlers[entry.getKey()] = storage;
handlers[i] = storage;
empty = false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.ramidzkh.mekae2.ae2.stack;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -24,17 +22,17 @@
public class MekanismStackExportStrategy implements StackExportStrategy {

private static final Logger LOGGER = LoggerFactory.getLogger(MekanismStackExportStrategy.class);
private final Map<Byte, BlockApiCache<? extends IChemicalHandler>> lookups;
private final BlockApiCache<? extends IChemicalHandler>[] lookups;
private final Direction fromSide;

public MekanismStackExportStrategy(ServerLevel level,
BlockPos fromPos,
Direction fromSide) {
this.lookups = Map.of(
MekanismKey.GAS, BlockApiCache.create(MekCapabilities.GAS_HANDLER_CAPABILITY, level, fromPos),
MekanismKey.INFUSION, BlockApiCache.create(MekCapabilities.INFUSION_HANDLER_CAPABILITY, level, fromPos),
MekanismKey.PIGMENT, BlockApiCache.create(MekCapabilities.PIGMENT_HANDLER_CAPABILITY, level, fromPos),
MekanismKey.SLURRY, BlockApiCache.create(MekCapabilities.SLURRY_HANDLER_CAPABILITY, level, fromPos));
this.lookups = new BlockApiCache[] {
BlockApiCache.create(MekCapabilities.GAS_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.INFUSION_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.PIGMENT_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.SLURRY_HANDLER_CAPABILITY, level, fromPos) };
this.fromSide = fromSide;
}

Expand All @@ -44,7 +42,7 @@ public long transfer(StackTransferContext context, AEKey what, long amount) {
return 0;
}

var storage = lookups.get(mekanismKey.getForm()).find(fromSide);
var storage = lookups[mekanismKey.getForm()].find(fromSide);

if (storage == null) {
return 0;
Expand Down Expand Up @@ -93,7 +91,7 @@ public long push(AEKey what, long amount, Actionable mode) {
return 0;
}

var storage = lookups.get(mekanismKey.getForm()).find(fromSide);
var storage = lookups[mekanismKey.getForm()].find(fromSide);

if (storage == null) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.ramidzkh.mekae2.ae2.stack;

import java.util.List;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -21,16 +19,17 @@
@SuppressWarnings("UnstableApiUsage")
public class MekanismStackImportStrategy implements StackImportStrategy {

private final List<BlockApiCache<? extends IChemicalHandler>> lookups;
private final BlockApiCache<? extends IChemicalHandler>[] lookups;
private final Direction fromSide;

public MekanismStackImportStrategy(ServerLevel level,
BlockPos fromPos,
Direction fromSide) {
this.lookups = List.of(BlockApiCache.create(MekCapabilities.GAS_HANDLER_CAPABILITY, level, fromPos),
this.lookups = new BlockApiCache[] {
BlockApiCache.create(MekCapabilities.GAS_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.INFUSION_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.PIGMENT_HANDLER_CAPABILITY, level, fromPos),
BlockApiCache.create(MekCapabilities.SLURRY_HANDLER_CAPABILITY, level, fromPos));
BlockApiCache.create(MekCapabilities.SLURRY_HANDLER_CAPABILITY, level, fromPos) };
this.fromSide = fromSide;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import mekanism.api.IMekanismAccess;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.runtime.IJeiRuntime;

import appeng.api.integrations.jei.IngredientConverters;

@JeiPlugin
public class AMJEIPlugin implements IModPlugin {

public AMJEIPlugin() {
@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
var helper = IMekanismAccess.INSTANCE.jeiHelper();

IngredientConverters
Expand Down

0 comments on commit 4f0d321

Please sign in to comment.