Merge pull request #28 from rguy98/testing

Upgrade Mekanism to 10.1
This commit is contained in:
TicTicBoooom
2021-12-24 17:30:07 +00:00
committed by GitHub
12 changed files with 338 additions and 12 deletions

View File

@@ -177,7 +177,7 @@ dependencies {
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
compileOnly 'org.projectlombok:lombok:1.18.18'
annotationProcessor 'org.projectlombok:lombok:1.18.18'
minecraft 'net.minecraftforge:forge:1.16.5-36.1.23'
minecraft 'net.minecraftforge:forge:1.16.5-36.2.21'
compileOnly 'com.google.code.gson:gson:2.8.7'
implementation 'org.spongepowered:mixin:0.8-SNAPSHOT'

View File

@@ -2,6 +2,6 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
mekanism_version=1.16.5-10.0.20.447
mekanism_version=1.16.5-10.1.0.455
mc_version=1.16.5
jei_version=7.+
jei_version=7.+

View File

@@ -5,13 +5,10 @@ import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.chemical.IChemicalHandler;
import mekanism.api.chemical.IChemicalTank;
import mekanism.api.chemical.gas.GasStack;
import net.minecraft.nbt.CompoundNBT;
import javax.annotation.Nonnull;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
public class MekChemicalInventory<CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> implements IChemicalHandler<CHEMICAL, STACK>, IChemicalTank<CHEMICAL, STACK> {
private STACK stack;

View File

@@ -0,0 +1,15 @@
package com.ticticboooom.mods.mm.inventory.mek;
import mekanism.api.chemical.infuse.IInfusionHandler;
import mekanism.api.chemical.infuse.InfuseType;
import mekanism.api.chemical.infuse.InfusionStack;
import mekanism.api.chemical.pigment.IPigmentHandler;
import mekanism.api.chemical.pigment.Pigment;
import mekanism.api.chemical.pigment.PigmentStack;
public class PortMekPigmentInventory extends MekChemicalInventory<Pigment, PigmentStack> implements IPigmentHandler {
public PortMekPigmentInventory(long capacity) {
super(PigmentStack.EMPTY, capacity, PigmentStack::new);
}
}

View File

@@ -0,0 +1,69 @@
package com.ticticboooom.mods.mm.ports.parser;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.ports.state.MekPigmentPortState;
import com.ticticboooom.mods.mm.ports.state.PortState;
import com.ticticboooom.mods.mm.ports.storage.MekPigmentPortStorage;
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
import lombok.SneakyThrows;
import mekanism.api.chemical.pigment.PigmentStack;
import mekanism.client.jei.MekanismJEI;
import mezz.jei.api.ingredients.IIngredients;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;
import java.util.List;
import java.util.function.Supplier;
public class MekPigmentPortParser extends PortFactory {
@Override
public void setIngredients(IIngredients ingredients, List<?> stacks, boolean input) {
if (input) {
ingredients.setInputs(MekanismJEI.TYPE_PIGMENT, (List<PigmentStack>)stacks);
} else {
ingredients.setOutputs(MekanismJEI.TYPE_PIGMENT, (List<PigmentStack>)stacks);
}
}
@Override
public PortState createState(JsonObject obj) {
DataResult<Pair<MekPigmentPortState, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(MekPigmentPortState.CODEC).apply(obj);
return apply.result().get().getFirst();
}
@SneakyThrows
@Override
public PortState createState(PacketBuffer buf) {
return buf.func_240628_a_(MekPigmentPortState.CODEC);
}
@Override
public Supplier<PortStorage> createStorage(JsonObject obj) {
return () -> {
DataResult<Pair<MekPigmentPortStorage, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(MekPigmentPortStorage.CODEC).apply(obj);
return apply.result().get().getFirst();
};
}
@SneakyThrows
@Override
public void write(PacketBuffer buf, PortState state) {
buf.func_240629_a_(MekPigmentPortState.CODEC, (MekPigmentPortState)state);
}
@Override
public ResourceLocation getInputOverlay() {
return new ResourceLocation(MM.ID, "block/compat_ports/mekanism_infusion_input_cutout");
}
@Override
public ResourceLocation getOutputOverlay() {
return new ResourceLocation(MM.ID, "block/compat_ports/mekanism_infusion_output_cutout");
}
}

View File

@@ -41,7 +41,7 @@ public class MekGasPortState extends PortState {
this.gas = gas;
this.amount = amount;
renderer = new ChemicalStackRenderer<>(amount, false, 16, 16, null);
renderer = new ChemicalStackRenderer<>(amount, 16, 16); // Fixed to meet Mekanism 10.1's revised code
}
@Override

View File

@@ -41,7 +41,7 @@ public class MekInfusePortState extends PortState {
public MekInfusePortState(String gas, long amount) {
this.infuse = gas;
this.amount = amount;
renderer = new ChemicalStackRenderer<>(amount, false, 16, 16, null);
renderer = new ChemicalStackRenderer<>(amount, 16, 16);
}
@Override

View File

@@ -0,0 +1,160 @@
package com.ticticboooom.mods.mm.ports.state;
import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.exception.InvalidProcessDefinitionException;
import com.ticticboooom.mods.mm.helper.RLUtils;
import com.ticticboooom.mods.mm.ports.storage.MekPigmentPortStorage;
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
import lombok.SneakyThrows;
import mekanism.api.Action;
import mekanism.api.MekanismAPI;
import mekanism.api.chemical.infuse.InfusionStack;
import mekanism.api.chemical.pigment.PigmentStack;
import mekanism.api.chemical.pigment.PigmentStack;
import mekanism.client.jei.ChemicalStackRenderer;
import mekanism.client.jei.MekanismJEI;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.gui.ingredient.IGuiIngredientGroup;
import mezz.jei.api.helpers.IJeiHelpers;
import mezz.jei.api.ingredients.IIngredientType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.StringTextComponent;
import java.util.List;
import java.util.Objects;
public class MekPigmentPortState extends PortState {
public static final Codec<MekPigmentPortState> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.STRING.fieldOf("pigment").forGetter(z -> z.pigment),
Codec.LONG.fieldOf("amount").forGetter(z -> z.amount)
).apply(x, MekPigmentPortState::new));
private final String pigment;
private final long amount;
public MekPigmentPortState(String gas, long amount) {
this.pigment = gas;
this.amount = amount;
renderer = new ChemicalStackRenderer<>(amount, 16, 16);
}
@Override
public void processRequirement(List<PortStorage> storage) {
long current = amount;
for (PortStorage st : storage) {
if (st instanceof MekPigmentPortStorage) {
MekPigmentPortStorage gasStorage = (MekPigmentPortStorage) st;
if (gasStorage.getInv().getStack().getType().getRegistryName().toString().equals(pigment)) {
PigmentStack extract = gasStorage.getInv().extractChemical(0, current, Action.EXECUTE);
current -= extract.getAmount();
}
if (current <= 0){
return;
}
}
}
}
@Override
public boolean validateRequirement(List<PortStorage> storage) {
long current = amount;
for (PortStorage st : storage) {
if (st instanceof MekPigmentPortStorage) {
MekPigmentPortStorage gasStorage = (MekPigmentPortStorage) st;
if (gasStorage.getInv().getStack().getType().getRegistryName().toString().equals(pigment)) {
PigmentStack extract = gasStorage.getInv().extractChemical(0, current, Action.SIMULATE);
current -= extract.getAmount();
}
if (current <= 0) {
return true;
}
}
}
return false;
}
@Override
public void processResult(List<PortStorage> storage) {
long current = amount;
for (PortStorage st : storage) {
if (st instanceof MekPigmentPortStorage) {
MekPigmentPortStorage gasStorage = (MekPigmentPortStorage) st;
PigmentStack extract = gasStorage.getInv().insertChemical(new PigmentStack(Objects.requireNonNull(MekanismAPI.pigmentRegistry().getValue(RLUtils.toRL(pigment))), current), Action.EXECUTE);
current -= current - extract.getAmount();
if (current <= 0) {
return;
}
}
}
}
@Override
public boolean validateResult(List<PortStorage> storage) {
long current = amount;
for (PortStorage st : storage) {
if (st instanceof MekPigmentPortStorage) {
MekPigmentPortStorage gasStorage = (MekPigmentPortStorage) st;
PigmentStack extract = gasStorage.getInv().insertChemical(new PigmentStack(Objects.requireNonNull(MekanismAPI.pigmentRegistry().getValue(RLUtils.toRL(pigment))), current), Action.SIMULATE);
current -= current - extract.getAmount();
if (current <= 0) {
return true;
}
}
}
return false;
}
@Override
public ResourceLocation getName() {
return new ResourceLocation(MM.ID, "mekanism_pigment");
}
@SneakyThrows
@Override
public void validateDefinition() {
if (!RLUtils.isRL(pigment)){
throw new InvalidProcessDefinitionException("Pigment Type: " + pigment + " is not a valid pigment type id (ResourceLocation)");
}
if (!MekanismAPI.pigmentRegistry().containsKey(RLUtils.toRL(pigment))){
throw new InvalidProcessDefinitionException("Pigment Type: " + pigment + " does not exist in the mekansim pigment registry");
}
}
private final ChemicalStackRenderer<PigmentStack> renderer;
@Override
public void render(MatrixStack ms, int x, int y, int mouseX, int mouseY, IJeiHelpers helpers) {
IDrawableStatic drawable = helpers.getGuiHelper().getSlotDrawable();
drawable.draw(ms, x, y);
}
@Override
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
IGuiIngredientGroup<PigmentStack> gasGroup = layout.getIngredientsGroup(MekanismJEI.TYPE_PIGMENT);
gasGroup.init(typeIndex, input, renderer, x + 1, y + 1, 16, 16, 0, 0);
gasGroup.set(typeIndex, new PigmentStack(MekanismAPI.pigmentRegistry().getValue(RLUtils.toRL(pigment)), amount));
if (this.getChance() < 1) {
gasGroup.addTooltipCallback((s, a, b, c) -> {
if (s == typeIndex) {
c.add(new StringTextComponent("Chance: " + this.getChance() * 100 + "%"));
}
});
}
}
@Override
public <T> List<T> getIngredient(boolean input) {
return (List<T>) ImmutableList.of(new PigmentStack(MekanismAPI.pigmentRegistry().getValue(RLUtils.toRL(pigment)), amount));
}
@Override
public IIngredientType<?> getJeiIngredientType() {
return MekanismJEI.TYPE_PIGMENT;
}
}

