Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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.

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.

  • Author
1 minute ago, Draco18s said:

Dead simple solution: give no fucks.

 

Could be that simple but I quite like those small details. ^^

Developer of Primeval Forest.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.