Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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);
        }
    }

 

:D

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.

Posted

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/

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.