From eef8b36572bc6d517ccc6c58aaa78d5b17623644 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Sun, 6 Oct 2024 16:53:26 +0200 Subject: [PATCH] Abstract implementation to common --- gradle.properties | 2 +- .../ColossalChestsInstance.java | 12 +++ .../colossalchests/RegistryEntries.java | 37 ++++++++++ .../colossalchests/RegistryEntriesCommon.java | 29 -------- .../criterion/ChestFormedTrigger.java | 0 .../criterion/ChestFormedTriggerConfig.java | 10 +-- .../colossalchests/block/ChestMaterial.java | 0 .../colossalchests/block/ChestWall.java | 37 ++-------- .../colossalchests/block/ChestWallConfig.java | 29 ++++++++ .../colossalchests/block/ColossalChest.java | 73 +++++++------------ .../block/ColossalChestConfig.java | 38 ++++++++++ .../block/IBlockChestMaterial.java | 0 .../colossalchests/block/Interface.java | 49 ++++--------- .../colossalchests/block/InterfaceConfig.java | 29 ++++++++ .../colossalchests/block/UncolossalChest.java | 17 +++-- .../block/UncolossalChestConfig.java | 28 +++++++ .../blockentity/BlockEntityColossalChest.java | 64 ++++++++-------- .../BlockEntityColossalChestConfig.java | 46 ++++++++++++ .../blockentity/BlockEntityInterface.java | 10 +-- .../BlockEntityInterfaceConfig.java | 28 +++++++ .../BlockEntityUncolossalChest.java | 21 +++--- .../BlockEntityUncolossalChestConfig.java | 33 +++++++++ .../ContainerScreenColossalChest.java | 10 +-- .../ContainerScreenUncolossalChest.java | 8 +- .../RenderTileEntityChestBase.java | 3 - .../RenderTileEntityColossalChest.java | 13 ---- .../RenderTileEntityUncolossalChest.java | 3 - .../container/ContainerColossalChest.java | 31 ++++---- .../ContainerColossalChestConfig.java | 25 +++++++ ...ossalChestConfigScreenFactoryProvider.java | 18 +++++ .../container/ContainerUncolossalChest.java | 6 +- .../ContainerUncolossalChestConfig.java | 25 +++++++ ...ossalChestConfigScreenFactoryProvider.java | 18 +++++ .../item/ItemBlockMaterial.java | 0 .../colossalchests/item/ItemUpgradeTool.java | 32 ++++---- .../item/ItemUpgradeToolConfig.java | 10 +-- ...tboundContainerSetContentPacketWindow.java | 0 ...lientboundContainerSetSlotPacketLarge.java | 0 ...rverboundContainerClickPacketOverride.java | 0 .../resources/META-INF/accesstransformer.cfg | 8 ++ .../colossalchests/ColossalChests.java | 49 +++++++------ .../colossalchests/RegistryEntries.java | 32 -------- .../colossalchests/block/ChestWallConfig.java | 32 -------- .../block/ChestWallConfigNeoForge.java | 23 ++++++ .../block/ChestWallNeoForge.java | 45 ++++++++++++ .../block/ColossalChestConfig.java | 40 ---------- .../block/ColossalChestConfigNeoForge.java | 23 ++++++ .../block/ColossalChestNeoForge.java | 45 ++++++++++++ .../colossalchests/block/InterfaceConfig.java | 32 -------- .../block/InterfaceConfigNeoForge.java | 23 ++++++ .../block/InterfaceNeoForge.java | 45 ++++++++++++ .../block/UncolossalChestConfig.java | 44 ----------- .../block/UncolossalChestConfigNeoForge.java | 21 ++++++ .../BlockEntityColossalChestConfig.java | 50 ------------- ...lockEntityColossalChestConfigNeoForge.java | 37 ++++++++++ .../BlockEntityColossalChestNeoForge.java | 20 +++++ .../BlockEntityInterfaceConfig.java | 46 ------------ .../BlockEntityInterfaceConfigNeoForge.java | 30 ++++++++ .../BlockEntityUncolossalChestConfig.java | 46 ------------ ...ckEntityUncolossalChestConfigNeoForge.java | 24 ++++++ ...eEntityUncolossalChestRenderNeoForge.java} | 13 ++-- ...RenderTileEntityColossalChestNeoForge.java | 25 +++++++ .../ContainerColossalChestConfig.java | 33 --------- .../ContainerUncolossalChestConfig.java | 33 --------- .../CommonCapabilitiesModCompat.java | 8 +- .../colossalchests/proxy/CommonProxy.java | 6 +- 66 files changed, 928 insertions(+), 699 deletions(-) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/ColossalChestsInstance.java create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/RegistryEntries.java delete mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/RegistryEntriesCommon.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java (100%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java (54%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java (100%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/block/ChestWall.java (77%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/block/ChestWallConfig.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java (78%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/block/IBlockChestMaterial.java (100%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/block/Interface.java (73%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/block/InterfaceConfig.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java (87%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java (87%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java (73%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java (90%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenColossalChest.java (91%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenUncolossalChest.java (94%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java (97%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java (95%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java (92%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java (89%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfigScreenFactoryProvider.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java (87%) create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java create mode 100644 loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfigScreenFactoryProvider.java rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/item/ItemBlockMaterial.java (100%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java (88%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeToolConfig.java (57%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java (100%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java (100%) rename {loader-neoforge => loader-common}/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java (100%) delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/RegistryEntries.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallConfig.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallConfigNeoForge.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallNeoForge.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfigNeoForge.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestNeoForge.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceConfig.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceConfigNeoForge.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceNeoForge.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfigNeoForge.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfigNeoForge.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestNeoForge.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfigNeoForge.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfigNeoForge.java rename loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/{ItemStackTileEntityUncolossalChestRender.java => ItemStackTileEntityUncolossalChestRenderNeoForge.java} (60%) create mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChestNeoForge.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java delete mode 100644 loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java diff --git a/gradle.properties b/gradle.properties index 93b933d9..53960b2d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -44,4 +44,4 @@ org.gradle.daemon=false org.gradle.caching=true # Common dependencies -cyclopscore_version=1.24.0-616 +cyclopscore_version=1.24.0-619 diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/ColossalChestsInstance.java b/loader-common/src/main/java/org/cyclops/colossalchests/ColossalChestsInstance.java new file mode 100644 index 00000000..e7d9088e --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/ColossalChestsInstance.java @@ -0,0 +1,12 @@ +package org.cyclops.colossalchests; + +import org.cyclops.cyclopscore.init.IModBase; + +/** + * @author rubensworks + */ +public class ColossalChestsInstance { + + public static IModBase MOD = null; + +} diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/RegistryEntries.java b/loader-common/src/main/java/org/cyclops/colossalchests/RegistryEntries.java new file mode 100644 index 00000000..d09ab4f2 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/RegistryEntries.java @@ -0,0 +1,37 @@ +package org.cyclops.colossalchests; + +import net.minecraft.advancements.CriterionTrigger; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.cyclops.colossalchests.advancement.criterion.ChestFormedTrigger; +import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; +import org.cyclops.colossalchests.blockentity.BlockEntityInterface; +import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; +import org.cyclops.colossalchests.inventory.container.ContainerColossalChest; +import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChest; +import org.cyclops.cyclopscore.config.DeferredHolderCommon; + +/** + * Referenced registry entries. + * @author rubensworks + */ +public class RegistryEntries { + + public static final DeferredHolderCommon ITEM_CHEST = DeferredHolderCommon.create(Registries.ITEM, ResourceLocation.parse("minecraft:chest")); + + public static final DeferredHolderCommon BLOCK_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK, ResourceLocation.parse("colossalchests:uncolossal_chest")); + + public static final DeferredHolderCommon, BlockEntityType> BLOCK_ENTITY_COLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:colossal_chest")); + public static final DeferredHolderCommon, BlockEntityType> BLOCK_ENTITY_INTERFACE = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:interface")); + public static final DeferredHolderCommon, BlockEntityType> BLOCK_ENTITY_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:uncolossal_chest")); + + public static final DeferredHolderCommon, MenuType> CONTAINER_COLOSSAL_CHEST = DeferredHolderCommon.create(Registries.MENU, ResourceLocation.parse("colossalchests:colossal_chest")); + public static final DeferredHolderCommon, MenuType> CONTAINER_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.MENU, ResourceLocation.parse("colossalchests:uncolossal_chest")); + + public static final DeferredHolderCommon, ChestFormedTrigger> TRIGGER_CHEST_FORMED = DeferredHolderCommon.create(Registries.TRIGGER_TYPE, ResourceLocation.parse("colossalchests:chest_formed")); + +} diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/RegistryEntriesCommon.java b/loader-common/src/main/java/org/cyclops/colossalchests/RegistryEntriesCommon.java deleted file mode 100644 index 889c49a8..00000000 --- a/loader-common/src/main/java/org/cyclops/colossalchests/RegistryEntriesCommon.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.cyclops.colossalchests; - -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import org.cyclops.cyclopscore.config.DeferredHolderCommon; - -/** - * Referenced registry entries. - * @author rubensworks - */ -public class RegistryEntriesCommon { // TODO: rename when done - - public static final DeferredHolderCommon ITEM_CHEST = DeferredHolderCommon.create(Registries.ITEM, ResourceLocation.parse("minecraft:chest")); - - public static final DeferredHolderCommon BLOCK_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK, ResourceLocation.parse("colossalchests:uncolossal_chest")); - - // TODO -// public static final DeferredHolderCommon, BlockEntityType> BLOCK_ENTITY_COLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:colossal_chest")); -// public static final DeferredHolderCommon, BlockEntityType> BLOCK_ENTITY_INTERFACE = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:interface")); -// public static final DeferredHolderCommon, BlockEntityType> BLOCK_ENTITY_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:uncolossal_chest")); -// -// public static final DeferredHolderCommon, MenuType> CONTAINER_COLOSSAL_CHEST = DeferredHolderCommon.create(Registries.MENU, ResourceLocation.parse("colossalchests:colossal_chest")); -// public static final DeferredHolderCommon, MenuType> CONTAINER_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.MENU, ResourceLocation.parse("colossalchests:uncolossal_chest")); -// -// public static final DeferredHolderCommon, ChestFormedTrigger> TRIGGER_CHEST_FORMED = DeferredHolderCommon.create(Registries.TRIGGER_TYPE, ResourceLocation.parse("colossalchests:chest_formed")); - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java b/loader-common/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java similarity index 100% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java rename to loader-common/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java similarity index 54% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java rename to loader-common/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java index 425cbbcc..bdf4b21e 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java @@ -1,20 +1,20 @@ package org.cyclops.colossalchests.advancement.criterion; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.cyclopscore.config.extendedconfig.CriterionTriggerConfig; +import org.cyclops.cyclopscore.config.extendedconfig.CriterionTriggerConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; /** * @author rubensworks * */ -public class ChestFormedTriggerConfig extends CriterionTriggerConfig { +public class ChestFormedTriggerConfig extends CriterionTriggerConfigCommon { /** * Make a new instance. */ - public ChestFormedTriggerConfig() { + public ChestFormedTriggerConfig(M mod) { super( - ColossalChests._instance, + mod, "chest_formed", new ChestFormedTrigger() ); diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java similarity index 100% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java rename to loader-common/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWall.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/ChestWall.java similarity index 77% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWall.java rename to loader-common/src/main/java/org/cyclops/colossalchests/block/ChestWall.java index d046cccb..d9ccb97f 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWall.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/block/ChestWall.java @@ -6,24 +6,20 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelWriter; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.BlockHitResult; import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; import org.cyclops.cyclopscore.block.multi.CubeDetector; -import org.cyclops.cyclopscore.helper.MinecraftHelpers; +import org.cyclops.cyclopscore.helper.IModHelpers; /** * Part of the Colossal Blood Chest multiblock structure. @@ -34,7 +30,7 @@ public class ChestWall extends Block implements CubeDetector.IDetectionListener, public static final BooleanProperty ENABLED = ColossalChest.ENABLED; - private final ChestMaterial material; + protected final ChestMaterial material; public ChestWall(Block.Properties properties, ChestMaterial material) { super(properties); @@ -72,11 +68,6 @@ public boolean propagatesSkylightDown(BlockState blockState, BlockGetter blockRe return blockState.getValue(ENABLED); } - @Override - public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) { - return true; - } - @Override public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { super.setPlacedBy(world, pos, state, placer, stack); @@ -86,31 +77,27 @@ public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntit @Override public void onPlace(BlockState blockStateNew, Level world, BlockPos blockPos, BlockState blockStateOld, boolean isMoving) { super.onPlace(blockStateNew, world, blockPos, blockStateOld, isMoving); - if(!world.captureBlockSnapshots && blockStateNew.getBlock() != blockStateOld.getBlock() && !blockStateNew.getValue(ENABLED)) { + if(!isCaptureBlockSnapshots(world) && blockStateNew.getBlock() != blockStateOld.getBlock() && !blockStateNew.getValue(ENABLED)) { ColossalChest.triggerDetector(this.material, world, blockPos, true, null); } } + protected boolean isCaptureBlockSnapshots(Level level) { + return false; + } + @Override public void destroy(LevelAccessor world, BlockPos blockPos, BlockState blockState) { if(blockState.getValue(ENABLED)) ColossalChest.triggerDetector(material, world, blockPos, false, null); super.destroy(world, blockPos, blockState); } - @Override - public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosion explosion) { - if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null); - // IForgeBlock.super.onBlockExploded(state, world, pos, explosion); - world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); - wasExploded(world, pos, explosion); - } - @Override public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean valid, BlockPos originCorner) { Block block = world.getBlockState(location).getBlock(); if(block == this) { boolean change = !world.getBlockState(location).getValue(ENABLED); - ((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), MinecraftHelpers.BLOCK_NOTIFY_CLIENT); + ((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), IModHelpers.get().getMinecraftHelpers().getBlockNotifyClient()); if(change) { BlockEntityColossalChest.detectStructure(world, location, size, valid, originCorner); } @@ -136,12 +123,4 @@ public boolean canSurvive(BlockState blockState, LevelReader world, BlockPos blo return super.canSurvive(blockState, world, blockPos) && ColossalChest.canPlace(world, blockPos); } - @Override - public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) { - if (this.material.isExplosionResistant()) { - return 10000F; - } - return 0; - } - } diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/block/ChestWallConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/ChestWallConfig.java new file mode 100644 index 00000000..3a7a03dd --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/block/ChestWallConfig.java @@ -0,0 +1,29 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; +import java.util.function.Function; + +/** + * @author rubensworks + */ +public class ChestWallConfig extends BlockConfigCommon { + public ChestWallConfig(M mod, String namedId, Function, ? extends Block> blockConstructor, @Nullable BiFunction, Block, ? extends Item> itemConstructor) { + super(mod, namedId, blockConstructor, itemConstructor); + } + + public Block.Properties getProperties() { + return Block.Properties.of() + .strength(5.0F) + .sound(SoundType.WOOD) + .requiresCorrectToolForDrops() + .noOcclusion() + .isValidSpawn((state, level, pos, entityType) -> false); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java similarity index 78% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java index 2df55c10..85e5afe1 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java @@ -20,38 +20,32 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelWriter; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; -import org.cyclops.cyclopscore.block.BlockWithEntityGui; +import org.cyclops.cyclopscore.block.BlockWithEntityGuiCommon; import org.cyclops.cyclopscore.block.multi.CubeDetector; import org.cyclops.cyclopscore.block.multi.DetectionResult; import org.cyclops.cyclopscore.datastructure.Wrapper; -import org.cyclops.cyclopscore.helper.BlockEntityHelpers; -import org.cyclops.cyclopscore.helper.InventoryHelpers; -import org.cyclops.cyclopscore.helper.LocationHelpers; -import org.cyclops.cyclopscore.helper.MinecraftHelpers; -import org.cyclops.cyclopscore.inventory.SimpleInventory; +import org.cyclops.cyclopscore.helper.IModHelpers; +import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon; import org.spongepowered.asm.mixin.Interface; import javax.annotation.Nullable; @@ -61,17 +55,17 @@ * * @author rubensworks */ -public class ColossalChest extends BlockWithEntityGui implements CubeDetector.IDetectionListener, IBlockChestMaterial { +public class ColossalChest extends BlockWithEntityGuiCommon implements CubeDetector.IDetectionListener, IBlockChestMaterial { public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED; - private final ChestMaterial material; + protected final ChestMaterial material; public final MapCodec codec; - public ColossalChest(Properties properties, ChestMaterial material) { + public ColossalChest(BlockBehaviour.Properties properties, ChestMaterial material) { super(properties, BlockEntityColossalChest::new); this.material = material; - this.codec = simpleCodec((props) -> new ColossalChest(props, material)); + this.codec = BlockBehaviour.simpleCodec((props) -> new ColossalChest(props, material)); material.setBlockCore(this); @@ -88,7 +82,7 @@ public MenuProvider getMenuProvider(BlockState p_49234_, Level p_49235_, BlockPo @Override @Nullable public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { - return level.isClientSide ? createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST.get(), BlockEntityColossalChest::lidAnimateTick) : null; + return level.isClientSide ? BaseEntityBlock.createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST.value(), BlockEntityColossalChest::lidAnimateTick) : null; } @Override @@ -141,23 +135,18 @@ public boolean propagatesSkylightDown(BlockState blockState, BlockGetter blockRe return blockState.getValue(ENABLED); } - @Override - public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) { - return true; - } - public static DetectionResult triggerDetector(ChestMaterial material, LevelAccessor world, BlockPos blockPos, boolean valid, @Nullable Player player) { DetectionResult detectionResult = material.getChestDetector().detect(world, blockPos, valid ? null : blockPos, new MaterialValidationAction(), true); if (player instanceof ServerPlayer && detectionResult.getError() == null) { BlockState blockState = world.getBlockState(blockPos); if (blockState.getValue(ENABLED)) { - BlockEntityColossalChest tile = BlockEntityHelpers.get(world, blockPos, BlockEntityColossalChest.class).orElse(null); + BlockEntityColossalChest tile = IModHelpers.get().getBlockEntityHelpers().get(world, blockPos, BlockEntityColossalChest.class).orElse(null); if (tile == null) { BlockPos corePos = getCoreLocation(material, world, blockPos); - tile = BlockEntityHelpers.get(world, corePos, BlockEntityColossalChest.class).orElse(null); + tile = IModHelpers.get().getBlockEntityHelpers().get(world, corePos, BlockEntityColossalChest.class).orElse(null); } - RegistryEntries.TRIGGER_CHEST_FORMED.get().test((ServerPlayer) player, material, tile.getSizeSingular()); + RegistryEntries.TRIGGER_CHEST_FORMED.value().test((ServerPlayer) player, material, tile.getSizeSingular()); } } return detectionResult; @@ -167,7 +156,7 @@ public static DetectionResult triggerDetector(ChestMaterial material, LevelAcces public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { super.setPlacedBy(world, pos, state, placer, stack); if (stack.has(DataComponents.CUSTOM_NAME)) { - BlockEntityColossalChest tile = BlockEntityHelpers.get(world, pos, BlockEntityColossalChest.class).orElse(null); + BlockEntityColossalChest tile = IModHelpers.get().getBlockEntityHelpers().get(world, pos, BlockEntityColossalChest.class).orElse(null); if (tile != null) { tile.setCustomName(stack.getHoverName()); tile.setSize(Vec3i.ZERO); @@ -179,17 +168,21 @@ public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntit @Override public void onPlace(BlockState blockStateNew, Level world, BlockPos blockPos, BlockState blockStateOld, boolean isMoving) { super.onPlace(blockStateNew, world, blockPos, blockStateOld, isMoving); - if(!world.captureBlockSnapshots && blockStateNew.getBlock() != blockStateOld.getBlock() && !blockStateNew.getValue(ENABLED)) { + if(!isCaptureBlockSnapshots(world) && blockStateNew.getBlock() != blockStateOld.getBlock() && !blockStateNew.getValue(ENABLED)) { triggerDetector(this.material, world, blockPos, true, null); } } + protected boolean isCaptureBlockSnapshots(Level level) { + return false; + } + @Override public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean valid, BlockPos originCorner) { Block block = world.getBlockState(location).getBlock(); if(block == this) { - ((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), MinecraftHelpers.BLOCK_NOTIFY_CLIENT); - BlockEntityColossalChest tile = BlockEntityHelpers.get(world, location, BlockEntityColossalChest.class).orElse(null); + ((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), IModHelpers.get().getMinecraftHelpers().getBlockNotifyClient()); + BlockEntityColossalChest tile = IModHelpers.get().getBlockEntityHelpers().get(world, location, BlockEntityColossalChest.class).orElse(null); if(tile != null) { tile.setMaterial(this.material); tile.setSize(valid ? size : Vec3i.ZERO); @@ -258,7 +251,7 @@ public static void addPlayerChatError(Player player, Component error) { @Override public void writeExtraGuiData(FriendlyByteBuf packetBuffer, Level world, Player player, BlockPos blockPos, BlockHitResult rayTraceResult) { - BlockEntityHelpers.get(world, blockPos, BlockEntityColossalChest.class).ifPresent(tile -> packetBuffer.writeInt(tile.getInventory().getContainerSize())); + IModHelpers.get().getBlockEntityHelpers().get(world, blockPos, BlockEntityColossalChest.class).ifPresent(tile -> packetBuffer.writeInt(tile.getInventory().getContainerSize())); } @Override @@ -276,22 +269,6 @@ public void destroy(LevelAccessor world, BlockPos blockPos, BlockState blockStat super.destroy(world, blockPos, blockState); } - @Override - public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosion explosion) { - if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null); - // IForgeBlock.super.onBlockExploded(state, world, pos, explosion); - world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); - wasExploded(world, pos, explosion); - } - - @Override - public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) { - if (this.material.isExplosionResistant()) { - return 10000F; - } - return 0; - } - @Override public boolean canSurvive(BlockState blockState, LevelReader world, BlockPos blockPos) { return super.canSurvive(blockState, world, blockPos) && ColossalChest.canPlace(world, blockPos); @@ -300,11 +277,11 @@ public boolean canSurvive(BlockState blockState, LevelReader world, BlockPos blo @Override public void onRemove(BlockState oldState, Level world, BlockPos blockPos, BlockState newState, boolean isMoving) { if (oldState.getBlock().getClass() != newState.getBlock().getClass()) { - BlockEntityHelpers.get(world, blockPos, BlockEntityColossalChest.class) + IModHelpers.get().getBlockEntityHelpers().get(world, blockPos, BlockEntityColossalChest.class) .ifPresent(tile -> { // Last inventory overrides inventory when the chest is in a disabled state. - SimpleInventory lastInventory = tile.getLastValidInventory(); - InventoryHelpers.dropItems(world, lastInventory != null ? lastInventory : tile.getInventory(), blockPos); + SimpleInventoryCommon lastInventory = tile.getLastValidInventory(); + IModHelpers.get().getInventoryHelpers().dropItems(world, lastInventory != null ? lastInventory : tile.getInventory(), blockPos); }); super.onRemove(oldState, world, blockPos, newState, isMoving); } @@ -329,7 +306,7 @@ public Component onValidate(BlockPos blockPos, BlockState blockState) { } return requiredMaterial.get() == material ? null : Component.translatable( "multiblock.colossalchests.error.material", Component.translatable(material.getUnlocalizedName()), - LocationHelpers.toCompactString(blockPos), + IModHelpers.get().getLocationHelpers().toCompactString(blockPos), Component.translatable(requiredMaterial.get().getUnlocalizedName())); } } diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java new file mode 100644 index 00000000..c7c144ea --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java @@ -0,0 +1,38 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import org.cyclops.cyclopscore.config.ConfigurablePropertyCommon; +import org.cyclops.cyclopscore.config.ModConfigLocation; +import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; +import java.util.function.Function; + +/** + * @author rubensworks + */ +public class ColossalChestConfig extends BlockConfigCommon { + + @ConfigurablePropertyCommon(namedId="colossal_chest", category = "machine", comment = "The maximum size a colossal chest can have.", isCommandable = true, configLocation = ModConfigLocation.SERVER) + public static int maxSize = 20; + + @ConfigurablePropertyCommon(namedId="colossal_chest", category = "general", comment = "If the chest should visually open when someone uses it.", isCommandable = true, configLocation = ModConfigLocation.CLIENT) + public static boolean chestAnimation = true; + + public ColossalChestConfig(M mod, String namedId, Function, ? extends Block> blockConstructor, @Nullable BiFunction, Block, ? extends Item> itemConstructor) { + super(mod, namedId, blockConstructor, itemConstructor); + } + + public Block.Properties getProperties() { + return Block.Properties.of() + .strength(5.0F) + .sound(SoundType.WOOD) + .requiresCorrectToolForDrops() + .noOcclusion() + .isValidSpawn((state, level, pos, entityType) -> false); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/IBlockChestMaterial.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/IBlockChestMaterial.java similarity index 100% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/block/IBlockChestMaterial.java rename to loader-common/src/main/java/org/cyclops/colossalchests/block/IBlockChestMaterial.java diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/Interface.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/Interface.java similarity index 73% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/block/Interface.java rename to loader-common/src/main/java/org/cyclops/colossalchests/block/Interface.java index b57b0a20..861f02d1 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/Interface.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/block/Interface.java @@ -7,45 +7,41 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelWriter; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.BlockHitResult; import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; import org.cyclops.colossalchests.blockentity.BlockEntityInterface; -import org.cyclops.cyclopscore.block.BlockWithEntity; +import org.cyclops.cyclopscore.block.BlockWithEntityCommon; import org.cyclops.cyclopscore.block.multi.CubeDetector; -import org.cyclops.cyclopscore.helper.BlockEntityHelpers; -import org.cyclops.cyclopscore.helper.MinecraftHelpers; +import org.cyclops.cyclopscore.helper.IModHelpers; /** * Part of the Colossal Blood Chest multiblock structure. * @author rubensworks * */ -public class Interface extends BlockWithEntity implements CubeDetector.IDetectionListener, IBlockChestMaterial { +public class Interface extends BlockWithEntityCommon implements CubeDetector.IDetectionListener, IBlockChestMaterial { public static final BooleanProperty ENABLED = ColossalChest.ENABLED; - private final ChestMaterial material; + protected final ChestMaterial material; public final MapCodec codec; public Interface(Block.Properties properties, ChestMaterial material) { super(properties, BlockEntityInterface::new); this.material = material; - this.codec = simpleCodec((props) -> new Interface(props, material)); + this.codec = BlockBehaviour.simpleCodec((props) -> new Interface(props, material)); material.setBlockInterface(this); @@ -84,11 +80,6 @@ public boolean propagatesSkylightDown(BlockState blockState, BlockGetter blockRe return blockState.getValue(ENABLED); } - @Override - public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) { - return true; - } - @Override public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { super.setPlacedBy(world, pos, state, placer, stack); @@ -98,37 +89,33 @@ public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntit @Override public void onPlace(BlockState blockStateNew, Level world, BlockPos blockPos, BlockState blockStateOld, boolean isMoving) { super.onPlace(blockStateNew, world, blockPos, blockStateOld, isMoving); - if(!world.captureBlockSnapshots && blockStateNew.getBlock() != blockStateOld.getBlock() && !blockStateNew.getValue(ENABLED)) { + if(!isCaptureBlockSnapshots(world) && blockStateNew.getBlock() != blockStateOld.getBlock() && !blockStateNew.getValue(ENABLED)) { ColossalChest.triggerDetector(this.material, world, blockPos, true, null); } } + protected boolean isCaptureBlockSnapshots(Level level) { + return false; + } + @Override public void destroy(LevelAccessor world, BlockPos blockPos, BlockState blockState) { if(blockState.getValue(ENABLED)) ColossalChest.triggerDetector(material, world, blockPos, false, null); super.destroy(world, blockPos, blockState); } - @Override - public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosion explosion) { - if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null); - // IForgeBlock.super.onBlockExploded(state, world, pos, explosion); - world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); - wasExploded(world, pos, explosion); - } - @Override public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean valid, BlockPos originCorner) { Block block = world.getBlockState(location).getBlock(); if(block == this) { boolean change = !(Boolean) world.getBlockState(location).getValue(ENABLED); - ((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), MinecraftHelpers.BLOCK_NOTIFY_CLIENT); + ((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), IModHelpers.get().getMinecraftHelpers().getBlockNotifyClient()); if(change) { BlockPos tileLocation = ColossalChest.getCoreLocation(material, world, location); - BlockEntityInterface tile = BlockEntityHelpers.get(world, location, BlockEntityInterface.class).orElse(null); + BlockEntityInterface tile = IModHelpers.get().getBlockEntityHelpers().get(world, location, BlockEntityInterface.class).orElse(null); if(tile != null && tileLocation != null) { tile.setCorePosition(tileLocation); - BlockEntityColossalChest core = BlockEntityHelpers.get(world, tileLocation, BlockEntityColossalChest.class).orElse(null); + BlockEntityColossalChest core = IModHelpers.get().getBlockEntityHelpers().get(world, tileLocation, BlockEntityColossalChest.class).orElse(null); if (core != null) { core.addInterface(location); } @@ -156,12 +143,4 @@ public boolean canSurvive(BlockState blockState, LevelReader world, BlockPos blo return super.canSurvive(blockState, world, blockPos) && ColossalChest.canPlace(world, blockPos); } - @Override - public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) { - if (this.material.isExplosionResistant()) { - return 10000F; - } - return 0; - } - } diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/block/InterfaceConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/InterfaceConfig.java new file mode 100644 index 00000000..a5fd01b0 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/block/InterfaceConfig.java @@ -0,0 +1,29 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; +import java.util.function.Function; + +/** + * @author rubensworks + */ +public class InterfaceConfig extends BlockConfigCommon { + public InterfaceConfig(M mod, String namedId, Function, ? extends Block> blockConstructor, @Nullable BiFunction, Block, ? extends Item> itemConstructor) { + super(mod, namedId, blockConstructor, itemConstructor); + } + + public Block.Properties getProperties() { + return Block.Properties.of() + .strength(5.0F) + .sound(SoundType.WOOD) + .requiresCorrectToolForDrops() + .noOcclusion() + .isValidSpawn((state, level, pos, entityType) -> false); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java similarity index 87% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java index a344f63e..0b116e1f 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java @@ -25,6 +25,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; @@ -39,8 +40,8 @@ import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; -import org.cyclops.cyclopscore.block.BlockWithEntityGui; -import org.cyclops.cyclopscore.helper.BlockEntityHelpers; +import org.cyclops.cyclopscore.block.BlockWithEntityGuiCommon; +import org.cyclops.cyclopscore.helper.IModHelpers; import javax.annotation.Nullable; @@ -49,11 +50,11 @@ * * @author rubensworks */ -public class UncolossalChest extends BlockWithEntityGui implements SimpleWaterloggedBlock { +public class UncolossalChest extends BlockWithEntityGuiCommon implements SimpleWaterloggedBlock { public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - public static final MapCodec CODEC = simpleCodec(UncolossalChest::new); + public static final MapCodec CODEC = BlockBehaviour.simpleCodec(UncolossalChest::new); private final VoxelShape SHAPE = Block.box(5.0D, 0.0D, 5.0D, 11.0D, 6, 11.0D); @@ -73,7 +74,7 @@ protected MapCodec codec() { @Override @Nullable public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { - return level.isClientSide ? createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_UNCOLOSSAL_CHEST.get(), BlockEntityUncolossalChest::lidAnimateTick) : null; + return level.isClientSide ? BaseEntityBlock.createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_UNCOLOSSAL_CHEST.value(), BlockEntityUncolossalChest::lidAnimateTick) : null; } @Override @@ -116,7 +117,7 @@ public RenderShape getRenderShape(BlockState state) { public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { super.setPlacedBy(world, pos, state, placer, stack); if (stack.has(DataComponents.CUSTOM_NAME)) { - BlockEntityUncolossalChest tile = BlockEntityHelpers.get(world, pos, BlockEntityUncolossalChest.class).orElse(null); + BlockEntityUncolossalChest tile = IModHelpers.get().getBlockEntityHelpers().get(world, pos, BlockEntityUncolossalChest.class).orElse(null); if (tile != null) { tile.setCustomName(stack.getHoverName()); } @@ -133,7 +134,7 @@ public void tick(BlockState blockState, ServerLevel level, BlockPos pos, RandomS @Override public void onRemove(BlockState blockState, Level level, BlockPos blockPos, BlockState blockStateNew, boolean p_60519_) { if (!blockState.is(blockStateNew.getBlock())) { - BlockEntityHelpers.get(level, blockPos, BlockEntityUncolossalChest.class) + IModHelpers.get().getBlockEntityHelpers().get(level, blockPos, BlockEntityUncolossalChest.class) .ifPresent(blockEntity -> { Containers.dropContents(level, blockPos, blockEntity.getInventory()); level.updateNeighbourForOutputSignal(blockPos, this); @@ -154,7 +155,7 @@ public boolean hasAnalogOutputSignal(BlockState blockState) { @Override public int getAnalogOutputSignal(BlockState blockState, Level world, BlockPos pos) { - return BlockEntityHelpers.get(world, pos, BlockEntityUncolossalChest.class) + return IModHelpers.get().getBlockEntityHelpers().get(world, pos, BlockEntityUncolossalChest.class) .map(tile -> AbstractContainerMenu.getRedstoneSignalFromContainer(tile.getInventory())) .orElse(0); } diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java new file mode 100644 index 00000000..fa8ac538 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java @@ -0,0 +1,28 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; + +/** + * Config for the {@link ColossalChest}. + * @author rubensworks + * + */ +public abstract class UncolossalChestConfig extends BlockConfigCommon { + + public UncolossalChestConfig(M mod) { + super( + mod, + "uncolossal_chest", + eConfig -> new UncolossalChest(Block.Properties.of() + .strength(5.0F) + .requiresCorrectToolForDrops() + .sound(SoundType.WOOD)), + (eConfig, block) -> new BlockItem(block, new Item.Properties()) + ); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java similarity index 87% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java index 8d607324..3010af5c 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java @@ -28,23 +28,19 @@ import net.minecraft.world.level.block.entity.LidBlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.colossalchests.GeneralConfig; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.block.ChestMaterial; import org.cyclops.colossalchests.block.ColossalChestConfig; import org.cyclops.colossalchests.inventory.container.ContainerColossalChest; -import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity; +import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntityCommon; import org.cyclops.cyclopscore.datastructure.EnumFacingMap; -import org.cyclops.cyclopscore.helper.BlockHelpers; import org.cyclops.cyclopscore.helper.DirectionHelpers; -import org.cyclops.cyclopscore.helper.InventoryHelpers; -import org.cyclops.cyclopscore.helper.LocationHelpers; +import org.cyclops.cyclopscore.helper.IModHelpers; import org.cyclops.cyclopscore.inventory.INBTInventory; -import org.cyclops.cyclopscore.inventory.IndexedInventory; -import org.cyclops.cyclopscore.inventory.LargeInventory; -import org.cyclops.cyclopscore.inventory.SimpleInventory; +import org.cyclops.cyclopscore.inventory.IndexedInventoryCommon; +import org.cyclops.cyclopscore.inventory.LargeInventoryCommon; +import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon; import org.cyclops.cyclopscore.persist.nbt.NBTPersist; import javax.annotation.Nullable; @@ -57,8 +53,7 @@ * @author rubensworks * */ -@OnlyIn(value = Dist.CLIENT, _interface = LidBlockEntity.class) -public class BlockEntityColossalChest extends CyclopsBlockEntity implements MenuProvider, LidBlockEntity { +public class BlockEntityColossalChest extends CyclopsBlockEntityCommon implements MenuProvider, LidBlockEntity { private final ContainerOpenersCounter openersCounter = new ContainerOpenersCounter() { protected void onOpen(Level level, BlockPos pos, BlockState blockState) { @@ -84,11 +79,11 @@ protected boolean isOwnContainer(Player player) { }; private final ChestLidController chestLidController = new ChestLidController(); - private SimpleInventory lastValidInventory = null; - private SimpleInventory inventory = null; + private SimpleInventoryCommon lastValidInventory = null; + private SimpleInventoryCommon inventory = null; @NBTPersist - private Vec3i size = LocationHelpers.copyLocation(Vec3i.ZERO); + private Vec3i size = IModHelpers.get().getLocationHelpers().copyLocation(Vec3i.ZERO); @NBTPersist private Vec3 renderOffset = new Vec3(0, 0, 0); private Component customName = null; @@ -104,7 +99,7 @@ protected boolean isOwnContainer(Player player) { private EnumFacingMap facingSlots = EnumFacingMap.newMap(); public BlockEntityColossalChest(BlockPos blockPos, BlockState blockState) { - super(RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST.get(), blockPos, blockState); + super(RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST.value(), blockPos, blockState); } /** @@ -139,7 +134,7 @@ public void setSize(Vec3i size) { slot++; } if(slot < this.lastValidInventory.getContainerSize()) { - InventoryHelpers.dropItems(getLevel(), this.lastValidInventory, getBlockPos()); + IModHelpers.get().getInventoryHelpers().dropItems(getLevel(), this.lastValidInventory, getBlockPos()); } this.lastValidInventory = null; } @@ -147,18 +142,18 @@ public void setSize(Vec3i size) { interfaceLocations.clear(); if(this.inventory != null) { if(GeneralConfig.ejectItemsOnDestroy) { - InventoryHelpers.dropItems(getLevel(), this.inventory, getBlockPos()); + IModHelpers.get().getInventoryHelpers().dropItems(getLevel(), this.inventory, getBlockPos()); this.lastValidInventory = null; } else { this.lastValidInventory = this.inventory; } } - setInventory(new LargeInventory(0, 0)); + setInventory(new LargeInventoryCommon(0, 0)); } // Send an immediate update onDirty(); - BlockHelpers.markForUpdate(getLevel(), getBlockPos()); + IModHelpers.get().getBlockHelpers().markForUpdate(getLevel(), getBlockPos()); } public void setMaterial(ChestMaterial material) { @@ -169,11 +164,11 @@ public ChestMaterial getMaterial() { return ChestMaterial.VALUES.get(this.materialId); } - public SimpleInventory getLastValidInventory() { + public SimpleInventoryCommon getLastValidInventory() { return lastValidInventory; } - public void setLastValidInventory(SimpleInventory lastValidInventory) { + public void setLastValidInventory(SimpleInventoryCommon lastValidInventory) { this.lastValidInventory = lastValidInventory; } @@ -185,11 +180,11 @@ protected boolean isClientSide() { return getLevel() != null && getLevel().isClientSide; } - protected LargeInventory constructInventory() { + protected LargeInventoryCommon constructInventory() { if (!isClientSide() && GeneralConfig.creativeChests) { return constructInventoryDebug(); } - LargeInventory inv = !isClientSide() ? new IndexedInventory(calculateInventorySize(), 64) { + LargeInventoryCommon inv = !isClientSide() ? new IndexedInventoryCommon(calculateInventorySize(), 64) { @Override public void startOpen(Player entityPlayer) { if (!entityPlayer.isSpectator()) { @@ -205,15 +200,15 @@ public void stopOpen(Player entityPlayer) { BlockEntityColossalChest.this.stopOpen(entityPlayer); } } - } : new LargeInventory(calculateInventorySize(), 64); + } : new LargeInventoryCommon(calculateInventorySize(), 64); inv.addDirtyMarkListener(this); return inv; } - protected LargeInventory constructInventoryDebug() { - LargeInventory inv = !isClientSide() ? new IndexedInventory(calculateInventorySize(), 64) - : new LargeInventory(calculateInventorySize(), 64); + protected LargeInventoryCommon constructInventoryDebug() { + LargeInventoryCommon inv = !isClientSide() ? new IndexedInventoryCommon(calculateInventorySize(), 64) + : new LargeInventoryCommon(calculateInventorySize(), 64); Random random = new Random(); for (int i = 0; i < inv.getContainerSize(); i++) { inv.setItem(i, new ItemStack(Iterables.get(BuiltInRegistries.ITEM, @@ -226,8 +221,8 @@ protected LargeInventory constructInventoryDebug() { public CompoundTag getUpdateTag(HolderLookup.Provider provider) { // Don't send the inventory to the client. // The client will receive the data once the gui is opened. - SimpleInventory oldInventory = this.inventory; - SimpleInventory oldLastInventory = this.lastValidInventory; + SimpleInventoryCommon oldInventory = this.inventory; + SimpleInventoryCommon oldLastInventory = this.lastValidInventory; this.inventory = null; this.lastValidInventory = null; this.recreateNullInventory = false; @@ -240,8 +235,8 @@ public CompoundTag getUpdateTag(HolderLookup.Provider provider) { @Override public void read(CompoundTag tag, HolderLookup.Provider provider) { - SimpleInventory oldInventory = this.inventory; - SimpleInventory oldLastInventory = this.lastValidInventory; + SimpleInventoryCommon oldInventory = this.inventory; + SimpleInventoryCommon oldLastInventory = this.lastValidInventory; if (getLevel() != null && getLevel().isClientSide) { // Don't read the inventory on the client. @@ -258,7 +253,7 @@ public void read(CompoundTag tag, HolderLookup.Provider provider) { } else { getInventory().read(provider, tag.getCompound("inventory")); if (tag.contains("lastValidInventory", Tag.TAG_COMPOUND)) { - this.lastValidInventory = new LargeInventory(tag.getInt("lastValidInventorySize"), this.inventory.getMaxStackSize()); + this.lastValidInventory = new LargeInventoryCommon(tag.getInt("lastValidInventorySize"), this.inventory.getMaxStackSize()); this.lastValidInventory.read(provider, tag.getCompound("lastValidInventory")); } } @@ -300,8 +295,7 @@ protected int calculateInventorySize() { return (int) Math.ceil((Math.pow(size, 3) * 27) * getMaterial().getInventoryMultiplier() / 9) * 9; } - public void setInventory(SimpleInventory inventory) { - invalidateCapabilities(); + public void setInventory(SimpleInventoryCommon inventory) { this.inventory = inventory; } @@ -313,7 +307,7 @@ protected void ensureInventoryInitialized() { public INBTInventory getInventory() { if(lastValidInventory != null) { - return new IndexedInventory(); + return new IndexedInventoryCommon(); } ensureInventoryInitialized(); if(inventory == null && this.recreateNullInventory) { diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java new file mode 100644 index 00000000..d1102537 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java @@ -0,0 +1,46 @@ +package org.cyclops.colossalchests.blockentity; + +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.cyclops.colossalchests.block.ChestMaterial; +import org.cyclops.colossalchests.client.render.blockentity.RenderTileEntityColossalChest; +import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; + +import java.util.stream.Collectors; + +/** + * Config for the {@link BlockEntityColossalChest}. + * @author rubensworks + * + */ +public class BlockEntityColossalChestConfig extends BlockEntityConfigCommon { + + public BlockEntityColossalChestConfig(M mod) { + super( + mod, + "colossal_chest", + (eConfig) -> new BlockEntityType<>(((BlockEntityColossalChestConfig) eConfig).getBlockEntitySupplier(), + ChestMaterial.VALUES.stream() + .map(ChestMaterial::getBlockCore) + .collect(Collectors.toSet()), null) + ); + } + + protected BlockEntityType.BlockEntitySupplier getBlockEntitySupplier() { + return BlockEntityColossalChest::new; + } + + protected BlockEntityRendererProvider getBlockEntityRendererProvider() { + return RenderTileEntityColossalChest::new; + } + + @Override + public void onRegistered() { + super.onRegistered(); + if (getMod().getModHelpers().getMinecraftHelpers().isClientSide()) { + getMod().getProxy().registerRenderer(getInstance(), getBlockEntityRendererProvider()); + } + } + +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java similarity index 73% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java rename to loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java index 39bef4f3..a186969c 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java @@ -4,8 +4,8 @@ import net.minecraft.core.Vec3i; import net.minecraft.world.level.block.state.BlockState; import org.cyclops.colossalchests.RegistryEntries; -import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity; -import org.cyclops.cyclopscore.helper.BlockEntityHelpers; +import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntityCommon; +import org.cyclops.cyclopscore.helper.IModHelpers; import org.cyclops.cyclopscore.persist.nbt.NBTPersist; import java.lang.ref.WeakReference; @@ -15,14 +15,14 @@ * @author rubensworks * */ -public class BlockEntityInterface extends CyclopsBlockEntity { +public class BlockEntityInterface extends CyclopsBlockEntityCommon { @NBTPersist private Vec3i corePosition = null; private WeakReference coreReference = new WeakReference(null); public BlockEntityInterface(BlockPos blockPos, BlockState blockState) { - super(RegistryEntries.BLOCK_ENTITY_INTERFACE.get(), blockPos, blockState); + super(RegistryEntries.BLOCK_ENTITY_INTERFACE.value(), blockPos, blockState); } public Vec3i getCorePosition() { @@ -40,7 +40,7 @@ public BlockEntityColossalChest getCore() { } if (coreReference.get() == null) { coreReference = new WeakReference<>( - BlockEntityHelpers.get(getLevel(), new BlockPos(corePosition), BlockEntityColossalChest.class).orElse(null)); + IModHelpers.get().getBlockEntityHelpers().get(getLevel(), new BlockPos(corePosition), BlockEntityColossalChest.class).orElse(null)); } return coreReference.get(); } diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java new file mode 100644 index 00000000..470ae708 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java @@ -0,0 +1,28 @@ +package org.cyclops.colossalchests.blockentity; + +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.cyclops.colossalchests.block.ChestMaterial; +import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; + +import java.util.stream.Collectors; + +/** + * Config for the {@link BlockEntityInterface}. + * @author rubensworks + * + */ +public class BlockEntityInterfaceConfig extends BlockEntityConfigCommon { + + public BlockEntityInterfaceConfig(M mod) { + super( + mod, + "interface", + (eConfig) -> new BlockEntityType<>(BlockEntityInterface::new, + ChestMaterial.VALUES.stream() + .map(ChestMaterial::getBlockInterface) + .collect(Collectors.toSet()), null) + ); + } + +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java similarity index 90% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java index 05165d9e..e5b1536f 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java @@ -21,12 +21,11 @@ import net.minecraft.world.level.block.entity.LidBlockEntity; import net.minecraft.world.level.block.state.BlockState; import org.cyclops.colossalchests.RegistryEntries; -import org.cyclops.colossalchests.RegistryEntriesCommon; import org.cyclops.colossalchests.block.UncolossalChest; import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChest; -import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity; -import org.cyclops.cyclopscore.helper.BlockHelpers; -import org.cyclops.cyclopscore.inventory.SimpleInventory; +import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntityCommon; +import org.cyclops.cyclopscore.helper.IModHelpers; +import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon; import javax.annotation.Nullable; @@ -35,7 +34,7 @@ * @author rubensworks * */ -public class BlockEntityUncolossalChest extends CyclopsBlockEntity implements MenuProvider, LidBlockEntity { +public class BlockEntityUncolossalChest extends CyclopsBlockEntityCommon implements MenuProvider, LidBlockEntity { private final ContainerOpenersCounter openersCounter = new ContainerOpenersCounter() { protected void onOpen(Level level, BlockPos pos, BlockState blockState) { @@ -63,11 +62,11 @@ protected boolean isOwnContainer(Player player) { private Component customName = null; - private final SimpleInventory inventory; + private final SimpleInventoryCommon inventory; public BlockEntityUncolossalChest(BlockPos blockPos, BlockState blockState) { - super(RegistryEntries.BLOCK_ENTITY_UNCOLOSSAL_CHEST.get(), blockPos, blockState); - this.inventory = new SimpleInventory(5, 64) { + super(RegistryEntries.BLOCK_ENTITY_UNCOLOSSAL_CHEST.value(), blockPos, blockState); + this.inventory = new SimpleInventoryCommon(5, 64) { @Override public void startOpen(Player entityPlayer) { if (!entityPlayer.isSpectator()) { @@ -87,7 +86,7 @@ public void stopOpen(Player entityPlayer) { this.inventory.addDirtyMarkListener(this); } - public SimpleInventory getInventory() { + public SimpleInventoryCommon getInventory() { return inventory; } @@ -179,8 +178,8 @@ public Direction getRotation() { } BlockState blockState = getLevel().getBlockState(getBlockPos()); - if(blockState.getBlock() != RegistryEntriesCommon.BLOCK_UNCOLOSSAL_CHEST.value()) return Direction.NORTH; - return BlockHelpers.getSafeBlockStateProperty(blockState, UncolossalChest.FACING, Direction.NORTH); + if(blockState.getBlock() != RegistryEntries.BLOCK_UNCOLOSSAL_CHEST.value()) return Direction.NORTH; + return IModHelpers.get().getBlockHelpers().getSafeBlockStateProperty(blockState, UncolossalChest.FACING, Direction.NORTH); } @Nullable diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java new file mode 100644 index 00000000..d5671777 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java @@ -0,0 +1,33 @@ +package org.cyclops.colossalchests.blockentity; + +import com.google.common.collect.Sets; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.cyclops.colossalchests.RegistryEntries; +import org.cyclops.colossalchests.client.render.blockentity.RenderTileEntityUncolossalChest; +import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; + +/** + * Config for the {@link BlockEntityUncolossalChest}. + * @author rubensworks + * + */ +public class BlockEntityUncolossalChestConfig extends BlockEntityConfigCommon { + + public BlockEntityUncolossalChestConfig(M mod) { + super( + mod, + "uncolossal_chest", + (eConfig) -> new BlockEntityType<>(BlockEntityUncolossalChest::new, + Sets.newHashSet(RegistryEntries.BLOCK_UNCOLOSSAL_CHEST.value()), null) + ); + } + + @Override + public void onRegistered() { + super.onRegistered(); + if (getMod().getModHelpers().getMinecraftHelpers().isClientSide()) { + getMod().getProxy().registerRenderer(getInstance(), RenderTileEntityUncolossalChest::new); + } + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenColossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenColossalChest.java similarity index 91% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenColossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenColossalChest.java index c21d3179..c24db717 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenColossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenColossalChest.java @@ -14,12 +14,12 @@ import net.minecraft.world.inventory.ClickType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.cyclops.colossalchests.ColossalChests; +import org.cyclops.colossalchests.ColossalChestsInstance; import org.cyclops.colossalchests.Reference; import org.cyclops.colossalchests.inventory.container.ContainerColossalChest; import org.cyclops.colossalchests.network.packet.ServerboundContainerClickPacketOverride; import org.cyclops.cyclopscore.client.gui.component.button.ButtonArrow; -import org.cyclops.cyclopscore.client.gui.container.ContainerScreenScrolling; +import org.cyclops.cyclopscore.client.gui.container.ContainerScreenScrollingCommon; import java.util.List; @@ -28,7 +28,7 @@ * @author rubensworks * */ -public class ContainerScreenColossalChest extends ContainerScreenScrolling { +public class ContainerScreenColossalChest extends ContainerScreenScrollingCommon { private static final int TEXTUREWIDTH = 195; private static final int TEXTUREHEIGHT = 194; @@ -90,7 +90,7 @@ protected void slotClicked(Slot slotIn, int slotId, int clickedButton, ClickType slotId = slotIn.index; } // Send our own packet, to avoid C0EPacketClickWindow to be sent to the server what would trigger an overflowable S30PacketWindowItems - handleInventoryMouseClick(this.container.containerId, slotId, clickedButton, clickType, this.getMinecraft().player); + handleInventoryMouseClick(this.container.containerId, slotId, clickedButton, clickType, this.minecraft.player); } // Adapted from MultiPlayerGameMode#handleInventoryMouseClick @@ -116,6 +116,6 @@ protected void handleInventoryMouseClick(int windowId, int slotId, int mouseButt } // Original: this.connection.send(new ServerboundContainerClickPacket(p_171800_, abstractcontainermenu.getStateId(), p_171801_, p_171802_, p_171803_, abstractcontainermenu.getCarried().copy(), changedSloits)); - ColossalChests._instance.getPacketHandler().sendToServer(new ServerboundContainerClickPacketOverride(windowId, abstractcontainermenu.getStateId(), slotId, mouseButtonClicked, clickType, abstractcontainermenu.getCarried().copy(), changedSlots)); + ColossalChestsInstance.MOD.getPacketHandlerCommon().sendToServer(new ServerboundContainerClickPacketOverride(windowId, abstractcontainermenu.getStateId(), slotId, mouseButtonClicked, clickType, abstractcontainermenu.getCarried().copy(), changedSlots)); } } diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenUncolossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenUncolossalChest.java similarity index 94% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenUncolossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenUncolossalChest.java index cf3e3b2d..a616a4af 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenUncolossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/client/gui/container/ContainerScreenUncolossalChest.java @@ -1,16 +1,16 @@ package org.cyclops.colossalchests.client.gui.container; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.resources.ResourceLocation; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChest; -import org.cyclops.cyclopscore.client.gui.container.ContainerScreenExtended; +import org.cyclops.cyclopscore.client.gui.container.ContainerScreenExtendedCommon; /** * @author rubensworks */ -public class ContainerScreenUncolossalChest extends ContainerScreenExtended { +public class ContainerScreenUncolossalChest extends ContainerScreenExtendedCommon { public ContainerScreenUncolossalChest(ContainerUncolossalChest container, Inventory inventory, Component title) { super(container, inventory, title); } diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java b/loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java similarity index 97% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java rename to loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java index 132bb243..fc43b011 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java @@ -16,8 +16,6 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.LidBlockEntity; import net.minecraft.world.level.block.state.properties.ChestType; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; import java.util.Calendar; @@ -25,7 +23,6 @@ * A modified copy of {@link ChestRenderer}. * @author rubensworks */ -@OnlyIn(Dist.CLIENT) public abstract class RenderTileEntityChestBase implements BlockEntityRenderer { private final ModelPart lid; diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java similarity index 95% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java index 020bfc6f..2ca985f7 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java @@ -15,10 +15,7 @@ import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.InventoryMenu; -import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.colossalchests.GeneralConfig; import org.cyclops.colossalchests.Reference; import org.cyclops.colossalchests.block.ChestMaterial; @@ -33,7 +30,6 @@ * @author rubensworks * */ -@OnlyIn(Dist.CLIENT) public class RenderTileEntityColossalChest extends RenderTileEntityChestBase { public static final Map TEXTURES_CHEST = Maps.newHashMap(); @@ -62,15 +58,6 @@ public RenderTileEntityColossalChest(BlockEntityRendererProvider.Context context super(context); } - @Override - public AABB getRenderBoundingBox(BlockEntityColossalChest blockEntity) { - int size = blockEntity.getSizeSingular(); - return new AABB( - Vec3.atLowerCornerOf(blockEntity.getBlockPos().subtract(new Vec3i(size, size, size))), - Vec3.atLowerCornerOf(blockEntity.getBlockPos().offset(size, size * 2, size)) - ); - } - @Override protected void handleRotation(BlockEntityColossalChest tile, PoseStack matrixStack) { // Move origin to center of chest diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java similarity index 92% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java index e8c61f1c..6d7dd0cb 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java @@ -4,8 +4,6 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.core.Direction; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; /** @@ -13,7 +11,6 @@ * @author rubensworks * */ -@OnlyIn(Dist.CLIENT) public class RenderTileEntityUncolossalChest extends RenderTileEntityChestBase { public RenderTileEntityUncolossalChest(BlockEntityRendererProvider.Context context) { diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java similarity index 89% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java index e7d766d4..ed9935f5 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java @@ -23,14 +23,15 @@ import net.minecraft.world.inventory.ResultSlot; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.cyclops.colossalchests.ColossalChests; +import org.cyclops.colossalchests.ColossalChestsInstance; import org.cyclops.colossalchests.GeneralConfig; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.network.packet.ClientboundContainerSetContentPacketWindow; import org.cyclops.colossalchests.network.packet.ClientboundContainerSetSlotPacketLarge; -import org.cyclops.cyclopscore.inventory.LargeInventory; -import org.cyclops.cyclopscore.inventory.SimpleInventory; -import org.cyclops.cyclopscore.inventory.container.ScrollingInventoryContainer; +import org.cyclops.cyclopscore.inventory.LargeInventoryCommon; +import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon; +import org.cyclops.cyclopscore.inventory.container.ContainerExtendedCommon; +import org.cyclops.cyclopscore.inventory.container.ScrollingInventoryContainerCommon; import org.cyclops.cyclopscore.inventory.slot.SlotExtended; import java.io.UnsupportedEncodingException; @@ -42,7 +43,7 @@ * @author rubensworks * */ -public class ContainerColossalChest extends ScrollingInventoryContainer { +public class ContainerColossalChest extends ScrollingInventoryContainerCommon { private static final int INVENTORY_OFFSET_X = 9; private static final int INVENTORY_OFFSET_Y = 112; @@ -65,11 +66,11 @@ public class ContainerColossalChest extends ScrollingInventoryContainer { private boolean firstDetectionCheck = true; public ContainerColossalChest(int id, Inventory playerInventory, FriendlyByteBuf data) { - this(id, playerInventory, new LargeInventory(data.readInt(), 64)); + this(id, playerInventory, new LargeInventoryCommon(data.readInt(), 64)); } public ContainerColossalChest(int id, Inventory playerInventory, Container inventory) { - super(RegistryEntries.CONTAINER_COLOSSAL_CHEST.get(), id, playerInventory, inventory, Collections.emptyList(), (item, pattern) -> true); + super(RegistryEntries.CONTAINER_COLOSSAL_CHEST.value(), id, playerInventory, inventory, Collections.emptyList(), (item, pattern) -> true); this.chestSlots = Lists.newArrayListWithCapacity(getSizeInventory()); this.inventoryItemStacks = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY); @@ -112,16 +113,16 @@ protected void disableSlot(int slotIndex) { Slot slot = getSlot(slotIndex); // Yes I know this is ugly. // If you are reading this and know a better way, please tell me. - setSlotPosX(slot, Integer.MIN_VALUE); - setSlotPosY(slot, Integer.MIN_VALUE); + ContainerExtendedCommon.setSlotPosX(slot, Integer.MIN_VALUE); + ContainerExtendedCommon.setSlotPosY(slot, Integer.MIN_VALUE); } protected void enableSlot(int slotIndex, int row, int column) { Slot slot = getSlot(slotIndex); // Yes I know this is ugly. // If you are reading this and know a better way, please tell me. - setSlotPosX(slot, CHEST_INVENTORY_OFFSET_X + column * 18); - setSlotPosY(slot, CHEST_INVENTORY_OFFSET_Y + row * 18); + ContainerExtendedCommon.setSlotPosX(slot, CHEST_INVENTORY_OFFSET_X + column * 18); + ContainerExtendedCommon.setSlotPosY(slot, CHEST_INVENTORY_OFFSET_Y + row * 18); } @Override @@ -158,7 +159,7 @@ public void addSlotListener(ContainerListener listener) { @Override public void broadcastChanges() { - int newState = ((SimpleInventory) inventory).getState(); + int newState = ((SimpleInventoryCommon) inventory).getState(); if (lastInventoryState != newState) { lastInventoryState = newState; detectAndSendChangesOverride(); @@ -193,7 +194,7 @@ protected void detectAndSendChangesOverride() { // Adapted from EntityPlayerMP#sendSlotContents protected void sendSlotContentsToPlayer(ServerPlayer player, AbstractContainerMenu containerToSend, int slotInd, ItemStack stack) { if (!(containerToSend.getSlot(slotInd) instanceof ResultSlot)) { - ColossalChests._instance.getPacketHandler().sendToPlayer( + ColossalChestsInstance.MOD.getPacketHandlerCommon().sendToPlayer( new ClientboundContainerSetSlotPacketLarge(containerToSend.containerId, getStateId(), slotInd, stack), player); } } @@ -256,7 +257,7 @@ public void updateCraftingInventory(ServerPlayer player, List allItem bufferSize += tagSize; } else { // Flush - ColossalChests._instance.getPacketHandler().sendToPlayer(new ClientboundContainerSetContentPacketWindow(containerId, getStateId(), sendBuffer), player); + ColossalChestsInstance.MOD.getPacketHandlerCommon().sendToPlayer(new ClientboundContainerSetContentPacketWindow(containerId, getStateId(), sendBuffer), player); sendBuffer = new CompoundTag(); sendList = new ListTag(); sendList.add(tag); @@ -268,7 +269,7 @@ public void updateCraftingInventory(ServerPlayer player, List allItem } if (sendList.size() > 0) { // Flush - ColossalChests._instance.getPacketHandler().sendToPlayer(new ClientboundContainerSetContentPacketWindow(containerId, getStateId(), sendBuffer), player); + ColossalChestsInstance.MOD.getPacketHandlerCommon().sendToPlayer(new ClientboundContainerSetContentPacketWindow(containerId, getStateId(), sendBuffer), player); } playerNetServerHandler.send(new ClientboundContainerSetSlotPacket(-1, getStateId(), -1, getCarried())); } diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java new file mode 100644 index 00000000..75f1b7aa --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java @@ -0,0 +1,25 @@ +package org.cyclops.colossalchests.inventory.container; + +import net.minecraft.world.flag.FeatureFlags; +import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigCommon; +import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigScreenFactoryProvider; +import org.cyclops.cyclopscore.init.IModBase; +import org.cyclops.cyclopscore.inventory.container.ContainerTypeDataCommon; + +/** + * Config for {@link ContainerColossalChest}. + * @author rubensworks + */ +public class ContainerColossalChestConfig extends GuiConfigCommon { + + public ContainerColossalChestConfig(M mod) { + super(mod, + "colossal_chest", + eConfig -> new ContainerTypeDataCommon<>(ContainerColossalChest::new, FeatureFlags.VANILLA_SET)); + } + + @Override + public GuiConfigScreenFactoryProvider getScreenFactoryProvider() { + return new ContainerColossalChestConfigScreenFactoryProvider(); + } +} diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfigScreenFactoryProvider.java b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfigScreenFactoryProvider.java new file mode 100644 index 00000000..749b6ee6 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfigScreenFactoryProvider.java @@ -0,0 +1,18 @@ +package org.cyclops.colossalchests.inventory.container; + +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import org.cyclops.colossalchests.client.gui.container.ContainerScreenColossalChest; +import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; +import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigScreenFactoryProvider; + +/** + * @author rubensworks + */ +public class ContainerColossalChestConfigScreenFactoryProvider extends GuiConfigScreenFactoryProvider { + @Override + public > MenuScreens.ScreenConstructor getScreenFactory() { + return new ScreenFactorySafe<>(ContainerScreenColossalChest::new); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java similarity index 87% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java rename to loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java index b5112e87..fa06539d 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java @@ -4,19 +4,19 @@ import net.minecraft.world.SimpleContainer; import net.minecraft.world.entity.player.Inventory; import org.cyclops.colossalchests.RegistryEntries; -import org.cyclops.cyclopscore.inventory.container.InventoryContainer; +import org.cyclops.cyclopscore.inventory.container.InventoryContainerCommon; /** * @author rubensworks */ -public class ContainerUncolossalChest extends InventoryContainer { +public class ContainerUncolossalChest extends InventoryContainerCommon { public ContainerUncolossalChest(int id, Inventory playerInventory) { this(id, playerInventory, new SimpleContainer(5)); } public ContainerUncolossalChest(int id, Inventory playerInventory, Container inventory) { - super(RegistryEntries.CONTAINER_UNCOLOSSAL_CHEST.get(), id, playerInventory, inventory); + super(RegistryEntries.CONTAINER_UNCOLOSSAL_CHEST.value(), id, playerInventory, inventory); this.addInventory(inventory, 0, 44, 20, 1, getSizeInventory()); this.addPlayerInventory(playerInventory, 8, 51); diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java new file mode 100644 index 00000000..acd9e825 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java @@ -0,0 +1,25 @@ +package org.cyclops.colossalchests.inventory.container; + +import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.inventory.MenuType; +import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigCommon; +import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigScreenFactoryProvider; +import org.cyclops.cyclopscore.init.IModBase; + +/** + * Config for {@link ContainerUncolossalChest}. + * @author rubensworks + */ +public class ContainerUncolossalChestConfig extends GuiConfigCommon { + + public ContainerUncolossalChestConfig(M mod) { + super(mod, + "uncolossal_chest", + eConfig -> new MenuType<>(ContainerUncolossalChest::new, FeatureFlags.VANILLA_SET)); + } + + @Override + public GuiConfigScreenFactoryProvider getScreenFactoryProvider() { + return new ContainerUncolossalChestConfigScreenFactoryProvider(); + } +} diff --git a/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfigScreenFactoryProvider.java b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfigScreenFactoryProvider.java new file mode 100644 index 00000000..27603014 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfigScreenFactoryProvider.java @@ -0,0 +1,18 @@ +package org.cyclops.colossalchests.inventory.container; + +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import org.cyclops.colossalchests.client.gui.container.ContainerScreenUncolossalChest; +import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; +import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigScreenFactoryProvider; + +/** + * @author rubensworks + */ +public class ContainerUncolossalChestConfigScreenFactoryProvider extends GuiConfigScreenFactoryProvider { + @Override + public > MenuScreens.ScreenConstructor getScreenFactory() { + return new ScreenFactorySafe<>(ContainerScreenUncolossalChest::new); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/item/ItemBlockMaterial.java b/loader-common/src/main/java/org/cyclops/colossalchests/item/ItemBlockMaterial.java similarity index 100% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/item/ItemBlockMaterial.java rename to loader-common/src/main/java/org/cyclops/colossalchests/item/ItemBlockMaterial.java diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java b/loader-common/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java similarity index 88% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java rename to loader-common/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java index 9428545c..0ae68b69 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java @@ -25,12 +25,10 @@ import org.cyclops.colossalchests.blockentity.BlockEntityInterface; import org.cyclops.cyclopscore.block.multi.DetectionResult; import org.cyclops.cyclopscore.datastructure.Wrapper; -import org.cyclops.cyclopscore.helper.BlockEntityHelpers; -import org.cyclops.cyclopscore.helper.BlockHelpers; -import org.cyclops.cyclopscore.helper.InventoryHelpers; -import org.cyclops.cyclopscore.helper.MinecraftHelpers; +import org.cyclops.cyclopscore.helper.IInventoryHelpers; +import org.cyclops.cyclopscore.helper.IModHelpers; import org.cyclops.cyclopscore.inventory.PlayerInventoryIterator; -import org.cyclops.cyclopscore.inventory.SimpleInventory; +import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon; import java.util.List; @@ -52,13 +50,14 @@ public boolean isUpgrade() { } @Override - public InteractionResult onItemUseFirst(ItemStack itemStack, UseOnContext context) { + public InteractionResult useOn(UseOnContext context) { + ItemStack itemStack = context.getItemInHand(); BlockState blockState = context.getLevel().getBlockState(context.getClickedPos()); if (blockState.getBlock() instanceof IBlockChestMaterial - && BlockHelpers.getSafeBlockStateProperty(blockState, ColossalChest.ENABLED, false)) { + && IModHelpers.get().getBlockHelpers().getSafeBlockStateProperty(blockState, ColossalChest.ENABLED, false)) { // Determine the chest core location BlockPos tileLocation = ColossalChest.getCoreLocation(((IBlockChestMaterial) blockState.getBlock()).getMaterial(), context.getLevel(), context.getClickedPos()); - final BlockEntityColossalChest tile = BlockEntityHelpers.get(context.getLevel(), tileLocation, BlockEntityColossalChest.class).orElse(null); + final BlockEntityColossalChest tile = IModHelpers.get().getBlockEntityHelpers().get(context.getLevel(), tileLocation, BlockEntityColossalChest.class).orElse(null); // Determine the new material type ChestMaterial newType = transformType(itemStack, tile.getMaterial()); @@ -142,7 +141,7 @@ && consumeItems(player, requiredWalls, true))) { // Update the chest material and move the contents to the new tile if(!world.isClientSide) { tile.setSize(Vec3i.ZERO); - SimpleInventory oldInventory = tile.getLastValidInventory(); + SimpleInventoryCommon oldInventory = tile.getLastValidInventory(); Direction oldRotation = tile.getRotation(); Vec3 oldRenderOffset = tile.getRenderOffset(); List oldInterfaceLocations = Lists.newArrayList(tile.getInterfaceLocations()); @@ -161,7 +160,7 @@ && consumeItems(player, requiredWalls, true))) { } world.setBlock(location, blockStateNew.setValue(ColossalChest.ENABLED, blockState.getValue(ColossalChest.ENABLED)), - MinecraftHelpers.BLOCK_NOTIFY_CLIENT); + IModHelpers.get().getMinecraftHelpers().getBlockNotifyClient()); if (blockState.getBlock() instanceof ColossalChest || blockState.getBlock() instanceof Interface) { tile.addInterface(location); @@ -170,7 +169,7 @@ && consumeItems(player, requiredWalls, true))) { }, false); // From this point on, use the new tile entity - BlockEntityColossalChest tileNew = BlockEntityHelpers.get(world, coreLocation.get(), BlockEntityColossalChest.class) + BlockEntityColossalChest tileNew = IModHelpers.get().getBlockEntityHelpers().get(world, coreLocation.get(), BlockEntityColossalChest.class) .orElseThrow(() -> new IllegalStateException("Could not find a colossal chest core location during upgrading.")); tileNew.setLastValidInventory(oldInventory); tileNew.setMaterial(newType); @@ -183,21 +182,22 @@ && consumeItems(player, requiredWalls, true))) { // Set the core position into the newly transformed interfaces for (BlockPos interfaceLocation : interfaceLocations) { - BlockEntityInterface tileInterface = BlockEntityHelpers.get(world, interfaceLocation, BlockEntityInterface.class) + BlockEntityInterface tileInterface = IModHelpers.get().getBlockEntityHelpers().get(world, interfaceLocation, BlockEntityInterface.class) .orElseThrow(() -> new IllegalStateException("Could not find a colossal chest interface location during upgrading.")); tileInterface.setCorePosition(coreLocation.get()); } - RegistryEntries.TRIGGER_CHEST_FORMED.get().test((ServerPlayer) player, newType, size.getX() + 1); + RegistryEntries.TRIGGER_CHEST_FORMED.value().test((ServerPlayer) player, newType, size.getX() + 1); } // Add the lower tier items to the players inventory again. ItemStack returnedCores = new ItemStack(currentType.getBlockCore(), requiredCores.getCount()); ItemStack returnedInterfaces = new ItemStack(currentType.getBlockInterface(), requiredInterfaces.getCount()); ItemStack returnedWalls = new ItemStack(currentType.getBlockWall(), requiredWalls.getCount()); - InventoryHelpers.tryReAddToStack(player, ItemStack.EMPTY, returnedCores, hand); - InventoryHelpers.tryReAddToStack(player, ItemStack.EMPTY, returnedInterfaces, hand); - InventoryHelpers.tryReAddToStack(player, ItemStack.EMPTY, returnedWalls, hand); + IInventoryHelpers inventoryHelpers = IModHelpers.get().getInventoryHelpers(); + inventoryHelpers.tryReAddToStack(player, ItemStack.EMPTY, returnedCores, hand); + inventoryHelpers.tryReAddToStack(player, ItemStack.EMPTY, returnedInterfaces, hand); + inventoryHelpers.tryReAddToStack(player, ItemStack.EMPTY, returnedWalls, hand); return null; } diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeToolConfig.java b/loader-common/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeToolConfig.java similarity index 57% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeToolConfig.java rename to loader-common/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeToolConfig.java index 550f8924..283e2003 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeToolConfig.java +++ b/loader-common/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeToolConfig.java @@ -1,18 +1,18 @@ package org.cyclops.colossalchests.item; import net.minecraft.world.item.Item; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.cyclopscore.config.extendedconfig.ItemConfig; +import org.cyclops.cyclopscore.config.extendedconfig.ItemConfigCommon; +import org.cyclops.cyclopscore.init.IModBase; /** * Config for the facade. * @author rubensworks */ -public class ItemUpgradeToolConfig extends ItemConfig { +public class ItemUpgradeToolConfig extends ItemConfigCommon { - public ItemUpgradeToolConfig(boolean upgrade) { + public ItemUpgradeToolConfig(M mod, boolean upgrade) { super( - ColossalChests._instance, + mod, "upgrade_tool" + (upgrade ? "" : "_reverse"), (eConfig) -> new ItemUpgradeTool(new Item.Properties() .stacksTo(1), diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java b/loader-common/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java similarity index 100% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java rename to loader-common/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java b/loader-common/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java similarity index 100% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java rename to loader-common/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java b/loader-common/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java similarity index 100% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java rename to loader-common/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java diff --git a/loader-common/src/main/resources/META-INF/accesstransformer.cfg b/loader-common/src/main/resources/META-INF/accesstransformer.cfg index f7574079..e55d1483 100644 --- a/loader-common/src/main/resources/META-INF/accesstransformer.cfg +++ b/loader-common/src/main/resources/META-INF/accesstransformer.cfg @@ -1,3 +1,11 @@ # Guis public net.minecraft.world.inventory.AbstractContainerMenu f_38848_ # listeners public net.minecraft.world.inventory.AbstractContainerMenu containerListeners + +# The following are required for GUI-specific classes in common +public net.minecraft.client.gui.screens.MenuScreens$ScreenConstructor +public net.minecraft.world.inventory.MenuType (Lnet/minecraft/world/inventory/MenuType$MenuSupplier;Lnet/minecraft/world/flag/FeatureFlagSet;)V +public net.minecraft.world.inventory.MenuType$MenuSupplier + +# The following are required for BlockEntity-specific classes in common +public net.minecraft.world.level.block.entity.BlockEntityType$BlockEntitySupplier diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/ColossalChests.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/ColossalChests.java index 41b5b565..bad333d2 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/ColossalChests.java +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/ColossalChests.java @@ -9,13 +9,13 @@ import org.apache.logging.log4j.Level; import org.cyclops.colossalchests.advancement.criterion.ChestFormedTriggerConfig; import org.cyclops.colossalchests.block.ChestMaterial; -import org.cyclops.colossalchests.block.ChestWallConfig; -import org.cyclops.colossalchests.block.ColossalChestConfig; -import org.cyclops.colossalchests.block.InterfaceConfig; -import org.cyclops.colossalchests.block.UncolossalChestConfig; -import org.cyclops.colossalchests.blockentity.BlockEntityColossalChestConfig; -import org.cyclops.colossalchests.blockentity.BlockEntityInterfaceConfig; -import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChestConfig; +import org.cyclops.colossalchests.block.ChestWallConfigNeoForge; +import org.cyclops.colossalchests.block.ColossalChestConfigNeoForge; +import org.cyclops.colossalchests.block.InterfaceConfigNeoForge; +import org.cyclops.colossalchests.block.UncolossalChestConfigNeoForge; +import org.cyclops.colossalchests.blockentity.BlockEntityColossalChestConfigNeoForge; +import org.cyclops.colossalchests.blockentity.BlockEntityInterfaceConfigNeoForge; +import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChestConfigNeoForge; import org.cyclops.colossalchests.condition.ConditionMetalVariantsSettingConfig; import org.cyclops.colossalchests.inventory.container.ContainerColossalChestConfig; import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChestConfig; @@ -24,7 +24,7 @@ import org.cyclops.colossalchests.modcompat.IronChestModCompat; import org.cyclops.colossalchests.proxy.ClientProxy; import org.cyclops.colossalchests.proxy.CommonProxy; -import org.cyclops.cyclopscore.config.ConfigHandler; +import org.cyclops.cyclopscore.config.ConfigHandlerCommon; import org.cyclops.cyclopscore.init.ModBaseVersionable; import org.cyclops.cyclopscore.modcompat.ModCompatLoader; import org.cyclops.cyclopscore.proxy.IClientProxy; @@ -44,7 +44,10 @@ public class ColossalChests extends ModBaseVersionable { public static ColossalChests _instance; public ColossalChests(IEventBus modEventBus) { - super(Reference.MOD_ID, (instance) -> _instance = instance, modEventBus); + super(Reference.MOD_ID, (instance) -> { + ColossalChestsInstance.MOD = instance; + _instance = instance; + }, modEventBus); } @Override @@ -67,35 +70,35 @@ protected ICommonProxy constructCommonProxy() { @Override protected CreativeModeTab.Builder constructDefaultCreativeModeTab(CreativeModeTab.Builder builder) { return super.constructDefaultCreativeModeTab(builder) - .icon(() -> new ItemStack(RegistryEntriesCommon.ITEM_CHEST)); + .icon(() -> new ItemStack(RegistryEntries.ITEM_CHEST)); } @Override - protected void onConfigsRegister(ConfigHandler configHandler) { + protected void onConfigsRegister(ConfigHandlerCommon configHandler) { super.onConfigsRegister(configHandler); configHandler.addConfigurable(new GeneralConfig<>(this)); for (ChestMaterial material : ChestMaterial.VALUES) { - configHandler.addConfigurable(new ChestWallConfig(material)); - configHandler.addConfigurable(new ColossalChestConfig(material)); - configHandler.addConfigurable(new InterfaceConfig(material)); + configHandler.addConfigurable(new ChestWallConfigNeoForge<>(this, material)); + configHandler.addConfigurable(new ColossalChestConfigNeoForge<>(this, material)); + configHandler.addConfigurable(new InterfaceConfigNeoForge<>(this, material)); } + configHandler.addConfigurable(new UncolossalChestConfigNeoForge<>(this)); - configHandler.addConfigurable(new UncolossalChestConfig()); - configHandler.addConfigurable(new ItemUpgradeToolConfig(true)); - configHandler.addConfigurable(new ItemUpgradeToolConfig(false)); + configHandler.addConfigurable(new ItemUpgradeToolConfig<>(this, true)); + configHandler.addConfigurable(new ItemUpgradeToolConfig<>(this, false)); - configHandler.addConfigurable(new BlockEntityColossalChestConfig()); - configHandler.addConfigurable(new BlockEntityInterfaceConfig()); - configHandler.addConfigurable(new BlockEntityUncolossalChestConfig()); + configHandler.addConfigurable(new BlockEntityColossalChestConfigNeoForge<>(this)); + configHandler.addConfigurable(new BlockEntityInterfaceConfigNeoForge<>(this)); + configHandler.addConfigurable(new BlockEntityUncolossalChestConfigNeoForge<>(this)); - configHandler.addConfigurable(new ContainerColossalChestConfig()); - configHandler.addConfigurable(new ContainerUncolossalChestConfig()); + configHandler.addConfigurable(new ContainerColossalChestConfig<>(this)); + configHandler.addConfigurable(new ContainerUncolossalChestConfig<>(this)); configHandler.addConfigurable(new ConditionMetalVariantsSettingConfig()); - configHandler.addConfigurable(new ChestFormedTriggerConfig()); + configHandler.addConfigurable(new ChestFormedTriggerConfig<>(this)); } /** diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/RegistryEntries.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/RegistryEntries.java deleted file mode 100644 index 4ddd198e..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/RegistryEntries.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.cyclops.colossalchests; - -import net.minecraft.advancements.CriterionTrigger; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.neoforged.neoforge.registries.DeferredHolder; -import org.cyclops.colossalchests.advancement.criterion.ChestFormedTrigger; -import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; -import org.cyclops.colossalchests.blockentity.BlockEntityInterface; -import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; -import org.cyclops.colossalchests.inventory.container.ContainerColossalChest; -import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChest; - -/** - * Referenced registry entries. - * @author rubensworks - */ -@Deprecated -public class RegistryEntries { // TODO: rm - - public static final DeferredHolder, BlockEntityType> BLOCK_ENTITY_COLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:colossal_chest")); - public static final DeferredHolder, BlockEntityType> BLOCK_ENTITY_INTERFACE = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:interface")); - public static final DeferredHolder, BlockEntityType> BLOCK_ENTITY_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:uncolossal_chest")); - - public static final DeferredHolder, MenuType> CONTAINER_COLOSSAL_CHEST = DeferredHolder.create(Registries.MENU, ResourceLocation.parse("colossalchests:colossal_chest")); - public static final DeferredHolder, MenuType> CONTAINER_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.MENU, ResourceLocation.parse("colossalchests:uncolossal_chest")); - - public static final DeferredHolder, ChestFormedTrigger> TRIGGER_CHEST_FORMED = DeferredHolder.create(Registries.TRIGGER_TYPE, ResourceLocation.parse("colossalchests:chest_formed")); - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallConfig.java deleted file mode 100644 index eb432df3..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.cyclops.colossalchests.block; - -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SoundType; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.item.ItemBlockMaterial; -import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig; - -/** - * Config for the {@link ChestWall}. - * @author rubensworks - * - */ -public class ChestWallConfig extends BlockConfig { - - public ChestWallConfig(ChestMaterial material) { - super( - ColossalChests._instance, - "chest_wall_" + material.getName(), - eConfig -> new ChestWall(Block.Properties.of() - .strength(5.0F) - .sound(SoundType.WOOD) - .requiresCorrectToolForDrops() - .noOcclusion() - .isValidSpawn((state, level, pos, entityType) -> false), - material), - (eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material) - ); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallConfigNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallConfigNeoForge.java new file mode 100644 index 00000000..64236aab --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallConfigNeoForge.java @@ -0,0 +1,23 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.world.item.Item; +import org.cyclops.colossalchests.item.ItemBlockMaterial; +import org.cyclops.cyclopscore.init.IModBase; + +/** + * Config for the {@link ChestWall}. + * @author rubensworks + * + */ +public class ChestWallConfigNeoForge extends ChestWallConfig { + + public ChestWallConfigNeoForge(M mod, ChestMaterial material) { + super( + mod, + "chest_wall_" + material.getName(), + eConfig -> new ChestWallNeoForge(((ChestWallConfig) eConfig).getProperties(), material), + (eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material) + ); + } + +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallNeoForge.java new file mode 100644 index 00000000..f0ace80d --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ChestWallNeoForge.java @@ -0,0 +1,45 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; + +/** + * @author rubensworks + */ +public class ChestWallNeoForge extends ChestWall { + public ChestWallNeoForge(Properties properties, ChestMaterial material) { + super(properties, material); + } + + @Override + public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) { + return true; + } + + @Override + protected boolean isCaptureBlockSnapshots(Level level) { + return level.captureBlockSnapshots; + } + + @Override + public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosion explosion) { + if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null); + // IForgeBlock.super.onBlockExploded(state, world, pos, explosion); + world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); + wasExploded(world, pos, explosion); + } + + @Override + public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) { + if (this.material.isExplosionResistant()) { + return 10000F; + } + return 0; + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java deleted file mode 100644 index e0d15b20..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.cyclops.colossalchests.block; - -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SoundType; -import net.neoforged.fml.config.ModConfig; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.item.ItemBlockMaterial; -import org.cyclops.cyclopscore.config.ConfigurableProperty; -import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig; - -/** - * Config for the {@link ColossalChest}. - * @author rubensworks - * - */ -public class ColossalChestConfig extends BlockConfig { - - @ConfigurableProperty(namedId="colossal_chest", category = "machine", comment = "The maximum size a colossal chest can have.", isCommandable = true, configLocation = ModConfig.Type.SERVER) - public static int maxSize = 20; - - @ConfigurableProperty(namedId="colossal_chest", category = "general", comment = "If the chest should visually open when someone uses it.", isCommandable = true, configLocation = ModConfig.Type.CLIENT) - public static boolean chestAnimation = true; - - public ColossalChestConfig(ChestMaterial material) { - super( - ColossalChests._instance, - "colossal_chest_" + material.getName(), - eConfig -> new ColossalChest(Block.Properties.of() - .strength(5.0F) - .sound(SoundType.WOOD) - .requiresCorrectToolForDrops() - .noOcclusion() - .isValidSpawn((state, level, pos, entityType) -> false), - material), - (eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material) - ); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfigNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfigNeoForge.java new file mode 100644 index 00000000..168024dc --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfigNeoForge.java @@ -0,0 +1,23 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.world.item.Item; +import org.cyclops.colossalchests.item.ItemBlockMaterial; +import org.cyclops.cyclopscore.init.IModBase; + +/** + * Config for the {@link ColossalChest}. + * @author rubensworks + * + */ +public class ColossalChestConfigNeoForge extends ColossalChestConfig { + + public ColossalChestConfigNeoForge(M mod, ChestMaterial material) { + super( + mod, + "colossal_chest_" + material.getName(), + eConfig -> new ColossalChestNeoForge(((ColossalChestConfig) eConfig).getProperties(), material), + (eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material) + ); + } + +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestNeoForge.java new file mode 100644 index 00000000..1f835c78 --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/ColossalChestNeoForge.java @@ -0,0 +1,45 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; + +/** + * @author rubensworks + */ +public class ColossalChestNeoForge extends ColossalChest { + public ColossalChestNeoForge(Properties properties, ChestMaterial material) { + super(properties, material); + } + + @Override + public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) { + return true; + } + + @Override + protected boolean isCaptureBlockSnapshots(Level level) { + return level.captureBlockSnapshots; + } + + @Override + public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosion explosion) { + if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null); + // IForgeBlock.super.onBlockExploded(state, world, pos, explosion); + world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); + wasExploded(world, pos, explosion); + } + + @Override + public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) { + if (this.material.isExplosionResistant()) { + return 10000F; + } + return 0; + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceConfig.java deleted file mode 100644 index 7d3819f2..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.cyclops.colossalchests.block; - -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SoundType; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.item.ItemBlockMaterial; -import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig; - -/** - * Config for the {@link Interface}. - * @author rubensworks - * - */ -public class InterfaceConfig extends BlockConfig { - - public InterfaceConfig(ChestMaterial material) { - super( - ColossalChests._instance, - "interface_" + material.getName(), - eConfig -> new Interface(Block.Properties.of() - .strength(5.0F) - .sound(SoundType.WOOD) - .requiresCorrectToolForDrops() - .noOcclusion() - .isValidSpawn((state, level, pos, entityType) -> false), - material), - (eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material) - ); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceConfigNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceConfigNeoForge.java new file mode 100644 index 00000000..56bf5f6a --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceConfigNeoForge.java @@ -0,0 +1,23 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.world.item.Item; +import org.cyclops.colossalchests.item.ItemBlockMaterial; +import org.cyclops.cyclopscore.init.IModBase; + +/** + * Config for the {@link Interface}. + * @author rubensworks + * + */ +public class InterfaceConfigNeoForge extends InterfaceConfig { + + public InterfaceConfigNeoForge(M mod, ChestMaterial material) { + super( + mod, + "interface_" + material.getName(), + eConfig -> new InterfaceNeoForge(((InterfaceConfig) eConfig).getProperties(), material), + (eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material) + ); + } + +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceNeoForge.java new file mode 100644 index 00000000..863f6824 --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/InterfaceNeoForge.java @@ -0,0 +1,45 @@ +package org.cyclops.colossalchests.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; + +/** + * @author rubensworks + */ +public class InterfaceNeoForge extends Interface { + public InterfaceNeoForge(Properties properties, ChestMaterial material) { + super(properties, material); + } + + @Override + public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) { + return true; + } + + @Override + protected boolean isCaptureBlockSnapshots(Level level) { + return level.captureBlockSnapshots; + } + + @Override + public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosion explosion) { + if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null); + // IForgeBlock.super.onBlockExploded(state, world, pos, explosion); + world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); + wasExploded(world, pos, explosion); + } + + @Override + public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) { + if (this.material.isExplosionResistant()) { + return 10000F; + } + return 0; + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java deleted file mode 100644 index 98284301..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.cyclops.colossalchests.block; - -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SoundType; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.client.render.blockentity.ItemStackTileEntityUncolossalChestRender; -import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig; - -import java.util.function.Consumer; - -/** - * Config for the {@link ColossalChest}. - * @author rubensworks - * - */ -public class UncolossalChestConfig extends BlockConfig { - - public UncolossalChestConfig() { - super( - ColossalChests._instance, - "uncolossal_chest", - eConfig -> new UncolossalChest(Block.Properties.of() - .strength(5.0F) - .requiresCorrectToolForDrops() - .sound(SoundType.WOOD)), - (eConfig, block) -> { - Item.Properties itemProperties = new Item.Properties(); - return new BlockItem(block, itemProperties) { - @Override - @OnlyIn(Dist.CLIENT) - public void initializeClient(Consumer consumer) { - consumer.accept(new ItemStackTileEntityUncolossalChestRender.ClientItemExtensions()); - } - }; - } - ); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfigNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfigNeoForge.java new file mode 100644 index 00000000..ff1051b9 --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfigNeoForge.java @@ -0,0 +1,21 @@ +package org.cyclops.colossalchests.block; + +import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent; +import org.cyclops.colossalchests.client.render.blockentity.ItemStackTileEntityUncolossalChestRenderNeoForge; +import org.cyclops.cyclopscore.init.ModBase; + +/** + * Config for the {@link ColossalChest}. + * @author rubensworks + * + */ +public class UncolossalChestConfigNeoForge extends UncolossalChestConfig { + + public UncolossalChestConfigNeoForge(M mod) { + super(mod); + if (mod.getModHelpers().getMinecraftHelpers().isClientSide()) { + mod.getModEventBus().addListener((RegisterClientExtensionsEvent event) -> event.registerItem(new ItemStackTileEntityUncolossalChestRenderNeoForge.ClientItemExtensions(), getItemInstance())); + } + } + +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java deleted file mode 100644 index 352b4c62..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.cyclops.colossalchests.blockentity; - -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.capabilities.Capabilities; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; -import net.neoforged.neoforge.items.wrapper.InvWrapper; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.block.ChestMaterial; -import org.cyclops.colossalchests.client.render.blockentity.RenderTileEntityColossalChest; -import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfig; - -import java.util.stream.Collectors; - -/** - * Config for the {@link BlockEntityColossalChest}. - * @author rubensworks - * - */ -public class BlockEntityColossalChestConfig extends BlockEntityConfig { - - public BlockEntityColossalChestConfig() { - super( - ColossalChests._instance, - "colossal_chest", - (eConfig) -> new BlockEntityType<>(BlockEntityColossalChest::new, - ChestMaterial.VALUES.stream() - .map(ChestMaterial::getBlockCore) - .collect(Collectors.toSet()), null) - ); - ColossalChests._instance.getModEventBus().addListener(this::registerCapabilities); - } - - @Override - @OnlyIn(Dist.CLIENT) - public void onRegistered() { - super.onRegistered(); - ColossalChests._instance.getProxy().registerRenderer(getInstance(), RenderTileEntityColossalChest::new); - } - - public void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - getInstance(), - (blockEntity, context) -> new InvWrapper(blockEntity.getInventory()) - ); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfigNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfigNeoForge.java new file mode 100644 index 00000000..b8a74c0a --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfigNeoForge.java @@ -0,0 +1,37 @@ +package org.cyclops.colossalchests.blockentity; + +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.items.wrapper.InvWrapper; +import org.cyclops.colossalchests.client.render.blockentity.RenderTileEntityColossalChestNeoForge; +import org.cyclops.cyclopscore.init.ModBase; + +/** + * @author rubensworks + */ +public class BlockEntityColossalChestConfigNeoForge extends BlockEntityColossalChestConfig { + public BlockEntityColossalChestConfigNeoForge(M mod) { + super(mod); + mod.getModEventBus().addListener(this::registerCapabilities); + } + + @Override + protected BlockEntityType.BlockEntitySupplier getBlockEntitySupplier() { + return BlockEntityColossalChestNeoForge::new; + } + + @Override + protected BlockEntityRendererProvider getBlockEntityRendererProvider() { + return RenderTileEntityColossalChestNeoForge::new; + } + + public void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + getInstance(), + (blockEntity, context) -> new InvWrapper(blockEntity.getInventory()) + ); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestNeoForge.java new file mode 100644 index 00000000..7d8f0779 --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestNeoForge.java @@ -0,0 +1,20 @@ +package org.cyclops.colossalchests.blockentity; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon; + +/** + * @author rubensworks + */ +public class BlockEntityColossalChestNeoForge extends BlockEntityColossalChest { + public BlockEntityColossalChestNeoForge(BlockPos blockPos, BlockState blockState) { + super(blockPos, blockState); + } + + @Override + public void setInventory(SimpleInventoryCommon inventory) { + invalidateCapabilities(); + super.setInventory(inventory); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java deleted file mode 100644 index fa0e6901..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.cyclops.colossalchests.blockentity; - -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.neoforged.neoforge.capabilities.Capabilities; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; -import net.neoforged.neoforge.items.wrapper.InvWrapper; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.block.ChestMaterial; -import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfig; - -import java.util.stream.Collectors; - -/** - * Config for the {@link BlockEntityInterface}. - * @author rubensworks - * - */ -public class BlockEntityInterfaceConfig extends BlockEntityConfig { - - public BlockEntityInterfaceConfig() { - super( - ColossalChests._instance, - "interface", - (eConfig) -> new BlockEntityType<>(BlockEntityInterface::new, - ChestMaterial.VALUES.stream() - .map(ChestMaterial::getBlockInterface) - .collect(Collectors.toSet()), null) - ); - ColossalChests._instance.getModEventBus().addListener(this::registerCapabilities); - } - - public void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - getInstance(), - (blockEntity, context) -> { - BlockEntityColossalChest core = blockEntity.getCore(); - if (core != null) { - return new InvWrapper(core.getInventory()); - } - return null; - } - ); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfigNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfigNeoForge.java new file mode 100644 index 00000000..9244d941 --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfigNeoForge.java @@ -0,0 +1,30 @@ +package org.cyclops.colossalchests.blockentity; + +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.items.wrapper.InvWrapper; +import org.cyclops.cyclopscore.init.ModBase; + +/** + * @author rubensworks + */ +public class BlockEntityInterfaceConfigNeoForge extends BlockEntityInterfaceConfig { + public BlockEntityInterfaceConfigNeoForge(M mod) { + super(mod); + mod.getModEventBus().addListener(this::registerCapabilities); + } + + public void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + getInstance(), + (blockEntity, context) -> { + BlockEntityColossalChest core = blockEntity.getCore(); + if (core != null) { + return new InvWrapper(core.getInventory()); + } + return null; + } + ); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java deleted file mode 100644 index 606ace11..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.cyclops.colossalchests.blockentity; - -import com.google.common.collect.Sets; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.capabilities.Capabilities; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; -import net.neoforged.neoforge.items.wrapper.InvWrapper; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.RegistryEntriesCommon; -import org.cyclops.colossalchests.client.render.blockentity.RenderTileEntityUncolossalChest; -import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfig; - -/** - * Config for the {@link BlockEntityUncolossalChest}. - * @author rubensworks - * - */ -public class BlockEntityUncolossalChestConfig extends BlockEntityConfig { - - public BlockEntityUncolossalChestConfig() { - super( - ColossalChests._instance, - "uncolossal_chest", - (eConfig) -> new BlockEntityType<>(BlockEntityUncolossalChest::new, - Sets.newHashSet(RegistryEntriesCommon.BLOCK_UNCOLOSSAL_CHEST.value()), null) - ); - ColossalChests._instance.getModEventBus().addListener(this::registerCapabilities); - } - - @Override - @OnlyIn(Dist.CLIENT) - public void onRegistered() { - super.onRegistered(); - ColossalChests._instance.getProxy().registerRenderer(getInstance(), RenderTileEntityUncolossalChest::new); - } - - public void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - getInstance(), - (blockEntity, context) -> new InvWrapper(blockEntity.getInventory()) - ); - } -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfigNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfigNeoForge.java new file mode 100644 index 00000000..6f5f98cf --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfigNeoForge.java @@ -0,0 +1,24 @@ +package org.cyclops.colossalchests.blockentity; + +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.items.wrapper.InvWrapper; +import org.cyclops.cyclopscore.init.ModBase; + +/** + * @author rubensworks + */ +public class BlockEntityUncolossalChestConfigNeoForge extends BlockEntityUncolossalChestConfig { + public BlockEntityUncolossalChestConfigNeoForge(M mod) { + super(mod); + mod.getModEventBus().addListener(this::registerCapabilities); + } + + public void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + getInstance(), + (blockEntity, context) -> new InvWrapper(blockEntity.getInventory()) + ); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRender.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRenderNeoForge.java similarity index 60% rename from loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRender.java rename to loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRenderNeoForge.java index 59467714..9d72a5da 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRender.java +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRenderNeoForge.java @@ -2,27 +2,24 @@ import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.core.BlockPos; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; -import org.cyclops.colossalchests.RegistryEntriesCommon; +import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; import org.cyclops.cyclopscore.client.render.blockentity.ItemStackBlockEntityRendererBase; /** * @author rubensworks */ -@OnlyIn(Dist.CLIENT) -public class ItemStackTileEntityUncolossalChestRender extends ItemStackBlockEntityRendererBase { +public class ItemStackTileEntityUncolossalChestRenderNeoForge extends ItemStackBlockEntityRendererBase { - public ItemStackTileEntityUncolossalChestRender() { - super(() -> new BlockEntityUncolossalChest(BlockPos.ZERO, RegistryEntriesCommon.BLOCK_UNCOLOSSAL_CHEST.value().defaultBlockState())); + public ItemStackTileEntityUncolossalChestRenderNeoForge() { + super(() -> new BlockEntityUncolossalChest(BlockPos.ZERO, RegistryEntries.BLOCK_UNCOLOSSAL_CHEST.value().defaultBlockState())); } public static class ClientItemExtensions implements IClientItemExtensions { @Override public BlockEntityWithoutLevelRenderer getCustomRenderer() { - return new ItemStackTileEntityUncolossalChestRender(); + return new ItemStackTileEntityUncolossalChestRenderNeoForge(); } } diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChestNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChestNeoForge.java new file mode 100644 index 00000000..ab956144 --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChestNeoForge.java @@ -0,0 +1,25 @@ +package org.cyclops.colossalchests.client.render.blockentity; + +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.core.Vec3i; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; + +/** + * @author rubensworks + */ +public class RenderTileEntityColossalChestNeoForge extends RenderTileEntityColossalChest { + public RenderTileEntityColossalChestNeoForge(BlockEntityRendererProvider.Context context) { + super(context); + } + + @Override + public AABB getRenderBoundingBox(BlockEntityColossalChest blockEntity) { + int size = blockEntity.getSizeSingular(); + return new AABB( + Vec3.atLowerCornerOf(blockEntity.getBlockPos().subtract(new Vec3i(size, size, size))), + Vec3.atLowerCornerOf(blockEntity.getBlockPos().offset(size, size * 2, size)) + ); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java deleted file mode 100644 index 64794d39..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.cyclops.colossalchests.inventory.container; - -import net.minecraft.client.gui.screens.MenuScreens; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.MenuAccess; -import net.minecraft.world.flag.FeatureFlags; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.client.gui.container.ContainerScreenColossalChest; -import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; -import org.cyclops.cyclopscore.config.extendedconfig.GuiConfig; -import org.cyclops.cyclopscore.inventory.container.ContainerTypeData; - -/** - * Config for {@link ContainerColossalChest}. - * @author rubensworks - */ -public class ContainerColossalChestConfig extends GuiConfig { - - public ContainerColossalChestConfig() { - super(ColossalChests._instance, - "colossal_chest", - eConfig -> new ContainerTypeData<>(ContainerColossalChest::new, FeatureFlags.VANILLA_SET)); - } - - @OnlyIn(Dist.CLIENT) - @Override - public > MenuScreens.ScreenConstructor getScreenFactory() { - return new ScreenFactorySafe<>(ContainerScreenColossalChest::new); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java deleted file mode 100644 index 0c833fd3..00000000 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.cyclops.colossalchests.inventory.container; - -import net.minecraft.client.gui.screens.inventory.MenuAccess; -import net.minecraft.client.gui.screens.MenuScreens; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.world.flag.FeatureFlags; -import net.minecraft.world.inventory.MenuType; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.client.gui.container.ContainerScreenUncolossalChest; -import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; -import org.cyclops.cyclopscore.config.extendedconfig.GuiConfig; - -/** - * Config for {@link ContainerUncolossalChest}. - * @author rubensworks - */ -public class ContainerUncolossalChestConfig extends GuiConfig { - - public ContainerUncolossalChestConfig() { - super(ColossalChests._instance, - "uncolossal_chest", - eConfig -> new MenuType<>(ContainerUncolossalChest::new, FeatureFlags.VANILLA_SET)); - } - - @OnlyIn(Dist.CLIENT) - @Override - public > MenuScreens.ScreenConstructor getScreenFactory() { - return new ScreenFactorySafe<>(ContainerScreenUncolossalChest::new); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/modcompat/CommonCapabilitiesModCompat.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/modcompat/CommonCapabilitiesModCompat.java index a8646b64..d311d1d1 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/modcompat/CommonCapabilitiesModCompat.java +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/modcompat/CommonCapabilitiesModCompat.java @@ -47,7 +47,7 @@ public ICompatInitializer createInitializer() { CapabilityConstructorRegistry registry = ColossalChests._instance.getCapabilityConstructorRegistry(); // Slotless item handler - registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST::get, + registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST::value, new ICapabilityConstructor>() { @Override public BaseCapability getCapability() { @@ -60,7 +60,7 @@ public ICapabilityProvider>() { @Override public BaseCapability getCapability() { @@ -81,7 +81,7 @@ public ICapabilityProvider>() { @Override public BaseCapability getCapability() { @@ -93,7 +93,7 @@ public ICapabilityProvider return (blockEntity, side) -> () -> ((SimpleInventory) blockEntity.getInventory()).getState(); } }); - registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_INTERFACE::get, + registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_INTERFACE::value, new ICapabilityConstructor>() { @Override public BaseCapability getCapability() { diff --git a/loader-neoforge/src/main/java/org/cyclops/colossalchests/proxy/CommonProxy.java b/loader-neoforge/src/main/java/org/cyclops/colossalchests/proxy/CommonProxy.java index e2801b27..43a6ce56 100644 --- a/loader-neoforge/src/main/java/org/cyclops/colossalchests/proxy/CommonProxy.java +++ b/loader-neoforge/src/main/java/org/cyclops/colossalchests/proxy/CommonProxy.java @@ -25,9 +25,9 @@ public void registerPacketHandlers(PacketHandler packetHandler) { super.registerPacketHandlers(packetHandler); // Register packets. - packetHandler.register(ClientboundContainerSetContentPacketWindow.TYPE, ClientboundContainerSetContentPacketWindow.CODEC); - packetHandler.register(ServerboundContainerClickPacketOverride.TYPE, ServerboundContainerClickPacketOverride.CODEC); - packetHandler.register(ClientboundContainerSetSlotPacketLarge.TYPE, ClientboundContainerSetSlotPacketLarge.CODEC); + packetHandler.register(ClientboundContainerSetContentPacketWindow.class, ClientboundContainerSetContentPacketWindow.TYPE, ClientboundContainerSetContentPacketWindow.CODEC); + packetHandler.register(ServerboundContainerClickPacketOverride.class, ServerboundContainerClickPacketOverride.TYPE, ServerboundContainerClickPacketOverride.CODEC); + packetHandler.register(ClientboundContainerSetSlotPacketLarge.class, ClientboundContainerSetSlotPacketLarge.TYPE, ClientboundContainerSetSlotPacketLarge.CODEC); } }