Posted August 6, 20178 yr Hello, I'm kinda new to modding, and I'm trying to make a wrench that can cycle though every facing of a block. I came up with a way to do so for every vanilla block (by editing the game code via MCP, without forge), but I had some troubles with the new launcher and so I tried creating a forge mod. What I have now do work for every block in vanilla but I'm experiencing a very weird thing for all rails : it just flaches to it's next possible facing and then back to it's previous state. Also every rail that I place faces the north_south direction, I can't place them to the east/west. My code doesn't change the way rails behave and no other block do the flash thing, I tried multiple ways of doing it and it is the only thing that happen. My code : public EnumActionResult onItemUse(EntityPlayer stack, World playerIn, BlockPos worldIn, EnumHand pos, EnumFacing hand, float facing, float hitX, float hitY) { ItemStack itemstack = stack.getHeldItem(pos); if (!stack.canPlayerEdit(worldIn.offset(hand), hand, itemstack)) { return EnumActionResult.FAIL; } else { IBlockState iblockstate = playerIn.getBlockState(worldIn); iblockstate = rotateState(iblockstate, iblockstate.getBlock(), playerIn, worldIn); if (playerIn.getBlockState(worldIn) != iblockstate) { setBlock(itemstack, stack, playerIn, worldIn, iblockstate); System.out.println("Rotation with wrench succeded!"); return EnumActionResult.SUCCESS; } else { System.out.println("Rotation with wrench failed!"); return EnumActionResult.FAIL; } } } public IBlockState rotateState(IBlockState iblockstate, Block block, World world, BlockPos blockPos) { if (!(block instanceof BlockRailBase) && !(block instanceof BlockLever)) { // rotating other blocks ... } else if (block instanceof BlockRailBase) { // here I am using the 'withRotation' method, but 'cycleProperty' outputs the same thing Rotation[] arotation = Rotation.values(); Rotation rotate = arotation[1]; System.out.println("old state :" + iblockstate); iblockstate = block.withRotation(iblockstate, rotate); System.out.println("new state :" + iblockstate); return iblockstate; } else { // rotating a lever... } // by default: return iblockstate; } protected void setBlock(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state) { worldIn.playSound(player, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, 1.0F); if (!worldIn.isRemote || true) // always true to have both Client and Server feedback on screen, else the rail stays the same on screen and doesn't flash to it's next facing and back again { System.out.println("Set Block result : " + worldIn.setBlockState(pos, state, 11)); if (MathHelper.getInt(worldIn.rand, 0, 4) == 0) { stack.damageItem(1, player); // 1 in 4 chance to damage the wrench. } } } The output on this when is right click a rail is : old state :minecraft:rail[shape=north_south] new state :minecraft:rail[shape=east_west] Set Block result : true Rotation with wrench succeded! On screen, the rail rotates but imediatly after it changes back to how it was before. Since this code works on vanilla but not on forge, is it a problem from forge or in my code ?
August 6, 20178 yr Corner rails connect up with nearby rail blocks automatically. If there's two possible orientations, then one is default and the other is only possible when the block is receiving power. These two effects are likely overriding your attempted change. By the way, if you want to know if a block has a given property: if(state.getProperties().containsKey(....)) Edited August 6, 20178 yr by Draco18s 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.
August 6, 20178 yr Author Thanks for the answer and for the tip. The thing is that this code works outside of forge, and even a rail which isn't connected to another rail on any side doesn't change. Here is 3 gifs of what is happening : - vanilla coding (no forge) -> what should be happening : http://gph.is/2ueCnHY - forge version : http://gph.is/2vCXDdX - edited forge version (changes both server and client) : http://gph.is/2ue6nUu What I think is happening is that forge sends a block update when I change the state of the rail. But how can I stop that ?
August 6, 20178 yr 21 minutes ago, Azathoth YS said: What I think is happening is that forge sends a block update when I change the state of the rail. But how can I stop that ? This line: worldIn.setBlockState(pos, state, 11)); That last number is a flag. One of the flags (either 1 or 2, I forget which) is responsible for notifying neighbors. You'll want to remove that flag. 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.
August 6, 20178 yr Author I tried changing the flag from 0 to 11 and none of them worked (also removing the flag sets it to 3). The problem doesn't seems to be the block update, as in my MCP-modified game, the rail do updates (flag 11). I also tried to delete the block and setting it again with the different state, but that also doesn't work. Even rotating a rail which doesn't have any neighbors doesn't work. I really don't know what else I can try.
August 6, 20178 yr Flag 0 won't do what you want either as one of the flags "sends the change to the client to be rerendered." 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.
August 6, 20178 yr Author I didn't explained what I did very well : I tried all flags from 0 up to 11, and none of them chaged anything.
August 6, 20178 yr I don't know then. 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.
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.