diff --git a/src/client/java/techreborn/client/ClientGuiType.java b/src/client/java/techreborn/client/ClientGuiType.java index 11eab3565..5dc19ab4c 100644 --- a/src/client/java/techreborn/client/ClientGuiType.java +++ b/src/client/java/techreborn/client/ClientGuiType.java @@ -28,9 +28,9 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.util.Identifier; import techreborn.blockentity.GuiType; -import techreborn.blockentity.data.DataDrivenBEProvider; import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity; import techreborn.blockentity.generator.SolarPanelBlockEntity; import techreborn.blockentity.generator.advanced.DieselGeneratorBlockEntity; @@ -82,6 +82,7 @@ public class ClientGuiType { public static final ClientGuiType DISTILLATION_TOWER = register(GuiType.DISTILLATION_TOWER, GuiDistillationTower::new); public static final ClientGuiType ELECTRIC_FURNACE = register(GuiType.ELECTRIC_FURNACE, GuiElectricFurnace::new); public static final ClientGuiType EXTRACTOR = register(GuiType.EXTRACTOR, GuiExtractor::new); + public static final ClientGuiType GRINDER = register(GuiType.GRINDER, GuiGrinder::new); public static final ClientGuiType FUSION_CONTROLLER = register(GuiType.FUSION_CONTROLLER, GuiFusionReactor::new); public static final ClientGuiType GAS_TURBINE = register(GuiType.GAS_TURBINE, GuiGasTurbine::new); public static final ClientGuiType GENERATOR = register(GuiType.GENERATOR, GuiGenerator::new); @@ -110,7 +111,6 @@ public class ClientGuiType { public static final ClientGuiType GREENHOUSE_CONTROLLER = register(GuiType.GREENHOUSE_CONTROLLER, GuiGreenhouseController::new); public static final ClientGuiType FLUID_REPLICATOR = register(GuiType.FLUID_REPLICATOR, GuiFluidReplicator::new); public static final ClientGuiType PLAYER_DETECTOR = register(GuiType.PLAYER_DETECTOR, GuiPlayerDetector::new); - public static final ClientGuiType DATA_DRIVEN = register(GuiType.DATA_DRIVEN, DataDrivenGui::new); public static final ClientGuiType BLOCK_BREAKER = register(GuiType.BLOCK_BREAKER, GuiBlockBreaker::new); public static final ClientGuiType BLOCK_PLACER = register(GuiType.BLOCK_PLACER, GuiBlockPlacer::new); @@ -132,7 +132,7 @@ public class ClientGuiType { this.guiType = Objects.requireNonNull(guiType); this.guiFactory = Objects.requireNonNull(guiFactory); - ScreenRegistry.register(guiType.getScreenHandlerType(), getGuiFactory()); + HandledScreens.register(guiType.getScreenHandlerType(), getGuiFactory()); TYPES.put(guiType.getIdentifier(), this); } diff --git a/src/client/java/techreborn/client/GuiFactory.java b/src/client/java/techreborn/client/GuiFactory.java index da45134dd..e5ca5251f 100644 --- a/src/client/java/techreborn/client/GuiFactory.java +++ b/src/client/java/techreborn/client/GuiFactory.java @@ -29,13 +29,14 @@ import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.text.Text; import reborncore.common.screen.BuiltScreenHandler; @Environment(EnvType.CLIENT) -public interface GuiFactory extends ScreenRegistry.Factory> { +public interface GuiFactory extends HandledScreens.Provider> { HandledScreen create(int syncId, PlayerEntity playerEntity, T blockEntity); @Override diff --git a/src/client/java/techreborn/client/gui/DataDrivenGui.java b/src/client/java/techreborn/client/gui/GuiGrinder.java similarity index 71% rename from src/client/java/techreborn/client/gui/DataDrivenGui.java rename to src/client/java/techreborn/client/gui/GuiGrinder.java index 81d87e2d0..66dc5e8a9 100644 --- a/src/client/java/techreborn/client/gui/DataDrivenGui.java +++ b/src/client/java/techreborn/client/gui/GuiGrinder.java @@ -1,7 +1,7 @@ /* * This file is part of TechReborn, licensed under the MIT License (MIT). * - * Copyright (c) 2020 TechReborn + * 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 @@ -29,38 +29,29 @@ import net.minecraft.entity.player.PlayerEntity; import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.common.screen.BuiltScreenHandler; -import techreborn.blockentity.data.DataDrivenBEProvider; -import techreborn.blockentity.data.DataDrivenSlot; -import techreborn.blockentity.data.SlotType; +import techreborn.blockentity.machine.tier1.GrinderBlockEntity; -public class DataDrivenGui extends GuiBase { +public class GuiGrinder extends GuiBase { + GrinderBlockEntity blockEntity; - private final DataDrivenBEProvider provider; - private final DataDrivenBEProvider.DataDrivenBlockEntity blockEntity; - - public DataDrivenGui(int syncID, final PlayerEntity player, final DataDrivenBEProvider.DataDrivenBlockEntity blockEntity) { + public GuiGrinder(int syncID, final PlayerEntity player, final GrinderBlockEntity blockEntity) { super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); this.blockEntity = blockEntity; - this.provider = blockEntity.getProvider(); } @Override protected void drawBackground(MatrixStack matrixStack, final float f, final int mouseX, final int mouseY) { super.drawBackground(matrixStack, f, mouseX, mouseY); final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; - final DataDrivenGui gui = this; - provider.getSlots().forEach(slot -> draw(matrixStack, gui, layer, slot)); + drawSlot(matrixStack, 8, 72, layer); + + drawSlot(matrixStack, 55, 45, layer); + drawOutputSlot(matrixStack, 101, 45, layer); + + builder.drawJEIButton(matrixStack, this, 158, 5, layer); } - - public void draw(MatrixStack matrixStack, GuiBase guiBase, GuiBase.Layer layer, DataDrivenSlot slot) { - if (slot.type() == SlotType.OUTPUT) { - guiBase.drawOutputSlot(matrixStack, slot.x(), slot.y(), layer); - } else { - guiBase.drawSlot(matrixStack, slot.x(), slot.y(), layer); - } - } @Override protected void drawForeground(MatrixStack matrixStack, final int mouseX, final int mouseY) { super.drawForeground(matrixStack, mouseX, mouseY); diff --git a/src/main/java/techreborn/blockentity/GuiType.java b/src/main/java/techreborn/blockentity/GuiType.java index 1356fdbeb..179541e75 100644 --- a/src/main/java/techreborn/blockentity/GuiType.java +++ b/src/main/java/techreborn/blockentity/GuiType.java @@ -41,7 +41,6 @@ import org.jetbrains.annotations.Nullable; import reborncore.api.blockentity.IMachineGuiHandler; import reborncore.common.screen.BuiltScreenHandler; import reborncore.common.screen.BuiltScreenHandlerProvider; -import techreborn.blockentity.data.DataDrivenBEProvider; import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity; import techreborn.blockentity.generator.SolarPanelBlockEntity; import techreborn.blockentity.generator.advanced.DieselGeneratorBlockEntity; @@ -108,6 +107,7 @@ public final class GuiType implements IMachineGuiHandler public static final GuiType RECYCLER = register("recycler"); public static final GuiType ROLLING_MACHINE = register("rolling_machine"); public static final GuiType SAWMILL = register("sawmill"); + public static final GuiType GRINDER = register("grinder"); public static final GuiType SCRAPBOXINATOR = register("scrapboxinator"); public static final GuiType SOLAR_PANEL = register("solar_panel"); public static final GuiType SEMIFLUID_GENERATOR = register("semifluid_generator"); @@ -118,7 +118,6 @@ public final class GuiType implements IMachineGuiHandler public static final GuiType GREENHOUSE_CONTROLLER = register("greenhouse_controller"); public static final GuiType FLUID_REPLICATOR = register("fluid_replicator"); public static final GuiType PLAYER_DETECTOR = register("player_detector"); - public static final GuiType DATA_DRIVEN = register("data_driven"); public static final GuiType BLOCK_BREAKER = register("block_breaker"); public static final GuiType BLOCK_PLACER = register("block_placer"); diff --git a/src/main/java/techreborn/blockentity/data/DataDrivenBEProvider.java b/src/main/java/techreborn/blockentity/data/DataDrivenBEProvider.java deleted file mode 100644 index 519ecef06..000000000 --- a/src/main/java/techreborn/blockentity/data/DataDrivenBEProvider.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2020 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.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.BlockState; -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.math.BlockPos; -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 org.jetbrains.annotations.Nullable; -import reborncore.common.crafting.RebornRecipeType; -import reborncore.common.recipes.RecipeCrafter; -import reborncore.common.screen.BuiltScreenHandler; -import reborncore.common.screen.BuiltScreenHandlerProvider; -import reborncore.common.screen.builder.BlockEntityScreenHandlerBuilder; -import reborncore.common.screen.builder.ScreenHandlerBuilder; -import reborncore.common.util.RebornInventory; -import reborncore.common.util.serialization.SerializationUtil; -import techreborn.blockentity.machine.GenericMachineBlockEntity; -import techreborn.init.ModRecipes; - -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.List; -import java.util.function.BiFunction; - -public class DataDrivenBEProvider extends BlockEntityType implements BiFunction { - - 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_TYPE, 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")); - // Ensure there is an energy slot, doing it here ensures it crashes on game load - Validate.isTrue(getEnergySlot() > 0); - } - - @Nullable - @Override - public DataDrivenBlockEntity instantiate(BlockPos pos, BlockState state) { - return new DataDrivenBlockEntity(this, pos, state); - } - - public BuiltScreenHandler createScreenHandler(DataDrivenBlockEntity blockEntity, int syncID, PlayerEntity player) { - BlockEntityScreenHandlerBuilder builder = new ScreenHandlerBuilder(identifier.getPath()).player(player.getInventory()) - .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 apply(BlockPos pos, BlockState state) { - return instantiate(pos, state); - } - - public static class DataDrivenBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider { - - private final DataDrivenBEProvider provider; - - private DataDrivenBlockEntity(DataDrivenBEProvider provider, BlockPos pos, BlockState state) { - super(provider, pos, state, 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 BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) { - return provider.createScreenHandler(this, syncID, player); - } - - public DataDrivenBEProvider getProvider() { - return provider; - } - } - - private int getEnergySlot() { - return slots.stream().filter(slot -> slot.type() == SlotType.ENERGY).findFirst().orElse(null).id(); - } - - private int countOfSlotType(SlotType type) { - return (int) slots.stream() - .filter(slot -> slot.type() == type) - .count(); - } - - private int[] slotIds(SlotType type) { - return slots.stream() - .filter(slot -> slot.type() == type) - .mapToInt(DataDrivenSlot::id) - .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/DataDrivenSlot.java b/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java deleted file mode 100644 index c9ff2a690..000000000 --- a/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2020 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.data; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import net.minecraft.util.JsonHelper; -import org.jetbrains.annotations.NotNull; -import reborncore.common.screen.builder.BlockEntityScreenHandlerBuilder; -import reborncore.common.util.serialization.SerializationUtil; - -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -public record DataDrivenSlot(int id, int x, int y, @NotNull SlotType type) { - - 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()); - } - - public void add(BlockEntityScreenHandlerBuilder inventoryBuilder) { - type.getSlotBiConsumer().accept(inventoryBuilder, this); - } -} diff --git a/src/main/java/techreborn/blockentity/data/SlotType.java b/src/main/java/techreborn/blockentity/data/SlotType.java deleted file mode 100644 index 3e9662a9c..000000000 --- a/src/main/java/techreborn/blockentity/data/SlotType.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2020 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.data; - - -import reborncore.common.screen.builder.BlockEntityScreenHandlerBuilder; - -import java.util.Arrays; -import java.util.function.BiConsumer; - -public enum SlotType { - // I'm really not a fan of the way I add the slots to the builder here - INPUT((builder, slot) -> { - builder.slot(slot.id(), slot.x(), slot.y()); - }), - OUTPUT((builder, slot) -> { - builder.outputSlot(slot.id(), slot.x(), slot.y()); - }), - ENERGY((builder, slot) -> { - builder.energySlot(slot.id(), slot.x(), slot.y()); - }); - - public static SlotType fromString(String string) { - return Arrays.stream(values()) - .filter(slotType -> slotType.name().equalsIgnoreCase(string)) - .findFirst() - .orElse(null); - } - - private final 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 new file mode 100644 index 000000000..b30867b5e --- /dev/null +++ b/src/main/java/techreborn/blockentity/machine/tier1/GrinderBlockEntity.java @@ -0,0 +1,57 @@ +/* + * 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.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.BlockPos; +import reborncore.common.recipes.RecipeCrafter; +import reborncore.common.screen.BuiltScreenHandler; +import reborncore.common.screen.BuiltScreenHandlerProvider; +import reborncore.common.screen.builder.ScreenHandlerBuilder; +import reborncore.common.util.RebornInventory; +import techreborn.blockentity.machine.GenericMachineBlockEntity; +import techreborn.config.TechRebornConfig; +import techreborn.init.ModRecipes; +import techreborn.init.TRBlockEntities; +import techreborn.init.TRContent; + +public class GrinderBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider { + + public GrinderBlockEntity(BlockPos pos, BlockState state) { + super(TRBlockEntities.GRINDER, pos, state, "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); + } + + @Override + public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) { + return new ScreenHandlerBuilder("grinder").player(player.getInventory()).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 deleted file mode 100644 index 483d8c80a..000000000 --- a/src/main/java/techreborn/blocks/DataDrivenMachineBlock.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2020 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.GuiType; -import techreborn.blockentity.data.DataDrivenBEProvider; - -/** - * @author modmuss50 - */ -public class DataDrivenMachineBlock extends GenericMachineBlock { - - private final DataDrivenBEProvider provider; - - public DataDrivenMachineBlock(String ident) { - super(GuiType.DATA_DRIVEN, null); - provider = DataDrivenBEProvider.create(this, new Identifier(ident)); - blockEntityClass = provider; - } - -} diff --git a/src/main/java/techreborn/config/TechRebornConfig.java b/src/main/java/techreborn/config/TechRebornConfig.java index 0266b90d7..da46ec825 100644 --- a/src/main/java/techreborn/config/TechRebornConfig.java +++ b/src/main/java/techreborn/config/TechRebornConfig.java @@ -351,6 +351,12 @@ public class TechRebornConfig { @Config(config = "machines", category = "extractor", key = "ExtractorMaxEnergy", comment = "Extractor Max Energy") public static int extractorMaxEnergy = 1_000; + @Config(config = "machines", category = "grinder", key = "GrinderInput", comment = "Grinder Max Input (Energy per tick)") + public static int grinderMaxInput = 32; + + @Config(config = "machines", category = "grinder", key = "GrinderMaxEnergy", comment = "Grinder Max Energy") + public static int grinderMaxEnergy = 1_000; + @Config(config = "machines", category = "compressor", key = "CompressorInput", comment = "Compressor Max Input (Energy per tick)") public static int compressorMaxInput = 32; diff --git a/src/main/java/techreborn/init/TRBlockEntities.java b/src/main/java/techreborn/init/TRBlockEntities.java index 1ccf4b8b5..afd6edb01 100644 --- a/src/main/java/techreborn/init/TRBlockEntities.java +++ b/src/main/java/techreborn/init/TRBlockEntities.java @@ -114,6 +114,7 @@ public class TRBlockEntities { public static final BlockEntityType FUSION_CONTROL_COMPUTER = register(FusionControlComputerBlockEntity::new, "fusion_control_computer", TRContent.Machine.FUSION_CONTROL_COMPUTER); public static final BlockEntityType LIGHTNING_ROD = register(LightningRodBlockEntity::new, "lightning_rod", TRContent.Machine.LIGHTNING_ROD); public static final BlockEntityType INDUSTRIAL_SAWMILL = register(IndustrialSawmillBlockEntity::new, "industrial_sawmill", TRContent.Machine.INDUSTRIAL_SAWMILL); + public static final BlockEntityType GRINDER = register(GrinderBlockEntity::new, "grinder", TRContent.Machine.GRINDER); public static final BlockEntityType SOLID_FUEL_GENERATOR = register(SolidFuelGeneratorBlockEntity::new, "solid_fuel_generator", TRContent.Machine.SOLID_FUEL_GENERATOR); public static final BlockEntityType EXTRACTOR = register(ExtractorBlockEntity::new, "extractor", TRContent.Machine.EXTRACTOR); public static final BlockEntityType RESIN_BASIN = register(ResinBasinBlockEntity::new, "resin_basin", TRContent.Machine.RESIN_BASIN); diff --git a/src/main/java/techreborn/init/TRContent.java b/src/main/java/techreborn/init/TRContent.java index 40d3156ea..481fd41f1 100644 --- a/src/main/java/techreborn/init/TRContent.java +++ b/src/main/java/techreborn/init/TRContent.java @@ -65,7 +65,6 @@ import techreborn.blockentity.machine.tier3.ChunkLoaderBlockEntity; import techreborn.blockentity.machine.tier3.IndustrialCentrifugeBlockEntity; import techreborn.blockentity.machine.tier3.MatterFabricatorBlockEntity; import techreborn.blockentity.storage.energy.AdjustableSUBlockEntity; -import techreborn.blocks.DataDrivenMachineBlock; import techreborn.blocks.GenericMachineBlock; import techreborn.blocks.cable.CableBlock; import techreborn.blocks.generator.BlockFusionCoil; @@ -670,7 +669,7 @@ public class TRContent { EXTRACTOR(new GenericMachineBlock(GuiType.EXTRACTOR, ExtractorBlockEntity::new)), RESIN_BASIN(new ResinBasinBlock(ResinBasinBlockEntity::new)), FLUID_REPLICATOR(new GenericMachineBlock(GuiType.FLUID_REPLICATOR, FluidReplicatorBlockEntity::new)), - GRINDER(new DataDrivenMachineBlock("techreborn:grinder")), + GRINDER(new GenericMachineBlock(GuiType.GRINDER, GrinderBlockEntity::new)), ELECTRIC_FURNACE(new GenericMachineBlock(GuiType.ELECTRIC_FURNACE, ElectricFurnaceBlockEntity::new)), IMPLOSION_COMPRESSOR(new GenericMachineBlock(GuiType.IMPLOSION_COMPRESSOR, ImplosionCompressorBlockEntity::new)), INDUSTRIAL_BLAST_FURNACE(new GenericMachineBlock(GuiType.BLAST_FURNACE, IndustrialBlastFurnaceBlockEntity::new)), diff --git a/src/main/resources/techreborn/machines/grinder.json b/src/main/resources/techreborn/machines/grinder.json deleted file mode 100644 index d06d502a6..000000000 --- a/src/main/resources/techreborn/machines/grinder.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "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