mirror of
https://github.com/TicTicBoooom-Mods/MasterfulMachinery.git
synced 2026-01-18 16:37:23 +01:00
fixed some bugs and finished jei support (for now)
This commit is contained in:
@@ -18,7 +18,7 @@ apply plugin: 'net.minecraftforge.gradle'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
version = '1.16.5-0.1.7-T' + System.currentTimeMillis()
|
||||
version = '1.16.5-0.1.13-T' + System.currentTimeMillis()
|
||||
group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = 'MasterfulMachinery'
|
||||
|
||||
|
||||
@@ -56,9 +56,10 @@ public class ControllerBlockEntity extends UpdatableTile implements ITickableTil
|
||||
if (index != -1) {
|
||||
update.setMsg("Found structure");
|
||||
onStructureFound(recipe, index);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
private void onStructureFound(MachineStructureRecipe structure, int index) {
|
||||
@@ -83,16 +84,16 @@ public class ControllerBlockEntity extends UpdatableTile implements ITickableTil
|
||||
|
||||
private void onPortsEstablished(List<IPortStorage> inputPorts, List<IPortStorage> outputPorts, MachineStructureRecipe structure) {
|
||||
List<MachineProcessRecipe> processRecipes = level.getRecipeManager().getAllRecipesFor(RecipeTypes.MACHINE_PROCESS);
|
||||
boolean processed = false;
|
||||
for (MachineProcessRecipe recipe : processRecipes) {
|
||||
if (recipe.matches(inputPorts, structure.getStructureId())) {
|
||||
this.update = recipe.process(inputPorts, outputPorts, this.update);
|
||||
update();
|
||||
return;
|
||||
} else {
|
||||
this.update.setTicksTaken(0);
|
||||
update();
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
if (!processed) {
|
||||
this.update.setTicksTaken(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.ticticboooom.mods.mm.client.jei.category;
|
||||
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.ControllerBlock;
|
||||
import com.ticticboooom.mods.mm.data.MachineProcessRecipe;
|
||||
import com.ticticboooom.mods.mm.data.MachineStructureRecipe;
|
||||
import com.ticticboooom.mods.mm.registration.MMLoader;
|
||||
import com.ticticboooom.mods.mm.registration.RecipeTypes;
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.JeiPlugin;
|
||||
@@ -9,8 +12,11 @@ import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
||||
import mezz.jei.api.registration.IRecipeRegistration;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@JeiPlugin
|
||||
public class MMJeiPlugin implements IModPlugin {
|
||||
@@ -21,13 +27,26 @@ public class MMJeiPlugin implements IModPlugin {
|
||||
|
||||
@Override
|
||||
public void registerRecipes(IRecipeRegistration registration) {
|
||||
List<MachineStructureRecipe> structureRecipes = Minecraft.getInstance().level.getRecipeManager().getAllRecipesFor(RecipeTypes
|
||||
.MACHINE_STRUCTURE);
|
||||
registration.addRecipes(structureRecipes, new ResourceLocation(MM.ID, "machine_structure"));
|
||||
List<MachineStructureRecipe> structureRecipes = Minecraft.getInstance().level.getRecipeManager().getAllRecipesFor(RecipeTypes.MACHINE_STRUCTURE);
|
||||
for (RegistryObject<ControllerBlock> block : MMLoader.BLOCKS) {
|
||||
registration.addRecipes(structureRecipes.stream().filter(x -> x.getControllerId().contains(block.get().getControllerId())).collect(Collectors.toList()), new ResourceLocation(MM.ID, "machine_structure_" + block.get().getControllerId()));
|
||||
}
|
||||
|
||||
List<MachineProcessRecipe> processRecipes = Minecraft.getInstance().level.getRecipeManager().getAllRecipesFor(RecipeTypes.MACHINE_PROCESS);
|
||||
for (MachineStructureRecipe structureRecipe : structureRecipes) {
|
||||
List<MachineProcessRecipe> recipes = processRecipes.stream().filter(x -> x.getStructureId().equals(structureRecipe.getStructureId())).collect(Collectors.toList());
|
||||
registration.addRecipes(recipes, new ResourceLocation(MM.ID, "machine_process_" + structureRecipe.getStructureId()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCategories(IRecipeCategoryRegistration registration) {
|
||||
registration.addRecipeCategories(new MachineStructureRecipeCategory(registration.getJeiHelpers()));
|
||||
for (RegistryObject<ControllerBlock> block : MMLoader.BLOCKS) {
|
||||
registration.addRecipeCategories(new MachineStructureRecipeCategory(registration.getJeiHelpers(), block.get()));
|
||||
}
|
||||
List<MachineStructureRecipe> structureRecipes = Minecraft.getInstance().level.getRecipeManager().getAllRecipesFor(RecipeTypes.MACHINE_STRUCTURE);
|
||||
for (MachineStructureRecipe structureRecipe : structureRecipes) {
|
||||
registration.addRecipeCategories(new MachineProcessRecipeCategory(registration.getJeiHelpers(), structureRecipe.getStructureId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,31 +3,50 @@ package com.ticticboooom.mods.mm.client.jei.category;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.data.MachineProcessRecipe;
|
||||
import com.ticticboooom.mods.mm.helper.RLUtils;
|
||||
import com.ticticboooom.mods.mm.ports.state.FluidPortState;
|
||||
import com.ticticboooom.mods.mm.ports.state.ItemPortState;
|
||||
import com.ticticboooom.mods.mm.ports.state.PortState;
|
||||
import com.ticticboooom.mods.mm.ports.storage.MekGasPortStorage;
|
||||
import com.ticticboooom.mods.mm.registration.RecipeTypes;
|
||||
import mekanism.api.chemical.gas.GasStack;
|
||||
import mekanism.api.recipes.inputs.chemical.ChemicalIngredientDeserializer;
|
||||
import mekanism.api.recipes.inputs.chemical.GasStackIngredient;
|
||||
import mekanism.client.jei.MekanismJEI;
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.gui.drawable.IDrawable;
|
||||
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 mezz.jei.api.ingredients.IIngredients;
|
||||
import mezz.jei.api.recipe.category.IRecipeCategory;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MachineProcessRecipeCategory implements IRecipeCategory<MachineProcessRecipe> {
|
||||
|
||||
private static final ResourceLocation overlayRl = new ResourceLocation(MM.ID, "textures/gui/gui_large_jei.png");
|
||||
|
||||
private IJeiHelpers helpers;
|
||||
private String title;
|
||||
private String structureId;
|
||||
|
||||
public MachineProcessRecipeCategory(IJeiHelpers helpers, String title) {
|
||||
public MachineProcessRecipeCategory(IJeiHelpers helpers, String structureId) {
|
||||
this.helpers = helpers;
|
||||
|
||||
this.title = title;
|
||||
this.structureId = structureId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getUid() {
|
||||
return new ResourceLocation(MM.ID, "machine_process");
|
||||
return new ResourceLocation(MM.ID, "machine_process_" + structureId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,11 +56,11 @@ public class MachineProcessRecipeCategory implements IRecipeCategory<MachineProc
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
return "Process";
|
||||
}
|
||||
|
||||
public IDrawable getBackground() {
|
||||
return helpers.getGuiHelper().createDrawable(overlayRl, 0, 0, 162, 150);
|
||||
return helpers.getGuiHelper().createBlankDrawable(162, 150);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,18 +70,75 @@ public class MachineProcessRecipeCategory implements IRecipeCategory<MachineProc
|
||||
|
||||
@Override
|
||||
public void setIngredients(MachineProcessRecipe recipe, IIngredients ingredients) {
|
||||
|
||||
for (PortState input : recipe.getInputs()) {
|
||||
input.setIngredient(ingredients, true);
|
||||
}
|
||||
for (PortState output : recipe.getOutputs()) {
|
||||
output.setIngredient(ingredients, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipe(IRecipeLayout recipeLayout, MachineProcessRecipe recipe, IIngredients ingredients) {
|
||||
final int inputWidth = 60;
|
||||
Map<String, Integer> indexMap = new HashMap<>();
|
||||
int currentX = 0;
|
||||
int currentY = 0;
|
||||
for (PortState input : recipe.getInputs()) {
|
||||
Integer index = indexMap.getOrDefault(input.getClass().toString(), 0);
|
||||
input.setupRecipe(recipeLayout, index, currentX, currentY, true);
|
||||
indexMap.put(input.getClass().toString(), ++index);
|
||||
currentX += 20;
|
||||
if (currentX >= inputWidth) {
|
||||
currentX = 0;
|
||||
currentY += 20;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final int offsetX = 95;
|
||||
currentX = offsetX;
|
||||
currentY = 0;
|
||||
for (PortState output : recipe.getOutputs()) {
|
||||
Integer index = indexMap.getOrDefault(output.getClass().toString(), 0);
|
||||
output.setupRecipe(recipeLayout, index, currentX, currentY, false);
|
||||
indexMap.put(output.getClass().toString(), ++index);
|
||||
currentX += 20;
|
||||
if (currentX >= inputWidth + offsetX) {
|
||||
currentX = offsetX;
|
||||
currentY += 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(MachineProcessRecipe recipe, MatrixStack matrixStack, double mouseX, double mouseY) {
|
||||
for (PortState input : recipe.getInputs()) {
|
||||
final int inputWidth = 60;
|
||||
|
||||
int currentX = 0;
|
||||
int currentY = 0;
|
||||
for (PortState input : recipe.getInputs()) {
|
||||
input.render(matrixStack, currentX, currentY, (int) mouseX, (int) mouseY, helpers);
|
||||
currentX += 20;
|
||||
if (currentX >= inputWidth) {
|
||||
currentX = 0;
|
||||
currentY += 20;
|
||||
}
|
||||
}
|
||||
|
||||
final int offsetX = 95;
|
||||
currentX = offsetX;
|
||||
currentY = 0;
|
||||
for (PortState output : recipe.getOutputs()) {
|
||||
output.render(matrixStack, currentX, currentY, (int) mouseX, (int) mouseY, helpers);
|
||||
currentX += 20;
|
||||
if (currentX >= inputWidth + offsetX) {
|
||||
currentX = offsetX;
|
||||
currentY += 20;
|
||||
}
|
||||
}
|
||||
|
||||
IDrawableStatic drawable = helpers.getGuiHelper().createDrawable(new ResourceLocation(MM.ID, "textures/gui/slot_parts.png"), 26, 0, 24, 17);
|
||||
drawable.draw(matrixStack, 66, 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
|
||||
private static final ResourceLocation iconRl = new ResourceLocation(MM.ID, "textures/items/blueprint.png");
|
||||
private static final ResourceLocation slotRl = new ResourceLocation(MM.ID, "textures/gui/slot_parts.png");
|
||||
private IJeiHelpers helpers;
|
||||
private ControllerBlock controller;
|
||||
private MachineStructureRecipe recipe;
|
||||
private float xRotation = 0;
|
||||
private double xLastMousePosition = 0;
|
||||
@@ -48,13 +49,14 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
|
||||
private int sliceY = 0;
|
||||
private boolean slicingActive = false;
|
||||
|
||||
public MachineStructureRecipeCategory(IJeiHelpers helpers) {
|
||||
public MachineStructureRecipeCategory(IJeiHelpers helpers, ControllerBlock controller) {
|
||||
this.helpers = helpers;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getUid() {
|
||||
return new ResourceLocation(MM.ID, "machine_structure");
|
||||
return new ResourceLocation(MM.ID, "machine_structure_" + controller.getControllerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,7 +66,7 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "Machine Structures";
|
||||
return controller.getControllerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,6 +86,7 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
|
||||
Ingredient ingredient = Ingredient.of(new ItemStack(MMSetup.BLUEPRINT.get()));
|
||||
ArrayList<Ingredient> objects = new ArrayList<>();
|
||||
objects.add(ingredient);
|
||||
objects.add(Ingredient.of(new ItemStack(ForgeRegistries.ITEMS.getValue(controller.getRegistryName()))));
|
||||
iIngredients.setInputIngredients(objects);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
|
||||
|
||||
List<PortState> inputStates = getStates(inputs);
|
||||
List<PortState> outputStates = getStates(outputs);
|
||||
|
||||
validateProcess(inputStates, outputStates, ticks, structureId, rl);
|
||||
return new MachineProcessRecipe(inputStates, outputStates, ticks, structureId, rl);
|
||||
}
|
||||
|
||||
@@ -259,5 +259,15 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
|
||||
return RecipeTypes.PROCESS.get().getRegistryType();
|
||||
}
|
||||
|
||||
|
||||
private void validateProcess(List<PortState> inputs, List<PortState> outputs, int ticks, String structureId, ResourceLocation rl) {
|
||||
for (PortState input : inputs) {
|
||||
input.validateDefinition();
|
||||
}
|
||||
|
||||
for (PortState output : outputs) {
|
||||
output.validateDefinition();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3i;
|
||||
import net.minecraft.world.World;
|
||||
@@ -60,13 +61,12 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
|
||||
List<MachineStructureRecipeKeyModel> rotated2 = new ArrayList<>();
|
||||
|
||||
for (MachineStructureRecipeKeyModel model : models) {
|
||||
BlockPos rotatedPos = new BlockPos(model.getPos().getZ(), model.getPos().getY(), model.getPos().getX());
|
||||
BlockPos rotatedPos = new BlockPos(model.getPos().getX(), model.getPos().getY(), model.getPos().getZ()).rotate(Rotation.CLOCKWISE_90);
|
||||
BlockPos rotatedPos1 = new BlockPos(model.getPos().getX(), model.getPos().getY(), model.getPos().getZ()).rotate(Rotation.CLOCKWISE_180);
|
||||
BlockPos rotatedPos2 = new BlockPos(model.getPos().getX(), model.getPos().getY(), model.getPos().getZ()).rotate(Rotation.COUNTERCLOCKWISE_90);
|
||||
|
||||
rotated.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(rotatedPos.getX(), rotatedPos.getY(), rotatedPos.getZ()), model.getTag(),model.getBlock(), model.getNbt()));
|
||||
|
||||
BlockPos rotatedPos1 = new BlockPos(-model.getPos().getX(), model.getPos().getY(), -model.getPos().getZ());
|
||||
rotated1.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(rotatedPos1.getX(), rotatedPos1.getY(), rotatedPos1.getZ()), model.getTag(),model.getBlock(), model.getNbt()));
|
||||
|
||||
BlockPos rotatedPos2 = new BlockPos(-model.getPos().getZ(), model.getPos().getY(), -model.getPos().getX());
|
||||
rotated2.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(rotatedPos2.getX(), rotatedPos2.getY(), rotatedPos2.getZ()), model.getTag(),model.getBlock(), model.getNbt()));
|
||||
}
|
||||
|
||||
@@ -280,11 +280,7 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
|
||||
throw new InvalidStructureDefinitionException("Block: " + model.getBlock() + " is defined but not a valid block id (ResourceLocation)");
|
||||
}
|
||||
} else if (!model.getTag().equals("")){
|
||||
if (RLUtils.isRL(model.getTag())) {
|
||||
if (!BlockTags.getAllTags().getAllTags().containsKey(RLUtils.toRL(model.getTag()))) {
|
||||
throw new InvalidStructureDefinitionException("Block Tag: " + model.getBlock() + " is not an existing block tag in the game");
|
||||
}
|
||||
} else {
|
||||
if (!RLUtils.isRL(model.getTag())) {
|
||||
throw new InvalidStructureDefinitionException("Block Tag: " + model.getBlock() + " is defined but not a valid block tag id (ResourceLocation)");
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.ticticboooom.mods.mm.exception;
|
||||
|
||||
public class InvalidProcessDefinitionException extends Exception {
|
||||
public InvalidProcessDefinitionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,6 @@ public class RLUtils {
|
||||
}
|
||||
|
||||
public static boolean isRL(String str) {
|
||||
return ResourceLocation.isValidResourceLocation(str);
|
||||
return ResourceLocation.tryParse(str) != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.ticticboooom.mods.mm.ports.state;
|
||||
|
||||
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.ports.storage.EnergyPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.IPortStorage;
|
||||
import lombok.Getter;
|
||||
import mezz.jei.api.gui.drawable.IDrawableStatic;
|
||||
import mezz.jei.api.helpers.IJeiHelpers;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
@@ -86,4 +89,10 @@ public static final Codec<EnergyPortState> CODEC =RecordCodecBuilder.create(x -
|
||||
public ResourceLocation getName() {
|
||||
return new ResourceLocation(MM.ID, "energy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack ms, int x, int y, int mouseX, int mouseY, IJeiHelpers helpers) {
|
||||
IDrawableStatic drawable = helpers.getGuiHelper().createDrawable(new ResourceLocation(MM.ID, "textures/gui/slot_parts.png"), 18, 61, 4, 18);
|
||||
drawable.draw(ms, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
package com.ticticboooom.mods.mm.ports.state;
|
||||
|
||||
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.util.FluidRenderer;
|
||||
import com.ticticboooom.mods.mm.exception.InvalidProcessDefinitionException;
|
||||
import com.ticticboooom.mods.mm.helper.RLUtils;
|
||||
import com.ticticboooom.mods.mm.ports.storage.FluidPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.IPortStorage;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import mezz.jei.api.constants.VanillaTypes;
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.gui.drawable.IDrawableStatic;
|
||||
import mezz.jei.api.helpers.IJeiHelpers;
|
||||
import mezz.jei.api.ingredients.IIngredientType;
|
||||
import mezz.jei.api.ingredients.IIngredients;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FluidPortState extends PortState {
|
||||
|
||||
@@ -114,4 +126,37 @@ public class FluidPortState extends PortState {
|
||||
public ResourceLocation getName() {
|
||||
return new ResourceLocation(MM.ID, "fluids");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void validateDefinition() {
|
||||
if (!RLUtils.isRL(fluid)) {
|
||||
throw new InvalidProcessDefinitionException("Fluid: " + fluid + " is not a valid id (ResourceLocation)");
|
||||
}
|
||||
if (!ForgeRegistries.FLUIDS.containsKey(RLUtils.toRL(fluid))) {
|
||||
throw new InvalidProcessDefinitionException("Fluid: " + fluid + " does not exist in the game's registered fluids");
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIngredient(IIngredients in, boolean input) {
|
||||
FluidStack stack = new FluidStack(ForgeRegistries.FLUIDS.getValue(RLUtils.toRL(fluid)), amount);
|
||||
if (input) {
|
||||
in.setInput(VanillaTypes.FLUID, stack);
|
||||
} else {
|
||||
in.setOutput(VanillaTypes.FLUID, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
|
||||
layout.getFluidStacks().init(typeIndex, input, x + 1, y + 1, 16, 16, 1, false, null);
|
||||
layout.getFluidStacks().set(typeIndex, new FluidStack(ForgeRegistries.FLUIDS.getValue(RLUtils.toRL(fluid)), 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,38 @@
|
||||
package com.ticticboooom.mods.mm.ports.state;
|
||||
|
||||
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.IPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.ItemPortStorage;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import mekanism.common.integration.projecte.IngredientHelper;
|
||||
import mezz.jei.api.constants.VanillaTypes;
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.gui.drawable.IDrawable;
|
||||
import mezz.jei.api.gui.drawable.IDrawableStatic;
|
||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
|
||||
import mezz.jei.api.helpers.IJeiHelpers;
|
||||
import mezz.jei.api.ingredients.IIngredientType;
|
||||
import mezz.jei.api.ingredients.IIngredients;
|
||||
import net.minecraft.data.ItemTagsProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ItemPortState extends PortState {
|
||||
|
||||
@@ -166,4 +183,66 @@ public class ItemPortState extends PortState {
|
||||
public ResourceLocation getName() {
|
||||
return new ResourceLocation(MM.ID, "items");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void validateDefinition() {
|
||||
if (!item.equals("")){
|
||||
if (!RLUtils.isRL(item)){
|
||||
throw new InvalidProcessDefinitionException("Item: " + item + " is not a valid item id (ResourceLocation)");
|
||||
}
|
||||
|
||||
if (!ForgeRegistries.ITEMS.containsKey(RLUtils.toRL(item))){
|
||||
throw new InvalidProcessDefinitionException("Item: " + item + " does not exist in the game's item registry");
|
||||
}
|
||||
} else if (!tag.equals("")){
|
||||
if (!RLUtils.isRL(tag)){
|
||||
throw new InvalidProcessDefinitionException("Item Tag: " + tag + " is not a valid item tag id (ResourceLocation)");
|
||||
}
|
||||
} else{
|
||||
throw new InvalidProcessDefinitionException("You must define a item id or item tag id in the items 'data' object");
|
||||
}
|
||||
}
|
||||
|
||||
private int tagIndex = 0;
|
||||
private int tagIndexIncremement = 0;
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIngredient(IIngredients in, boolean input) {
|
||||
if (!item.equals("") && RLUtils.isRL(item)) {
|
||||
if (input){
|
||||
in.setInput(VanillaTypes.ITEM, new ItemStack(ForgeRegistries.ITEMS.getValue(RLUtils.toRL(item)), this.count));
|
||||
} else {
|
||||
in.setOutput(VanillaTypes.ITEM, new ItemStack(ForgeRegistries.ITEMS.getValue(RLUtils.toRL(item)), this.count));
|
||||
}
|
||||
} else if (!tag.equals("") && RLUtils.isRL(tag)) {
|
||||
ITag<Item> tag = ItemTags.getAllTags().getTag(RLUtils.toRL(this.tag));
|
||||
assert tag != null;
|
||||
Stream<ItemStack> itemStackStream = tag.getValues().stream().map(x -> new ItemStack(x.getItem(), this.count));
|
||||
if (input){
|
||||
in.setInputs(VanillaTypes.ITEM, itemStackStream.collect(Collectors.toList()));
|
||||
} else {
|
||||
in.setOutputs(VanillaTypes.ITEM, itemStackStream.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
|
||||
layout.getItemStacks().init(typeIndex, input, x, y);
|
||||
if (!item.equals("") && RLUtils.isRL(item)) {
|
||||
layout.getItemStacks().set(typeIndex, new ItemStack(ForgeRegistries.ITEMS.getValue(RLUtils.toRL(item)), this.count));
|
||||
} else if (!tag.equals("") && RLUtils.isRL(tag)) {
|
||||
ITag<Item> tag = ItemTags.getAllTags().getTag(RLUtils.toRL(this.tag));
|
||||
assert tag != null;
|
||||
Stream<ItemStack> itemStackStream = tag.getValues().stream().map(z -> new ItemStack(z.getItem(), this.count));
|
||||
layout.getItemStacks().set(typeIndex, itemStackStream.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
package com.ticticboooom.mods.mm.ports.state;
|
||||
|
||||
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.IPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.MekGasPortStorage;
|
||||
import lombok.SneakyThrows;
|
||||
import mekanism.api.Action;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.chemical.gas.GasStack;
|
||||
import mekanism.api.inventory.AutomationType;
|
||||
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 mezz.jei.api.ingredients.IIngredients;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
@@ -99,4 +109,38 @@ public class MekGasPortState extends PortState {
|
||||
public ResourceLocation getName() {
|
||||
return new ResourceLocation(MM.ID, "mekanism_gas");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void validateDefinition() {
|
||||
if (!RLUtils.isRL(gas)){
|
||||
throw new InvalidProcessDefinitionException("Gas: " + gas + " is not a valid gas id (ResourceLocation)");
|
||||
}
|
||||
|
||||
if (!MekanismAPI.gasRegistry().containsKey(RLUtils.toRL(gas))){
|
||||
throw new InvalidProcessDefinitionException("Gas: " + gas + " does not exist in the mekansim gas registry");
|
||||
}
|
||||
}
|
||||
|
||||
@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<GasStack> gasGroup = layout.getIngredientsGroup(MekanismJEI.TYPE_GAS);
|
||||
gasGroup.init(typeIndex, input, x + 1, y + 1);
|
||||
gasGroup.set(typeIndex, new GasStack(MekanismAPI.gasRegistry().getValue(RLUtils.toRL(gas)), 1000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIngredient(IIngredients in, boolean input) {
|
||||
if (input){
|
||||
in.setInput(MekanismJEI.TYPE_GAS, new GasStack(MekanismAPI.gasRegistry().getValue(RLUtils.toRL(gas)), 1000));
|
||||
} else {
|
||||
in.setOutput(MekanismJEI.TYPE_GAS, new GasStack(MekanismAPI.gasRegistry().getValue(RLUtils.toRL(gas)), 1000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
package com.ticticboooom.mods.mm.ports.state;
|
||||
|
||||
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.IPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.MekSlurryPortStorage;
|
||||
import lombok.SneakyThrows;
|
||||
import mekanism.api.Action;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.chemical.gas.GasStack;
|
||||
import mekanism.api.chemical.slurry.SlurryStack;
|
||||
import mekanism.api.inventory.AutomationType;
|
||||
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 mezz.jei.api.ingredients.IIngredients;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
@@ -101,4 +112,39 @@ public class MekSlurryPortState extends PortState {
|
||||
public ResourceLocation getName() {
|
||||
return new ResourceLocation(MM.ID, "mekanism_slurry");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void validateDefinition() {
|
||||
if (!RLUtils.isRL(slurry)){
|
||||
throw new InvalidProcessDefinitionException("Slurry: " + slurry + " is not a valid slurry id (ResourceLocation)");
|
||||
}
|
||||
|
||||
if (!MekanismAPI.slurryRegistry().containsKey(RLUtils.toRL(slurry))){
|
||||
throw new InvalidProcessDefinitionException("Slurry: " + slurry + " does not exist in the mekansim slurry registry");
|
||||
}
|
||||
}
|
||||
|
||||
@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<SlurryStack> gasGroup = layout.getIngredientsGroup(MekanismJEI.TYPE_SLURRY);
|
||||
gasGroup.init(typeIndex, input, x + 1, y+ 1);
|
||||
gasGroup.set(typeIndex, new SlurryStack(MekanismAPI.slurryRegistry().getValue(RLUtils.toRL(slurry)), 1000));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setIngredient(IIngredients in, boolean input) {
|
||||
if (input) {
|
||||
in.setInput(MekanismJEI.TYPE_SLURRY, new SlurryStack(MekanismAPI.slurryRegistry().getValue(RLUtils.toRL(slurry)), 1000));
|
||||
} else {
|
||||
in.setOutput(MekanismJEI.TYPE_SLURRY, new SlurryStack(MekanismAPI.slurryRegistry().getValue(RLUtils.toRL(slurry)), 1000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.ports.storage.IPortStorage;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.helpers.IJeiHelpers;
|
||||
import mezz.jei.api.ingredients.IIngredients;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
@@ -18,4 +21,13 @@ public abstract class PortState {
|
||||
public abstract void processResult(List<IPortStorage> storage);
|
||||
public abstract boolean validateResult(List<IPortStorage> storage);
|
||||
public abstract ResourceLocation getName();
|
||||
public void validateDefinition() {}
|
||||
public void render(MatrixStack ms, int x, int y, int mouseX, int mouseY, IJeiHelpers helpers) {}
|
||||
public void setIngredient(IIngredients in, boolean input){
|
||||
|
||||
}
|
||||
|
||||
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 2.0 KiB |
Reference in New Issue
Block a user