mirror of
https://github.com/TicTicBoooom-Mods/MasterfulMachinery.git
synced 2026-03-18 21:40:34 +01:00
catching some errors to remove call stacks
This commit is contained in:
@@ -113,11 +113,11 @@ public class MM {
|
||||
}
|
||||
|
||||
for (RegistryObject<ControllerBlock> 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<MachinePortBlock> 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<MachinePortBlock> block : MMLoader.OPORT_BLOCKS) {
|
||||
|
||||
@@ -33,14 +33,18 @@ public class GuiBlockRenderBuilder {
|
||||
private Vector3f prePosition = new Vector3f();
|
||||
private TileEntityRenderer<TileEntity> 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();
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
|
||||
|
||||
private boolean canTake(List<PortStorage> 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<IInventory> {
|
||||
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<IInventory> {
|
||||
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<IInventory> {
|
||||
}
|
||||
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<IInventory> {
|
||||
|
||||
public static final class Serializer implements IRecipeSerializer<MachineProcessRecipe> {
|
||||
|
||||
@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<PortState> inputStates = getStates(inputs);
|
||||
List<PortState> outputStates = getStates(outputs);
|
||||
validateProcess(inputStates, outputStates, ticks, structureId, rl);
|
||||
return new MachineProcessRecipe(inputStates, outputStates, ticks, structureId, rl);
|
||||
List<PortState> inputStates = getStates(inputs);
|
||||
List<PortState> 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<IInventory> {
|
||||
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<IInventory> {
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
private void validateProcess(List<PortState> inputs, List<PortState> outputs, int ticks, String structureId, ResourceLocation rl) {
|
||||
private void validateProcess(List<PortState> inputs, List<PortState> 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<IInventory> {
|
||||
}
|
||||
}
|
||||
|
||||
@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)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,6 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (Map.Entry<String, String> stringStringEntry : model.getProperties().entrySet()) {
|
||||
for (Map.Entry<Property<?>, Comparable<?>> propertyEntry : blockState.getValues().entrySet()) {
|
||||
if (propertyEntry.getKey().getName().equals(stringStringEntry.getKey())) {
|
||||
@@ -207,33 +206,39 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
|
||||
|
||||
@Override
|
||||
public MachineStructureRecipe read(ResourceLocation rl, JsonObject obj) {
|
||||
JsonElement controllerIdJson = obj.get("controllerId");
|
||||
List<String> 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<String> 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<Pair<List<List<String>>, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(Codec.list(Codec.list(Codec.STRING))).apply(obj.getAsJsonArray("layout"));
|
||||
List<List<String>> layout = apply.result().get().getFirst();
|
||||
|
||||
List<MachineStructureRecipeKeyModel> 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<Pair<List<List<String>>, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(Codec.list(Codec.list(Codec.STRING))).apply(obj.getAsJsonArray("layout"));
|
||||
List<List<String>> layout = apply.result().get().getFirst();
|
||||
|
||||
List<MachineStructureRecipeKeyModel> result = getResult(obj.getAsJsonObject("legend"), layout);
|
||||
|
||||
|
||||
validateStructure(result, ids, id, rl);
|
||||
return new MachineStructureRecipe(result, ids, id, rl, name);
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<MachineStructureRecipeKeyModel> getResult(JsonObject legend, List<List<String>> layout) {
|
||||
private List<MachineStructureRecipeKeyModel> getResult(JsonObject legend, List<List<String>> layout) throws InvalidStructureDefinitionException {
|
||||
HashMap<Character, MachineStructureRecipeLegendModel> model = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : legend.entrySet()) {
|
||||
DataResult<Pair<MachineStructureRecipeLegendModel, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(MachineStructureRecipeLegendModel.CODEC).apply(entry.getValue());
|
||||
@@ -267,8 +272,7 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
|
||||
return result;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private Vector3i getControllerPos(List<List<String>> layout) {
|
||||
private Vector3i getControllerPos(List<List<String>> layout) throws InvalidStructureDefinitionException {
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
for (List<String> layer : layout) {
|
||||
@@ -337,8 +341,7 @@ public class MachineStructureRecipe implements IRecipe<IInventory> {
|
||||
return RecipeTypes.STRUCTURE.get().getRegistryType();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void validateStructure(List<MachineStructureRecipeKeyModel> models, List<String> controllerId, String id, ResourceLocation rl) {
|
||||
private void validateStructure(List<MachineStructureRecipeKeyModel> models, List<String> controllerId, String id, ResourceLocation rl) throws InvalidStructureDefinitionException {
|
||||
for (MachineStructureRecipeKeyModel model : models) {
|
||||
if (!model.getBlock().equals("")) {
|
||||
if (RLUtils.isRL(model.getBlock())) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user