Cliff122 Posted March 10, 2016 Share Posted March 10, 2016 Hi! I wanted to add a few custom signs to my mod so I looked a little at the default code and tried to create them as I normally do. public static void init() { public static Block spruce_standing_sign; public static Block spruce_wall_sign; } public static void register() { spruce_standing_sign = new BlockStandingSign().setUnlocalizedName("spruce_standing_sign"); spruce_wall_sign = new BlockWallSign().setUnlocalizedName("spruce_wall_sign"); } Since the BlockStandingSign and BlockWallSign were public and I didn't need to change anything in them I didn't create my own blockclasses for them. The only thing I changed was ItemSign were I overrode the "onItemUse" method so it would place my custom sign. @Override public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (side == EnumFacing.DOWN) { return false; } else if (!worldIn.getBlockState(pos).getBlock().getMaterial().isSolid()) { return false; } else { pos = pos.offset(side); if (!playerIn.canPlayerEdit(pos, side, stack)) { return false; } else if (!Blocks.standing_sign.canPlaceBlockAt(worldIn, pos)) { return false; } else if (worldIn.isRemote) { return true; } else { if (side == EnumFacing.UP) { int i = MathHelper.floor_double((double)((playerIn.rotationYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15; worldIn.setBlockState(pos, SBMBlocks.spruce_standing_sign.getDefaultState().withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)), 3); } else { worldIn.setBlockState(pos, SBMBlocks.spruce_wall_sign.getDefaultState().withProperty(BlockWallSign.FACING, side), 3); } --stack.stackSize; TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntitySign && !ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack)) { playerIn.openEditSign((TileEntitySign)tileentity); } return true; } } } } This worked great on walls but when I tried to place a standing sign it had the right hitbox, was the right block according to F3 but it had no pole and wasn't rotated properly. Basically it was a floating wallsign. I cannot figure out what's wrong as I have not changed anything except the item which I have checked countless times. I'm a beginner though so it might just be some silly mistake I have missed. Oh and also, how would I go about adding a custom texture to it? Signs don't seem to have models. Quote Link to comment Share on other sites More sharing options...
Cliff122 Posted March 11, 2016 Author Share Posted March 11, 2016 Noone knows anything?? Quote Link to comment Share on other sites More sharing options...
Choonster Posted March 11, 2016 Share Posted March 11, 2016 Signs are rendered by TileEntitySignRenderer , this only renders a standing sign if the Block is Blocks.standing_sign . I suggest adapting the rendering code from this class into your own TESR that uses instanceof to check whether the sign is standing or not and uses your own texture. Use ClientRegistry.bindTileEntitySpecialRenderer from your client proxy to register the TESR . You'll need to create your own TileEntity class that extends TileEntitySign and Block classes that extend BlockWallSign / BlockStandingSign and override Block#createTileEntity(World, IBlockState) to create your TileEntity instead of TileEntitySign . Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
Cliff122 Posted March 11, 2016 Author Share Posted March 11, 2016 Signs are rendered by TileEntitySignRenderer , this only renders a standing sign if the Block is Blocks.standing_sign . I suggest adapting the rendering code from this class into your own TESR that uses instanceof to check whether the sign is standing or not and uses your own texture. Use ClientRegistry.bindTileEntitySpecialRenderer from your client proxy to register the TESR . You'll need to create your own TileEntity class that extends TileEntitySign and Block classes that extend BlockWallSign / BlockStandingSign and override Block#createTileEntity(World, IBlockState) to create your TileEntity instead of TileEntitySign . That seems to have done it, thanks! Now my only problem is that the particle effects from breaking the block are pink and black. Since the signs don't have a blockmodel I'm not sure how to change that. Quote Link to comment Share on other sites More sharing options...
Cliff122 Posted March 11, 2016 Author Share Posted March 11, 2016 Signs are rendered by TileEntitySignRenderer , this only renders a standing sign if the Block is Blocks.standing_sign . I suggest adapting the rendering code from this class into your own TESR that uses instanceof to check whether the sign is standing or not and uses your own texture. Use ClientRegistry.bindTileEntitySpecialRenderer from your client proxy to register the TESR . You'll need to create your own TileEntity class that extends TileEntitySign and Block classes that extend BlockWallSign / BlockStandingSign and override Block#createTileEntity(World, IBlockState) to create your TileEntity instead of TileEntitySign . That seems to have done it, thanks! Now my only problem is that the particle effects from breaking the block are pink and black. Since the signs don't have a blockmodel I'm not sure how to change that. I actually noticed right now that the text on the sign doesn't save when i exit the world, the log says: [19:18:04] [server thread/ERROR] [FML]: A TileEntity type nu.aksberg.sbm.tileentity.TileEntitySpruceSign has throw an exception trying to write state. It will not persist. Report this to the mod author java.lang.RuntimeException: class nu.aksberg.sbm.tileentity.TileEntitySpruceSign is missing a mapping! This is a bug! What's that all about? Quote Link to comment Share on other sites More sharing options...
Choonster Posted March 11, 2016 Share Posted March 11, 2016 That seems to have done it, thanks! Now my only problem is that the particle effects from breaking the block are pink and black. Since the signs don't have a blockmodel I'm not sure how to change that. It looks like Minecraft hardcodes the textures for its blocks that don't use a standard model (e.g. signs, liquids). You can probably create a dummy JSON model and specify its "particle" texture. You'll need a blockstates file that tells Minecraft to use the model (which won't actually be rendered) and an IStateMapper that ignores the state and always maps to the same variant of the blockstates file. I actually noticed right now that the text on the sign doesn't save when i exit the world, the log says: [19:18:04] [server thread/ERROR] [FML]: A TileEntity type nu.aksberg.sbm.tileentity.TileEntitySpruceSign has throw an exception trying to write state. It will not persist. Report this to the mod author java.lang.RuntimeException: class nu.aksberg.sbm.tileentity.TileEntitySpruceSign is missing a mapping! This is a bug! What's that all about? Every TileEntity you add must be registered using GameRegister.registerTileEntity . Make sure you include your mod ID in the TileEntity 's ID so you don't conflict with other mods. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
Cliff122 Posted March 11, 2016 Author Share Posted March 11, 2016 It looks like Minecraft hardcodes the textures for its blocks that don't use a standard model (e.g. signs, liquids). You can probably create a dummy JSON model and specify its "particle" texture. You'll need a blockstates file that tells Minecraft to use the model (which won't actually be rendered) and an IStateMapper that ignores the state and always maps to the same variant of the blockstates file. I have made a model file called spruce_sign.json: { "parent": "block/cube_all", "textures": { "particle": "blocks/planks_spruce" } } and a blockstate also called spruce_sign.json: { "variants": { "normal": { "model": "sbm:spruce_sign" } } } but I don't quite understand how to use IStateMapper . Could you explain in a little more detail? Quote Link to comment Share on other sites More sharing options...
Choonster Posted March 12, 2016 Share Posted March 12, 2016 but I don't quite understand how to use IStateMapper . Could you explain in a little more detail? Create an anonymous class that extends StateMapperBase and override the getModelResourceLocation method to return a ModelResourceLocation pointing to the variant in your blockstates file. In this case, use the ModelResourceLocation(String resourceName, String variant) constructor with "sbm:spruce_sign" as the resource name (i.e. assets/sbm/blockstates/spruce_sign.json) and "normal" as the variant. Call ModelLoader.setCustomStateMapper from your client proxy in preInit with your Block as the first argument and this anonymous class as the second argument. I do something similar for my fluid blocks here. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
Cliff122 Posted March 12, 2016 Author Share Posted March 12, 2016 but I don't quite understand how to use IStateMapper . Could you explain in a little more detail? Create an anonymous class that extends StateMapperBase and override the getModelResourceLocation method to return a ModelResourceLocation pointing to the variant in your blockstates file. In this case, use the ModelResourceLocation(String resourceName, String variant) constructor with "sbm:spruce_sign" as the resource name (i.e. assets/sbm/blockstates/spruce_sign.json) and "normal" as the variant. Call ModelLoader.setCustomStateMapper from your client proxy in preInit with your Block as the first argument and this anonymous class as the second argument. I do something similar for my fluid blocks here. Okay, everything seems to work now! Thanks a bunch for all the help, I wouldn't have been able to do this without it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.