Added ability to define ports as structure parts rather than individual blocks.

This commit is contained in:
Quarris
2021-09-28 19:58:04 +01:00
parent 07e4fdba71
commit a21d8534db
13 changed files with 406 additions and 106 deletions

View File

@@ -8,8 +8,8 @@
"name": "Item",
"id": "simple",
"data": {
"rows": 3,
"columns": 3
"rows": 1,
"columns": 1
}
},
{
@@ -17,7 +17,7 @@
"name": "Energy",
"id": "simple",
"data": {
"capacity": 1000000000
"capacity": 1000000
}
},
{
@@ -25,7 +25,7 @@
"name": "Fluid",
"id": "simple",
"data": {
"capacity": 10000
"capacity": 5000
}
},
{
@@ -35,7 +35,7 @@
"data": {
"criticalPressure": 7,
"dangerPressure": 5,
"volume": 10000
"volume": 7000
}
},
{
@@ -43,7 +43,7 @@
"name": "Mana",
"id": "simple",
"data": {
"capacity": 100000
"capacity": 50000
}
},
{
@@ -51,7 +51,7 @@
"name": "Starlight",
"id": "simple",
"data": {
"capacity": 1000
"capacity": 500
}
},
{
@@ -67,7 +67,7 @@
"name": "Gas",
"id": "simple",
"data": {
"capacity": 100000000
"capacity": 100000
}
},
{
@@ -75,7 +75,7 @@
"name": "Slurry",
"id": "simple",
"data": {
"capacity": 100000000
"capacity": 100000
}
},
{
@@ -83,7 +83,7 @@
"name": "Infuse",
"id": "simple",
"data": {
"capacity": 100000000
"capacity": 100000
}
},
{

View File

@@ -0,0 +1,106 @@
{
"controllerId": "mid",
"name": "Mid",
"ports": [
{
"type": "masterfulmachinery:items",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Item",
"id": "intermediate",
"data": {
"rows": 3,
"columns": 3
}
},
{
"type": "masterfulmachinery:energy",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Energy",
"id": "intermediate",
"data": {
"capacity": 1000000000
}
},
{
"type": "masterfulmachinery:fluids",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Fluid",
"id": "intermediate",
"data": {
"capacity": 10000
}
},
{
"type": "masterfulmachinery:pncr_pressure",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Pressure",
"id": "intermediate",
"data": {
"criticalPressure": 7,
"dangerPressure": 5,
"volume": 10000
}
},
{
"type": "masterfulmachinery:botania_mana",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Mana",
"id": "intermediate",
"data": {
"capacity": 100000
}
},
{
"type": "masterfulmachinery:astral_starlight",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Starlight",
"id": "intermediate",
"data": {
"capacity": 1000
}
},
{
"type": "masterfulmachinery:create_rotation",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Rotation",
"id": "intermediate",
"data": {
"stress": 3
}
},
{
"type": "masterfulmachinery:mekanism_gas",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Gas",
"id": "intermediate",
"data": {
"capacity": 100000000
}
},
{
"type": "masterfulmachinery:mekanism_slurry",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Slurry",
"id": "intermediate",
"data": {
"capacity": 100000000
}
},
{
"type": "masterfulmachinery:mekanism_infuse",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Infuse",
"id": "intermediate",
"data": {
"capacity": 100000000
}
},
{
"type": "masterfulmachinery:weather",
"textureOverride": "minecraft:block/red_terracotta",
"name": "Weather",
"id": "intermediate",
"data": {}
}
]
}

View File

@@ -3,9 +3,13 @@ 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.block.ControllerBlock;
import com.ticticboooom.mods.mm.block.MachinePortBlock;
import com.ticticboooom.mods.mm.client.util.GuiBlockRenderBuilder;
import com.ticticboooom.mods.mm.data.MachineStructureRecipe;
import com.ticticboooom.mods.mm.data.model.structure.MachineStructureBlockPos;
import com.ticticboooom.mods.mm.data.model.structure.MachineStructurePort;
import com.ticticboooom.mods.mm.data.model.structure.MachineStructureRecipeKeyModel;
import com.ticticboooom.mods.mm.helper.RLUtils;
import com.ticticboooom.mods.mm.registration.MMLoader;
import com.ticticboooom.mods.mm.registration.MMSetup;
import mezz.jei.api.gui.IRecipeLayout;
@@ -50,10 +54,11 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
private int sliceY = 0;
private boolean slicingActive = false;
private Map<Integer, Integer> tagIndexes = new HashMap<>();
private Map<Integer, Integer> tagIndexCounter = new HashMap<>();
private float scaleFactor = 1F;
private int tickTimer = 0;
private Map<MachineStructureBlockPos, Integer> variantIndices = new HashMap<>();
public MachineStructureRecipeCategory(IJeiHelpers helpers, ControllerBlock controller) {
this.helpers = helpers;
this.controller = controller;
@@ -76,6 +81,7 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
@Override
public IDrawable getBackground() {
return helpers.getGuiHelper().createDrawable(overlayRl, 0, 0, 162, 150);
}
@@ -98,25 +104,22 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
}
@Override
public void setRecipe(IRecipeLayout iRecipeLayout, MachineStructureRecipe machineStructureRecipe, IIngredients iIngredients) {
public void setRecipe(IRecipeLayout iRecipeLayout, MachineStructureRecipe recipe, IIngredients iIngredients) {
this.xRotation = 0;
this.yRotation = 0;
this.yLastMousePosition = 0;
this.xLastMousePosition = 0;
this.scaleFactor = 1.2f;
this.recipe = recipe;
this.sliceY = 0;
this.slicingActive = false;
this.variantIndices.clear();
this.tickTimer = 0;
}
@Override
public void draw(MachineStructureRecipe recipe, MatrixStack matrixStack, double mouseX, double mouseY) {
if (this.recipe != recipe) {
this.recipe = null;
xRotation = 0;
yRotation = 0;
sliceY = 0;
slicingActive = false;
}
Minecraft mc = Minecraft.getInstance();
if (xLastMousePosition == 0) {
xLastMousePosition = mouseX;
@@ -125,20 +128,21 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
yLastMousePosition = mouseY;
}
// Do mouse rotations
if (GLFW.glfwGetMouseButton(mc.getMainWindow().getHandle(), GLFW.GLFW_MOUSE_BUTTON_1) != 0) {
double relMoveX = mouseX - xLastMousePosition;
double relMoveY = mouseY - yLastMousePosition;
xRotation += relMoveX;
yRotation += relMoveY;
}
// Calculate distances
int furthestX = Integer.MAX_VALUE;
int nearestX = Integer.MIN_VALUE;
int furthestZ = Integer.MAX_VALUE;
int nearestZ = Integer.MIN_VALUE;
int topY = Integer.MIN_VALUE;
int bottomY = Integer.MAX_VALUE;
for (MachineStructureRecipeKeyModel part : recipe.getModels().get(0)) {
furthestX = Math.min(part.getPos().getX(), furthestX);
nearestX = Math.max(part.getPos().getX(), nearestX);
@@ -147,6 +151,8 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
topY = Math.max(part.getPos().getY(), topY);
bottomY = Math.min(part.getPos().getY(), bottomY);
}
// Do mouse scroll zoom
if (GLFW.glfwGetMouseButton(mc.getMainWindow().getHandle(), GLFW.GLFW_MOUSE_BUTTON_RIGHT) != 0) {
if (scrollLastPos == 0) {
scrollLastPos = (int) mouseY;
@@ -157,22 +163,25 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
nearestX++;
nearestZ++;
float centreX = ((float) nearestX - furthestX) / 2f;
float centerY = ((float) topY - bottomY) / 2f;
float centreZ = ((float) nearestZ - furthestZ) / 2f;
mc.fontRenderer.drawString(matrixStack, recipe.getName(), 2, 2, 0xFFFFFFFF);
// Get the block parts for the layer
List<MachineStructureRecipeKeyModel> parts = recipe.getModels().get(0);
if (slicingActive) {
parts = parts.stream().filter(x -> x.getPos().getY() == sliceY).collect(Collectors.toList());
}
//float sizeX = 162, sizeY = 121;
//float scaledSizeX = sizeX / scaleFactor, scaledSizeY = sizeY / scaleFactor;
float tx = 6.5f, ty = -5, tz = 10;
//float tx = 6.5f, ty = -5, tz = 10;
float tx = 0, ty = 0, tz = 10;
Vector3f prePos = new Vector3f(tx, ty, tz);
Vector3f offset = new Vector3f(centreX / 2, centerY / 2, centreZ / 2);
int i = 0;
// Render the block parts
for (MachineStructureRecipeKeyModel part : parts) {
tagIndexes.putIfAbsent(i, 0);
tagIndexCounter.putIfAbsent(i, 0);
if (part.getBlock().isEmpty() && part.getTag().isEmpty()) {
variantIndices.putIfAbsent(part.getPos(), 0);
if (part.getBlock().isEmpty() && part.getTag().isEmpty() && part.getPort() == null) {
continue;
}
@@ -184,65 +193,75 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
if (block != null) {
BlockState defaultState = block.getDefaultState();
defaultState = with(defaultState, part.getProperties());
new GuiBlockRenderBuilder(defaultState).at(bp)
.withPrePosition(new Vector3f(tx, ty, tz))
.withRotation(new Quaternion(new Vector3f(1, 0, 0), 15 + yRotation, true))
.withRotation(new Quaternion(new Vector3f(0, -1, 0), 225 - xRotation, true))
.withScale(new Vector3f(scaleFactor, -scaleFactor, scaleFactor))
.withOffset(new Vector3f(-0.5f, -0.5f, -0.5f))
.finalize(matrixStack);
renderBlock(defaultState, bp, prePos, offset, matrixStack);
}
} else if (!part.getTag().equals("")) {
ResourceLocation resourceLocation = new ResourceLocation(part.getTag());
ITag<Block> tag = BlockTags.getCollection().getTagByID(resourceLocation);
if (tag != null) {
Integer index = tagIndexes.get(i);
Integer index = this.variantIndices.get(part.getPos());
Block block = tag.getAllElements().get((int) Math.floor(index / 50.0));
index++;
if (index >= (tag.getAllElements().size()) * 50) {
index = 0;
}
Block block = tag.getAllElements().get(index);
if (this.tickTimer == 0) {
this.variantIndices.put(part.getPos(), (index+1) % tag.getAllElements().size());
}
tagIndexes.put(i, index);
if (block != null) {
BlockState defaultState = block.getDefaultState();
defaultState = with(defaultState, part.getProperties());
new GuiBlockRenderBuilder(defaultState).at(bp)
.withPrePosition(new Vector3f(tx, ty, tz))
.withRotation(new Quaternion(new Vector3f(1, 0, 0), 15 + yRotation, true))
.withRotation(new Quaternion(new Vector3f(0, -1, 0), 225 - xRotation, true))
.withScale(new Vector3f(scaleFactor, -scaleFactor, scaleFactor))
.withOffset(new Vector3f(-0.5f, -0.5f, -0.5f))
.finalize(matrixStack);
if (block != null) {
BlockState defaultState = block.getDefaultState();
defaultState = with(defaultState, part.getProperties());
renderBlock(defaultState, bp, prePos, offset, matrixStack);
}
} else if (part.getPort() != null) {
MachineStructurePort port = part.getPort();
ArrayList<RegistryObject<MachinePortBlock>> ports = port.isInput() ? MMLoader.IPORT_BLOCKS : MMLoader.OPORT_BLOCKS;
Integer index = this.variantIndices.get(part.getPos());
String controllerId = port.getControllerId().get(index);
if (this.tickTimer == 0) {
this.variantIndices.put(part.getPos(), (index+1) % port.getControllerId().size());
}
String type = port.getType();
MachinePortBlock block = null;
for (RegistryObject<MachinePortBlock> regPortBlock : ports) {
MachinePortBlock portBlock = regPortBlock.get();
if (portBlock.getPortTypeId().equals(RLUtils.toRL(type)) && portBlock.getControllerId().equals(controllerId)) {
block = portBlock;
break;
}
}
if (block != null) {
BlockState defaultState = block.getDefaultState();
defaultState = with(defaultState, part.getProperties());
renderBlock(defaultState, bp, prePos, offset, matrixStack);
}
}
}
// Render the controller block
if (sliceY == 0) {
ControllerBlock block = null;
MachineStructureBlockPos controllerPos = new MachineStructureBlockPos(0, 0, 0);
this.variantIndices.putIfAbsent(controllerPos, 0);
Integer index = this.variantIndices.get(controllerPos);
String controller = recipe.getControllerId().get(index);
if (this.tickTimer == 0) {
this.variantIndices.put(controllerPos, (index+1) % recipe.getControllerId().size());
}
for (RegistryObject<ControllerBlock> reg : MMLoader.BLOCKS) {
if (recipe.getControllerId().contains(reg.get().getControllerId())) {
if (reg.get().getControllerId().equals(controller)) {
block = reg.get();
}
}
if (block != null) {
BlockState defaultState = block.getDefaultState().with(DirectionalBlock.FACING, Direction.NORTH);
new GuiBlockRenderBuilder(defaultState).at(new BlockPos(0, 0, 0))
.withPrePosition(new Vector3f(tx, ty, tz))
.withRotation(new Quaternion(new Vector3f(1, 0, 0), 15 + yRotation, true))
.withRotation(new Quaternion(new Vector3f(0, -1, 0), 225 - xRotation, true))
.withScale(new Vector3f(scaleFactor, -scaleFactor, scaleFactor))
.withOffset(new Vector3f(-0.5f, -0.5f, -0.5f))
.finalize(matrixStack);
renderBlock(defaultState, new BlockPos(0, 0, 0), prePos, offset, matrixStack);
}
}
this.recipe = recipe;
// End tick
xLastMousePosition = mouseX;
yLastMousePosition = mouseY;
getButton().draw(matrixStack, 144, 125);
if (++this.tickTimer % 40 == 0) {
this.tickTimer = 0;
}
}
@Override
@@ -296,4 +315,14 @@ public class MachineStructureRecipeCategory implements IRecipeCategory<MachineSt
return defaultState;
}
private void renderBlock(BlockState defaultState, BlockPos bp, Vector3f prePos, Vector3f offset, MatrixStack ms) {
new GuiBlockRenderBuilder(defaultState).at(bp)
.withPrePosition(prePos)
.withRotation(new Quaternion(new Vector3f(1, 0, 0), 15 + yRotation, true))
.withRotation(new Quaternion(new Vector3f(0, -1, 0), 225 - xRotation, true))
.withScale(new Vector3f(scaleFactor, -scaleFactor, scaleFactor))
.withOffset(offset)
.finalize(ms);
}
}

View File

@@ -10,6 +10,8 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
public class PortBlockContainerScreen extends ContainerScreen<PortBlockContainer> {
private static final ResourceLocation GUI = new ResourceLocation(MM.ID, "textures/gui/port_gui.png");
private final PortBlockContainer container;
public PortBlockContainerScreen(PortBlockContainer container, PlayerInventory p_i51105_2_, ITextComponent p_i51105_3_) {
@@ -17,18 +19,16 @@ public class PortBlockContainerScreen extends ContainerScreen<PortBlockContainer
this.container = container;
}
private static final ResourceLocation GUI = new ResourceLocation(MM.ID, "textures/gui/port_gui.png");
@Override
public void render(MatrixStack p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) {
super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
this.renderHoveredTooltip(p_230430_1_, p_230430_2_, p_230430_3_);
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
super.render(ms, mouseX, mouseY, partialTicks);
this.renderHoveredTooltip(ms, mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(MatrixStack stack, float partialTicks, int x, int y) {
this.renderBackground(stack);
container.getTile().getStorage().render(stack, x, y, this.guiLeft, this.guiTop, this);
}
@Override

View File

@@ -2,7 +2,6 @@ package com.ticticboooom.mods.mm.data;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
@@ -10,15 +9,12 @@ import com.mojang.serialization.JsonOps;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.block.ControllerBlock;
import com.ticticboooom.mods.mm.block.MachinePortBlock;
import com.ticticboooom.mods.mm.data.model.structure.MachineStructureBlockPos;
import com.ticticboooom.mods.mm.data.model.structure.MachineStructureObject;
import com.ticticboooom.mods.mm.data.model.structure.MachineStructureRecipeKeyModel;
import com.ticticboooom.mods.mm.data.model.structure.MachineStructureRecipeLegendModel;
import com.ticticboooom.mods.mm.block.tile.IMachinePortTile;
import com.ticticboooom.mods.mm.data.model.structure.*;
import com.ticticboooom.mods.mm.exception.InvalidStructureDefinitionException;
import com.ticticboooom.mods.mm.helper.RLUtils;
import com.ticticboooom.mods.mm.nbt.NBTActionParser;
import com.ticticboooom.mods.mm.nbt.NBTValidator;
import com.ticticboooom.mods.mm.registration.MMLoader;
import com.ticticboooom.mods.mm.registration.MMPorts;
import com.ticticboooom.mods.mm.registration.RecipeTypes;
import lombok.Getter;
import lombok.SneakyThrows;
@@ -29,8 +25,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraft.state.Property;
import net.minecraft.tags.BlockTags;
@@ -45,7 +39,6 @@ import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.*;
public class MachineStructureRecipe implements IRecipe<IInventory> {
@@ -70,9 +63,9 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
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.getProperties()));
rotated1.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(rotatedPos1.getX(), rotatedPos1.getY(), rotatedPos1.getZ()), model.getTag(), model.getBlock(), model.getProperties()));
rotated2.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(rotatedPos2.getX(), rotatedPos2.getY(), rotatedPos2.getZ()), model.getTag(), model.getBlock(), model.getProperties()));
rotated.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(rotatedPos.getX(), rotatedPos.getY(), rotatedPos.getZ()), model.getTag(), model.getBlock(), model.getProperties(), model.getPort()));
rotated1.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(rotatedPos1.getX(), rotatedPos1.getY(), rotatedPos1.getZ()), model.getTag(), model.getBlock(), model.getProperties(), model.getPort()));
rotated2.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(rotatedPos2.getX(), rotatedPos2.getY(), rotatedPos2.getZ()), model.getTag(), model.getBlock(), model.getProperties(), model.getPort()));
}
this.models = new ArrayList<>();
@@ -142,6 +135,18 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
valid = tag.contains(blockState.getBlock());
} else if (!model.getBlock().equals("")) {
valid = blockState.getBlock().getRegistryName().toString().equals(model.getBlock());
} else if (model.getPort() != null) {
MachineStructurePort structurePort = model.getPort();
TileEntity portBlockEntity = world.getTileEntity(pos);
if (portBlockEntity instanceof IMachinePortTile && blockState.getBlock() instanceof MachinePortBlock) {
IMachinePortTile portTile = (IMachinePortTile) portBlockEntity;
MachinePortBlock portBlock = ((MachinePortBlock) blockState.getBlock());
if (portTile.isInput() == structurePort.isInput() &&
portBlock.getPortTypeId().equals(RLUtils.toRL(structurePort.getType()))) {
List<String> controllerIds = structurePort.getControllerId() != null ? structurePort.getControllerId() : this.controllerId;
valid = controllerIds.contains(portBlock.getControllerId());
}
}
}
if (!valid) {
@@ -228,7 +233,6 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
List<MachineStructureRecipeKeyModel> result = getResult(obj.getAsJsonObject("legend"), layout);
validateStructure(result, ids, id, rl);
MM.LOG.debug("Added structure '{}' with id '{}'", rl, id);
return new MachineStructureRecipe(result, ids, id, rl, name);
@@ -262,7 +266,7 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
}
MachineStructureRecipeLegendModel machineStructureRecipeLegendModel = model.get(c);
BlockPos pos = new BlockPos(x, y, z).subtract(new BlockPos(controllerPos));
result.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(pos.getX(), pos.getY(), pos.getZ()), machineStructureRecipeLegendModel.getTag(), machineStructureRecipeLegendModel.getBlock(), machineStructureRecipeLegendModel.getProperties()));
result.add(new MachineStructureRecipeKeyModel(new MachineStructureBlockPos(pos.getX(), pos.getY(), pos.getZ()), machineStructureRecipeLegendModel.getTag(), machineStructureRecipeLegendModel.getBlock(), machineStructureRecipeLegendModel.getProperties(), machineStructureRecipeLegendModel.getPort()));
}
z++;
}
@@ -355,8 +359,14 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
if (!RLUtils.isRL(model.getTag())) {
throw new InvalidStructureDefinitionException("Block Tag: " + model.getBlock() + " is defined but not a valid block tag id (ResourceLocation)");
}
} else if (model.getPort() != null) {
if (!MMPorts.PORTS.containsKey(RLUtils.toRL(model.getPort().getType()))) {
throw new InvalidStructureDefinitionException("Port: " + model.getPort() + " is defined but not a valid port type id (ResourceLocation)");
} else if (!controllerId.containsAll(model.getPort().getControllerId())) {
throw new InvalidStructureDefinitionException("Port: " + model.getPort() + " is defined but not a valid port controller id specified (ResourceLocation)");
}
} else {
throw new InvalidStructureDefinitionException("YUo must define at least 1 'block' or 'tag' per port within the 'data' object");
throw new InvalidStructureDefinitionException("You must define at least 1 'block' or 'tag' per port within the 'data' object");
}
}

