Fixed rendering of liquids under floors

This commit is contained in:
Anuken
2025-07-27 23:52:19 -04:00
parent 479a84ba32
commit 0a2d8576fd
2 changed files with 33 additions and 17 deletions

View File

@@ -10,6 +10,7 @@ import mindustry.content.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.world.*;
import mindustry.world.blocks.environment.*;
import static mindustry.Vars.*;
@@ -67,7 +68,7 @@ public enum EditorTool{
}else if(mode == 2){
//draw teams
editor.drawCircle(x, y, tile -> tile.setTeam(editor.drawTeam));
}else if(mode == 3){
}else if(mode == 3 && !(editor.drawBlock instanceof Floor f && f.isLiquid)){
editor.drawBlocks(x, y, false, true, tile -> tile.floor().isLiquid);
}

View File

@@ -233,6 +233,21 @@ public class Floor extends Block{
@Override
public void drawBase(Tile tile){
drawMain(tile);
if(drawEdgeIn){
drawEdges(tile);
}
drawOverlay(tile);
if(tile.overlay() != Blocks.air && tile.floor() == this && isLiquid){
Draw.alpha(1f - overlayAlpha);
drawMain(tile);
Draw.color();
}
}
public void drawMain(Tile tile){
if(tilingVariants > 0){
int index = Mathf.randomSeed(Point2.pack(tile.x / tilingSize, tile.y / tilingSize), 0, tilingVariants - 1);
TextureRegion[][] regions = tilingRegions[index];
@@ -258,10 +273,6 @@ public class Floor extends Block{
}
Draw.alpha(1f);
if(drawEdgeIn){
drawEdges(tile);
}
drawOverlay(tile);
}
public boolean checkAutotileSame(Tile tile, @Nullable Tile other){
@@ -279,13 +290,7 @@ public class Floor extends Block{
public void drawOverlay(Tile tile){
Floor floor = tile.overlay();
if(floor != Blocks.air && floor != this){
if(isLiquid){
Draw.alpha(overlayAlpha);
}
floor.drawBase(tile);
if(isLiquid){
Draw.alpha(1f);
}
}
}
@@ -351,11 +356,15 @@ public class Floor extends Block{
Point2 point = Geometry.d8[i];
Tile other = tile.nearby(point);
if(other != null && other.floor().drawEdgeOut && doEdge(tile, other, other.floor()) && other.floor().cacheLayer == realCache && other.floor().edges(tile.x, tile.y) != null){
if(!blended.getAndSet(other.floor().id)){
blenders.add(other.floor());
if(other == null) continue;
Floor ob = (this == tile.floor() || other.overlay() == Blocks.air ? other.floor() : other.overlay());
if(ob.drawEdgeOut && doEdge(tile, other, ob) && other.floor().cacheLayer == realCache && ob.edges(tile.x, tile.y) != null){
if(!blended.getAndSet(ob.id)){
blenders.add(ob);
}
dirs[i] = other.floorID();
dirs[i] = ob.id;
}
}
@@ -363,13 +372,19 @@ public class Floor extends Block{
}
protected void drawBlended(Tile tile, boolean checkId){
blenders.sort(a -> a.id);
//prioritize the "actual" floor over other floors to fix weird square corners
blenders.sort(a -> a.id + (tile.floor() != this && a == tile.floor() ? 99999 : 0));
for(Floor block : blenders){
for(int i = 0; i < 8; i++){
Point2 point = Geometry.d8[i];
Tile other = tile.nearby(point);
if(other != null && other.floor() == block && (!checkId || dirs[i] == block.id)){
if(other == null) continue;
Floor ob = (this == tile.floor() || other.overlay() == Blocks.air ? other.floor() : other.overlay());
if(ob == block && (!checkId || dirs[i] == block.id)){
TextureRegion region = block.edge(tile.x, tile.y, 1 - point.x, 1 - point.y);
Draw.rect(region, tile.worldx(), tile.worldy());
}