Jump to content

[1.12.2] [UNSOLVED] TileEntity priority Multiblock (performance)


Bektor

Recommended Posts

Hi,

 

I've just finished my basic fluid tank and I want to have it work now as a multi-block with different priorities:

Unbenannt.thumb.png.2e1e3272ec0250a09e4506d213fbb0e4.png

The numbers represent the priorities. Multiply tanks with the same priority mean that those parts of the tank will be filled equaly at the same time.

Only when all blocks with the priority 1 are completly full all blocks with the priority 2 will begin to fill.

 

Currently I'm only building up the list of all surrounding blocks. Note: Improvements of the code (regarding look and performance) are highly welcome. ;)

    public void generateMultiblock() {
        this.findTanks();
    }
    
    public void disbandMultiblock() {
        
    }
    
    private void findTanks() {
        this.tempTank = new HashSet<>();
        
        ArrayList<BlockPos> adjacentTanks = null;
        ArrayList<BlockPos> currentTanks = new ArrayList<>();
        
        // add this to the list to initiate the search
        currentTanks.add(this.getPos());
        // searches around all blocks and all adjacent blocks
        do {
            for(BlockPos curTank : currentTanks) {
                adjacentTanks = this.findAdjacentTanks(curTank);
                for(BlockPos adTank : adjacentTanks) {
                    // add to list but make sure it's no duplicate
                    if(this.tempTank.add(adTank))
                        currentTanks.add(adTank);
                }
            }
            currentTanks.clear();
        } while (currentTanks.size() > 0);
    }
    
    private ArrayList<BlockPos> findAdjacentTanks(BlockPos tank) {
        if(tank == null)
            return null;
        ArrayList<BlockPos> adjacentTanks = new ArrayList<>();
        
        for(EnumFacing face : EnumFacing.VALUES) {
            // find tile entity in offset direction
            BlockPos offset = tank.offset(face);
            TileEntity tile = this.getWorld().getTileEntity(offset);
            if(tile != null && tile instanceof TileEntityFluidTank) {
                // check if the tile entity is already connected to another tank as it can't have two masters
                if(!((TileEntityFluidTank)tile).isConnected())
                    adjacentTanks.add(offset);
            }
        }
        return adjacentTanks;
    }

 

It should also be noted that my TileEntityFluidTank is currently emtpy except for the isConnected method which currently always returns false (functionality to return true when already connected to a master block isn't quite there yet)

Only the master block contains fluid logic and can hold fluids! The other blocks hold the fluid just client side (in terms of rendering), meaning that they don't have one line and should not have one line of code to handle fluids except for a value used

for rendering (like x amount of fluid stored which is only used to render the x amount of fluid inside the tank at the location).

 

I'm just having problems on how to get a performant way to build up the whole priority list. 

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

Dead simple solution: give no fucks.

Tank "is there a tank below me with available space?" insert liquid.

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.

Link to comment
Share on other sites

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.