This commit is contained in:
Anuken
2021-10-26 20:34:45 -04:00
parent 0242fd25e1
commit 705c85281c
9 changed files with 158 additions and 4 deletions
@@ -149,11 +149,13 @@ public class Floor extends Block{
@Override
public void drawBase(Tile tile){
Mathf.rand.setSeed(tile.pos());
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
drawEdges(tile);
drawOverlay(tile);
}
public void drawOverlay(Tile tile){
Floor floor = tile.overlay();
if(floor != Blocks.air && floor != this){ //ore should never have itself on top, but it's possible, so prevent a crash in that case
floor.drawBase(tile);
@@ -165,6 +167,16 @@ public class Floor extends Block{
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};
}
//TODO currently broken for dynamically edited floor tiles
/** @return true if this floor should be updated in the render loop, e.g. for effects. Do NOT overuse this! */
public boolean updateRender(Tile tile){
return false;
}
public void renderUpdate(UpdateRenderState tile){
}
/** @return whether this floor has a valid surface on which to place things, e.g. scorch marks. */
public boolean hasSurface(){
return !isLiquid && !solid;
@@ -251,4 +263,15 @@ public class Floor extends Block{
return block.edges()[x][2 - y];
}
public static class UpdateRenderState{
public Tile tile;
public Floor floor;
public float data;
public UpdateRenderState(Tile tile, Floor floor){
this.tile = tile;
this.floor = floor;
}
}
}
@@ -1,2 +1,76 @@
package mindustry.world.blocks.environment;public class SteamVent {
package mindustry.world.blocks.environment;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.world.*;
import static mindustry.Vars.*;
//can't use an overlay for this because it spans multiple tiles
public class SteamVent extends Floor{
public static final Point2[] offsets = {
new Point2(0, 0),
new Point2(1, 0),
new Point2(1, 1),
new Point2(0, 1),
new Point2(-1, 1),
new Point2(-1, 0),
new Point2(-1, -1),
new Point2(0, -1),
new Point2(1, -1),
};
public Block parent = Blocks.air;
public Effect effect = Fx.ventSteam;
public float effectSpacing = 15f;
static{
for(var p : offsets){
p.sub(1, 1);
}
}
public SteamVent(String name){
super(name);
variants = 1;
inEditor = false;
}
@Override
public void drawBase(Tile tile){
parent.drawBase(tile);
if(checkAdjacent(tile)){
Mathf.rand.setSeed(tile.pos());
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx() - tilesize, tile.worldy() - tilesize);
}
}
@Override
public boolean updateRender(Tile tile){
return checkAdjacent(tile);
}
@Override
public void renderUpdate(UpdateRenderState state){
if(state.tile.block() == Blocks.air && (state.data += Time.delta) >= effectSpacing){
effect.at(state.tile.x * tilesize - tilesize, state.tile.y * tilesize - tilesize);
state.data = 0f;
}
}
public boolean checkAdjacent(Tile tile){
for(var point : offsets){
Tile other = Vars.world.tile(tile.x + point.x, tile.y + point.y);
if(other == null || other.floor() != this){
return false;
}
}
return true;
}
}