diff --git a/src/main/java/techreborn/blockentity/data/DataDrivenBEProvider.java b/src/main/java/techreborn/blockentity/data/DataDrivenBEProvider.java new file mode 100644 index 000000000..ccccaa63e --- /dev/null +++ b/src/main/java/techreborn/blockentity/data/DataDrivenBEProvider.java @@ -0,0 +1,138 @@ +package techreborn.blockentity.data; + +import com.google.common.collect.ImmutableSet; +import com.google.gson.JsonObject; +import net.fabricmc.loader.launch.common.FabricLauncherBase; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Identifier; +import net.minecraft.util.JsonHelper; +import net.minecraft.util.registry.Registry; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.text.WordUtils; +import reborncore.client.containerBuilder.IContainerProvider; +import reborncore.client.containerBuilder.builder.BuiltContainer; +import reborncore.client.containerBuilder.builder.ContainerBlockEntityInventoryBuilder; +import reborncore.client.containerBuilder.builder.ContainerBuilder; +import reborncore.common.crafting.RebornRecipeType; +import reborncore.common.recipes.RecipeCrafter; +import reborncore.common.util.RebornInventory; +import reborncore.common.util.serialization.SerializationUtil; +import techreborn.blockentity.GenericMachineBlockEntity; +import techreborn.init.ModRecipes; + +import javax.annotation.Nullable; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.List; +import java.util.function.Supplier; + +public class DataDrivenBEProvider extends BlockEntityType implements Supplier { + + private final Identifier identifier; + private final Block block; + private final int energy; + private final int maxInput; + + private final List slots; + + public static DataDrivenBEProvider create(Block block, Identifier identifier){ + String location = String.format("%s/machines/%s.json", identifier.getNamespace(), identifier.getPath()); + JsonObject jsonObject; + try { + jsonObject = SerializationUtil.GSON.fromJson(IOUtils.toString(FabricLauncherBase.getLauncher().getResourceAsStream(location), StandardCharsets.UTF_8), JsonObject.class); + } catch (Exception e) { + throw new RuntimeException("failed to read json: " + location, e); + } + Identifier id = new Identifier(JsonHelper.getString(jsonObject, "name")); + DataDrivenBEProvider provider = new DataDrivenBEProvider(block, jsonObject); + Registry.register(Registry.BLOCK_ENTITY, id, provider); + return provider; + } + + private DataDrivenBEProvider(Block block, JsonObject jsonObject) { + super(null, ImmutableSet.copyOf(Collections.singletonList(block)), null); + this.block = block; + this.identifier = new Identifier(JsonHelper.getString(jsonObject, "name")); + this.energy = JsonHelper.getInt(jsonObject, "energy"); + this.maxInput = JsonHelper.getInt(jsonObject, "maxInput"); + this.slots = DataDrivenSlot.read(JsonHelper.getArray(jsonObject, "slots")); + Validate.isTrue(getEnergySlot() > 0); //Ensure there is an energy slot, doing it here so it crashes on game load + } + + @Nullable + @Override + public DataDrivenBlockEntity instantiate() { + return new DataDrivenBlockEntity(this); + } + + public BuiltContainer createContainer(DataDrivenBlockEntity blockEntity, int syncID, PlayerEntity player) { + ContainerBlockEntityInventoryBuilder builder = new ContainerBuilder(identifier.getPath()).player(player.inventory) + .inventory().hotbar().addInventory().blockEntity(blockEntity); + + slots.forEach(dataDrivenSlot -> dataDrivenSlot.add(builder)); + + builder.syncEnergyValue().syncCrafterValue(); + + return builder.addInventory().create(blockEntity, syncID); + } + + //Used by the GenericMachineBlock + @Override + public BlockEntity get() { + return instantiate(); + } + + public static class DataDrivenBlockEntity extends GenericMachineBlockEntity implements IContainerProvider { + + private final DataDrivenBEProvider provider; + + private DataDrivenBlockEntity(DataDrivenBEProvider provider) { + super(provider, provider.getSimpleName(), provider.maxInput, provider.energy, provider.block, provider.getEnergySlot()); + this.provider = provider; + + RebornRecipeType recipeType = ModRecipes.byName(provider.identifier); + Validate.notNull(recipeType); + + this.inventory = new RebornInventory<>(provider.slots.size(), provider.getSimpleName() + "BlockEntity", 64, this); + this.crafter = new RecipeCrafter(recipeType, this, provider.countOfSlotType(SlotType.INPUT), provider.countOfSlotType(SlotType.OUTPUT), this.inventory, provider.slotIds(SlotType.INPUT), provider.slotIds(SlotType.OUTPUT)); + } + + @Override + public BuiltContainer createContainer(int syncID, PlayerEntity player) { + return provider.createContainer(this,syncID, player); + } + + public DataDrivenBEProvider getProvider() { + return provider; + } + } + + private int getEnergySlot() { + return slots.stream().filter(slot -> slot.getType() == SlotType.ENERGY).findFirst().orElse(null).getId(); + } + + private int countOfSlotType(SlotType type){ + return (int) slots.stream() + .filter(slot -> slot.getType() == type) + .count(); + } + + private int[] slotIds(SlotType type){ + return slots.stream() + .filter(slot -> slot.getType() == type) + .mapToInt(DataDrivenSlot::getId) + .toArray(); + } + + public List getSlots() { + return Collections.unmodifiableList(slots); + } + + private String getSimpleName(){ + return WordUtils.capitalize(identifier.getPath()); + } +} diff --git a/src/main/java/techreborn/blockentity/data/DataDrivenGui.java b/src/main/java/techreborn/blockentity/data/DataDrivenGui.java new file mode 100644 index 000000000..eebedaf5f --- /dev/null +++ b/src/main/java/techreborn/blockentity/data/DataDrivenGui.java @@ -0,0 +1,36 @@ +package techreborn.blockentity.data; + +import net.minecraft.entity.player.PlayerEntity; +import reborncore.client.containerBuilder.builder.BuiltContainer; +import reborncore.client.gui.builder.GuiBase; +import reborncore.client.gui.guibuilder.GuiBuilder; + +public class DataDrivenGui extends GuiBase { + + private final DataDrivenBEProvider provider; + private final DataDrivenBEProvider.DataDrivenBlockEntity blockEntity; + + public DataDrivenGui(int syncID, final PlayerEntity player, final DataDrivenBEProvider.DataDrivenBlockEntity blockEntity) { + super(player, blockEntity, blockEntity.createContainer(syncID, player)); + this.blockEntity = blockEntity; + this.provider = blockEntity.getProvider(); + } + + @Override + protected void drawBackground(final float f, final int mouseX, final int mouseY) { + super.drawBackground(f, mouseX, mouseY); + final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; + final DataDrivenGui gui = this; + + provider.getSlots().forEach(slot -> slot.draw(gui, layer)); + } + + @Override + protected void drawForeground(final int mouseX, final int mouseY) { + super.drawForeground(mouseX, mouseY); + final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND; + + builder.drawProgressBar(this, blockEntity.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); + builder.drawMultiEnergyBar(this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); + } +} \ No newline at end of file diff --git a/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java b/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java new file mode 100644 index 000000000..ce816d676 --- /dev/null +++ b/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java @@ -0,0 +1,69 @@ +package techreborn.blockentity.data; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.util.JsonHelper; +import org.apache.commons.lang3.Validate; +import reborncore.client.containerBuilder.builder.ContainerBlockEntityInventoryBuilder; +import reborncore.client.gui.builder.GuiBase; +import reborncore.common.util.serialization.SerializationUtil; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +public class DataDrivenSlot { + + public static List read(JsonArray jsonArray){ + AtomicInteger idCount = new AtomicInteger(); + return SerializationUtil.stream(jsonArray) + .map(JsonElement::getAsJsonObject) + .map(json -> new DataDrivenSlot(idCount.getAndIncrement(), JsonHelper.getInt(json, "x"), JsonHelper.getInt(json, "y"), SlotType.fromString(JsonHelper.getString(json, "type")))) + .collect(Collectors.toList()); + } + + private final int id; + private final int x; + private final int y; + private final SlotType type; + + public DataDrivenSlot(int id, int x, int y, SlotType type) { + this.id = id; + this.x = x; + this.y = y; + this.type = type; + Validate.notNull(type); + } + + public int getId() { + return id; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public SlotType getType() { + return type; + } + + public void add(ContainerBlockEntityInventoryBuilder inventoryBuilder){ + type.getSlotBiConsumer().accept(inventoryBuilder, this); + } + + @Environment(EnvType.CLIENT) + public void draw(GuiBase guiBase, GuiBase.Layer layer){ + //TODO find a better way to do this + if(getType() == SlotType.OUTPUT){ + guiBase.drawOutputSlot(getX(), getY(), layer); + } else { + guiBase.drawSlot(getX(), getY(), layer); + } + } +} diff --git a/src/main/java/techreborn/blockentity/data/SlotType.java b/src/main/java/techreborn/blockentity/data/SlotType.java new file mode 100644 index 000000000..ee8af4f68 --- /dev/null +++ b/src/main/java/techreborn/blockentity/data/SlotType.java @@ -0,0 +1,36 @@ +package techreborn.blockentity.data; + +import reborncore.client.containerBuilder.builder.ContainerBlockEntityInventoryBuilder; + +import java.util.Arrays; +import java.util.function.BiConsumer; + +public enum SlotType { + //Im really not a fan of the way I add the slots to the builder here + INPUT((builder, slot) -> { + builder.slot(slot.getId(), slot.getX(), slot.getY()); + }), + OUTPUT((builder, slot) -> { + builder.outputSlot(slot.getId(), slot.getX(), slot.getY()); + }), + ENERGY((builder, slot) -> { + builder.energySlot(slot.getId(), slot.getX(), slot.getY()); + }); + + public static SlotType fromString(String string){ + return Arrays.stream(values()) + .filter(slotType -> slotType.name().equalsIgnoreCase(string)) + .findFirst() + .orElse(null); + } + + private BiConsumer slotBiConsumer; + + SlotType(BiConsumer slotBiConsumer) { + this.slotBiConsumer = slotBiConsumer; + } + + public BiConsumer getSlotBiConsumer() { + return slotBiConsumer; + } +} diff --git a/src/main/java/techreborn/blockentity/machine/tier1/GrinderBlockEntity.java b/src/main/java/techreborn/blockentity/machine/tier1/GrinderBlockEntity.java deleted file mode 100644 index d64ed9921..000000000 --- a/src/main/java/techreborn/blockentity/machine/tier1/GrinderBlockEntity.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2018 TechReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package techreborn.blockentity.machine.tier1; - -import net.minecraft.entity.player.PlayerEntity; -import reborncore.client.containerBuilder.IContainerProvider; -import reborncore.client.containerBuilder.builder.BuiltContainer; -import reborncore.client.containerBuilder.builder.ContainerBuilder; -import reborncore.common.recipes.RecipeCrafter; -import reborncore.common.util.RebornInventory; -import techreborn.blockentity.GenericMachineBlockEntity; -import techreborn.config.TechRebornConfig; -import techreborn.init.ModRecipes; -import techreborn.init.TRBlockEntities; -import techreborn.init.TRContent; - -public class GrinderBlockEntity extends GenericMachineBlockEntity implements IContainerProvider { - - public GrinderBlockEntity() { - super(TRBlockEntities.GRINDER, "Grinder", TechRebornConfig.grinderMaxInput, TechRebornConfig.grinderMaxEnergy, TRContent.Machine.GRINDER.block, 2); - final int[] inputs = new int[] { 0 }; - final int[] outputs = new int[] { 1 }; - this.inventory = new RebornInventory<>(3, "GrinderBlockEntity", 64, this); - this.crafter = new RecipeCrafter(ModRecipes.GRINDER, this, 2, 1, this.inventory, inputs, outputs); -} - - // IContainerProvider - @Override - public BuiltContainer createContainer(int syncID, final PlayerEntity player) { - return new ContainerBuilder("grinder").player(player.inventory).inventory().hotbar().addInventory().blockEntity(this) - .slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue().syncCrafterValue() - .addInventory().create(this, syncID); - } -} \ No newline at end of file diff --git a/src/main/java/techreborn/blocks/DataDrivenMachineBlock.java b/src/main/java/techreborn/blocks/DataDrivenMachineBlock.java new file mode 100644 index 000000000..cb6923502 --- /dev/null +++ b/src/main/java/techreborn/blocks/DataDrivenMachineBlock.java @@ -0,0 +1,45 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2018 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.blocks; + +import net.minecraft.util.Identifier; +import techreborn.blockentity.data.DataDrivenBEProvider; +import techreborn.client.EGui; + +/** + * @author modmuss50 + * + */ +public class DataDrivenMachineBlock extends GenericMachineBlock { + + private final DataDrivenBEProvider provider; + + public DataDrivenMachineBlock(String ident){ + super(EGui.DATA_DRIVEN, null); + provider = DataDrivenBEProvider.create(this, new Identifier(ident)); + blockEntityClass = provider; + } + +} diff --git a/src/main/java/techreborn/blocks/GenericMachineBlock.java b/src/main/java/techreborn/blocks/GenericMachineBlock.java index a053779db..996d33d9b 100644 --- a/src/main/java/techreborn/blocks/GenericMachineBlock.java +++ b/src/main/java/techreborn/blocks/GenericMachineBlock.java @@ -24,14 +24,14 @@ package techreborn.blocks; -import java.util.function.Supplier; - import net.minecraft.block.entity.BlockEntity; import net.minecraft.world.BlockView; import reborncore.api.blockentity.IMachineGuiHandler; import reborncore.common.blocks.BlockMachineBase; import techreborn.client.EGui; +import java.util.function.Supplier; + /** * @author drcrazy * @@ -39,7 +39,7 @@ import techreborn.client.EGui; public class GenericMachineBlock extends BlockMachineBase { private EGui gui; - private Supplier blockEntityClass; + Supplier blockEntityClass; public GenericMachineBlock(EGui gui, Supplier blockEntityClass) { super(); diff --git a/src/main/java/techreborn/client/EGui.java b/src/main/java/techreborn/client/EGui.java index a70c7e6fd..f721d49cc 100644 --- a/src/main/java/techreborn/client/EGui.java +++ b/src/main/java/techreborn/client/EGui.java @@ -56,7 +56,6 @@ public enum EGui implements IMachineGuiHandler { FUSION_CONTROLLER, GAS_TURBINE, GENERATOR, - GRINDER, HIGH_VOLTAGE_SU, IDSU, IMPLOSION_COMPRESSOR, @@ -80,7 +79,9 @@ public enum EGui implements IMachineGuiHandler { VACUUM_FREEZER, SOLID_CANNING_MACHINE, WIRE_MILL, - FLUID_REPLICATOR; + FLUID_REPLICATOR, + + DATA_DRIVEN; private final boolean containerBuilder; diff --git a/src/main/java/techreborn/client/GuiHandler.java b/src/main/java/techreborn/client/GuiHandler.java index b3a8367e6..dbb7d5efa 100644 --- a/src/main/java/techreborn/client/GuiHandler.java +++ b/src/main/java/techreborn/client/GuiHandler.java @@ -37,6 +37,8 @@ import reborncore.client.containerBuilder.IContainerProvider; import techreborn.blockentity.ChargeOMatBlockEntity; import techreborn.blockentity.DigitalChestBlockEntity; import techreborn.blockentity.IndustrialCentrifugeBlockEntity; +import techreborn.blockentity.data.DataDrivenBEProvider; +import techreborn.blockentity.data.DataDrivenGui; import techreborn.blockentity.fusionReactor.FusionControlComputerBlockEntity; import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity; import techreborn.blockentity.generator.advanced.DieselGeneratorBlockEntity; @@ -58,7 +60,6 @@ import techreborn.blockentity.storage.LowVoltageSUBlockEntity; import techreborn.blockentity.storage.MediumVoltageSUBlockEntity; import techreborn.blockentity.storage.idsu.InterdimensionalSUBlockEntity; import techreborn.blockentity.storage.lesu.LapotronicSUBlockEntity; -import techreborn.client.container.ContainerDestructoPack; import techreborn.client.gui.*; public class GuiHandler { @@ -77,6 +78,10 @@ public class GuiHandler { private static AbstractContainerScreen getClientGuiElement(final EGui gui, final PlayerEntity player, BlockPos pos, int syncID) { final BlockEntity blockEntity = player.world.getBlockEntity(pos); + if(blockEntity instanceof DataDrivenBEProvider.DataDrivenBlockEntity){ + return new DataDrivenGui(syncID, player, (DataDrivenBEProvider.DataDrivenBlockEntity) blockEntity); + } + switch (gui) { case AESU: return new GuiAESU(syncID, player, (AdjustableSUBlockEntity) blockEntity); @@ -114,8 +119,6 @@ public class GuiHandler { return new GuiGasTurbine(syncID, player, (GasTurbineBlockEntity) blockEntity); case GENERATOR: return new GuiGenerator(syncID, player, (SolidFuelGeneratorBlockEntity) blockEntity); - case GRINDER: - return new GuiGrinder(syncID, player, (GrinderBlockEntity) blockEntity); case IDSU: return new GuiIDSU(syncID, player, (InterdimensionalSUBlockEntity) blockEntity); case IMPLOSION_COMPRESSOR: diff --git a/src/main/java/techreborn/client/gui/GuiGrinder.java b/src/main/java/techreborn/client/gui/GuiGrinder.java deleted file mode 100644 index 75555513f..000000000 --- a/src/main/java/techreborn/client/gui/GuiGrinder.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2018 TechReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package techreborn.client.gui; - -import net.minecraft.entity.player.PlayerEntity; -import reborncore.client.containerBuilder.builder.BuiltContainer; -import reborncore.client.gui.builder.GuiBase; -import reborncore.client.gui.guibuilder.GuiBuilder; -import techreborn.blockentity.machine.tier1.GrinderBlockEntity; - -public class GuiGrinder extends GuiBase { - - GrinderBlockEntity blockEntity; - - public GuiGrinder(int syncID, final PlayerEntity player, final GrinderBlockEntity blockEntity) { - super(player, blockEntity, blockEntity.createContainer(syncID, player)); - this.blockEntity = blockEntity; - } - - @Override - protected void drawBackground(final float f, final int mouseX, final int mouseY) { - super.drawBackground(f, mouseX, mouseY); - final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; - - drawSlot(8, 72, layer); - - drawSlot(55, 45, layer); - drawOutputSlot(101, 45, layer); - - builder.drawJEIButton(this, 158, 5, layer); - } - - @Override - protected void drawForeground(final int mouseX, final int mouseY) { - super.drawForeground(mouseX, mouseY); - final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND; - - builder.drawProgressBar(this, blockEntity.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); - builder.drawMultiEnergyBar(this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); - } -} diff --git a/src/main/java/techreborn/init/ModRecipes.java b/src/main/java/techreborn/init/ModRecipes.java index 8cf1be46d..8c4c37a4f 100644 --- a/src/main/java/techreborn/init/ModRecipes.java +++ b/src/main/java/techreborn/init/ModRecipes.java @@ -25,6 +25,7 @@ package techreborn.init; import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; import reborncore.common.crafting.RebornRecipe; import reborncore.common.crafting.RebornRecipeType; import reborncore.common.crafting.RecipeManager; @@ -53,4 +54,8 @@ public class ModRecipes { public static final RebornRecipeType ROLLING_MACHINE = RecipeManager.newRecipeType(RollingMachineRecipe.class, new Identifier("techreborn:rolling_machine")); public static final RebornRecipeType SOLID_CANNING_MACHINE = RecipeManager.newRecipeType(RebornRecipe.class, new Identifier("techreborn:solid_canning_machine")); public static final RebornRecipeType WIRE_MILL = RecipeManager.newRecipeType(RebornRecipe.class, new Identifier("techreborn:wire_mill")); + + public static RebornRecipeType byName(Identifier identifier){ + return (RebornRecipeType) Registry.RECIPE_SERIALIZER.get(identifier); + } } diff --git a/src/main/java/techreborn/init/TRBlockEntities.java b/src/main/java/techreborn/init/TRBlockEntities.java index a626f1c7b..b9dde69b6 100644 --- a/src/main/java/techreborn/init/TRBlockEntities.java +++ b/src/main/java/techreborn/init/TRBlockEntities.java @@ -101,7 +101,6 @@ public class TRBlockEntities { public static final BlockEntityType FUSION_CONTROL_COMPUTER = register(FusionControlComputerBlockEntity.class, "fusion_control_computer", TRContent.Machine.FUSION_CONTROL_COMPUTER); public static final BlockEntityType LIGHTNING_ROD = register(LightningRodBlockEntity.class, "lightning_rod", TRContent.Machine.LIGHTNING_ROD); public static final BlockEntityType INDUSTRIAL_SAWMILL = register(IndustrialSawmillBlockEntity.class, "industrial_sawmill", TRContent.Machine.INDUSTRIAL_SAWMILL); - public static final BlockEntityType GRINDER = register(GrinderBlockEntity.class, "grinder", TRContent.Machine.GRINDER); public static final BlockEntityType SOLID_FUEL_GENEREATOR = register(SolidFuelGeneratorBlockEntity.class, "solid_fuel_generator", TRContent.Machine.SOLID_FUEL_GENERATOR); public static final BlockEntityType EXTRACTOR = register(ExtractorBlockEntity.class, "extractor", TRContent.Machine.EXTRACTOR); public static final BlockEntityType COMPRESSOR = register(CompressorBlockEntity.class, "compressor", TRContent.Machine.COMPRESSOR); diff --git a/src/main/java/techreborn/init/TRContent.java b/src/main/java/techreborn/init/TRContent.java index 118e485d4..413419477 100644 --- a/src/main/java/techreborn/init/TRContent.java +++ b/src/main/java/techreborn/init/TRContent.java @@ -384,7 +384,7 @@ public class TRContent { DISTILLATION_TOWER(new GenericMachineBlock(EGui.DISTILLATION_TOWER, DistillationTowerBlockEntity::new)), EXTRACTOR(new GenericMachineBlock(EGui.EXTRACTOR, ExtractorBlockEntity::new)), FLUID_REPLICATOR(new GenericMachineBlock(EGui.FLUID_REPLICATOR, FluidReplicatorBlockEntity::new)), - GRINDER(new GenericMachineBlock(EGui.GRINDER, GrinderBlockEntity::new)), + GRINDER(new DataDrivenMachineBlock("techreborn:grinder")), ELECTRIC_FURNACE(new GenericMachineBlock(EGui.ELECTRIC_FURNACE, ElectricFurnaceBlockEntity::new)), IMPLOSION_COMPRESSOR(new GenericMachineBlock(EGui.IMPLOSION_COMPRESSOR, ImplosionCompressorBlockEntity::new)), INDUSTRIAL_BLAST_FURNACE(new GenericMachineBlock(EGui.BLAST_FURNACE, IndustrialBlastFurnaceBlockEntity::new)), diff --git a/src/main/resources/techreborn/machines/grinder.json b/src/main/resources/techreborn/machines/grinder.json new file mode 100644 index 000000000..d06d502a6 --- /dev/null +++ b/src/main/resources/techreborn/machines/grinder.json @@ -0,0 +1,35 @@ +{ + "name": "techreborn:grinder", + "energy": 1000, + "maxInput": 32, + "slots": [ + { + "type": "input", + "x": 55, + "y": 45 + }, + { + "type": "output", + "x": 101, + "y": 45 + }, + { + "type": "energy", + "x": 7, + "y": 72 + } + ], + "gui": [ + { + "type": "progress_bar", + "x": 76, + "y": 48, + "direction": "right" + }, + { + "type": "energy_bar", + "x": 9, + "y": 19 + } + ] +} \ No newline at end of file