Posted November 26, 20168 yr How do I make a block with metadata and how do I have that block make a new block with metadata? For an example I want to have a block and that block will get an input, north, for example and then create a new block in the north direction. Then it would send that metadata of north to the next block. In the end it would make a line of blocks going north. I don't optimize my code before it works.
November 26, 20168 yr http://mcforge.readthedocs.io/en/latest/blockstates/states/ 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.
November 26, 20168 yr Hi If you want the line of blocks to spread itself slowly, you could use BLock.updateTick() with worldIn.scheduleUpdate(); Look in BlockFire.updateTick() for more clues - the fire spreads itself in a very similar way to what you want. -TGG
November 26, 20168 yr Important caveat (something I just ran into): Vanilla Minecraft won't process updates for blocks with material AIR (it explicitly tests for them and aborts processing). So if you're spreading something like smoke (some variation of air), then scheduled (and random tick) updates will be ignored 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.
November 28, 20168 yr Author I've tried to read the minecraft forge documentation for block states but it's such a mess I can't make any sense out of it. Could someone help me with the actual code? Help is greatly appriciated. I don't optimize my code before it works.
November 28, 20168 yr I've tried to read the minecraft forge documentation for block states but it's such a mess I can't make any sense out of it. Could someone help me with the actual code? Help is greatly appriciated. Blockstates are created when you apply a property to them in this case you will want to use PropertyInteger. Code wise you will need to override getMetaFromState(IBlockState), getStateFromMeta(int meta), and createBlockState(). For an example look at BlockFurnace, BlockWool, BlockPiston. Those all have BlockStates although I don't think any use PropertyInteger, but they are applied the same way. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
November 28, 20168 yr BlockCrops and BlockReeds both use integers. By the way, be aware of the BlockEvent.CropGrowEvent and its two sub events. You should fire these at the appropriate times if you are not using subclassing a class that does, or not calling super.updateTick(). Look at BlockCrops, Reeds, Cactus, Netherwart, CocoPods, and a couple others for examples of useage. 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.
November 28, 20168 yr BlockCrops and BlockReeds both use integers. By the way, be aware of the BlockEvent.CropGrowEvent and its two sub events. You should fire these at the appropriate times if you are not using subclassing a class that does, or not calling super.updateTick(). Look at BlockCrops, Reeds, Cactus, Netherwart, CocoPods, and a couple others for examples of useage. Good point lol, I always forget that those use BlockStates...., but he isn't making a crop so he shouldn't have to worry about that event. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
November 28, 20168 yr Good point lol, I always forget that those use BlockStates...., but he isn't making a crop so he shouldn't have to worry about that event. One of his other threads is about is. 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.
November 28, 20168 yr Author The winner is Animefan8888. I am not making crops. I don't optimize my code before it works.
November 28, 20168 yr I am not making crops. Hmm, thought one of your other threads was....never mind 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.
November 29, 20168 yr Author Okay so I've tried a few things and I can't get blockstates to work for me. The premise of this block is ...I want to have a block and that block will get an input, north, for example and then create a new block in the north direction. Then it would send that metadata of north to the next block. In the end it would make a line of blocks going north. I wrote out my code and it doesn't work. Could someone tell me how to operate this code? The block state code was originally from net.minecraft.block.BlockCrops.class. package TestMod.tutorial.block; import java.util.Random; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class OrangeGoo extends BlockBase{ public static final PropertyInteger SDIR = PropertyInteger.create("sdir", 0, 6); public OrangeGoo(String name){ super(Material.ROCK, name); setTickRandomly(true); setHardness(0.1f); setResistance(1f); } //metadata protected PropertyInteger getSDirProperty(){return SDIR;} protected int getSDir(IBlockState state){return (state.getValue(this.getSDirProperty()));} public IBlockState withSDir(int sdir){return this.getDefaultState().withProperty(this.getSDirProperty(), sdir);} @Override public IBlockState getStateFromMeta(int meta){return this.withSDir(meta);} @Override public int getMetaFromState(IBlockState state){return this.getSDir(state);} @Override protected BlockStateContainer createBlockState(){return new BlockStateContainer(this, new IProperty[] {SDIR});} //creative tab @Override public OrangeGoo setCreativeTab(CreativeTabs tab){ super.setCreativeTab(tab); return this; } int direction; //spreading block public void blockSpread(World world, IBlockState state, BlockPos posNumber, BlockPos inversePos,int direction,int j){ if(world.getBlockState(inversePos).getBlock() == ModBlocks.greengoo && world.getBlockState(posNumber).getBlock() != ModBlocks.redgoo){ if(j==direction){ world.setBlockState(posNumber, ModBlocks.orangegoo.getDefaultState()); world.setBlockState(posNumber, state.withProperty(SDIR, direction), 6); // Alternative - (SDIR, Integer.valueOf(direction)), 6); } } } @Override public void updateTick(World world, BlockPos pos, IBlockState state, Random rand){ int j = (state.getValue(SDIR)); BlockPos pos0 = new BlockPos((pos.getX()), (pos.getY()) , pos.getZ()); BlockPos xplus = new BlockPos((pos.getX()+1), (pos.getY()) , pos.getZ());//1 BlockPos xminus = new BlockPos((pos.getX()-1), (pos.getY()) , pos.getZ());//2 BlockPos yplus = new BlockPos((pos.getX()), (pos.getY()+1) , pos.getZ());//3 BlockPos yminus = new BlockPos((pos.getX()), (pos.getY()-1) , pos.getZ());//4 BlockPos zplus = new BlockPos((pos.getX()), (pos.getY()) , pos.getZ()+1);//5 BlockPos zminus = new BlockPos((pos.getX()), (pos.getY()) , pos.getZ()-1);//6 blockSpread(world, state, xplus, xminus,1,j); blockSpread(world, state, xminus, xplus,2,j); blockSpread(world, state, yplus, yminus,3,j); blockSpread(world, state, yminus, yplus,4,j); blockSpread(world, state, zplus, zminus,5,j); blockSpread(world, state, zminus, zplus,6,j); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY){ int j = (state.getValue(SDIR)); BlockPos pos0 = new BlockPos((pos.getX()), (pos.getY()) , pos.getZ()); BlockPos xplus = new BlockPos((pos.getX()+1), (pos.getY()) , pos.getZ());//1 BlockPos xminus = new BlockPos((pos.getX()-1), (pos.getY()) , pos.getZ());//2 BlockPos yplus = new BlockPos((pos.getX()), (pos.getY()+1) , pos.getZ());//3 BlockPos yminus = new BlockPos((pos.getX()), (pos.getY()-1) , pos.getZ());//4 BlockPos zplus = new BlockPos((pos.getX()), (pos.getY()) , pos.getZ()+1);//5 BlockPos zminus = new BlockPos((pos.getX()), (pos.getY()) , pos.getZ()-1);//6 blockSpread(world, state, xplus, xminus,1,j); blockSpread(world, state, xminus, xplus,2,j); blockSpread(world, state, yplus, yminus,3,j); blockSpread(world, state, yminus, yplus,4,j); blockSpread(world, state, zplus, zminus,5,j); blockSpread(world, state, zminus, zplus,6,j); return false;} } I don't optimize my code before it works.
November 29, 20168 yr #1 your formatting in a couple of places is awful. #2 you do not need a getter method for your static property #3 why are you using an integer to represent direction? Why not use BlockDirectional.FACING? #4 why are you setting the block twice? world.setBlockState(posNumber, ModBlocks.orangegoo.getDefaultState()); world.setBlockState(posNumber, state.withProperty(SDIR, direction), 6); You should only need the second line, but why are you using flags 2,4 and not 1,2? #5 your updateTick method is garbage. EnumFacing.values and pos.offset(facing) exist, not to mention EnumFacing#getOpposite(). 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.
November 29, 20168 yr Author #1 I forgot to mention that my code was a mess. #2 I copied it from the vanilla MC code. #3 I didn't know much of it or how to use it. #4 I didn't know if I had to place the block before setting the data and didn't realize that the second line would also place the block. #5 Didn't know that those were things, once again, my code is awful and I want it to work before I optimize it. Thanks for the help I don't optimize my code before it works.
November 29, 20168 yr Author #1 The previous reply still didn't answer how to use block states. I know my code is messy and the block placement works for now. I just need to no how to use the block states to do what I want it to do. #2 Also how do I code it in so the block has the same textures in game for each block state. Right now I'm getting the error texture when it's placed but the actual texture when in hand. I don't optimize my code before it works.
November 29, 20168 yr #1 The previous reply still didn't answer how to use block states. I know my code is messy and the block placement works for now. I just need to no how to use the block states to do what I want it to do. IBlockState state = someBlock.getDefaultState().withProperty(FACING,EnumFacing.WEST).withProperty(SomeOtherProp, Value); world.setBlockState(pos, state, 3); #2 Also how do I code it in so the block has the same textures in game for each block state. Right now I'm getting the error texture when it's placed but the actual texture when in hand. That's up to your blockstate.json file. 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.
November 29, 20168 yr For the spreading you can also do this: @Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if(worldIn.isRemote) return; // Spread BlockPos blockpos = pos.offset(EnumFacing.NORTH); IBlockState blockState = worldIn.getBlockState(blockpos); // If your Block should only grow on Stone. For example. if(blockState.getBlock() == Blocks.STONE) { int newState = state.getValue(SDIR) + 1 > 6 ? 6 : state.getValue(SDIR) + 1; worldIn.setBlockState(blockpos, this.getDefaultState().withProperty(SDIR, newState)); } } } And I hope this solve your block texture problem: { "forge_marker": 1, "defaults": { "model": "cube_all", "textures": { "all": "modid:blocks/example_block" }, "transform": "forge:default-block" }, "variants": { "sdir": { "0" : {}, "1" : {}, "2" : {}, "3" : {}, "4" : {}, "5" : {}, "6" : {} }, "inventory":[{}] } } I don't if just writing this instead the property name is enough. The code above works for me. "variants": { "normal":[{}], "inventory":[{}] }
November 29, 20168 yr Are UP and DOWN valid directions for your spreading? If not, then you want to use the BlockHorizontal extension of BlockDirectional. It limits its property to the four compass points, and they're separately indexed 0..3. 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.
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.