Posted August 12, 20196 yr Hi I'm trying to do a TileEntity on one of my blocks which is only supposed to store a single value and then, later on, attach a TileEntityRenderer to display that value (and of course do stuff depending on that value). I've created the TileEntityType without any errors in the log, added the override functions in my block class, but whenever I try and get the data it crashes on a NullPointerException and doing exceptions such as creating a new one only results in it creating a new TileEntity. TreeTapTileEntity.java Spoiler public class TreeTapTileEntity extends TileEntity { private int volume = 0; public TreeTapTileEntity() { super(IntercraftTileEntities.TREETAP); } public CompoundNBT write(CompoundNBT compound) { compound.putInt("volume", this.volume); return compound; } public void read(CompoundNBT compound) { this.volume = compound.getInt("volume"); } } TreeTap.java Spoiler @Override public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { TileEntity tile = worldIn.getTileEntity(pos); System.out.println(tile.getTileData().getInt("volume")); } @Override public boolean hasTileEntity() { return true; } @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new TreeTapTileEntity(); } IntercraftTileEntites.java Spoiler public static final TileEntityType<TreeTapTileEntity> TREETAP; static { TREETAP = buildTE("treetap",TileEntityType.Builder.create(TreeTapTileEntity::new,IntercraftBlocks.TREETAP)); } private static TileEntityType buildTE(String registryName, TileEntityType.Builder builder) { TileEntityType type = builder.build(null); type.setRegistryName(Reference.MODID,registryName); return type; } Edited August 12, 20196 yr by Simon_kungen Title typo.
August 12, 20196 yr 44 minutes ago, Simon_kungen said: whenever I try and get the data it crashes on a NullPointerException Crashes doesnt post crash. What value is null? Is it the te or is it the tile data? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 12, 20196 yr Author 1 minute ago, Animefan8888 said: Crashes doesnt post crash. What value is null? Is it the te or is it the tile data? Oh, whoops. Here it is: crash-2019-08-12_18.32.59-client.txt
August 12, 20196 yr 1 hour ago, Simon_kungen said: public boolean hasTileEntity() Try overriding the BlockState sensitive version VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 12, 20196 yr Author 1 minute ago, Animefan8888 said: Try overriding the BlockState sensitive version What do you mean?
August 12, 20196 yr 9 minutes ago, Simon_kungen said: What'd you mean with "sensitive version"? It has a BlockState parameter VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 12, 20196 yr Author 1 minute ago, Animefan8888 said: It has a BlockState parameter Like this? @Override public boolean hasTileEntity(BlockState state) { return true; } It doesn't appear to crash anymore. But I don't seem to get my value out of that particular block. TreeTapTileEntity.java public class TreeTapTileEntity extends TileEntity { private int volume = 0; public TreeTapTileEntity() { super(IntercraftTileEntities.TREETAP); } @Override public CompoundNBT write(CompoundNBT compound) { compound.putInt("volume", this.volume); return compound; } @Override public void read(CompoundNBT compound) { this.volume = compound.getInt("volume"); } public int getVolume() { return this.volume; } } TreeTap.java public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { TreeTapTileEntity tile = (TreeTapTileEntity) worldIn.getTileEntity(pos); System.out.println(tile.getVolume()); }
August 12, 20196 yr 10 minutes ago, Simon_kungen said: But I don't seem to get my value out of that particular block. What do you mean? From the code you've shown I do you mean it's always 0? Because of course it would be you never set it to anything else. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 12, 20196 yr Author 1 minute ago, Animefan8888 said: What do you mean? From the code you've shown I do you mean it's always 0? Because of course it would be you never set it to anything else. Oh, sorry, what I meant is that it keeps setting back to the default value 0 every time I re-loads the game/world. I added the ITickableTileEntity interface to it as I'm going to need it. public class TreeTapTileEntity extends TileEntity implements ITickableTileEntity { private int volume = 0; private boolean canFill = false; public TreeTapTileEntity() { super(IntercraftTileEntities.TREETAP); } @Override public void tick() { if (canFill) { volume++; } } @Override public CompoundNBT write(CompoundNBT compound) { compound.putInt("volume", this.volume); compound.putBoolean("can_fill",this.canFill); return compound; } @Override public void read(CompoundNBT compound) { this.volume = compound.getInt("volume"); this.canFill = compound.getBoolean("can_fill"); } public int getVolume() { return this.volume; } public void setCanFill(boolean bool) { canFill = bool; } }
August 12, 20196 yr 32 minutes ago, Simon_kungen said: Oh, sorry, what I meant is that it keeps setting back to the default value 0 every time I re-loads the game/world. I added the ITickableTileEntity interface to it as I'm going to need it. If I'm not mistaking you also have to call the supers on read and write. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 12, 20196 yr Author 8 minutes ago, Animefan8888 said: If I'm not mistaking you also have to call the supers on read and write. Yup, totally missed that, thanks!
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.