diff --git a/src/main/java/techreborn/blocks/GenericMachineBlock.java b/src/main/java/techreborn/blocks/GenericMachineBlock.java index d7e691179..81774d1dc 100644 --- a/src/main/java/techreborn/blocks/GenericMachineBlock.java +++ b/src/main/java/techreborn/blocks/GenericMachineBlock.java @@ -3,6 +3,8 @@ */ package techreborn.blocks; +import java.util.function.Supplier; + import net.minecraft.block.entity.BlockEntity; import net.minecraft.world.BlockView; import reborncore.api.blockentity.IMachineGuiHandler; @@ -11,15 +13,14 @@ import techreborn.client.EGui; /** * @author drcrazy - * @param * */ public class GenericMachineBlock extends BlockMachineBase { private EGui gui; - private Class blockEntityClass; + private Supplier blockEntityClass; - public GenericMachineBlock(EGui gui, Class blockEntityClass) { + public GenericMachineBlock(EGui gui, Supplier blockEntityClass) { super(); this.blockEntityClass = blockEntityClass; this.gui = gui; @@ -30,14 +31,7 @@ public class GenericMachineBlock extends BlockMachineBase { if (blockEntityClass == null) { return null; } - BlockEntity blockEntity = null; - try { - blockEntity = (BlockEntity) blockEntityClass.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - throw new RuntimeException("Failed to create BlockEntity blockEntity", e); - } - - return blockEntity; + return blockEntityClass.get(); } @Override diff --git a/src/main/java/techreborn/blocks/tier1/BlockAlloySmelter.java b/src/main/java/techreborn/blocks/tier1/BlockAlloySmelter.java deleted file mode 100644 index 45f36012f..000000000 --- a/src/main/java/techreborn/blocks/tier1/BlockAlloySmelter.java +++ /dev/null @@ -1,49 +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.blocks.tier1; - -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 techreborn.blockentity.machine.tier1.AlloySmelterBlockEntity; - -public class BlockAlloySmelter extends BlockMachineBase { - - public BlockAlloySmelter() { - super(); - } - - @Override - public BlockEntity createBlockEntity(BlockView worldIn) { - return new AlloySmelterBlockEntity(); - } - - @Override - public IMachineGuiHandler getGui() { - return EGui.ALLOY_SMELTER; - } -} diff --git a/src/main/java/techreborn/blocks/tier1/BlockAutoCraftingTable.java b/src/main/java/techreborn/blocks/tier1/BlockAutoCraftingTable.java deleted file mode 100644 index 96e03091b..000000000 --- a/src/main/java/techreborn/blocks/tier1/BlockAutoCraftingTable.java +++ /dev/null @@ -1,45 +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.blocks.tier1; - -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 techreborn.blockentity.machine.tier1.AutoCraftingTableBlockEntity; - -public class BlockAutoCraftingTable extends BlockMachineBase { - - @Override - public BlockEntity createBlockEntity(BlockView worldIn) { - return new AutoCraftingTableBlockEntity(); - } - - @Override - public IMachineGuiHandler getGui() { - return EGui.AUTO_CRAFTING_TABLE; - } -} diff --git a/src/main/java/techreborn/blocks/tier1/BlockCompressor.java b/src/main/java/techreborn/blocks/tier1/BlockCompressor.java deleted file mode 100644 index 6c9834928..000000000 --- a/src/main/java/techreborn/blocks/tier1/BlockCompressor.java +++ /dev/null @@ -1,45 +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.blocks.tier1; - -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 techreborn.blockentity.machine.tier1.CompressorBlockEntity; - -public class BlockCompressor extends BlockMachineBase { - - @Override - public BlockEntity createBlockEntity(BlockView worldIn) { - return new CompressorBlockEntity(); - } - - @Override - public IMachineGuiHandler getGui() { - return EGui.COMPRESSOR; - } -} diff --git a/src/main/java/techreborn/blocks/tier1/BlockElectricFurnace.java b/src/main/java/techreborn/blocks/tier1/BlockElectricFurnace.java deleted file mode 100644 index 3703ae29a..000000000 --- a/src/main/java/techreborn/blocks/tier1/BlockElectricFurnace.java +++ /dev/null @@ -1,45 +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.blocks.tier1; - -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 techreborn.blockentity.machine.tier1.ElectricFurnaceBlockEntity; - -public class BlockElectricFurnace extends BlockMachineBase { - - @Override - public BlockEntity createBlockEntity(BlockView worldIn) { - return new ElectricFurnaceBlockEntity(); - } - - @Override - public IMachineGuiHandler getGui() { - return EGui.ELECTRIC_FURNACE; - } -} diff --git a/src/main/java/techreborn/blocks/tier1/BlockExtractor.java b/src/main/java/techreborn/blocks/tier1/BlockExtractor.java deleted file mode 100644 index 51599117b..000000000 --- a/src/main/java/techreborn/blocks/tier1/BlockExtractor.java +++ /dev/null @@ -1,45 +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.blocks.tier1; - -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 techreborn.blockentity.machine.tier1.ExtractorBlockEntity; - -public class BlockExtractor extends BlockMachineBase { - - @Override - public BlockEntity createBlockEntity(BlockView worldIn) { - return new ExtractorBlockEntity(); - } - - @Override - public IMachineGuiHandler getGui() { - return EGui.EXTRACTOR; - } -} diff --git a/src/main/java/techreborn/blocks/tier1/BlockRecycler.java b/src/main/java/techreborn/blocks/tier1/BlockRecycler.java deleted file mode 100644 index 77cc44be1..000000000 --- a/src/main/java/techreborn/blocks/tier1/BlockRecycler.java +++ /dev/null @@ -1,45 +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.blocks.tier1; - -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 techreborn.blockentity.machine.tier1.RecyclerBlockEntity; - -public class BlockRecycler extends BlockMachineBase { - - @Override - public BlockEntity createBlockEntity(BlockView worldIn) { - return new RecyclerBlockEntity(); - } - - @Override - public IMachineGuiHandler getGui() { - return EGui.RECYCLER; - } -} diff --git a/src/main/java/techreborn/blocks/tier1/BlockRollingMachine.java b/src/main/java/techreborn/blocks/tier1/BlockRollingMachine.java deleted file mode 100644 index 0ef585167..000000000 --- a/src/main/java/techreborn/blocks/tier1/BlockRollingMachine.java +++ /dev/null @@ -1,45 +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.blocks.tier1; - -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 techreborn.blockentity.machine.tier1.RollingMachineBlockEntity; - -public class BlockRollingMachine extends BlockMachineBase { - - @Override - public BlockEntity createBlockEntity(BlockView worldIn) { - return new RollingMachineBlockEntity(); - } - - @Override - public IMachineGuiHandler getGui() { - return EGui.ROLLING_MACHINE; - } -} diff --git a/src/main/java/techreborn/blocks/tier1/BlockScrapboxinator.java b/src/main/java/techreborn/blocks/tier1/BlockScrapboxinator.java deleted file mode 100644 index 00c5d13c8..000000000 --- a/src/main/java/techreborn/blocks/tier1/BlockScrapboxinator.java +++ /dev/null @@ -1,45 +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.blocks.tier1; - -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 techreborn.blockentity.machine.tier1.ScrapboxinatorBlockEntity; - -public class BlockScrapboxinator extends BlockMachineBase { - - @Override - public BlockEntity createBlockEntity(BlockView worldIn) { - return new ScrapboxinatorBlockEntity(); - } - - @Override - public IMachineGuiHandler getGui() { - return EGui.SCRAPBOXINATOR; - } -} diff --git a/src/main/java/techreborn/init/TRContent.java b/src/main/java/techreborn/init/TRContent.java index 5f40e4e0b..b8c4babbd 100644 --- a/src/main/java/techreborn/init/TRContent.java +++ b/src/main/java/techreborn/init/TRContent.java @@ -365,16 +365,16 @@ public class TRContent { public enum Machine implements ItemConvertible { - ALLOY_SMELTER(new BlockAlloySmelter()), - ASSEMBLY_MACHINE(new GenericMachineBlock(EGui.ASSEMBLING_MACHINE, AssemblingMachineBlockEntity.class)), - AUTO_CRAFTING_TABLE(new BlockAutoCraftingTable()), + ALLOY_SMELTER(new GenericMachineBlock(EGui.ALLOY_SMELTER, () -> new AlloySmelterBlockEntity())), + ASSEMBLY_MACHINE(new GenericMachineBlock(EGui.ASSEMBLING_MACHINE, () -> new AssemblingMachineBlockEntity())), + AUTO_CRAFTING_TABLE(new GenericMachineBlock(EGui.AUTO_CRAFTING_TABLE, () -> new AutoCraftingTableBlockEntity())), CHEMICAL_REACTOR(new BlockChemicalReactor()), - COMPRESSOR(new BlockCompressor()), + COMPRESSOR(new GenericMachineBlock(EGui.COMPRESSOR, () -> new CompressorBlockEntity())), DISTILLATION_TOWER(new BlockDistillationTower()), - EXTRACTOR(new BlockExtractor()), + EXTRACTOR(new GenericMachineBlock(EGui.EXTRACTOR, () -> new ExtractorBlockEntity())), FLUID_REPLICATOR(new BlockFluidReplicator()), - GRINDER(new GenericMachineBlock(EGui.GRINDER, GrinderBlockEntity.class)), - ELECTRIC_FURNACE(new BlockElectricFurnace()), + GRINDER(new GenericMachineBlock(EGui.GRINDER, () -> new GrinderBlockEntity())), + ELECTRIC_FURNACE(new GenericMachineBlock(EGui.ELECTRIC_FURNACE, () -> new ElectricFurnaceBlockEntity())), IMPLOSION_COMPRESSOR(new BlockImplosionCompressor()), INDUSTRIAL_BLAST_FURNACE(new BlockIndustrialBlastFurnace()), INDUSTRIAL_CENTRIFUGE(new BlockIndustrialCentrifuge()), @@ -384,9 +384,9 @@ public class TRContent { IRON_ALLOY_FURNACE(new BlockIronAlloyFurnace()), IRON_FURNACE(new BlockIronFurnace()), MATTER_FABRICATOR(new BlockMatterFabricator()), - RECYCLER(new BlockRecycler()), - ROLLING_MACHINE(new BlockRollingMachine()), - SCRAPBOXINATOR(new BlockScrapboxinator()), + RECYCLER(new GenericMachineBlock(EGui.RECYCLER, () -> new RecyclerBlockEntity())), + ROLLING_MACHINE(new GenericMachineBlock(EGui.ROLLING_MACHINE, () -> new RollingMachineBlockEntity())), + SCRAPBOXINATOR(new GenericMachineBlock(EGui.SCRAPBOXINATOR, () -> new ScrapboxinatorBlockEntity())), VACUUM_FREEZER(new BlockVacuumFreezer()), DIESEL_GENERATOR(new BlockDieselGenerator()),