Lambda Posted December 8, 2016 Posted December 8, 2016 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, Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Lambda Posted December 9, 2016 Author Posted December 9, 2016 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; } } } } } Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Lambda Posted December 9, 2016 Author Posted December 9, 2016 Ah sorry: Still won't remove from the list. Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Animefan8888 Posted December 9, 2016 Posted December 9, 2016 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. Quote 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.
Lambda Posted December 9, 2016 Author Posted December 9, 2016 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>(); Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Animefan8888 Posted December 9, 2016 Posted December 9, 2016 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. Quote 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.
Lambda Posted December 9, 2016 Author Posted December 9, 2016 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? Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Animefan8888 Posted December 10, 2016 Posted December 10, 2016 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. Quote 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.
trollworkout Posted December 11, 2016 Posted December 11, 2016 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. Quote 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.
Draco18s Posted December 11, 2016 Posted December 11, 2016 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); } } Quote 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.
trollworkout Posted December 11, 2016 Posted December 11, 2016 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); } } Quote 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.
Lambda Posted December 11, 2016 Author Posted December 11, 2016 How would I get another instance of a te to compare it to? Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
larsgerrits Posted December 11, 2016 Posted December 11, 2016 World#getTileEntity(BlockPos) Quote 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/
Lambda Posted December 11, 2016 Author Posted December 11, 2016 Yes I know that, I need to be able to grab another te and check their blockpos Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
larsgerrits Posted December 11, 2016 Posted December 11, 2016 Well, every TileEntity has a getPos() method which you can use. Quote 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/
Lambda Posted December 11, 2016 Author Posted December 11, 2016 How would I get two of the TEs from the list and compare them, thats my question Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
larsgerrits Posted December 11, 2016 Posted December 11, 2016 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> . Quote 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/
Lambda Posted December 11, 2016 Author Posted December 11, 2016 Ah! That seemed to work, Thanks! Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Recommended Posts
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.