View File

@@ -3,9 +3,12 @@ package com.ticticboooom.mods.mm.data.model.structure;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import net.minecraft.util.math.vector.Vector3i;
import java.util.Objects;
@Getter
@AllArgsConstructor
public class MachineStructureBlockPos implements Comparable<MachineStructureBlockPos> {
@@ -22,7 +25,22 @@ public class MachineStructureBlockPos implements Comparable<MachineStructureBloc
@Override
public int compareTo(MachineStructureBlockPos other) {
return new Vector3i(this.x, this.y, this.z).compareTo(new Vector3i(other.x, other.y, other.z));
return toVector().compareTo(other.toVector());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
MachineStructureBlockPos that = (MachineStructureBlockPos) o;
return toVector().equals(that.toVector());
}
@Override
public int hashCode() {
return toVector().hashCode();
}
public Vector3i toVector(){

View File

@@ -0,0 +1,31 @@
package com.ticticboooom.mods.mm.data.model.structure;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@ToString
@Getter
@AllArgsConstructor
public class MachineStructurePort {
public static final Codec<MachineStructurePort> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.STRING.fieldOf("type").forGetter(z -> z.type),
Codec.BOOL.fieldOf("input").forGetter(z -> z.input),
Codec.either(Codec.STRING, Codec.list(Codec.STRING)).xmap(
either -> either.map(Collections::singletonList, Function.identity()),
ids -> ids.size() == 1 ? Either.left(ids.get(0)) : Either.right(ids)
).optionalFieldOf("controllerId").forGetter(z -> Optional.ofNullable(z.controllerId))
).apply(x, (w, y, z) -> new MachineStructurePort(w, y, z.orElse(null))));
private final String type;
private final boolean input;
private final List<String> controllerId;
}

