Posted August 14, 20178 yr Half-Slabs that I've created move their positions from being half_slab_bottom to half_slab_top and I don't know why. *Note: There are no error messages in console when booting the game, placing the slabs, or opening the world. GitHub: https://github.com/NoEffort/Basic Video: https://www.youtube.com/watch?v=wh3eUJmlx-w Spoiler C:\ForgeModded\Basic\src\main\java\com\noeffort\basic\init\slab\CustomBlockSlab.java package com.noeffort.basic.init.blocks.slab; import com.noeffort.basic.init.BlockInit; import net.minecraft.block.BlockSlab; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import java.util.Random; public abstract class CustomBlockSlab extends BlockSlab { public CustomBlockSlab(String name, float hardness, float resistance) { super(Material.WOOD); setUnlocalizedName(name); setRegistryName(name); IBlockState state = this.blockState.getBaseState(); if(!this.isDouble()) { state = state.withProperty(HALF, EnumBlockHalf.BOTTOM); } setDefaultState(state); this.useNeighborBrightness = true; } @Override public String getUnlocalizedName(int meta) { return this.getUnlocalizedName(); } @Override public IProperty<?> getVariantProperty() { return HALF; } @Override public Comparable<?> getTypeForItem(ItemStack stack) { return EnumBlockHalf.BOTTOM; } @Override public int damageDropped(IBlockState state) { return 0; } @Override public IBlockState getStateFromMeta(int meta) { if(!this.isDouble()) { return this.getDefaultState().withProperty(HALF, EnumBlockHalf.values()[meta % EnumBlockHalf.values().length]); } return this.getDefaultState(); } @Override public int getMetaFromState(IBlockState state) { if(!this.isDouble()) { return 0; } return ((EnumBlockHalf)state.getValue(HALF)).ordinal() + 1; } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(BlockInit.strange_plank_slab_half); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {HALF}); } } Spoiler C:\ForgeModded\Basic\src\main\java\com\noeffort\basic\init\slab\CustomBlockHalfSlab.java package com.noeffort.basic.init.blocks.slab; import net.minecraft.block.SoundType; public class CustomBlockHalfSlab extends CustomBlockSlab { public CustomBlockHalfSlab(String name,float hardness, float resistance, SoundType sound) { super(name, hardness, resistance); setSoundType(sound); } @Override public boolean isDouble() { return false; } } Spoiler C:\ForgeModded\Basic\src\main\java\com\noeffort\basic\init\slab\CustomBlockDoubleSlab.java package com.noeffort.basic.init.blocks.slab; import net.minecraft.block.SoundType; public class CustomBlockDoubleSlab extends CustomBlockSlab { public CustomBlockDoubleSlab(String name, float hardness, float resistance, SoundType sound) { super(name, hardness, resistance); setSoundType(sound); } @Override public boolean isDouble() { return true; } } Spoiler C:\ForgeModded\Basic\src\main\java\com\noeffort\basic\init\BlockInit.java package com.noeffort.basic.init; import com.noeffort.basic.Basic; import com.noeffort.basic.init.blocks.CustomBlockStairs; import com.noeffort.basic.init.blocks.CustomGem; import com.noeffort.basic.init.blocks.CustomLog; import com.noeffort.basic.init.blocks.CustomOre; import com.noeffort.basic.init.blocks.CustomPlank; import com.noeffort.basic.init.blocks.slab.CustomBlockDoubleSlab; import com.noeffort.basic.init.blocks.slab.CustomBlockHalfSlab; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemSlab; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.common.registry.ForgeRegistries; public class BlockInit { public static Block strange_log; public static Block strange_plank; public static Block strange_ore; public static Block nether_strange_ore, end_strange_ore; public static Block strange_block; public static Block strange_plank_stairs; public static CustomBlockHalfSlab strange_plank_slab_half; public static CustomBlockDoubleSlab strange_plank_slab_double; public static void init() { strange_log = new CustomLog("strange_log", 1.0f, 2.0f, 1, SoundType.WOOD); strange_plank = new CustomPlank("strange_plank", 1.0f, 2.0f, 1, SoundType.WOOD); strange_ore = new CustomOre("strange_ore", 2.0f, 4.0f, 2, SoundType.STONE); strange_block = new CustomGem("strange_block", 3.2f, 5.0f, 2, SoundType.METAL); nether_strange_ore = new CustomOre("nether_strange_ore", 2.0f, 4.0f, 2, SoundType.STONE); end_strange_ore = new CustomOre("end_strange_ore", 2.5f, 4.5f, 2, SoundType.STONE); strange_plank_stairs = new CustomBlockStairs("strange_plank_stairs", strange_plank.getDefaultState(), SoundType.WOOD); strange_plank_slab_half = new CustomBlockHalfSlab("strange_plank_slab_half", 1.0f, 2.0f, SoundType.WOOD); strange_plank_slab_double = new CustomBlockDoubleSlab("strange_plank_slab_double", 1.0f, 2.0f, SoundType.WOOD); } public static void register() { registerBlock(strange_log); registerBlock(strange_plank); registerBlock(strange_ore); registerBlock(strange_block); registerBlock(nether_strange_ore); registerBlock(end_strange_ore); registerBlock(strange_plank_stairs); registerBlock(strange_plank_slab_half, new ItemSlab(strange_plank_slab_half, strange_plank_slab_half, strange_plank_slab_double)); ForgeRegistries.BLOCKS.register(strange_plank_slab_double); } public static void registerBlock(Block block) { ForgeRegistries.BLOCKS.register(block); block.setCreativeTab(Basic.basictab); ItemBlock item = new ItemBlock(block); item.setRegistryName(block.getRegistryName()); ForgeRegistries.ITEMS.register(item); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } public static void registerBlock(Block block, ItemBlock itemBlock) { ForgeRegistries.BLOCKS.register(block); block.setCreativeTab(Basic.basictab); itemBlock.setRegistryName(block.getRegistryName()); ForgeRegistries.ITEMS.register(itemBlock); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } } All help is appreciated! Edited August 14, 20178 yr by NoEffort +Added [SOLVED] tag
August 14, 20178 yr Set some break points and run in the debugger. You'll probably run into a place where you're setting a state to its default properties (forgot to append a withProperty? This method is suspicious: @Override public IBlockState getStateFromMeta(int meta) { if(!this.isDouble()) { return this.getDefaultState().withProperty(HALF, EnumBlockHalf.values()[meta % EnumBlockHalf.values().length]); } return this.getDefaultState(); } Why ignore meta and return default? The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
August 14, 20178 yr 5 hours ago, NoEffort said: @Override public int getMetaFromState(IBlockState state) { if(!this.isDouble()) { return 0; } return ((EnumBlockHalf)state.getValue(HALF)).ordinal() + 1; } In this method, you check whether your slab is not double - then if it is not double you don't store the half in metadata. Then in the corresponding read method you ignore the metadata if the slab is not double. Edited August 14, 20178 yr by Jay Avery
August 14, 20178 yr Author 2 hours ago, jeffryfisher said: Set some break points and run in the debugger. You'll probably run into a place where you're setting a state to its default properties (forgot to append a withProperty? This method is suspicious: @Override public IBlockState getStateFromMeta(int meta) { if(!this.isDouble()) { return this.getDefaultState().withProperty(HALF, EnumBlockHalf.values()[meta % EnumBlockHalf.values().length]); } return this.getDefaultState(); } Why ignore meta and return default? Because it worked in theory. Also, the game did crash when setting a breakpoint on this method. [ALSO] This method did not need to be changed in the end. 2 minutes ago, Jay Avery said: In this method, you check whether your slab is not double - then if it is not double you don't store the half in metadata. Keen eye, much obliged! I did not mean to call isDouble() with !
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.