View File

@@ -41,7 +41,7 @@ public class MekSlurryPortState extends PortState {
public MekSlurryPortState(String gas, long amount) {
this.slurry = gas;
this.amount = amount;
renderer = new ChemicalStackRenderer<>(amount, false, 16, 16, null);
renderer = new ChemicalStackRenderer<>(amount, 16, 16);
}
@Override

View File

@@ -0,0 +1,84 @@
package com.ticticboooom.mods.mm.ports.storage;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.helper.GuiHelper;
import com.ticticboooom.mods.mm.helper.RLUtils;
import com.ticticboooom.mods.mm.inventory.mek.PortMekInfuseInventory;
import com.ticticboooom.mods.mm.inventory.mek.PortMekPigmentInventory;
import lombok.Getter;
import mekanism.api.MekanismAPI;
import mekanism.api.chemical.infuse.InfusionStack;
import mekanism.api.chemical.pigment.PigmentStack;
import mekanism.common.capabilities.Capabilities;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import java.util.Objects;
public class MekPigmentPortStorage extends PortStorage {
public static final Codec<MekPigmentPortStorage> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.LONG.fieldOf("capacity").forGetter(z -> z.capacity)
).apply(x, MekPigmentPortStorage::new));
@Getter
private final PortMekPigmentInventory inv;
private long capacity;
private final LazyOptional<PortMekPigmentInventory> invLO;
public MekPigmentPortStorage(long capacity) {
inv = new PortMekPigmentInventory(capacity);
this.capacity = capacity;
invLO = LazyOptional.of(() -> inv);
}
@Override
public <T> LazyOptional<T> getLO() {
return invLO.cast();
}
@Override
public <T> boolean validate(Capability<T> cap) {
return cap == Capabilities.PIGMENT_HANDLER_CAPABILITY;
}
@Override
public CompoundNBT save(CompoundNBT nbt) {
nbt.putString("pigment", inv.getStack().getType().getRegistryName().toString());
nbt.putLong("amount", inv.getStack().getAmount());
return nbt;
}
@Override
public void load(CompoundNBT nbt) {
if (nbt.contains("pigment")){
inv.setStack(new PigmentStack(Objects.requireNonNull(MekanismAPI.pigmentRegistry().getValue(RLUtils.toRL(nbt.getString("pigment")))), nbt.getLong("amount")));
}
}
@Override
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
Minecraft.getInstance().textureManager.bindTexture(new ResourceLocation(MM.ID, "textures/gui/port_gui.png"));
screen.blit(stack, left, top, 0, 0, 175, 256);
int barX = left + 175 - 30;
int barY = top + 20;
int barWidth = 18;
int barHeight = 108;
screen.blit(stack, barX, barY, 175, 18, barWidth, barHeight);
float pct = 0;
if (inv.getStack().getAmount() > 0) {
pct = (float) inv.getStack().getAmount() / inv.getTankCapacity(0);
}
GuiHelper.renderVerticallyFilledBar(stack, screen, barX, barY, 193, 18, barWidth, barHeight, pct);
AbstractGui.drawString(stack, Minecraft.getInstance().fontRenderer, inv.getStack().getType().getTextComponent().getString(), left + 30, top + 60, 0xfefefe);
AbstractGui.drawString(stack, Minecraft.getInstance().fontRenderer, inv.getStack().getAmount() + "mB", left + 30, top + 80, 0xfefefe);
}
}