View File

@@ -1,13 +1,10 @@
package com.ticticboooom.mods.mm.data.model.structure;
import com.mojang.serialization.Codec;
import com.mojang.serialization.Keyable;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.ArrayList;
import java.util.Map;
import java.util.Optional;
@@ -15,14 +12,16 @@ import java.util.Optional;
@AllArgsConstructor
public class MachineStructureRecipeKeyModel {
public static final Codec<MachineStructureRecipeKeyModel> CODEC = RecordCodecBuilder.create(x -> x.group(
MachineStructureBlockPos.CODEC.fieldOf("pos").forGetter(z -> z.pos),
Codec.STRING.optionalFieldOf("tag").forGetter(z -> Optional.of(z.tag)),
Codec.STRING.optionalFieldOf("block").forGetter(z -> Optional.of(z.block)),
Codec.unboundedMap(Codec.STRING, Codec.STRING).optionalFieldOf("nbt").forGetter(z -> Optional.ofNullable(z.properties))
).apply(x, (w0, w, y, z) -> new MachineStructureRecipeKeyModel(w0, w.orElse(""), y.orElse(""), z.orElse(null))));
private MachineStructureBlockPos pos;
MachineStructureBlockPos.CODEC.fieldOf("pos").forGetter(z -> z.pos),
Codec.STRING.optionalFieldOf("tag").forGetter(z -> Optional.of(z.tag)),
Codec.STRING.optionalFieldOf("block").forGetter(z -> Optional.of(z.block)),
Codec.unboundedMap(Codec.STRING, Codec.STRING).optionalFieldOf("nbt").forGetter(z -> Optional.ofNullable(z.properties)),
MachineStructurePort.CODEC.optionalFieldOf("port").forGetter(z -> Optional.ofNullable(z.port))
).apply(x, (w0, w, y, z, z0) -> new MachineStructureRecipeKeyModel(w0, w.orElse(""), y.orElse(""), z.orElse(null), z0.orElse(null))));
private MachineStructureBlockPos pos;
private final String tag;
private final String block;
private final Map<String, String> properties;
private final MachineStructurePort port;
}

