I need some java code to make my block emit redstone

Started by aidanete on Mon, 02/08/2021 - 13:48

Topic category: Advanced modding

Last seen on 20:28, 10. Mar 2021
Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I need some java code to make my block emit redstone
Mon, 02/08/2021 - 13:48

Yes, I actually know that is impossible to do it in normal way, so I'll get direct to the point.

I need some java code that makes my normal MCreator generated block emit redstone, and if possible an easy way on changing the power emitted without having big knowledge about java and so. (Maybe with NBT tags or something?)

What I have to change or modify on the code? That's what I'm asking. I know a bit of programming, but not much of Java and yes, I tried to find my own way to do it or in the forums, but nothing, so help will be appreciated :D

 

Last seen on 20:28, 10. Mar 2021
Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Still needing help
Wed, 02/10/2021 - 11:46

Still needing help

I am not 100% sure if anyone…
Thu, 02/11/2021 - 18:19

I am not 100% sure if anyone here has ready-made code at this moment, including me, this is probably the reason for lack of reply so far

Last seen on 20:28, 10. Mar 2021
Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Well, no problem, but if…
Sat, 02/13/2021 - 13:32

Well, no problem, but if anyone knows a bit of java and has enough time, probably trying that and finding a good solution to share with all the community would be great :D

Last seen on 10:21, 14. Apr 2021
Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
The way to make a block emit…
Sat, 02/13/2021 - 17:31

The way to make a block emit redstone is:

   public boolean canProvidePower(BlockState state) {
      return true;
   }
It's power level is this:

public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
      return 15;
   }

 

Put this in your block class and you will have a block that emits redstone power.

I'll experiment and try to find you a way to change the power based on NBT.

Last seen on 10:21, 14. Apr 2021
Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I've found a solution. First…
Sat, 02/13/2021 - 20:44

I've found a solution.

First make the block a tile entity.

Make a procedure that gives the block a number NBT data. You can call it "MODpowerLevel" or anything else you choose.

Then put this code in your block class:

public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
            TileEntity _tileEntity = world.getTileEntity(pos);
            if(_tileEntity != null){
                int _powerLevel = _tileEntity.getTileData().getInt("MODpowerLevel");
            }
            
            return _powerLevel;

The usual power level is a number from 0 to 15; 15 being the amount of blocks powered by a redstone block.

If you change the name of the nbt number data you will have to change the name in the code.

int _powerLevel = _tileEntity.getTileData().getInt("MODpowerLevel"); <- Change MODpowerLevel to your custom name if you want.

Last seen on 20:28, 10. Mar 2021
Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Thanks nwn That looks like…
Sun, 02/14/2021 - 16:59

Thanks nwn

That looks like might work but I can't get the world of the block, that was one of the issues I was getting trying to code it by myself. I think if I achieve to get the world of the block in there it may work.

So, if somebody knows actually how to get it, say it here.

 

Thanks all :D

Last seen on 10:21, 14. Apr 2021
Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I think if the code is in…
Sun, 02/14/2021 - 17:34

I think if the code is in the CustomTileEntity() the world is already provided. You can always use this.getWorld() though.

Last seen on 20:28, 10. Mar 2021
Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Yeah, I added it there but…
Wed, 02/17/2021 - 11:18

Yeah, I added it there but it just doesn't work so I need to search further.

 

Thanks anyways :D