View File

@@ -16,11 +16,12 @@ public class MMPorts {
PORTS.put(new ResourceLocation(MM.ID, "items"), new MasterfulPortType(new ResourceLocation(MM.ID, "items"), new ItemPortParser()));
PORTS.put(new ResourceLocation(MM.ID, "fluids"), new MasterfulPortType(new ResourceLocation(MM.ID, "fluids"), new FluidPortParser()));
PORTS.put(new ResourceLocation(MM.ID, "energy"),new MasterfulPortType(new ResourceLocation(MM.ID, "energy"), new EnergyPortParser()));
// PORTS.put(new ResourceLocation(MM.ID, "weather"),new MasterfulPortType(new ResourceLocation(MM.ID, "weather"), new WeatherPortParser()));
//PORTS.put(new ResourceLocation(MM.ID, "weather"),new MasterfulPortType(new ResourceLocation(MM.ID, "weather"), new WeatherPortParser()));
if (ModList.get().isLoaded("mekanism")) {
PORTS.put(new ResourceLocation(MM.ID, "mekanism_gas"),new MasterfulPortType(new ResourceLocation(MM.ID, "mekanism_gas"), new MekGasPortParser()));
PORTS.put(new ResourceLocation(MM.ID, "mekanism_slurry"),new MasterfulPortType(new ResourceLocation(MM.ID, "mekanism_slurry"), new MekSlurryPortParser()));
PORTS.put(new ResourceLocation(MM.ID, "mekanism_infuse"),new MasterfulPortType(new ResourceLocation(MM.ID, "mekanism_infuse"), new MekInfusePortParser()));
PORTS.put(new ResourceLocation(MM.ID, "mekanism_pigment"),new MasterfulPortType(new ResourceLocation(MM.ID, "mekanism_pigment"), new MekPigmentPortParser()));
}
if (ModList.get().isLoaded("pneumaticcraft")){
PORTS.put(new ResourceLocation(MM.ID, "pncr_pressure"),new MasterfulPortType(new ResourceLocation(MM.ID, "pncr_pressure"), new PneumaticPortParser()));

View File

@@ -1,2 +1,2 @@
#Sun Nov 28 19:05:29 GMT 2021
VERSION_CODE=866
#Thu Dec 23 07:37:00 EST 2021
VERSION_CODE=894