View File

@@ -2,13 +2,10 @@ package com.ticticboooom.mods.mm.data.model.structure;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.ticticboooom.mods.mm.nbt.model.NBTModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.nbt.CompoundNBT;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@@ -16,13 +13,14 @@ import java.util.Optional;
@AllArgsConstructor
public class MachineStructureRecipeLegendModel {
public static final Codec<MachineStructureRecipeLegendModel> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.STRING.optionalFieldOf("tag").forGetter(z -> Optional.of(z.tag)),
Codec.STRING.optionalFieldOf("block").forGetter(z -> Optional.of(z.block)),
Codec.unboundedMap(Codec.STRING, Codec.STRING).optionalFieldOf("props").forGetter(z -> Optional.ofNullable(z.properties))
).apply(x, (w, y, z) -> new MachineStructureRecipeLegendModel(w.orElse(""), y.orElse(""), z.orElse(null))));
Codec.STRING.optionalFieldOf("tag").forGetter(z -> Optional.of(z.tag)),
Codec.STRING.optionalFieldOf("block").forGetter(z -> Optional.of(z.block)),
Codec.unboundedMap(Codec.STRING, Codec.STRING).optionalFieldOf("props").forGetter(z -> Optional.ofNullable(z.properties)),
MachineStructurePort.CODEC.optionalFieldOf("port").forGetter(z -> Optional.ofNullable(z.port))
).apply(x, (w, y, z, z0) -> new MachineStructureRecipeLegendModel(w.orElse(""), y.orElse(""), z.orElse(null), z0.orElse(null))));
private final String tag;
private final String block;
@Setter
private Map<String, String> properties;
private final MachineStructurePort port;
}

