Jump to content

kpGamer

Members
  • Posts

    2
  • Joined

  • Last visited

kpGamer's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. @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; } }
  2. 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; }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.