Posted April 29, 20205 yr Hello modders. I can't seem to update a boolean property on the server. I confirmed that I can update another property (enum type) for the same block. I also confirmed that I can update the block state object with the correct property before attempting to update the server. After I run setBlockState on the world object, the boolean property does not change, but the enum property does change. Can someone please tell me what I'm missing in the code below? // enum property public static final EnumProperty<RailShape> POWERSHAPE = EnumProperty.<RailShape>create("shape", RailShape.class, new Predicate<RailShape>() { public boolean apply(RailShape p_apply_1_) { return p_apply_1_ != RailShape.NORTH_EAST && p_apply_1_ != RailShape.NORTH_WEST && p_apply_1_ != RailShape.SOUTH_EAST && p_apply_1_ != RailShape.SOUTH_WEST; } }); // boolean property public static final BooleanProperty POWERED = BooleanProperty.create("powered"); @Override public ActionResultType onItemUse(ItemUseContext context) { // get context World worldIn = context.getWorld(); BlockPos pos = context.getPos(); PlayerEntity player = context.getPlayer(); if(!worldIn.isRemote) { if (worldIn.getBlockState(pos).getBlock().getRegistryName().toString().equals("minecraft:powered_rail")){ BlockState blockState = worldIn.getBlockState(pos); TestMod.LOGGER.debug("** Properties:"); TestMod.LOGGER.debug(" old POWERED: " + blockState.get(POWERED)); TestMod.LOGGER.debug(" old POWERSHAPE: " + blockState.get(POWERSHAPE)); blockState = blockState.with(POWERED, true).with(POWERSHAPE, RailShape.NORTH_SOUTH); worldIn.getWorld().setBlockState(pos, blockState); worldIn.notifyBlockUpdate(pos, blockState, blockState, 3); // check for the update blockState = worldIn.getWorld().getBlockState(pos); // Enum property is updated (POWERSHAPE), but bolean property (POWERED) was not TestMod.LOGGER.debug(" new block state POWERED: " + blockState.get(POWERED)); TestMod.LOGGER.debug(" new block state POWERSHAPE: " + blockState.get(POWERSHAPE)); } return ActionResultType.PASS; }
April 29, 20205 yr Show more of your code. Is this a subclass of powered rail? If so, the parent class is probably resetting it based on the neighboring blocks not providing power. 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.
April 29, 20205 yr Author @Draco18s thanks for the quick response. I posted more code below. It is not a subclass of powered rail. It is an a separate item that extends Item. public class TestModItem extends Item { // shape of a powered rail, which cannot turn public static final EnumProperty<RailShape> POWERSHAPE = EnumProperty.<RailShape>create("shape", RailShape.class, new Predicate<RailShape>() { public boolean apply(RailShape p_apply_1_) { return p_apply_1_ != RailShape.NORTH_EAST && p_apply_1_ != RailShape.NORTH_WEST && p_apply_1_ != RailShape.SOUTH_EAST && p_apply_1_ != RailShape.SOUTH_WEST; } }); // powered boolean property public static final BooleanProperty POWERED = BooleanProperty.create("powered"); public TestModItem() { super(new Item.Properties().group(ModItemGroups.TestMod_GROUP)); } @Override public ActionResultType onItemUse(ItemUseContext context) { // get context World worldIn = context.getWorld(); BlockPos pos = context.getPos(); PlayerEntity player = context.getPlayer(); if(!worldIn.isRemote) { if (worldIn.getBlockState(pos).getBlock().getRegistryName().toString().equals("minecraft:powered_rail")){ BlockState blockState = worldIn.getBlockState(pos); TestMod.LOGGER.debug("** Properties:"); TestMod.LOGGER.debug(" old POWERED: " + blockState.get(POWERED)); TestMod.LOGGER.debug(" old POWERSHAPE: " + blockState.get(POWERSHAPE)); blockState = blockState.with(POWERED, true).with(POWERSHAPE, RailShape.NORTH_SOUTH); worldIn.getWorld().setBlockState(pos, blockState); worldIn.notifyBlockUpdate(pos, blockState, blockState, 3); blockState = worldIn.getWorld().getBlockState(pos); TestMod.LOGGER.debug(" new block state POWERED: " + blockState.get(POWERED)); TestMod.LOGGER.debug(" new block state POWERSHAPE: " + blockState.get(POWERSHAPE)); } return ActionResultType.PASS; } }
April 29, 20205 yr 46 minutes ago, kpGamer said: if (worldIn.getBlockState(pos).getBlock().getRegistryName().toString().equals("minecraft:powered_rail")){ Ok, so, 1, just use Blocks.POWERED_RAIL. There is zero reason to use string comparison on registry names. Two, I was right. Powered rail will automatically update its own state based on the presence or absence of redstone power in the world. You can't "fool" it into having power when there is none. Edited April 29, 20205 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.
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.