View File

@@ -0,0 +1,33 @@
{
"type": "masterfulmachinery:machine_structure",
"id": "test_tiered_fluids",
"controllerId": [
"basic",
"mid"
],
"name": "Test Tiered Fluids",
"layout": [
[
"1C2"
]
],
"legend": {
"1": {
"port": {
"type": "masterfulmachinery:fluids",
"input": true,
"controllerId": [
"basic",
"mid"
]
}
},
"2": {
"port": {
"type": "masterfulmachinery:fluids",
"input": false,
"controllerId": "mid"
}
}
}
}

View File

@@ -0,0 +1,52 @@
{
"type": "masterfulmachinery:machine_structure",
"id": "variable_io",
"controllerId": "basic",
"name": "Variable IO",
"layout": [
[
")C)",
"*+*",
")*)"
],
[
"),)",
"-./",
")0)"
],
[
")))",
")1)",
")))"
]
],
"legend": {
"0": {
"block": "masterfulmachinery:basic_simple_port_fluids_output"
},
"1": {
"block": "masterfulmachinery:basic_simple_port_mekanism_gas_output"
},
")": {
"block": "minecraft:polished_blackstone"
},
"*": {
"block": "masterfulmachinery:basic_simple_port_energy_output"
},
"+": {
"block": "masterfulmachinery:basic_simple_port_items_output"
},
",": {
"block": "minecraft:glass"
},
"-": {
"block": "masterfulmachinery:basic_simple_port_items_input"
},
".": {
"block": "minecraft:water"
},
"/": {
"block": "masterfulmachinery:basic_simple_port_fluids_input"
}
}
}

View File

@@ -0,0 +1,24 @@
{
"type": "masterfulmachinery:machine_process",
"structureId": "test_tiered_fluid",
"controllerId": ["basic", "mid"],
"ticks": 20,
"inputs": [
{
"type": "masterfulmachinery:fluids",
"data": {
"fluid": "minecraft:water",
"amount": 50
}
}
],
"outputs": [
{
"type": "masterfulmachinery:fluids",
"data": {
"fluid": "minecraft:water",
"amount": 1
}
}
]
}

View File

@@ -1,2 +1,2 @@
#Fri Sep 03 00:36:37 BST 2021
VERSION_CODE=766
#Tue Sep 28 18:52:49 BST 2021
VERSION_CODE=785