mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
[1.18] Make it easier to register custom skull blocks models (#8351)
This commit is contained in:
1 parent
e1ad29edd0
commit
b0a64ff8ac
8 files changed
+213
No files matched your search
+10
@@ -0,0 +1,10 @@
|
||||
--- a/net/minecraft/client/renderer/blockentity/SkullBlockRenderer.java
|
||||
+++ b/net/minecraft/client/renderer/blockentity/SkullBlockRenderer.java
|
||||
@@ -52,6 +_,7 @@
|
||||
builder.put(SkullBlock.Types.ZOMBIE, new SkullModel(p_173662_.m_171103_(ModelLayers.f_171224_)));
|
||||
builder.put(SkullBlock.Types.CREEPER, new SkullModel(p_173662_.m_171103_(ModelLayers.f_171130_)));
|
||||
builder.put(SkullBlock.Types.DRAGON, new DragonHeadModel(p_173662_.m_171103_(ModelLayers.f_171135_)));
|
||||
+ net.minecraftforge.fml.ModLoader.get().postEvent(new net.minecraftforge.client.event.EntityRenderersEvent.CreateSkullModels(builder, p_173662_));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.EntityModel;
|
||||
import net.minecraft.client.model.SkullModelBase;
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
@@ -20,6 +22,8 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.SkullBlock;
|
||||
import net.minecraft.world.level.block.SkullBlock.Type;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
@@ -130,4 +134,36 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
return entityModels;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a safe place to register models for the skull block
|
||||
*/
|
||||
public static class CreateSkullModels extends EntityRenderersEvent
|
||||
{
|
||||
private final ImmutableMap.Builder<Type,SkullModelBase> builder;
|
||||
private final EntityModelSet entityModelSet;
|
||||
|
||||
public CreateSkullModels(ImmutableMap.Builder<Type,SkullModelBase> builder, EntityModelSet entityModelSet)
|
||||
{
|
||||
this.builder = builder;
|
||||
this.entityModelSet = entityModelSet;
|
||||
}
|
||||
|
||||
public EntityModelSet getEntityModelSet()
|
||||
{
|
||||
return entityModelSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the constructor for a skull block with the given {@link SkullBlock.Type}.
|
||||
* These will be inserted into the maps used by the item, entity, and block model renderers at the appropiate time.
|
||||
*
|
||||
* @param type Unique skull type. Will cause an exception if multiple mods (including vanilla) register models for the same type
|
||||
* @param model Model instance. A typical implementation will simply do {@code new SkullModel(entityModelSet.bakeLayer(layerLocation))}
|
||||
*/
|
||||
public void registerSkullModel(SkullBlock.Type type, SkullModelBase model)
|
||||
{
|
||||
builder.put(type, model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,7 @@ public net.minecraft.client.renderer.block.model.ItemTransforms$Deserializer <in
|
||||
public net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher f_112253_ # fontRenderer - needed for rendering text in TESR items before entering world
|
||||
public net.minecraft.client.renderer.blockentity.BlockEntityRenderers m_173590_(Lnet/minecraft/world/level/block/entity/BlockEntityType;Lnet/minecraft/client/renderer/blockentity/BlockEntityRendererProvider;)V # register
|
||||
private-f net.minecraft.client.renderer.blockentity.PistonHeadRenderer f_112441_ # blockRenderer - it's static so we need to un-finalize in case this class loads to early.
|
||||
public net.minecraft.client.renderer.blockentity.SkullBlockRenderer f_112519_ # SKIN_BY_TYPE
|
||||
public net.minecraft.client.renderer.entity.EntityRenderDispatcher f_114362_ # renderers
|
||||
public net.minecraft.client.renderer.entity.EntityRenderers m_174036_(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/client/renderer/entity/EntityRendererProvider;)V # register
|
||||
protected net.minecraft.client.renderer.entity.ItemEntityRenderer m_115042_(Lnet/minecraft/world/item/ItemStack;)I # getRenderAmount
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Minecraft Forge - Forge Development LLC
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.client.model.SkullModel;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.SkullBlockRenderer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.StandingAndWallBlockItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SkullBlock;
|
||||
import net.minecraft.world.level.block.WallSkullBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.common.ForgeConfig.Client;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.Lazy;
|
||||
import net.minecraftforge.debug.block.CustomSignsTest.CustomSignBlockEntity;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
/**
|
||||
* Adds a blaze head block and item to test the event for registering a custom skull model and to demonstrate the proper way to register a custom mob skull.
|
||||
*
|
||||
* To test it, locate "blaze_head", and test the item model, the model in the players head slot, the model in an armor stand, the wall block model, and the floor block model.
|
||||
* Should appear identical in shape to vanilla heads such as zombies or skeletons, but use the blaze skin.
|
||||
*/
|
||||
@Mod(CustomHeadTest.MODID)
|
||||
public class CustomHeadTest
|
||||
{
|
||||
static final String MODID = "custom_head_test";
|
||||
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, MODID);
|
||||
private static final RegistryObject<Block> BLAZE_HEAD = BLOCKS.register("blaze_head", () -> new CustomSkullBlock(SkullType.BLAZE, BlockBehaviour.Properties.of(Material.DECORATION).strength(1.0F)));
|
||||
private static final RegistryObject<Block> BLAZE_HEAD_WALL = BLOCKS.register("blaze_wall_head", () -> new CustomWallSkullBlock(SkullType.BLAZE, BlockBehaviour.Properties.of(Material.DECORATION).strength(1.0F).lootFrom(BLAZE_HEAD)));
|
||||
private static final RegistryObject<Item> BLAZE_HEAD_ITEM = ITEMS.register("blaze_head", () -> new StandingAndWallBlockItem(BLAZE_HEAD.get(), BLAZE_HEAD_WALL.get(), new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS).rarity(Rarity.UNCOMMON)));
|
||||
private static final RegistryObject<BlockEntityType<CustomSkullBlockEntity>> CUSTOM_SKULL = BLOCK_ENTITIES.register("custom_skull", () -> BlockEntityType.Builder.of(CustomSkullBlockEntity::new, BLAZE_HEAD.get(), BLAZE_HEAD_WALL.get()).build(null));
|
||||
|
||||
public CustomHeadTest()
|
||||
{
|
||||
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
BLOCKS.register(modBus);
|
||||
ITEMS.register(modBus);
|
||||
BLOCK_ENTITIES.register(modBus);
|
||||
}
|
||||
|
||||
private static class CustomSkullBlock extends SkullBlock
|
||||
{
|
||||
public CustomSkullBlock(Type type, Properties props)
|
||||
{
|
||||
super(type, props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
return new CustomSkullBlockEntity(pos, state);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CustomWallSkullBlock extends WallSkullBlock
|
||||
{
|
||||
public CustomWallSkullBlock(SkullBlock.Type type, Properties props)
|
||||
{
|
||||
super(type, props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
return new CustomSkullBlockEntity(pos, state);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CustomSkullBlockEntity extends SkullBlockEntity
|
||||
{
|
||||
public CustomSkullBlockEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<?> getType()
|
||||
{
|
||||
return CUSTOM_SKULL.get();
|
||||
}
|
||||
}
|
||||
|
||||
private enum SkullType implements SkullBlock.Type
|
||||
{
|
||||
BLAZE
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(value= Dist.CLIENT, bus = Bus.MOD, modid = MODID)
|
||||
private static class ClientEvents
|
||||
{
|
||||
static final ModelLayerLocation BLAZE_HEAD_LAYER = new ModelLayerLocation(BLAZE_HEAD.getId(), "main");
|
||||
|
||||
@SubscribeEvent
|
||||
static void registerLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event)
|
||||
{
|
||||
event.registerLayerDefinition(BLAZE_HEAD_LAYER, Lazy.of(SkullModel::createMobHeadLayer));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
static void registerLayerDefinitions(EntityRenderersEvent.RegisterRenderers event)
|
||||
{
|
||||
event.registerBlockEntityRenderer(CUSTOM_SKULL.get(), SkullBlockRenderer::new);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
static void clientSetupEvent(FMLClientSetupEvent event)
|
||||
{
|
||||
event.enqueueWork(() -> SkullBlockRenderer.SKIN_BY_TYPE.put(SkullType.BLAZE, new ResourceLocation("textures/entity/blaze.png")));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
static void registerSkullModel(EntityRenderersEvent.CreateSkullModels event)
|
||||
{
|
||||
event.registerSkullModel(SkullType.BLAZE, new SkullModel(event.getEntityModelSet().bakeLayer(ClientEvents.BLAZE_HEAD_LAYER)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,8 @@ license="LGPL v2.1"
|
||||
modId="create_entity_classification_test"
|
||||
[[mods]]
|
||||
modId="ender_mask_test"
|
||||
[[mods]]
|
||||
modId="custom_head_test"
|
||||
[[mods]]
|
||||
modId="raid_enum_test"
|
||||
[[mods]]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "minecraft:block/skull"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "minecraft:block/skull"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"parent": "minecraft:item/template_skull"
|
||||
}
|
||||
Reference in new issue
Block a user