mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Add support for custom WoodTypes (#7623)
This commit is contained in:
1 parent
f4fd1c2f16
commit
aacba8e38e
11 files changed
+189
No files matched your search
@@ -0,0 +1,14 @@
|
||||
--- a/net/minecraft/block/WoodType.java
|
||||
+++ b/net/minecraft/block/WoodType.java
|
||||
@@ -32,4 +_,11 @@
|
||||
public String func_227048_b_() {
|
||||
return this.field_227045_h_;
|
||||
}
|
||||
+
|
||||
+ /**
|
||||
+ * Use this to create a new {@link WoodType}. Make sure to register its rendering by enqueuing Atlases.addWoodType(...) during client setup..
|
||||
+ */
|
||||
+ public static WoodType create(String name) {
|
||||
+ return new WoodType(name);
|
||||
+ }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
--- a/net/minecraft/client/renderer/Atlases.java
|
||||
+++ b/net/minecraft/client/renderer/Atlases.java
|
||||
@@ -129,7 +_,8 @@
|
||||
}
|
||||
|
||||
public static RenderMaterial func_228773_a_(WoodType p_228773_0_) {
|
||||
- return new RenderMaterial(field_228746_e_, new ResourceLocation("entity/signs/" + p_228773_0_.func_227048_b_()));
|
||||
+ ResourceLocation location = new ResourceLocation(p_228773_0_.func_227048_b_());
|
||||
+ return new RenderMaterial(field_228746_e_, new ResourceLocation(location.func_110624_b(), "entity/signs/" + location.func_110623_a()));
|
||||
}
|
||||
|
||||
private static RenderMaterial func_228774_a_(String p_228774_0_) {
|
||||
@@ -156,5 +_,12 @@
|
||||
default:
|
||||
return p_228772_1_;
|
||||
}
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Not threadsafe. Enqueue it in client setup.
|
||||
+ */
|
||||
+ public static void addWoodType(WoodType woodType) {
|
||||
+ field_228750_i_.put(woodType, func_228773_a_(woodType));
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/client/renderer/tileentity/SignTileEntityRenderer.java
|
||||
+++ b/net/minecraft/client/renderer/tileentity/SignTileEntityRenderer.java
|
||||
@@ -89,7 +_,7 @@
|
||||
woodtype = WoodType.field_227038_a_;
|
||||
}
|
||||
|
||||
- return Atlases.func_228773_a_(woodtype);
|
||||
+ return Atlases.field_228750_i_.get(woodtype);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@@ -164,6 +164,7 @@ public class ForgeHooksClient
|
||||
StartupMessageManager.mcLoaderConsumer().ifPresent(c->c.accept("Atlas Stitching : "+map.location().toString()));
|
||||
ModLoader.get().postEvent(new TextureStitchEvent.Pre(map, resourceLocations));
|
||||
// ModelLoader.White.INSTANCE.register(map); // TODO Custom TAS
|
||||
Atlases.SIGN_MATERIALS.values().forEach(material -> resourceLocations.add(material.texture()));
|
||||
}
|
||||
|
||||
public static void onTextureStitchedPost(AtlasTexture map)
|
||||
|
||||
@@ -93,6 +93,7 @@ public net.minecraft.block.WitherSkeletonWallSkullBlock <init>(Lnet/minecraft/bl
|
||||
public net.minecraft.block.WoodButtonBlock <init>(Lnet/minecraft/block/AbstractBlock$Properties;)V
|
||||
#endgroup
|
||||
public net.minecraft.block.Block func_180637_b(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/util/math/BlockPos;I)V # dropXpOnBlockBreak
|
||||
public net.minecraft.block.WoodType func_227047_a_(Lnet/minecraft/block/WoodType;)Lnet/minecraft/block/WoodType; # register
|
||||
public net.minecraft.block.FireBlock func_220274_q(Lnet/minecraft/block/BlockState;)I # func_220274_q
|
||||
public net.minecraft.block.FireBlock func_220275_r(Lnet/minecraft/block/BlockState;)I # func_220275_r
|
||||
public-f net.minecraft.client.GameSettings field_74324_K # keyBindings
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.tileentity.SignTileEntityRenderer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.SignItem;
|
||||
import net.minecraft.tileentity.SignTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@Mod(CustomSignsTest.MODID)
|
||||
public class CustomSignsTest
|
||||
{
|
||||
public static final boolean ENABLE = true;
|
||||
public static final String MODID = "custom_signs_test";
|
||||
|
||||
public static final WoodType TEST_WOOD_TYPE = WoodType.create(new ResourceLocation(MODID, "test").toString());
|
||||
|
||||
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
|
||||
public static final RegistryObject<CustomStandingSignBlock> TEST_STANDING_SIGN = BLOCKS.register("test_sign", () -> new CustomStandingSignBlock(Block.Properties.of(Material.WOOD).noCollission().strength(1.0F).sound(SoundType.WOOD), CustomSignsTest.TEST_WOOD_TYPE));
|
||||
public static final RegistryObject<CustomWallSignBlock> TEST_WALL_SIGN = BLOCKS.register("test_wall_sign", () -> new CustomWallSignBlock(Block.Properties.of(Material.WOOD).noCollission().strength(1.0F).sound(SoundType.WOOD), CustomSignsTest.TEST_WOOD_TYPE));
|
||||
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
public static final RegistryObject<SignItem> TEST_SIGN = ITEMS.register("test_sign", () -> new SignItem((new Item.Properties()).stacksTo(16).tab(ItemGroup.TAB_DECORATIONS), TEST_STANDING_SIGN.get(), TEST_WALL_SIGN.get()));
|
||||
|
||||
private static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, MODID);
|
||||
public static final RegistryObject<TileEntityType<CustomSignTileEntity>> CUSTOM_SIGN = TILE_ENTITIES.register("custom_sign", () -> TileEntityType.Builder.of(CustomSignTileEntity::new, TEST_WALL_SIGN.get(), TEST_STANDING_SIGN.get()).build(null));
|
||||
|
||||
public CustomSignsTest()
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
final IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
BLOCKS.register(eventBus);
|
||||
ITEMS.register(eventBus);
|
||||
TILE_ENTITIES.register(eventBus);
|
||||
|
||||
eventBus.addListener(this::clientSetup);
|
||||
eventBus.addListener(this::commonSetup);
|
||||
}
|
||||
}
|
||||
|
||||
private void clientSetup(final FMLClientSetupEvent event)
|
||||
{
|
||||
ClientRegistry.bindTileEntityRenderer(CUSTOM_SIGN.get(), SignTileEntityRenderer::new);
|
||||
event.enqueueWork(() -> {
|
||||
Atlases.addWoodType(TEST_WOOD_TYPE);
|
||||
});
|
||||
}
|
||||
|
||||
private void commonSetup(final FMLCommonSetupEvent event)
|
||||
{
|
||||
event.enqueueWork(() -> WoodType.register(TEST_WOOD_TYPE));
|
||||
}
|
||||
|
||||
public static class CustomStandingSignBlock extends StandingSignBlock
|
||||
{
|
||||
|
||||
public CustomStandingSignBlock(Properties propertiesIn, WoodType woodTypeIn)
|
||||
{
|
||||
super(propertiesIn, woodTypeIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState stateIn)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newBlockEntity(IBlockReader worldIn)
|
||||
{
|
||||
return new CustomSignTileEntity();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomWallSignBlock extends WallSignBlock
|
||||
{
|
||||
|
||||
public CustomWallSignBlock(Properties propertiesIn, WoodType woodTypeIn)
|
||||
{
|
||||
super(propertiesIn, woodTypeIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState stateIn)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newBlockEntity(IBlockReader worldIn)
|
||||
{
|
||||
return new CustomSignTileEntity();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomSignTileEntity extends SignTileEntity
|
||||
{
|
||||
@Override
|
||||
public TileEntityType<CustomSignTileEntity> getType()
|
||||
{
|
||||
return CUSTOM_SIGN.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,8 @@ license="LGPL v2.1"
|
||||
modId="custom_sound_type_test"
|
||||
[[mods]]
|
||||
modId="item_modifier_test"
|
||||
[[mods]]
|
||||
modId="custom_signs_test"
|
||||
[[mods]]
|
||||
modId="shader_fix_test"
|
||||
[[mods]]
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"variants": {
|
||||
"": { "model": "custom_signs_test:block/test_sign" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"variants": {
|
||||
"": { "model": "custom_signs_test:block/test_sign" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"textures": {
|
||||
"particle": "minecraft:block/oak_planks"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Reference in new issue
Block a user