Posted December 8, 20168 yr Hey there, So I'm looking for a way to detect when a certain TE is broken. I need it so that when the TE is broken, remove it from a list. Here is what I current have: @Override public void updateEntity() { super.updateEntity(); System.out.print(standsAround.size()); if(!worldObj.isRemote) { for (EnumFacing facing : EnumFacing.HORIZONTALS) { for(int i = 0; i < maxSearchRange; i++) { BlockPos pos = getPos().offset(facing, i); TileEntity te = worldObj.getTileEntity(pos); if (te instanceof TileEntityStand) { standsAround.add(te); } if(i >= maxSearchRange) { return; } } } } } Thanks, Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 9, 20168 yr Author Okay, I have a 'updateWithInverval' built in with my BaseTile so will switch to that.. Okay, I have switched to a WeakHashMap , and it seems to work okay, however, still wont remove from the list. @Override public void updateEntity() { super.updateEntity(); System.out.print(standsAround.size()); if(!worldObj.isRemote && sendUpdateWithInterval()) { for (EnumFacing facing : EnumFacing.HORIZONTALS) { for(int i = 0; i < maxSearchRange; i++) { BlockPos pos = getPos().offset(facing, i); TileEntity te = worldObj.getTileEntity(pos); if (te instanceof TileEntityStand) { if(!te.isInvalid()) { standsAround.put(te, pos); } else { standsAround.remove(te); } } if(i >= maxSearchRange) { return; } } } } } Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 9, 20168 yr Author Ah sorry: Still won't remove from the list. Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 9, 20168 yr Ah sorry: Still won't remove from the list. Your code won't work because you are checking to see if the worlds version of the te is invalid. Really the simplest way to do this would be to loop through like you are, but without the invalid check and only add. (Side note why do you need a map? The TE stores its BlockPos). Once you have added them check through the currently a map for TEs that are invalid. Or check if the TE still exists in the World by doing World#getTileEntity(listTE.getPos()) != null. Or similar. 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.
December 9, 20168 yr Author So something like this? @Override public void updateEntity() { super.updateEntity(); System.out.print(standsAround.size()); if (!worldObj.isRemote && sendUpdateChecksWithInterval()) { for (EnumFacing facing : EnumFacing.HORIZONTALS) { for (int i = 0; i < maxSearchRange; i++) { BlockPos pos = getPos().offset(facing, i); TileEntity te = worldObj.getTileEntity(pos); if (te instanceof TileEntityStand) { this.standsAround.add(te); } if (i >= maxSearchRange) { return; } } } validateTEs(); } } public void validateTEs() { for(int i = 0; i < standsAround.size(); i++) { TileEntity te = standsAround.get(i); if(te.getPos() == null) { standsAround.remove(te); }else { return; } if(i >= standsAround.size()) { return; } } } Edit: Oh and my list being: public final List<TileEntity> standsAround = new ArrayList<TileEntity>(); Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 9, 20168 yr So something like this? @Override public void updateEntity() { super.updateEntity(); System.out.print(standsAround.size()); if (!worldObj.isRemote && sendUpdateChecksWithInterval()) { for (EnumFacing facing : EnumFacing.HORIZONTALS) { for (int i = 0; i < maxSearchRange; i++) { BlockPos pos = getPos().offset(facing, i); TileEntity te = worldObj.getTileEntity(pos); if (te instanceof TileEntityStand) { this.standsAround.add(te); } if (i >= maxSearchRange) { return; } } } validateTEs(); } } public void validateTEs() { for(int i = 0; i < standsAround.size(); i++) { TileEntity te = standsAround.get(i); if(te.getPos() == null) { standsAround.remove(te); }else { return; } if(i >= standsAround.size()) { return; } } } Edit: Oh and my list being: public final List<TileEntity> standsAround = new ArrayList<TileEntity>(); Close but in your validate method call worldObj.getTileEntity(te.getPos()) == null instead of if the pos is null. 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.
December 9, 20168 yr Author Yeah that seemed to work, however, would you know how I'd get rid of duplicates? So the size isnt something crazy. just 1,2,3,4? Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 10, 20168 yr Yeah that seemed to work, however, would you know how I'd get rid of duplicates? So the size isnt something crazy. just 1,2,3,4? Compare blockpos of the TEs. 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.
December 11, 20168 yr Some more ideas you could build built-in-obsolescence in your TEs so they don't become rogue. Every so often check if they are still attached to a block. If the block is gone make it self destruct. I tell my blocks to always kill their own TE just before they get destroyed. Disclaimer: I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.
December 11, 20168 yr I tell my blocks to always kill their own TE just before they get destroyed. ...You know that vanilla already does that for you, right? public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { if (hasTileEntity(state) && !(this instanceof BlockContainer)) { worldIn.removeTileEntity(pos); } } 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.
December 11, 20168 yr I tell my blocks to always kill their own TE just before they get destroyed. ...You know that vanilla already does that for you, right? public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { if (hasTileEntity(state) && !(this instanceof BlockContainer)) { worldIn.removeTileEntity(pos); } } Disclaimer: I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.
December 11, 20168 yr Author How would I get another instance of a te to compare it to? Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 11, 20168 yr World#getTileEntity(BlockPos) Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
December 11, 20168 yr Author Yes I know that, I need to be able to grab another te and check their blockpos Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 11, 20168 yr Well, every TileEntity has a getPos() method which you can use. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
December 11, 20168 yr Author How would I get two of the TEs from the list and compare them, thats my question Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 11, 20168 yr Instead of checking for duplicates when reading the values, check for duplicated when adding them to the List . There's List<T>#contains(T) which returns true if T is already in the List<T> . Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
December 11, 20168 yr Author Ah! That seemed to work, Thanks! Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
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.