Colored wall block

This commit is contained in:
Anuken
2025-07-15 11:45:56 -04:00
parent 547ceff736
commit b714651055
12 changed files with 113 additions and 13 deletions

View File

@@ -566,6 +566,11 @@ public class Block extends UnlockableContent implements Senseable{
return forceDark;
}
/** If true, the 'map edge' darkness will be applied to this block. */
public boolean isDarkened(Tile tile){
return solid && ((!synthetic() && fillsTile) || checkForceDark(tile));
}
@Override
public void setStats(){
super.setStats();
@@ -940,6 +945,9 @@ public class Block extends UnlockableContent implements Senseable{
return (envEnabled & env) != 0 && (envDisabled & env) == 0 && (envRequired == 0 || (envRequired & env) == envRequired);
}
/** Called when this block is set on the specified tile. */
public void blockChanged(Tile tile){}
/** Called when building of this block begins. */
public void placeBegan(Tile tile, Block previous){
@@ -951,7 +959,7 @@ public class Block extends UnlockableContent implements Senseable{
}
/** Called when building of this block ends. */
public void placeEnded(Tile tile, @Nullable Unit builder){
public void placeEnded(Tile tile, @Nullable Unit builder, @Nullable Object config){
}

View File

@@ -172,7 +172,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{
}
public boolean isDarkened(){
return block.solid && ((!block.synthetic() && block.fillsTile) || block.checkForceDark(this));
return block.isDarkened(this);
}
public Floor floor(){
@@ -280,6 +280,8 @@ public class Tile implements Position, QuadTreeObject, Displayable{
changed();
changing = false;
block.blockChanged(this);
}
public void setBlock(Block type, Team team){

View File

@@ -77,10 +77,8 @@ public class ConstructBlock extends Block{
if(block instanceof OverlayFloor overlay){
tile.setOverlay(overlay);
overlay.placed(tile, config);
}else if(block instanceof Floor floor){
tile.setFloor(floor);
floor.placed(tile, config);
}else{
tile.setBlock(block, team, rotation);
}
@@ -114,7 +112,7 @@ public class ConstructBlock extends Block{
if(shouldPlay()) block.placeSound.at(tile, block.placePitchChange ? calcPitch(true) : 1f);
}
block.placeEnded(tile, builder);
block.placeEnded(tile, builder, config);
Events.fire(new BlockBuildEndEvent(tile, builder, team, false, config));
}

View File

@@ -6,6 +6,7 @@ import arc.math.geom.*;
import arc.util.*;
import mindustry.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
@@ -135,7 +136,7 @@ public class ColoredFloor extends Floor{
}
@Override
public void placed(Tile tile, @Nullable Object config){
public void placeEnded(Tile tile, @Nullable Unit builder, @Nullable Object config){
//config is assumed to be an integer RGBA color
if(config instanceof Integer i){
tile.extraData = i;

View File

@@ -0,0 +1,74 @@
package mindustry.world.blocks.environment;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.world.*;
public class ColoredWall extends StaticWall{
/** If the alpha value of the color is set to this value, different colors are ignored and no border is drawn. */
public static final int flagIgnoreDifferentColor = 1;
/** If the alpha value of the color is set to this value, the wall will have darkness applied, as other walls do. */
public static final int flagApplyDarkness = 2;
public Color defaultColor = Color.white;
protected int defaultColorRgba;
public ColoredWall(String name){
super(name);
saveData = true;
}
@Override
public void init(){
super.init();
defaultColorRgba = defaultColor.rgba();
}
@Override
public void drawBase(Tile tile){
//make sure to mask out the alpha channel - it's generally undesirable, and leads to invisible blocks when the data is not initialized
Draw.color(tile.extraData | 0xff);
super.drawBase(tile);
Draw.color();
}
@Override
public void blockChanged(Tile tile){
//reset to white
tile.extraData = defaultColorRgba;
}
@Override
public void placeEnded(Tile tile, @Nullable Unit builder, @Nullable Object config){
//config is assumed to be an integer RGBA color
if(config instanceof Integer i){
tile.extraData = i;
}
}
@Override
public void drawPlanRegion(BuildPlan plan, Eachable<BuildPlan> list){
if(plan.config instanceof Integer i){
Draw.tint(Tmp.c1.set(i | 0xff));
}
drawDefaultPlanRegion(plan, list);
}
@Override
public boolean checkAutotileSame(Tile tile, @Nullable Tile other){
return other != null && other.block() == this && ((tile.extraData & flagIgnoreDifferentColor) != 0 || tile.extraData == other.extraData);
}
@Override
public boolean isDarkened(Tile tile){
return (tile.extraData & flagApplyDarkness) != 0;
}
@Override
public int minimapColor(Tile tile){
return tile.extraData | 0xff;
}
}

View File

@@ -290,9 +290,6 @@ public class Floor extends Block{
/** Called when this floor is set on the specified tile. */
public void floorChanged(Tile tile){}
/** Called when this floor or overlay is placed on a tile. The config may be null. */
public void placed(Tile tile, @Nullable Object config){}
/** @return whether to index this floor by flag */
public boolean shouldIndex(Tile tile){
return true;

View File

@@ -44,7 +44,7 @@ public class RemoveOre extends OverlayFloor{
}
@Override
public void placeEnded(Tile tile, @Nullable Unit builder){
public void placeEnded(Tile tile, @Nullable Unit builder, Object config){
tile.setOverlay(Blocks.air);
}

View File

@@ -43,7 +43,7 @@ public class RemoveWall extends Block{
}
@Override
public void placeEnded(Tile tile, @Nullable Unit builder){
public void placeEnded(Tile tile, @Nullable Unit builder, Object config){
tile.setBlock(Blocks.air);
if(tile.overlay().wallOre){
tile.setOverlay(Blocks.air);

View File

@@ -4,6 +4,7 @@ import arc.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.graphics.*;
@@ -40,7 +41,7 @@ public class StaticWall extends Prop{
for(int i = 0; i < 8; i++){
Tile other = tile.nearby(Geometry.d8[i]);
if(other != null && other.block() == this){
if(checkAutotileSame(tile, other)){
bits |= (1 << i);
}
}
@@ -65,6 +66,10 @@ public class StaticWall extends Prop{
}
}
public boolean checkAutotileSame(Tile tile, @Nullable Tile other){
return other != null && other.block() == this;
}
@Override
public void load(){
super.load();