mirror of
https://github.com/TicTicBoooom-Mods/MasterfulMachinery.git
synced 2026-03-18 21:40:34 +01:00
fixed energy slot rendering on EVERYTHING
This commit is contained in:
@@ -156,7 +156,7 @@ dependencies {
|
||||
// at runtime, use the full JEI jar
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}")
|
||||
|
||||
implementation fg.deobf("curse.maven:tesseractapi-462718:3293214")
|
||||
implementation fg.deobf('me.desht.pneumaticcraft:pneumaticcraft-repressurized:1.16.5-2.12.2-186');
|
||||
// You may put jars on which you depend on in ./libs or you may define them like so..
|
||||
// compile "some.group:artifact:version:classifier"
|
||||
// compile "some.group:artifact:version"
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -20,7 +21,7 @@ public class ControllerBlockContainer extends Container {
|
||||
super(p_i50105_1_, windowId);
|
||||
this.tile = tile;
|
||||
int playerOffsetX = 8;
|
||||
int playerOffsetY = 141;
|
||||
int playerOffsetY = 121;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
this.addSlot(new Slot(inv, 9 + (j * 9 + i), i* 18 + playerOffsetX, j* 18 + playerOffsetY));
|
||||
@@ -28,7 +29,7 @@ public class ControllerBlockContainer extends Container {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
this.addSlot(new Slot(inv, i,8 + (i * 18), 199));
|
||||
this.addSlot(new Slot(inv, i,8 + (i * 18), 179));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,4 +43,8 @@ public class ControllerBlockContainer extends Container {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(PlayerEntity p_82846_1_, int p_82846_2_) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ package com.ticticboooom.mods.mm.client.jei.category;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.ControllerBlock;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.EnergyIngredientHelper;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.EnergyIngredientRenderer;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.EnergyIngredientType;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.*;
|
||||
import com.ticticboooom.mods.mm.data.MachineProcessRecipe;
|
||||
import com.ticticboooom.mods.mm.data.MachineStructureRecipe;
|
||||
import com.ticticboooom.mods.mm.registration.MMLoader;
|
||||
@@ -30,6 +28,10 @@ public class MMJeiPlugin implements IModPlugin {
|
||||
public static final EnergyIngredientRenderer ENERGY_TYPE_RENDERER = new EnergyIngredientRenderer();
|
||||
public static final EnergyIngredientHelper ENERGY_TYPE_HELPER = new EnergyIngredientHelper();
|
||||
|
||||
public static final PNCPressureIngredientType PRESSURE_TYPE = new PNCPressureIngredientType();
|
||||
public static final PNCPressureIngredientRenderer PRESSURE_TYPE_RENDERER = new PNCPressureIngredientRenderer();
|
||||
public static final PNCPressureIngredientHelper PRESSURE_TYPE_HELPER = new PNCPressureIngredientHelper();
|
||||
|
||||
@Override
|
||||
public ResourceLocation getPluginUid() {
|
||||
return new ResourceLocation(MM.ID, "jei_main");
|
||||
@@ -38,6 +40,7 @@ public class MMJeiPlugin implements IModPlugin {
|
||||
@Override
|
||||
public void registerIngredients(IModIngredientRegistration registration) {
|
||||
registration.register(MMJeiPlugin.ENERGY_TYPE, ImmutableList.of(), ENERGY_TYPE_HELPER, ENERGY_TYPE_RENDERER);
|
||||
registration.register(MMJeiPlugin.PRESSURE_TYPE, ImmutableList.of(), PRESSURE_TYPE_HELPER, PRESSURE_TYPE_RENDERER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,43 +1,44 @@
|
||||
package com.ticticboooom.mods.mm.client.jei.ingredients;
|
||||
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.EnergyStack;
|
||||
import mezz.jei.api.ingredients.IIngredientHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class EnergyIngredientHelper implements IIngredientHelper<Integer> {
|
||||
public class EnergyIngredientHelper implements IIngredientHelper<EnergyStack> {
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getMatch(Iterable<Integer> ingredients, Integer ingredientToMatch) {
|
||||
public EnergyStack getMatch(Iterable<EnergyStack> ingredients, EnergyStack ingredientToMatch) {
|
||||
return ingredientToMatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(Integer ingredient) {
|
||||
public String getDisplayName(EnergyStack ingredient) {
|
||||
return "Forge Energy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueId(Integer ingredient) {
|
||||
return ingredient + "";
|
||||
public String getUniqueId(EnergyStack ingredient) {
|
||||
return "fe_" + ingredient + "_fe";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModId(Integer ingredient) {
|
||||
return "forge";
|
||||
public String getModId(EnergyStack ingredient) {
|
||||
return "mjkbnhsadfhvdasjeu";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourceId(Integer ingredient) {
|
||||
return "";
|
||||
public String getResourceId(EnergyStack ingredient) {
|
||||
return "fe_" + ingredient.getAmount() + "_fe";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer copyIngredient(Integer ingredient) {
|
||||
return ingredient;
|
||||
public EnergyStack copyIngredient(EnergyStack ingredient) {
|
||||
return new EnergyStack(ingredient.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorInfo(@Nullable Integer ingredient) {
|
||||
public String getErrorInfo(@Nullable EnergyStack ingredient) {
|
||||
return "Error";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.EnergyStack;
|
||||
import lombok.Setter;
|
||||
import mezz.jei.api.gui.drawable.IDrawableStatic;
|
||||
import mezz.jei.api.helpers.IJeiHelpers;
|
||||
@@ -17,20 +18,22 @@ import javax.annotation.Nullable;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class EnergyIngredientRenderer implements IIngredientRenderer<Integer> {
|
||||
public class EnergyIngredientRenderer implements IIngredientRenderer<EnergyStack> {
|
||||
@Setter
|
||||
private IJeiHelpers helpers;
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int xPosition, int yPosition, @Nullable Integer ingredient) {
|
||||
IDrawableStatic drawable = helpers.getGuiHelper().createDrawable(new ResourceLocation(MM.ID, "textures/gui/slot_parts.png"), 19, 62, 16, 16);
|
||||
drawable.draw(matrixStack, xPosition, yPosition);
|
||||
public void render(MatrixStack matrixStack, int xPosition, int yPosition, @Nullable EnergyStack ingredient) {
|
||||
if (ingredient != null) {
|
||||
IDrawableStatic drawable = helpers.getGuiHelper().createDrawable(new ResourceLocation(MM.ID, "textures/gui/slot_parts.png"), 19, 62, 16, 16);
|
||||
drawable.draw(matrixStack, xPosition, yPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITextComponent> getTooltip(Integer ingredient, ITooltipFlag tooltipFlag) {
|
||||
public List<ITextComponent> getTooltip(EnergyStack ingredient, ITooltipFlag tooltipFlag) {
|
||||
return Lists.newArrayList(
|
||||
new StringTextComponent("Forge Energy"),
|
||||
new StringTextComponent(NumberFormat.getInstance().format(ingredient) + " FE")
|
||||
new StringTextComponent(NumberFormat.getInstance().format(ingredient.getAmount()) + " FE")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.ticticboooom.mods.mm.client.jei.ingredients;
|
||||
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.EnergyStack;
|
||||
import mezz.jei.api.ingredients.IIngredientType;
|
||||
|
||||
public class EnergyIngredientType implements IIngredientType<Integer> {
|
||||
public class EnergyIngredientType implements IIngredientType<EnergyStack> {
|
||||
@Override
|
||||
public Class<? extends Integer> getIngredientClass() {
|
||||
return Integer.class;
|
||||
public Class<? extends EnergyStack> getIngredientClass() {
|
||||
return EnergyStack.class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.ticticboooom.mods.mm.client.jei.ingredients;
|
||||
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.PressureStack;
|
||||
import mezz.jei.api.ingredients.IIngredientHelper;
|
||||
import mezz.jei.api.ingredients.IIngredientType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PNCPressureIngredientHelper implements IIngredientHelper<PressureStack> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PressureStack getMatch(Iterable<PressureStack> ingredients, PressureStack ingredientToMatch) {
|
||||
return ingredientToMatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(PressureStack ingredient) {
|
||||
return "Pressure";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueId(PressureStack ingredient) {
|
||||
return ingredient.getAmount() + "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModId(PressureStack ingredient) {
|
||||
return "pneumaticcraft";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourceId(PressureStack ingredient) {
|
||||
return "pressure";
|
||||
}
|
||||
|
||||
@Override
|
||||
public PressureStack copyIngredient(PressureStack ingredient) {
|
||||
return new PressureStack(ingredient.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorInfo(@Nullable PressureStack ingredient) {
|
||||
return "Error";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ticticboooom.mods.mm.client.jei.ingredients;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.PressureStack;
|
||||
import mezz.jei.api.ingredients.IIngredientRenderer;
|
||||
import mezz.jei.api.ingredients.IIngredientType;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class PNCPressureIngredientRenderer implements IIngredientRenderer<PressureStack> {
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int xPosition, int yPosition, @Nullable PressureStack ingredient) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITextComponent> getTooltip(PressureStack ingredient, ITooltipFlag tooltipFlag) {
|
||||
return Lists.newArrayList(
|
||||
new StringTextComponent("PNC Pressure"),
|
||||
new StringTextComponent(ingredient.getAmount() + "Units")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.ticticboooom.mods.mm.client.jei.ingredients;
|
||||
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.PressureStack;
|
||||
import mezz.jei.api.ingredients.IIngredientType;
|
||||
|
||||
public class PNCPressureIngredientType implements IIngredientType<PressureStack> {
|
||||
@Override
|
||||
public Class<? extends PressureStack> getIngredientClass() {
|
||||
return PressureStack.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ticticboooom.mods.mm.client.jei.ingredients.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class EnergyStack {
|
||||
@Getter
|
||||
@Setter
|
||||
private int amount;
|
||||
|
||||
public EnergyStack(int amount){
|
||||
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ticticboooom.mods.mm.client.jei.ingredients.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class PressureStack {
|
||||
@Getter
|
||||
@Setter
|
||||
private float amount;
|
||||
|
||||
public PressureStack(float amount){
|
||||
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,6 @@ package com.ticticboooom.mods.mm.inventory;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
import tesseract.api.gt.GTConsumer;
|
||||
import tesseract.api.gt.IEnergyHandler;
|
||||
import tesseract.util.Dir;
|
||||
|
||||
public class PortEnergyInventory implements IEnergyStorage {
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
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.client.jei.category.MMJeiPlugin;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.PressureStack;
|
||||
import com.ticticboooom.mods.mm.ports.state.FluidPortState;
|
||||
import com.ticticboooom.mods.mm.ports.state.PneumaticPortState;
|
||||
import com.ticticboooom.mods.mm.ports.state.PortState;
|
||||
import com.ticticboooom.mods.mm.ports.storage.FluidPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PneumaticPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import lombok.SneakyThrows;
|
||||
import mezz.jei.api.constants.VanillaTypes;
|
||||
import mezz.jei.api.ingredients.IIngredients;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PneumaticPortParser implements IPortFactory{
|
||||
|
||||
@Override
|
||||
public Supplier<PortStorage> createStorage(JsonObject obj) {
|
||||
return () -> {
|
||||
DataResult<Pair<PneumaticPortStorage, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(PneumaticPortStorage.CODEC).apply(obj);
|
||||
return apply.result().get().getFirst();
|
||||
};
|
||||
}
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void write(PacketBuffer buf, PortState state) {
|
||||
buf.writeWithCodec(PneumaticPortState.CODEC, ((PneumaticPortState) state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIngredients(IIngredients ingredients, List<?> stacks, boolean input) {
|
||||
if (input) {
|
||||
ingredients.setInputs(MMJeiPlugin.PRESSURE_TYPE, (List<PressureStack>)stacks);
|
||||
} else {
|
||||
ingredients.setOutputs(MMJeiPlugin.PRESSURE_TYPE, (List<PressureStack>)stacks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PortState createState(JsonObject obj) {
|
||||
DataResult<Pair<PneumaticPortState, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(PneumaticPortState.CODEC).apply(obj);
|
||||
return apply.result().get().getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public PortState createState(PacketBuffer buf) {
|
||||
return buf.readWithCodec(PneumaticPortState.CODEC);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.client.jei.category.MMJeiPlugin;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.EnergyStack;
|
||||
import com.ticticboooom.mods.mm.ports.storage.EnergyPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import lombok.Getter;
|
||||
@@ -108,9 +109,9 @@ public static final Codec<EnergyPortState> CODEC =RecordCodecBuilder.create(x -
|
||||
|
||||
@Override
|
||||
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
|
||||
IGuiIngredientGroup<Integer> group = layout.getIngredientsGroup(MMJeiPlugin.ENERGY_TYPE);
|
||||
IGuiIngredientGroup<EnergyStack> group = layout.getIngredientsGroup(MMJeiPlugin.ENERGY_TYPE);
|
||||
group.init(typeIndex, input, x + 1, y + 1);
|
||||
group.set(typeIndex, amount);
|
||||
group.set(typeIndex, new EnergyStack(amount));
|
||||
if (this.getChance() < 1){
|
||||
group.addTooltipCallback((s, a, b, c) -> {
|
||||
if (s == typeIndex) {
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.ticticboooom.mods.mm.ports.state;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
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.client.jei.category.MMJeiPlugin;
|
||||
import com.ticticboooom.mods.mm.client.jei.ingredients.model.PressureStack;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PneumaticPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
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 org.lwjgl.system.CallbackI;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PneumaticPortState extends PortState {
|
||||
|
||||
public static final Codec<PneumaticPortState> CODEC = RecordCodecBuilder.create(x -> x.group(
|
||||
Codec.FLOAT.fieldOf("pressure").forGetter(z -> z.pressure)
|
||||
).apply(x, PneumaticPortState::new));
|
||||
|
||||
private float pressure;
|
||||
|
||||
public PneumaticPortState(float pressure) {
|
||||
this.pressure = pressure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processRequirement(List<PortStorage> storage) {
|
||||
float current = pressure;
|
||||
for (PortStorage portStorage : storage) {
|
||||
if (portStorage instanceof PneumaticPortStorage){
|
||||
PneumaticPortStorage pnc = (PneumaticPortStorage) portStorage;
|
||||
float prePressure = pnc.getInv().getPressure();
|
||||
pnc.getInv().setPressure(pnc.getInv().getPressure() - current);
|
||||
current -= prePressure;
|
||||
if (current <= 0){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateRequirement(List<PortStorage> storage) {
|
||||
float current = pressure;
|
||||
for (PortStorage portStorage : storage) {
|
||||
if (portStorage instanceof PneumaticPortStorage){
|
||||
PneumaticPortStorage pnc = (PneumaticPortStorage) portStorage;
|
||||
float prePressure = pnc.getInv().getPressure();
|
||||
current -= prePressure;
|
||||
if (current <= 0){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processResult(List<PortStorage> storage) {
|
||||
float current = pressure;
|
||||
for (PortStorage portStorage : storage) {
|
||||
if (portStorage instanceof PneumaticPortStorage){
|
||||
PneumaticPortStorage pnc = (PneumaticPortStorage) portStorage;
|
||||
float prePressure = pnc.getInv().getPressure();
|
||||
if (pnc.getInv().getPressure() - current > pnc.getInv().getDangerPressure()){
|
||||
pnc.getInv().setPressure(pnc.getInv().getDangerPressure());
|
||||
current -= pnc.getInv().getDangerPressure() - prePressure;
|
||||
} else {
|
||||
pnc.getInv().setPressure(prePressure + current);
|
||||
current -= prePressure;
|
||||
}
|
||||
if (current <= 0){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateResult(List<PortStorage> storage) {
|
||||
float current = pressure;
|
||||
for (PortStorage portStorage : storage) {
|
||||
if (portStorage instanceof PneumaticPortStorage){
|
||||
PneumaticPortStorage pnc = (PneumaticPortStorage) portStorage;
|
||||
float prePressure = pnc.getInv().getPressure();
|
||||
if (pnc.getInv().getPressure() - current > pnc.getInv().getDangerPressure()){
|
||||
pnc.getInv().setPressure(pnc.getInv().getDangerPressure());
|
||||
current -= pnc.getInv().getDangerPressure() - prePressure;
|
||||
} else {
|
||||
pnc.getInv().setPressure(prePressure + current);
|
||||
current -= prePressure;
|
||||
}
|
||||
if (current <= 0){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return new ResourceLocation(MM.ID, "pressure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredientType<?> getJeiIngredientType() {
|
||||
return MMJeiPlugin.PRESSURE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> getIngredient(boolean input) {
|
||||
return (List<T>) Lists.newArrayList(new PressureStack(pressure));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
|
||||
IGuiIngredientGroup<PressureStack> group = layout.getIngredientsGroup(MMJeiPlugin.PRESSURE_TYPE);
|
||||
group.init(typeIndex, input, x, y);
|
||||
group.set(typeIndex, new PressureStack(pressure));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack ms, int x, int y, int mouseX, int mouseY, IJeiHelpers helpers) {
|
||||
IDrawableStatic slot = helpers.getGuiHelper().getSlotDrawable();
|
||||
slot.draw(ms, x, y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
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.block.tile.MachinePortBlockEntity;
|
||||
import lombok.Getter;
|
||||
import me.desht.pneumaticcraft.api.PNCCapabilities;
|
||||
import me.desht.pneumaticcraft.common.capabilities.MachineAirHandler;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
public class PneumaticPortStorage extends PortStorage {
|
||||
|
||||
public static final Codec<PneumaticPortStorage> CODEC = RecordCodecBuilder.create(x -> x.group(
|
||||
Codec.FLOAT.fieldOf("dangerPressure").forGetter(z -> z.danger),
|
||||
Codec.FLOAT.fieldOf("criticalPressure").forGetter(z -> z.critical),
|
||||
Codec.INT.fieldOf("volume").forGetter(z -> z.volume)
|
||||
).apply(x, PneumaticPortStorage::new));
|
||||
|
||||
@Getter
|
||||
private MachineAirHandler inv;
|
||||
private final LazyOptional<MachineAirHandler> invLO;
|
||||
private float danger;
|
||||
private float critical;
|
||||
private int volume;
|
||||
|
||||
public PneumaticPortStorage(float danger, float critical, int volume) {
|
||||
this.danger = danger;
|
||||
this.critical = critical;
|
||||
this.volume = volume;
|
||||
inv = new MachineAirHandler(danger, critical, volume);
|
||||
invLO = LazyOptional.of(() -> inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getLO() {
|
||||
return invLO.cast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean validate(Capability<T> cap) {
|
||||
return cap == PNCCapabilities.AIR_HANDLER_MACHINE_CAPABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT save(CompoundNBT nbt) {
|
||||
CompoundNBT compound = new CompoundNBT();
|
||||
nbt.putFloat("pressure", inv.getPressure());
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundNBT nbt) {
|
||||
inv.setPressure(nbt.getFloat("pressure"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(MachinePortBlockEntity tile) {
|
||||
this.inv.tick(tile);
|
||||
}
|
||||
}
|
||||
@@ -31,4 +31,8 @@ public abstract class PortStorage {
|
||||
container.addSlot(new Slot(inv, i,8 + (i * 18), 199));
|
||||
}
|
||||
};
|
||||
|
||||
public void tick(MachinePortBlockEntity tile) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 13 KiB |
Reference in New Issue
Block a user