Fix the Obsidian chest rendering as a gold chest, and fix the chest models crashing clients running on servers.

This commit is contained in:
Alexander Behrhof 2021-07-28 22:21:43 -04:00
parent db2540c968
commit c56c0d1942
9 changed files with 49 additions and 84 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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<IronChestBlock> IRON_CHEST = register(
"iron_chest", () -> new IronChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getIronChestItemStackRenderer());
IronChestsTypes.IRON);
public static final RegistryObject<GoldChestBlock> GOLD_CHEST = register(
"gold_chest", () -> new GoldChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getGoldChestItemStackRenderer());
IronChestsTypes.GOLD);
public static final RegistryObject<DiamondChestBlock> DIAMOND_CHEST = register(
"diamond_chest", () -> new DiamondChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getDiamondChestItemStackRenderer());
IronChestsTypes.DIAMOND);
public static final RegistryObject<CopperChestBlock> COPPER_CHEST = register(
"copper_chest", () -> new CopperChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getCopperChestItemStackRenderer());
IronChestsTypes.COPPER);
public static final RegistryObject<SilverChestBlock> SILVER_CHEST = register(
"silver_chest", () -> new SilverChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getSilverChestItemStackRenderer());
IronChestsTypes.SILVER);
public static final RegistryObject<CrystalChestBlock> CRYSTAL_CHEST = register(
"crystal_chest", () -> new CrystalChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getCrystalChestItemStackRenderer());
IronChestsTypes.CRYSTAL);
public static final RegistryObject<ObsidianChestBlock> OBSIDIAN_CHEST = register(
"obsidian_chest", () -> new ObsidianChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getObsidianChestItemStackRenderer());
IronChestsTypes.OBSIDIAN);
public static final RegistryObject<DirtChestBlock> DIRT_CHEST = register(
"dirt_chest", () -> new DirtChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getDirtChestItemStackRenderer());
IronChestsTypes.DIRT);
//HELPERS
private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Supplier<Callable<BlockEntityWithoutLevelRenderer>> renderMethod) {
return register(name, sup, block -> item(block, renderMethod));
private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, IronChestsTypes chestType) {
return register(name, sup, block -> item(block, () -> () -> chestType));
}
private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Function<RegistryObject<T>, Supplier<? extends Item>> itemCreator) {
@ -82,47 +68,7 @@ public class IronChestsBlocks {
return BLOCKS.register(name, sup);
}
private static Supplier<BlockItem> item(final RegistryObject<? extends Block> block, final Supplier<Callable<BlockEntityWithoutLevelRenderer>> renderMethod) {
return () -> new IronChestBlockItem(block.get(), new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP), renderMethod);
}
@OnlyIn(Dist.CLIENT)
public static Callable<BlockEntityWithoutLevelRenderer> 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<BlockEntityWithoutLevelRenderer> 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<BlockEntityWithoutLevelRenderer> 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<BlockEntityWithoutLevelRenderer> 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<BlockEntityWithoutLevelRenderer> 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<BlockEntityWithoutLevelRenderer> 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<BlockEntityWithoutLevelRenderer> 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<BlockEntityWithoutLevelRenderer> getDirtChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new DirtChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIRT_CHEST.get().defaultBlockState()));
private static Supplier<BlockItem> item(final RegistryObject<? extends Block> block, Supplier<Callable<IronChestsTypes>> chestType) {
return () -> new IronChestBlockItem(block.get(), new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP), chestType);
}
}

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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<BlockEntityWithoutLevelRenderer> itemRenderer;
protected Supplier<IronChestsTypes> type;
public IronChestBlockItem(Block block, Properties properties, Supplier<Callable<BlockEntityWithoutLevelRenderer>> itemRenderer) {
public IronChestBlockItem(Block block, Properties properties, Supplier<Callable<IronChestsTypes>> 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<BlockEntity> 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);
}
});
}