Jump to content

1.15.2 Help Updating BooleanProperty on server


kpGamer

Recommended Posts

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;
    }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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;
    }
}

Link to comment
Share on other sites

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 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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So, I try to make a katana, with katana and scabbard, is that possible to make 2 different models to be on player while he holding item? Katana in hands, and scabbard at belt. 
    • I created a server with the Pixelmon mod, it's fine and everything but a person enters and the server closes, I don't know how to explain it very well but I attach the detailed file of the error that happens to me https://mclo.gs/eSemvtq This error had not happened to me until now, so I don't understand very well why this happens, could you help me solve it?
    • When I create the server and log in it lets me play, but a person ends up joining and it sends me an error and the server closes The report says Exception in server tick Loop I put here what the console tells me because I honestly don't know how to explain it: https://mclo.gs/eSemvtq I use Forge mods and this has not happened to me until now 
    • Sorry I wasn't on this site for a few days. But anyways, if you just simply want to install forge to play with mods, you need to click on the installer option, thqat way, forge will be automatically installed to your device at the version you chose. Then you could just open Minecraft launcher to play on that version.
    • I've been putting together a modpack for a few weeks, and it's worked just fine. Until today, I logged onto my survival world and went exploring. As soon as I entered my boat the game froze and crashed. Now when I try to start the world, nothing loads and the game crashes. I tried creating a new world and the same thing happened when I tried to use a boat. Here's the latest crash report from the original world: If anyone knows how to fix the issue, I'd really appreciate the help, thanks.
  • Topics

×
×
  • Create New...

Important Information

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