I need some help with my Mod. I want to copy the String-NBT-Data of a CommandBlock, the Command it contains in my case, and save it into a variable or at least just being able to get it. The Problem is, that the "Get NBT Text Tag <tag> of Block at <x> <y-1> <z> if it has TileEntity"-Block
return (new Object() {
public String getValue(IWorld world, BlockPos pos, String tag) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null)
return tileEntity.getTileData().getString(tag);
return "";
}
}.getValue(world, new BlockPos((int) x, (int) (y - 1), (int) z), "Command"));
does not work with its tag "Command". Is this just the wrong tag? The return-value is always empty in the end.
The tag "Command" isn't wrong, but you're fetching it from the wrong place. Assuming you're working with 1.16, you need to get the command blocks tile entity reference to the class CommandBlockLogic to get the proper output that you're looking for.
Rollback Post to RevisionRollBack
"You know you're joke is good when you have to explain it to everyone."
First of all, Thank you for helping me out, but does it mean that I just need to replace the TileEntity with the CommandBlockTileEntity and import the required .class? The way I did it is not working, it always fails at compiling the code... Do you know what this exactly means?
First of all, Thank you for helping me out, but does it mean that I just need to replace the TileEntity with the CommandBlockTileEntity and import the required .class? The way I did it is not working, it always fails at compiling the code... Do you know what this exactly means?
Thank you!
-BissNik
No. This does not mean you need to replace your TileEntity code, but instead run a check to make sure that it's a command block, then cast the TileEntity to a TileEntityCommandBlock after your check, then from there you're able to reference the CommandBlockLogic class using the method getCommandBlock. From there you can fetch the command I believe
Rollback Post to RevisionRollBack
"You know you're joke is good when you have to explain it to everyone."
Hello there!
I need some help with my Mod. I want to copy the String-NBT-Data of a CommandBlock, the Command it contains in my case, and save it into a variable or at least just being able to get it. The Problem is, that the "Get NBT Text Tag <tag> of Block at <x> <y-1> <z> if it has TileEntity"-Block
does not work with its tag "Command". Is this just the wrong tag? The return-value is always empty in the end.
Hope someone can help me out.
Best Wishes,
-BissNik
The tag "Command" isn't wrong, but you're fetching it from the wrong place. Assuming you're working with 1.16, you need to get the command blocks tile entity reference to the class CommandBlockLogic to get the proper output that you're looking for.
"You know you're joke is good when you have to explain it to everyone."
Hello,
First of all, Thank you for helping me out, but does it mean that I just need to replace the TileEntity with the CommandBlockTileEntity and import the required .class? The way I did it is not working, it always fails at compiling the code... Do you know what this exactly means?
Thank you!
-BissNik
Was that different in earlier Versions?
No. This does not mean you need to replace your TileEntity code, but instead run a check to make sure that it's a command block, then cast the TileEntity to a TileEntityCommandBlock after your check, then from there you're able to reference the CommandBlockLogic class using the method getCommandBlock. From there you can fetch the command I believe
"You know you're joke is good when you have to explain it to everyone."