From c56c0d19429f5f9098cbd56e870f8c2bf54e423f Mon Sep 17 00:00:00 2001 From: Alexander Behrhof Date: Wed, 28 Jul 2021 22:21:43 -0400 Subject: [PATCH] Fix the Obsidian chest rendering as a gold chest, and fix the chest models crashing clients running on servers. --- gradle.properties | 4 +- .../common/ai/CatsSitOnChestsHandler.java | 1 - .../common/block/CrystalChestBlock.java | 1 - .../common/block/IronChestBlock.java | 1 - .../common/block/IronChestsBlocks.java | 78 +++---------------- .../common/block/ObsidianChestBlock.java | 2 +- .../entity/AbstractIronChestBlockEntity.java | 3 - .../common/item/ChestUpgradeItem.java | 3 - .../common/item/IronChestBlockItem.java | 40 ++++++++-- 9 files changed, 49 insertions(+), 84 deletions(-) diff --git a/gradle.properties b/gradle.properties index 66a95f9..62e1f66 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,8 +12,8 @@ minecraft_range=[1.17.1,1.18) # Forge Version Information loader_range=[33.0,) -forge_version=37.0.12 -forge_range=[37.0.1,) +forge_version=37.0.13 +forge_range=[37.0.13,) # Mappings Information mappings_version=1.17.1 diff --git a/src/main/java/com/progwml6/ironchest/common/ai/CatsSitOnChestsHandler.java b/src/main/java/com/progwml6/ironchest/common/ai/CatsSitOnChestsHandler.java index b6d7963..71a40ac 100644 --- a/src/main/java/com/progwml6/ironchest/common/ai/CatsSitOnChestsHandler.java +++ b/src/main/java/com/progwml6/ironchest/common/ai/CatsSitOnChestsHandler.java @@ -4,7 +4,6 @@ import com.progwml6.ironchest.IronChests; import net.minecraft.world.entity.ai.goal.CatSitOnBlockGoal; import net.minecraft.world.entity.ai.goal.WrappedGoal; import net.minecraft.world.entity.animal.Cat; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; diff --git a/src/main/java/com/progwml6/ironchest/common/block/CrystalChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/CrystalChestBlock.java index b1b6a8b..1352c37 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/CrystalChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/CrystalChestBlock.java @@ -3,7 +3,6 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.entity.AbstractIronChestBlockEntity; import com.progwml6.ironchest.common.block.entity.CrystalChestBlockEntity; import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes; -import com.progwml6.ironchest.common.block.entity.SilverChestBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; diff --git a/src/main/java/com/progwml6/ironchest/common/block/IronChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/IronChestBlock.java index 7c254c9..2abfe1c 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/IronChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/IronChestBlock.java @@ -7,7 +7,6 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import javax.annotation.Nullable; -import java.util.function.Supplier; public class IronChestBlock extends AbstractIronChestBlock { diff --git a/src/main/java/com/progwml6/ironchest/common/block/IronChestsBlocks.java b/src/main/java/com/progwml6/ironchest/common/block/IronChestsBlocks.java index eafa11a..8eb5b53 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/IronChestsBlocks.java +++ b/src/main/java/com/progwml6/ironchest/common/block/IronChestsBlocks.java @@ -1,26 +1,12 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.IronChests; -import com.progwml6.ironchest.client.model.inventory.IronChestItemStackRenderer; -import com.progwml6.ironchest.common.block.entity.CopperChestBlockEntity; -import com.progwml6.ironchest.common.block.entity.CrystalChestBlockEntity; -import com.progwml6.ironchest.common.block.entity.DiamondChestBlockEntity; -import com.progwml6.ironchest.common.block.entity.DirtChestBlockEntity; -import com.progwml6.ironchest.common.block.entity.GoldChestBlockEntity; -import com.progwml6.ironchest.common.block.entity.IronChestBlockEntity; -import com.progwml6.ironchest.common.block.entity.ObsidianChestBlockEntity; -import com.progwml6.ironchest.common.block.entity.SilverChestBlockEntity; import com.progwml6.ironchest.common.item.IronChestBlockItem; import com.progwml6.ironchest.common.item.IronChestsItems; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; -import net.minecraft.core.BlockPos; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.material.Material; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fmllegacy.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; @@ -36,40 +22,40 @@ public class IronChestsBlocks { public static final RegistryObject IRON_CHEST = register( "iron_chest", () -> new IronChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), - () -> getIronChestItemStackRenderer()); + IronChestsTypes.IRON); public static final RegistryObject GOLD_CHEST = register( "gold_chest", () -> new GoldChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), - () -> getGoldChestItemStackRenderer()); + IronChestsTypes.GOLD); public static final RegistryObject DIAMOND_CHEST = register( "diamond_chest", () -> new DiamondChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), - () -> getDiamondChestItemStackRenderer()); + IronChestsTypes.DIAMOND); public static final RegistryObject COPPER_CHEST = register( "copper_chest", () -> new CopperChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), - () -> getCopperChestItemStackRenderer()); + IronChestsTypes.COPPER); public static final RegistryObject SILVER_CHEST = register( "silver_chest", () -> new SilverChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), - () -> getSilverChestItemStackRenderer()); + IronChestsTypes.SILVER); public static final RegistryObject CRYSTAL_CHEST = register( "crystal_chest", () -> new CrystalChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), - () -> getCrystalChestItemStackRenderer()); + IronChestsTypes.CRYSTAL); public static final RegistryObject OBSIDIAN_CHEST = register( "obsidian_chest", () -> new ObsidianChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), - () -> getObsidianChestItemStackRenderer()); + IronChestsTypes.OBSIDIAN); public static final RegistryObject DIRT_CHEST = register( "dirt_chest", () -> new DirtChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), - () -> getDirtChestItemStackRenderer()); + IronChestsTypes.DIRT); //HELPERS - private static RegistryObject register(String name, Supplier sup, Supplier> renderMethod) { - return register(name, sup, block -> item(block, renderMethod)); + private static RegistryObject register(String name, Supplier sup, IronChestsTypes chestType) { + return register(name, sup, block -> item(block, () -> () -> chestType)); } private static RegistryObject register(String name, Supplier sup, Function, Supplier> itemCreator) { @@ -82,47 +68,7 @@ public class IronChestsBlocks { return BLOCKS.register(name, sup); } - private static Supplier item(final RegistryObject block, final Supplier> renderMethod) { - return () -> new IronChestBlockItem(block.get(), new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP), renderMethod); - } - - @OnlyIn(Dist.CLIENT) - public static Callable getIronChestItemStackRenderer() { - return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new IronChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.IRON_CHEST.get().defaultBlockState())); - } - - @OnlyIn(Dist.CLIENT) - public static Callable getGoldChestItemStackRenderer() { - return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new GoldChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.GOLD_CHEST.get().defaultBlockState())); - } - - @OnlyIn(Dist.CLIENT) - public static Callable getDiamondChestItemStackRenderer() { - return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new DiamondChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIAMOND_CHEST.get().defaultBlockState())); - } - - @OnlyIn(Dist.CLIENT) - public static Callable getCopperChestItemStackRenderer() { - return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new CopperChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.COPPER_CHEST.get().defaultBlockState())); - } - - @OnlyIn(Dist.CLIENT) - public static Callable getSilverChestItemStackRenderer() { - return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new SilverChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.SILVER_CHEST.get().defaultBlockState())); - } - - @OnlyIn(Dist.CLIENT) - public static Callable getCrystalChestItemStackRenderer() { - return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new CrystalChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.CRYSTAL_CHEST.get().defaultBlockState())); - } - - @OnlyIn(Dist.CLIENT) - public static Callable getObsidianChestItemStackRenderer() { - return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new ObsidianChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.OBSIDIAN_CHEST.get().defaultBlockState())); - } - - @OnlyIn(Dist.CLIENT) - public static Callable getDirtChestItemStackRenderer() { - return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new DirtChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIRT_CHEST.get().defaultBlockState())); + private static Supplier item(final RegistryObject block, Supplier> chestType) { + return () -> new IronChestBlockItem(block.get(), new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP), chestType); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/ObsidianChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/ObsidianChestBlock.java index 95cffbd..4f49393 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/ObsidianChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/ObsidianChestBlock.java @@ -12,7 +12,7 @@ import javax.annotation.Nullable; public class ObsidianChestBlock extends AbstractIronChestBlock { public ObsidianChestBlock(BlockBehaviour.Properties properties) { - super(properties, IronChestsBlockEntityTypes.GOLD_CHEST::get, IronChestsTypes.GOLD); + super(properties, IronChestsBlockEntityTypes.OBSIDIAN_CHEST::get, IronChestsTypes.OBSIDIAN); } @Nullable diff --git a/src/main/java/com/progwml6/ironchest/common/block/entity/AbstractIronChestBlockEntity.java b/src/main/java/com/progwml6/ironchest/common/block/entity/AbstractIronChestBlockEntity.java index fad16f5..0c89127 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/entity/AbstractIronChestBlockEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/entity/AbstractIronChestBlockEntity.java @@ -16,10 +16,7 @@ import net.minecraft.world.CompoundContainer; import net.minecraft.world.Container; import net.minecraft.world.ContainerHelper; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.ChestMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; diff --git a/src/main/java/com/progwml6/ironchest/common/item/ChestUpgradeItem.java b/src/main/java/com/progwml6/ironchest/common/item/ChestUpgradeItem.java index f6b2d59..125b130 100644 --- a/src/main/java/com/progwml6/ironchest/common/item/ChestUpgradeItem.java +++ b/src/main/java/com/progwml6/ironchest/common/item/ChestUpgradeItem.java @@ -5,7 +5,6 @@ import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.entity.AbstractIronChestBlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.ChestBlock; -import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -19,8 +18,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.level.Level; -import java.util.List; - public class ChestUpgradeItem extends Item { private final IronChestsUpgradeType type; diff --git a/src/main/java/com/progwml6/ironchest/common/item/IronChestBlockItem.java b/src/main/java/com/progwml6/ironchest/common/item/IronChestBlockItem.java index 4c34953..cff3a57 100644 --- a/src/main/java/com/progwml6/ironchest/common/item/IronChestBlockItem.java +++ b/src/main/java/com/progwml6/ironchest/common/item/IronChestBlockItem.java @@ -1,10 +1,25 @@ package com.progwml6.ironchest.common.item; +import com.progwml6.ironchest.client.model.inventory.IronChestItemStackRenderer; +import com.progwml6.ironchest.common.block.IronChestsBlocks; +import com.progwml6.ironchest.common.block.IronChestsTypes; +import com.progwml6.ironchest.common.block.entity.CopperChestBlockEntity; +import com.progwml6.ironchest.common.block.entity.CrystalChestBlockEntity; +import com.progwml6.ironchest.common.block.entity.DiamondChestBlockEntity; +import com.progwml6.ironchest.common.block.entity.DirtChestBlockEntity; +import com.progwml6.ironchest.common.block.entity.GoldChestBlockEntity; +import com.progwml6.ironchest.common.block.entity.IronChestBlockEntity; +import com.progwml6.ironchest.common.block.entity.ObsidianChestBlockEntity; +import com.progwml6.ironchest.common.block.entity.SilverChestBlockEntity; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; +import net.minecraft.core.BlockPos; import net.minecraft.world.item.BlockItem; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.IItemRenderProperties; +import net.minecraftforge.fml.DistExecutor; import java.util.concurrent.Callable; import java.util.function.Consumer; @@ -12,13 +27,14 @@ import java.util.function.Supplier; public class IronChestBlockItem extends BlockItem { - protected Supplier itemRenderer; + protected Supplier type; - public IronChestBlockItem(Block block, Properties properties, Supplier> itemRenderer) { + public IronChestBlockItem(Block block, Properties properties, Supplier> type) { super(block, properties); - BlockEntityWithoutLevelRenderer tmp = net.minecraftforge.fml.DistExecutor.callWhenOn(Dist.CLIENT, itemRenderer); - this.itemRenderer = tmp == null ? null : () -> tmp; + IronChestsTypes tempType = DistExecutor.callWhenOn(Dist.CLIENT, type); + + this.type = tempType == null ? null : () -> tempType; } @Override @@ -28,8 +44,20 @@ public class IronChestBlockItem extends BlockItem { consumer.accept(new IItemRenderProperties() { @Override public BlockEntityWithoutLevelRenderer getItemStackRenderer() { - System.out.println(itemRenderer); - return itemRenderer.get(); + Supplier modelToUse; + + switch (type.get()) { + case GOLD -> modelToUse = () -> new GoldChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.GOLD_CHEST.get().defaultBlockState()); + case DIAMOND -> modelToUse = () -> new DiamondChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIAMOND_CHEST.get().defaultBlockState()); + case COPPER -> modelToUse = () -> new CopperChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.COPPER_CHEST.get().defaultBlockState()); + case SILVER -> modelToUse = () -> new SilverChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.SILVER_CHEST.get().defaultBlockState()); + case CRYSTAL -> modelToUse = () -> new CrystalChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.CRYSTAL_CHEST.get().defaultBlockState()); + case OBSIDIAN -> modelToUse = () -> new ObsidianChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.OBSIDIAN_CHEST.get().defaultBlockState()); + case DIRT -> modelToUse = () -> new DirtChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIRT_CHEST.get().defaultBlockState()); + default -> modelToUse = () -> new IronChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.IRON_CHEST.get().defaultBlockState()); + } + + return new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), modelToUse); } }); }