Started by
aidanete
on
Topic category: Advanced modding
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
Still needing help
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
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
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.
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.
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
I think if the code is in the CustomTileEntity() the world is already provided. You can always use this.getWorld() though.
Yeah, I added it there but it just doesn't work so I need to search further.
Thanks anyways :D