Jump to content

[1.16.x] Creating an item that powers redstone stuff without overriding blocks


NorthWestWind

Recommended Posts

I want to make an item that when the user holds it, it powers a redstone wire or piston under the player (which means 2 blocks under).

Here is my approach in LivingUpdateEvent when the player have the item:

    Vector3d pos = entity.getPositionVec();
    BlockPos blockPos = new BlockPos(pos);
    BlockState state = entity.world.getBlockState(blockPos);
    BlockState understate = entity.world.getBlockState(blockPos.down());
    if (state.func_235901_b_(BlockStateProperties.POWERED)) entity.world.setBlockState(blockPos, state.with(BlockStateProperties.POWERED, true), 3);
    if (understate.func_235901_b_(BlockStateProperties.POWERED)) entity.world.setBlockState(blockPos, understate.with(BlockStateProperties.POWERED, true), 3);
    if (state.func_235901_b_(BlockStateProperties.POWER_0_15)) entity.world.setBlockState(blockPos, state.with(BlockStateProperties.POWER_0_15, 15), 3);
    if (understate.func_235901_b_(BlockStateProperties.POWER_0_15)) entity.world.setBlockState(blockPos, understate.with(BlockStateProperties.POWER_0_15, 15), 3);
    if (state.func_235901_b_(BlockStateProperties.LIT)) entity.world.setBlockState(blockPos, state.with(BlockStateProperties.LIT, true), 3);
    if (understate.func_235901_b_(BlockStateProperties.LIT)) entity.world.setBlockState(blockPos, understate.with(BlockStateProperties.LIT, true), 3);
    if (state.func_235901_b_(BlockStateProperties.EXTENDED)) entity.world.setBlockState(blockPos, state.with(BlockStateProperties.EXTENDED, true), 3);
    if (understate.func_235901_b_(BlockStateProperties.EXTENDED)) entity.world.setBlockState(blockPos, understate.with(BlockStateProperties.EXTENDED, true), 3);

And it is just very buggy.

Link to comment
Share on other sites

1 hour ago, NorthWestWind said:

And it is just very buggy.

Yes, because the power is coming from nowhere. As soon as you change the blockstate the game makes all the adjacent blocks check whether they should still be powered (etc) and find that no, they shouldn't be, and then the block you fiddled with sees that one of the other blocks updated its state to not be powered and turns off again.

 

Realistically you'll never get this to work the way you want it to.

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

4 hours ago, NorthWestWind said:

Well that's bad.

 

Now that I think about it, maybe I should add a block that constantly emit redstone signal when the player is having the item near it.

Would it work?

 

you could have an invisible and uncolidable block that's placed on the players feet whenever they're holding the item, I think this is asolve to the original problem.

Link to comment
Share on other sites

On 2/6/2021 at 12:01 AM, kiou.23 said:

you could have an invisible and uncolidable block that's placed on the players feet whenever they're holding the item, I think this is asolve to the original problem.

Except for all the situations where that space isn't air.
Oh and wouldn't supply power in the desired location.

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.

Announcements



×
×
  • Create New...

Important Information

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