Skip to content

Commit

Permalink
Update for Mekanism chemical variant unification
Browse files Browse the repository at this point in the history
Update to 1.21.1
  • Loading branch information
ramidzkh committed Aug 21, 2024
1 parent 0886dd5 commit 1944864
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 807 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
plugins {
id("net.neoforged.moddev") version "0.1.126"
id("net.neoforged.moddev") version "1.0.17"
id("com.matthewprenger.cursegradle") version "1.4.0"
id("com.diffplug.spotless") version "6.25.0"
id("com.modrinth.minotaur") version "2.8.7"
}

group = "me.ramidzkh"
version = System.getenv("APPMEK_VERSION") ?: "0.0.0"
version = System.getenv("APPMEK_VERSION") ?: "1.6.0"

repositories {
maven {
Expand Down Expand Up @@ -52,7 +52,7 @@ dependencies {
compileOnly("mekanism:Mekanism:${minecraft_version}-${mekanism_version}:api")
runtimeOnly("mekanism:Mekanism:${minecraft_version}-${mekanism_version}:all")

implementation("dev.emi:emi-neoforge:${project.emi_version}+${project.minecraft_version}")
implementation("dev.emi:emi-neoforge:${project.emi_version}")

compileOnly("curse.maven:jade-324717:${jade_id}")
}
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
minecraft_version=1.21
neoforge_version=21.0.87-beta
ae2_version=19.0.11-alpha
mekanism_version=10.6.5.52
emi_version=1.1.10
jade_id=5493270
minecraft_version=1.21.1
neoforge_version=21.1.22
ae2_version=19.0.20-beta
mekanism_version=10.7.0.55
emi_version=1.1.12+1.21
jade_id=5427817

loader_version_range=[1,)
neo_version_range=[21.0,)
ae2_version_range=[19.0.11-alpha,20.0.0)
mekanism_version_range=[10.6.5,11-)
ae2_version_range=[19.0.20-beta,20.0.0)
mekanism_version_range=[10.7.0,11-)

org.gradle.caching=true
org.gradle.configuration-cache=true
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/ramidzkh/mekae2/AMMenus.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AMMenus {

public static final MenuType<MEStorageMenu> PORTABLE_CHEMICAL_CELL_TYPE = MenuTypeBuilder
.create(MEStorageMenu::new, IPortableTerminal.class)
.build("portable_chemical_cell");
.build(AppliedMekanistics.id("portable_chemical_cell"));

@SuppressWarnings("RedundantTypeArguments")
public static void initialize(IEventBus bus) {
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/me/ramidzkh/mekae2/AppliedMekanistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,15 @@ public AppliedMekanistics(IEventBus bus) {
}

private void registerPartCapabilities(RegisterPartCapabilitiesEvent event) {
event.register(MekCapabilities.GAS.block(), (part, context) -> part.getGasHandler(),
ChemicalP2PTunnelPart.class);
event.register(MekCapabilities.INFUSION.block(), (part, context) -> part.getInfuseHandler(),
ChemicalP2PTunnelPart.class);
event.register(MekCapabilities.PIGMENT.block(), (part, context) -> part.getPigmentHandler(),
ChemicalP2PTunnelPart.class);
event.register(MekCapabilities.SLURRY.block(), (part, context) -> part.getSlurryHandler(),
event.register(MekCapabilities.CHEMICAL.block(), (part, context) -> part.getExposedApi(),
ChemicalP2PTunnelPart.class);
}

private void registerGenericAdapters(RegisterCapabilitiesEvent event) {
for (var block : BuiltInRegistries.BLOCK) {
if (event.isBlockRegistered(AECapabilities.GENERIC_INTERNAL_INV, block)) {
registerGenericInvAdapter(event, block, MekCapabilities.GAS.block(),
GenericStackChemicalStorage.OfGas::new);
registerGenericInvAdapter(event, block, MekCapabilities.INFUSION.block(),
GenericStackChemicalStorage.OfInfusion::new);
registerGenericInvAdapter(event, block, MekCapabilities.PIGMENT.block(),
GenericStackChemicalStorage.OfPigment::new);
registerGenericInvAdapter(event, block, MekCapabilities.SLURRY.block(),
GenericStackChemicalStorage.OfSlurry::new);
registerGenericInvAdapter(event, block, MekCapabilities.CHEMICAL.block(),
GenericStackChemicalStorage::new);
}
}
}
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/me/ramidzkh/mekae2/MekCapabilities.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.ramidzkh.mekae2;

import java.util.List;

import org.jetbrains.annotations.Nullable;

import net.minecraft.core.Direction;
Expand All @@ -11,25 +9,16 @@

import mekanism.api.MekanismAPI;
import mekanism.api.chemical.IChemicalHandler;
import mekanism.api.chemical.gas.IGasHandler;
import mekanism.api.chemical.infuse.IInfusionHandler;
import mekanism.api.chemical.pigment.IPigmentHandler;
import mekanism.api.chemical.slurry.ISlurryHandler;

public class MekCapabilities {

private MekCapabilities() {
}

public static final CapSet<IGasHandler> GAS = new CapSet<>(rl("gas_handler"), IGasHandler.class);
public static final CapSet<IInfusionHandler> INFUSION = new CapSet<>(rl("infusion_handler"),
IInfusionHandler.class);
public static final CapSet<IPigmentHandler> PIGMENT = new CapSet<>(rl("pigment_handler"), IPigmentHandler.class);
public static final CapSet<ISlurryHandler> SLURRY = new CapSet<>(rl("slurry_handler"), ISlurryHandler.class);

public static final List<CapSet<?>> HANDLERS = List.of(GAS, INFUSION, PIGMENT, SLURRY);
public static final CapSet<IChemicalHandler> CHEMICAL = new CapSet<>(rl("chemical_handler"),
IChemicalHandler.class);

public record CapSet<T extends IChemicalHandler<?, ?>>(BlockCapability<T, @Nullable Direction> block,
public record CapSet<T extends IChemicalHandler>(BlockCapability<T, @Nullable Direction> block,
ItemCapability<T, Void> item) {
public CapSet(ResourceLocation name, Class<T> handlerClass) {
this(BlockCapability.createSided(name, handlerClass), ItemCapability.createVoid(name, handlerClass));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

import me.ramidzkh.mekae2.MekCapabilities;
import mekanism.api.Action;
import mekanism.api.chemical.gas.GasStack;
import mekanism.api.chemical.infuse.InfusionStack;
import mekanism.api.chemical.pigment.PigmentStack;
import mekanism.api.chemical.slurry.SlurryStack;

import appeng.api.behaviors.ContainerItemStrategy;
import appeng.api.config.Actionable;
Expand All @@ -29,16 +25,14 @@ public GenericStack getContainedStack(ItemStack stack) {
return null;
}

for (var capability : MekCapabilities.HANDLERS) {
var handler = stack.getCapability(capability.item());
var handler = stack.getCapability(MekCapabilities.CHEMICAL.item());

if (handler != null) {
var chemical = handler.extractChemical(Long.MAX_VALUE, Action.SIMULATE);
var key = MekanismKey.of(chemical);
if (handler != null) {
var chemical = handler.extractChemical(Long.MAX_VALUE, Action.SIMULATE);
var key = MekanismKey.of(chemical);

if (key != null) {
return new GenericStack(key, chemical.getAmount());
}
if (key != null) {
return new GenericStack(key, chemical.getAmount());
}
}

Expand All @@ -50,10 +44,8 @@ public GenericStack getContainedStack(ItemStack stack) {
public ItemStack findCarriedContext(Player player, AbstractContainerMenu menu) {
var carried = menu.getCarried();

for (var capability : MekCapabilities.HANDLERS) {
if (carried.getCapability(capability.item()) != null) {
return carried;
}
if (carried.getCapability(MekCapabilities.CHEMICAL.item()) != null) {
return carried;
}

return null;
Expand All @@ -63,97 +55,35 @@ public ItemStack findCarriedContext(Player player, AbstractContainerMenu menu) {
public @Nullable ItemStack findPlayerSlotContext(Player player, int slot) {
var carried = player.getInventory().getItem(slot);

for (var capability : MekCapabilities.HANDLERS) {
if (carried.getCapability(capability.item()) != null) {
return carried;
}
if (carried.getCapability(MekCapabilities.CHEMICAL.item()) != null) {
return carried;
}

return null;
}

@Override
public long extract(ItemStack context, MekanismKey what, long amount, Actionable mode) {
var stack = what.withAmount(amount);
var action = Action.fromFluidAction(mode.getFluidAction());

if (stack instanceof GasStack gas) {
var handler = context.getCapability(MekCapabilities.GAS.item());

if (handler != null) {
return handler.extractChemical(gas, action).getAmount();
} else {
return 0L;
}
} else if (stack instanceof InfusionStack infusion) {
var handler = context.getCapability(MekCapabilities.INFUSION.item());
var handler = context.getCapability(MekCapabilities.CHEMICAL.item());

if (handler != null) {
return handler.extractChemical(infusion, action).getAmount();
} else {
return 0L;
}
} else if (stack instanceof PigmentStack pigment) {
var handler = context.getCapability(MekCapabilities.PIGMENT.item());

if (handler != null) {
return handler.extractChemical(pigment, action).getAmount();
} else {
return 0L;
}
} else if (stack instanceof SlurryStack slurry) {
var handler = context.getCapability(MekCapabilities.SLURRY.item());

if (handler != null) {
return handler.extractChemical(slurry, action).getAmount();
} else {
return 0L;
}
} else {
throw new UnsupportedOperationException();
if (handler == null) {
return 0L;
}

return handler.extractChemical(what.withAmount(amount), Action.fromFluidAction(mode.getFluidAction()))
.getAmount();
}

@Override
public long insert(ItemStack context, MekanismKey what, long amount, Actionable mode) {
var stack = what.withAmount(amount);
var action = Action.fromFluidAction(mode.getFluidAction());

if (stack instanceof GasStack gas) {
var handler = context.getCapability(MekCapabilities.GAS.item());

if (handler != null) {
return amount - handler.insertChemical(gas, action).getAmount();
} else {
return 0L;
}
} else if (stack instanceof InfusionStack infusion) {
var handler = context.getCapability(MekCapabilities.INFUSION.item());

if (handler != null) {
return amount - handler.insertChemical(infusion, action).getAmount();
} else {
return 0L;
}
} else if (stack instanceof PigmentStack pigment) {
var handler = context.getCapability(MekCapabilities.PIGMENT.item());

if (handler != null) {
return amount - handler.insertChemical(pigment, action).getAmount();
} else {
return 0L;
}
} else if (stack instanceof SlurryStack slurry) {
var handler = context.getCapability(MekCapabilities.SLURRY.item());
var handler = context.getCapability(MekCapabilities.CHEMICAL.item());

if (handler != null) {
return amount - handler.insertChemical(slurry, action).getAmount();
} else {
return 0L;
}
} else {
throw new UnsupportedOperationException();
if (handler == null) {
return 0L;
}

return amount - handler.insertChemical(what.withAmount(amount), Action.fromFluidAction(mode.getFluidAction()))
.getAmount();
}

@Override
Expand Down
Loading

0 comments on commit 1944864

Please sign in to comment.