diff --git a/src/main/java/com/ticticboooom/mods/mm/MM.java b/src/main/java/com/ticticboooom/mods/mm/MM.java index 4def8df..1b23306 100644 --- a/src/main/java/com/ticticboooom/mods/mm/MM.java +++ b/src/main/java/com/ticticboooom/mods/mm/MM.java @@ -113,11 +113,11 @@ public class MM { } for (RegistryObject block : MMLoader.BLOCKS) { - RenderTypeLookup.setRenderLayer(block.get(), layer -> layer == RenderType.getSolid() || layer == RenderType.getTranslucent()); + RenderTypeLookup.setRenderLayer(block.get(), layer ->layer == RenderType.getCutout() || layer == RenderType.getSolid() || layer == RenderType.getTranslucent()); } for (RegistryObject block : MMLoader.IPORT_BLOCKS) { - RenderTypeLookup.setRenderLayer(block.get(), layer -> layer == RenderType.getSolid() || layer == RenderType.getTranslucent()); + RenderTypeLookup.setRenderLayer(block.get(), layer -> layer == RenderType.getCutout() || layer == RenderType.getSolid() || layer == RenderType.getTranslucent()); } for (RegistryObject block : MMLoader.OPORT_BLOCKS) { diff --git a/src/main/java/com/ticticboooom/mods/mm/client/util/GuiBlockRenderBuilder.java b/src/main/java/com/ticticboooom/mods/mm/client/util/GuiBlockRenderBuilder.java index 33c05e5..da0c8b6 100644 --- a/src/main/java/com/ticticboooom/mods/mm/client/util/GuiBlockRenderBuilder.java +++ b/src/main/java/com/ticticboooom/mods/mm/client/util/GuiBlockRenderBuilder.java @@ -33,14 +33,18 @@ public class GuiBlockRenderBuilder { private Vector3f prePosition = new Vector3f(); private TileEntityRenderer ter = null; private TileEntity tile; - private static final IBlockReader reader= new AirBlockReader(); + private static final IBlockReader reader = new AirBlockReader(); + public GuiBlockRenderBuilder(BlockState blockState) { this.blockState = blockState; position = new BlockPos(0, 0, 0); - tile = blockState.createTileEntity(reader); - if (tile != null) { - ter = TileEntityRendererDispatcher.instance.getRenderer(tile); - } + try { + + tile = blockState.createTileEntity(reader); + if (tile != null) { + ter = TileEntityRendererDispatcher.instance.getRenderer(tile); + } + } catch (Exception ignored) {} } public GuiBlockRenderBuilder at(BlockPos position) { @@ -89,9 +93,11 @@ public class GuiBlockRenderBuilder { transformMatrix(ms); brd.renderBlock(blockState, ms, buf, 0xF000F0, OverlayTexture.NO_OVERLAY, EmptyModelData.INSTANCE); - if (ter != null) { - ter.render(tile, 1.f, ms, buf, 0xF000F0, OverlayTexture.NO_OVERLAY); - } + try { + if (ter != null) { + ter.render(tile, 1.f, ms, buf, 0xF000F0, OverlayTexture.NO_OVERLAY); + } + } catch (Exception ignored) {} buf.finish(); ms.pop(); cleanupRender(); diff --git a/src/main/java/com/ticticboooom/mods/mm/data/MachineProcessRecipe.java b/src/main/java/com/ticticboooom/mods/mm/data/MachineProcessRecipe.java index e6386e1..734fa14 100644 --- a/src/main/java/com/ticticboooom/mods/mm/data/MachineProcessRecipe.java +++ b/src/main/java/com/ticticboooom/mods/mm/data/MachineProcessRecipe.java @@ -59,7 +59,7 @@ public class MachineProcessRecipe implements IRecipe { private boolean canTake(List inputPorts) { for (PortState input : inputs) { - if (!input.isConsumePerTick()){ + if (!input.isConsumePerTick()) { if (!input.validateRequirement(inputPorts)) { return false; } @@ -109,7 +109,7 @@ public class MachineProcessRecipe implements IRecipe { int index = 0; if (update.getTicksTaken() >= ticks) { for (PortState input : inputs) { - if (inputRolls.get(index) < input.getChance()){ + if (inputRolls.get(index) < input.getChance()) { input.processRequirement(inputPorts); index++; } @@ -130,7 +130,7 @@ public class MachineProcessRecipe implements IRecipe { index = 0; for (PortState input : inputs) { if (input.isConsumePerTick()) { - if (inputRolls.get(index) < input.getChance()){ + if (inputRolls.get(index) < input.getChance()) { if (!input.validateRequirement(inputPorts)) { canTick = false; } @@ -165,7 +165,7 @@ public class MachineProcessRecipe implements IRecipe { } update.setTicksTaken(update.getTicksTaken() + 1); } - update.setMsg((int)(((float)update.getTicksTaken() /(float)ticks) * 100) + "%"); + update.setMsg((int) (((float) update.getTicksTaken() / (float) ticks) * 100) + "%"); return update; } @@ -206,18 +206,22 @@ public class MachineProcessRecipe implements IRecipe { public static final class Serializer implements IRecipeSerializer { - @SneakyThrows @Override public MachineProcessRecipe read(ResourceLocation rl, JsonObject obj) { - int ticks = obj.get("ticks").getAsInt(); - String structureId = obj.get("structureId").getAsString(); - JsonArray inputs = obj.get("inputs").getAsJsonArray(); - JsonArray outputs = obj.get("outputs").getAsJsonArray(); + try { + int ticks = obj.get("ticks").getAsInt(); + String structureId = obj.get("structureId").getAsString(); + JsonArray inputs = obj.get("inputs").getAsJsonArray(); + JsonArray outputs = obj.get("outputs").getAsJsonArray(); - List inputStates = getStates(inputs); - List outputStates = getStates(outputs); - validateProcess(inputStates, outputStates, ticks, structureId, rl); - return new MachineProcessRecipe(inputStates, outputStates, ticks, structureId, rl); + List inputStates = getStates(inputs); + List outputStates = getStates(outputs); + validateProcess(inputStates, outputStates, ticks, structureId, rl); + return new MachineProcessRecipe(inputStates, outputStates, ticks, structureId, rl); + } catch (InvalidProcessDefinitionException e) { + MM.LOG.error("InvalidProcessDefinition: " + e.getMessage()); + } + return null; } @SneakyThrows @@ -229,7 +233,7 @@ public class MachineProcessRecipe implements IRecipe { boolean perTick = false; if (out.has("perTick")) { perTick = out.get("perTick").getAsBoolean(); - } else if (out.has("consumePerTick")){ + } else if (out.has("consumePerTick")) { perTick = out.get("consumePerTick").getAsBoolean(); } @@ -317,8 +321,7 @@ public class MachineProcessRecipe implements IRecipe { } - @SneakyThrows - private void validateProcess(List inputs, List outputs, int ticks, String structureId, ResourceLocation rl) { + private void validateProcess(List inputs, List outputs, int ticks, String structureId, ResourceLocation rl) throws InvalidProcessDefinitionException { for (PortState input : inputs) { input.validateDefinition(); commonValidate(input); @@ -330,15 +333,14 @@ public class MachineProcessRecipe implements IRecipe { } } - @SneakyThrows - private void commonValidate(PortState state) { + private void commonValidate(PortState state) throws InvalidProcessDefinitionException { if (!state.supportsChances() && state.getChance() != 1) { throw new InvalidProcessDefinitionException("Port Type: " + state.getName() + " does not support chanced operations (chance)"); } - if (state.getChance() < 0 || state.getChance() > 1){ + if (state.getChance() < 0 || state.getChance() > 1) { throw new InvalidProcessDefinitionException("Ingredient chance must be between 0 and 1"); } - if (!state.supportsPerTick() && state.isConsumePerTick()){ + if (!state.supportsPerTick() && state.isConsumePerTick()) { throw new InvalidProcessDefinitionException("Port Type: " + state.getName() + " does not support per tick operations (perTick)"); } } diff --git a/src/main/java/com/ticticboooom/mods/mm/data/MachineStructureRecipe.java b/src/main/java/com/ticticboooom/mods/mm/data/MachineStructureRecipe.java index 8423b1d..b09903b 100644 --- a/src/main/java/com/ticticboooom/mods/mm/data/MachineStructureRecipe.java +++ b/src/main/java/com/ticticboooom/mods/mm/data/MachineStructureRecipe.java @@ -153,7 +153,6 @@ public class MachineStructureRecipe implements IRecipe { } - for (Map.Entry stringStringEntry : model.getProperties().entrySet()) { for (Map.Entry, Comparable> propertyEntry : blockState.getValues().entrySet()) { if (propertyEntry.getKey().getName().equals(stringStringEntry.getKey())) { @@ -207,33 +206,39 @@ public class MachineStructureRecipe implements IRecipe { @Override public MachineStructureRecipe read(ResourceLocation rl, JsonObject obj) { - JsonElement controllerIdJson = obj.get("controllerId"); - List ids = new ArrayList<>(); - if (controllerIdJson.isJsonPrimitive()) { - ids.add(controllerIdJson.getAsString()); - } else { - for (JsonElement jsonElement : controllerIdJson.getAsJsonArray()) { - ids.add(jsonElement.getAsString()); + try { + + JsonElement controllerIdJson = obj.get("controllerId"); + List ids = new ArrayList<>(); + if (controllerIdJson.isJsonPrimitive()) { + ids.add(controllerIdJson.getAsString()); + } else { + for (JsonElement jsonElement : controllerIdJson.getAsJsonArray()) { + ids.add(jsonElement.getAsString()); + } } + String id = obj.get("id").getAsString(); + String name = ""; + if (obj.has("name")) { + name = obj.get("name").getAsString(); + } else { + name = id; + } + DataResult>, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(Codec.list(Codec.list(Codec.STRING))).apply(obj.getAsJsonArray("layout")); + List> layout = apply.result().get().getFirst(); + + List result = getResult(obj.getAsJsonObject("legend"), layout); + + + validateStructure(result, ids, id, rl); + return new MachineStructureRecipe(result, ids, id, rl, name); + } catch (InvalidStructureDefinitionException e) { + MM.LOG.error("InvalidStructureDefinition: " + e.getMessage()); } - String id = obj.get("id").getAsString(); - String name = ""; - if (obj.has("name")) { - name = obj.get("name").getAsString(); - } else { - name = id; - } - DataResult>, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(Codec.list(Codec.list(Codec.STRING))).apply(obj.getAsJsonArray("layout")); - List> layout = apply.result().get().getFirst(); - - List result = getResult(obj.getAsJsonObject("legend"), layout); - - - validateStructure(result, ids, id, rl); - return new MachineStructureRecipe(result, ids, id, rl, name); + return null; } - private List getResult(JsonObject legend, List> layout) { + private List getResult(JsonObject legend, List> layout) throws InvalidStructureDefinitionException { HashMap model = new HashMap<>(); for (Map.Entry entry : legend.entrySet()) { DataResult> apply = JsonOps.INSTANCE.withDecoder(MachineStructureRecipeLegendModel.CODEC).apply(entry.getValue()); @@ -267,8 +272,7 @@ public class MachineStructureRecipe implements IRecipe { return result; } - @SneakyThrows - private Vector3i getControllerPos(List> layout) { + private Vector3i getControllerPos(List> layout) throws InvalidStructureDefinitionException { int y = 0; int z = 0; for (List layer : layout) { @@ -337,8 +341,7 @@ public class MachineStructureRecipe implements IRecipe { return RecipeTypes.STRUCTURE.get().getRegistryType(); } - @SneakyThrows - private void validateStructure(List models, List controllerId, String id, ResourceLocation rl) { + private void validateStructure(List models, List controllerId, String id, ResourceLocation rl) throws InvalidStructureDefinitionException { for (MachineStructureRecipeKeyModel model : models) { if (!model.getBlock().equals("")) { if (RLUtils.isRL(model.getBlock())) { diff --git a/src/main/java/com/ticticboooom/mods/mm/datagen/gen/MMBlockStateProvider.java b/src/main/java/com/ticticboooom/mods/mm/datagen/gen/MMBlockStateProvider.java index 34fce2f..398c721 100644 --- a/src/main/java/com/ticticboooom/mods/mm/datagen/gen/MMBlockStateProvider.java +++ b/src/main/java/com/ticticboooom/mods/mm/datagen/gen/MMBlockStateProvider.java @@ -14,6 +14,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.data.DataGenerator; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.ForgeRenderTypes; import net.minecraftforge.client.model.generators.*; import net.minecraftforge.client.model.generators.loaders.MultiLayerModelBuilder; import net.minecraftforge.common.data.ExistingFileHelper; @@ -160,7 +161,7 @@ public class MMBlockStateProvider extends BlockStateProvider { } public void dynamicBlockModel(ResourceLocation loc, ResourceLocation baseModel, ResourceLocation overlayTexture) { - models().getBuilder(loc.toString()).parent(new ModelFile.UncheckedModelFile(mcLoc("block/block"))) + models().getBuilder(loc.toString()).parent(new ModelFile.UncheckedModelFile(baseModel)) .texture("particle", overlayTexture) .transforms() .transform(ModelBuilder.Perspective.THIRDPERSON_LEFT) @@ -175,13 +176,16 @@ public class MMBlockStateProvider extends BlockStateProvider { .end() .end() .customLoader(MultiLayerModelBuilder::begin) - .submodel(RenderType.getSolid(), this.models().nested().parent(new ModelFile.UncheckedModelFile(baseModel))) + .submodel(RenderType.getTranslucent(), this.models().nested().parent(new ModelFile.UncheckedModelFile(baseModel)).parent(new ModelFile.UncheckedModelFile(mcLoc("block/block")))) .submodel(RenderType.getTranslucent(), this.models().nested().parent(new ModelFile.UncheckedModelFile(mcLoc("block/block"))) .texture("overlay", overlayTexture) .element() .from(0, 0, 0) .to(16, 16, 16) - .allFaces((dir, uv) -> uv.texture("#overlay")) + .face(Direction.NORTH) + .texture("#overlay") + //.allFaces((dir, uv) -> uv.uvs(0F,0F, 16F,16F)) + .end() .end() ) .end(); @@ -202,7 +206,7 @@ public class MMBlockStateProvider extends BlockStateProvider { .end() .end() .customLoader(MultiLayerModelBuilder::begin) - .submodel(RenderType.getSolid(), this.models().nested().parent(new ModelFile.UncheckedModelFile(baseModel))) + .submodel(RenderType.getTranslucent(), this.models().nested().parent(new ModelFile.UncheckedModelFile(baseModel))) .submodel(RenderType.getTranslucent(), this.models().nested().parent(new ModelFile.UncheckedModelFile(mcLoc("block/block"))) .texture("overlay", overlayTexture) .element()