Posted January 26, 20187 yr Hello! I recently added the propertyDirection tag to my block "Drill". No errors are shown in the console or FML log, but the block for some reason doesn't follow the direction it should be placed in. (Minecraft Forge 1.10.2 in Eclipse) Block (BlockDrill.java) package archieab.andustry.blocks; import java.util.List; import archieab.andustry.Reference; import archieab.andustry.blocks.item.IMetaBlockName; import archieab.andustry.handlers.EnumHandler.MacTypes; import net.minecraft.block.Block; import net.minecraft.block.BlockPistonBase; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; public class BlockDrill extends Block implements IMetaBlockName { public static final PropertyEnum TYPE = PropertyEnum.create("type", MacTypes.class); public static final PropertyDirection FACING = PropertyDirection.create("facing"); public BlockDrill(String unlocalizedName) { super(Material.IRON); this.setUnlocalizedName(unlocalizedName); this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName)); this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, MacTypes.BASIC).withProperty(FACING, EnumFacing.NORTH)); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {TYPE,FACING}); } @Override public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return super.onBlockPlaced(worldIn, pos, BlockPistonBase.getFacingFromEntity(pos, placer), hitX, hitY, hitZ, meta, placer); } @Override public int getMetaFromState(IBlockState state) { MacTypes type = (MacTypes) state.getValue(TYPE); return type.getID(); } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(TYPE, MacTypes.values()[meta]); } @Override public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { for(int i = 0; i < MacTypes.values().length; i++) { list.add(new ItemStack(itemIn, 1, i)); } } @Override public String getSpecialName(ItemStack stack) { return MacTypes.values()[stack.getItemDamage()].getName(); } @Override public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos))); } @Override public int damageDropped(IBlockState state) { return getMetaFromState(state); } } Blockstate json (drill.json) { "variants": { "facing=north,type=basic": { "model": "and:block_drill_basic" }, "facing=south,type=basic": { "model": "and:block_drill_basic", "y": 180 }, "facing=east,type=basic": { "model": "and:block_drill_basic", "y": 90 }, "facing=west,type=basic": { "model": "and:block_drill_basic", "y": 270 }, "facing=up,type=basic": { "model": "and:block_drill_basic", "x": 270 }, "facing=down,type=basic": { "model": "and:block_drill_basic", "y": 90 }, "facing=north,type=advanced": { "model": "and:block_drill_advanced" }, "facing=south,type=advanced": { "model": "and:block_drill_advanced", "y": 180 }, "facing=east,type=advanced": { "model": "and:block_drill_advanced", "y": 90 }, "facing=west,type=advanced": { "model": "and:block_drill_advanced", "y": 270 }, "facing=up,type=advanced": { "model": "and:block_drill_advanced", "x": 270 }, "facing=down,type=advanced": { "model": "and:block_drill_advanced", "y": 90 } } } Basic drill model (block_drill_basic.json) { "parent": "block/cube", "textures": { "particle": "and:blocks/block_drill_basic_front", "north": "and:blocks/block_drill_basic_front", "south": "and:blocks/machine_frame_basic", "east": "and:blocks/machine_frame_basic", "west": "and:blocks/machine_frame_basic", "up": "and:blocks/block_drill_basic_top", "down": "and:blocks/machine_frame_basic" } } Advanced drill model (block_drill_advanced.json) Quote { "parent": "block/cube", "textures": { "particle": "and:blocks/block_drill_advanced_front", "north": "and:blocks/block_drill_advanced_front", "south": "and:blocks/machine_frame_advanced", "east": "and:blocks/machine_frame_advanced", "west": "and:blocks/machine_frame_advanced", "up": "and:blocks/block_drill_advanced_top", "down": "and:blocks/machine_frame_advanced" } } Basic drill item model (block_drill_basic.json) { "parent": "and:block/block_drill_basic" } Advanced drill item model (block_drill_advanced.json) { "parent": "and:block/block_drill_advanced" } Any help would be greatly appreciated. Edited January 26, 20187 yr by diesieben07 syntax highlighting
January 26, 20187 yr 11 minutes ago, archieab said: @Override public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return super.onBlockPlaced(worldIn, pos, BlockPistonBase.getFacingFromEntity(pos, placer), hitX, hitY, hitZ, meta, placer); } @Override public int getMetaFromState(IBlockState state) { MacTypes type = (MacTypes) state.getValue(TYPE); return type.getID(); } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(TYPE, MacTypes.values()[meta]); } Your getMetaFromState and getStateFromMeta don't deal with the FACING property at all. Your onBlockPlaced method does fuckall. As I said in your other thread: 14 minutes ago, Draco18s said: ...a single method that you overrode in order to do....nothing. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 26, 20187 yr Author 9 minutes ago, Draco18s said: Your getMetaFromState and getStateFromMeta don't deal with the FACING property at all. Your onBlockPlaced method does fuckall. As I said in your other thread: The tutorial I’m following must be incorrect. Could you suggest a way to decide the block’s direction?
January 26, 20187 yr Are there vanilla blocks that do this? How do they do it? Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 26, 20187 yr 14 minutes ago, diesieben07 said: Not it doesn't. Look closely. Ah, you're right. I saw the super call (with a base class of Block, which generally doesn't do much), but I didn't see that it called BlockPistonBase.getFacingFromEntity. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 26, 20187 yr Author Could you elaborate on what I need to do now? (I have a fairly amateur knowledge of Java)
January 26, 20187 yr Author Thank you very much (both of you) for the support and I will get back to you tomorrow.
January 27, 20187 yr Author 9 hours ago, diesieben07 said: In the methods mentioned above you need to not only encode the TYPE property, but also the FACING property. I've now updated my block's .java file. package archieab.andustry.blocks; import java.util.List; import archieab.andustry.Reference; import archieab.andustry.blocks.item.IMetaBlockName; import archieab.andustry.handlers.EnumHandler.MacTypes; import net.minecraft.block.Block; import net.minecraft.block.BlockPistonBase; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; public class BlockDrill extends Block implements IMetaBlockName { public static final PropertyEnum TYPE = PropertyEnum.create("type", MacTypes.class); public static final PropertyDirection FACING = PropertyDirection.create("facing"); public BlockDrill(String unlocalizedName) { super(Material.IRON); this.setUnlocalizedName(unlocalizedName); this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName)); this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, MacTypes.BASIC).withProperty(FACING, EnumFacing.NORTH)); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {TYPE,FACING}); } @Override public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { return this.getDefaultState().withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer)) .withProperty(TYPE, getStateFromMeta(meta * EnumFacing.values().length).getValue(TYPE)); } @Override public int getMetaFromState(IBlockState state) { MacTypes type = (MacTypes) state.getValue(TYPE); EnumFacing facing = (EnumFacing) state.getValue(FACING); int meta = type.getID() * EnumFacing.values().length + facing.ordinal(); return meta; } @Override public IBlockState getStateFromMeta(int meta) { MacTypes type = MacTypes.values()[(int)(meta / EnumFacing.values().length) % MacTypes.values().length]; EnumFacing facing = EnumFacing.values()[meta % EnumFacing.values().length]; return this.getDefaultState().withProperty(TYPE, type).withProperty(FACING, facing); } @Override public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { for(int i = 0; i < MacTypes.values().length; i++) { list.add(new ItemStack(itemIn, 1, i)); } } @Override public String getSpecialName(ItemStack stack) { return MacTypes.values()[stack.getItemDamage()].getName(); } @Override public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos))); } @Override public int damageDropped(IBlockState state) { return getMetaFromState(state); } } Now, for some reason, my EnumFacing.getDirectionFromEntityLiving is throwing an error "The method getDirectionFromEntityLiving(BlockPos, EntityLivingBase) is undefined for the type EnumFacing". Here is my EnumHandler, if it helps with troubleshooting: package archieab.andustry.handlers; import net.minecraft.util.IStringSerializable; public class EnumHandler { public static enum MacTypes implements IStringSerializable { BASIC("basic", 0), ADVANCED("advanced", 1); private int ID; private String name; private MacTypes(String name, int ID) { this.ID = ID; this.name = name; } @Override public String getName() { return this.name; } public int getID() { return ID; } @Override public String toString() { return getName(); } } } Additionally, my block will now always place with the facing tag "=up". Any help would be appreciated!
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.