Removed Tile#bc(), use Tile.build instead
This commit is contained in:
@@ -41,8 +41,9 @@ public class Build{
|
||||
if(tile.build != null) prevBuild.add(tile.build);
|
||||
|
||||
tile.setBlock(sub, team, rotation);
|
||||
tile.<ConstructBuild>bc().setDeconstruct(previous);
|
||||
tile.<ConstructBuild>bc().prevBuild = prevBuild;
|
||||
var build = (ConstructBuild)tile.build;
|
||||
build.setDeconstruct(previous);
|
||||
build.prevBuild = prevBuild;
|
||||
tile.build.health = tile.build.maxHealth * prevPercent;
|
||||
if(unit != null && unit.isPlayer()) tile.build.lastAccessed = unit.getPlayer().name;
|
||||
|
||||
@@ -85,7 +86,7 @@ public class Build{
|
||||
|
||||
tile.setBlock(sub, team, rotation);
|
||||
|
||||
ConstructBuild build = tile.bc();
|
||||
var build = (ConstructBuild)tile.build;
|
||||
|
||||
build.setConstruct(previous.size == sub.size ? previous : Blocks.air, result);
|
||||
build.prevBuild = prevBuild;
|
||||
@@ -150,10 +151,10 @@ public class Build{
|
||||
!check.floor().placeableOn || //solid wall
|
||||
!((type.canReplace(check.block()) || //can replace type
|
||||
//controversial change: allow rebuilding damaged blocks
|
||||
//this could be buggy and abusable, so I'm not enabling it yet
|
||||
//this could be buggy and abuse-able, so I'm not enabling it yet
|
||||
//note that this requires a change in BuilderComp as well
|
||||
//(type == check.block() && check.centerX() == x && check.centerY() == y && check.build != null && check.build.health < check.build.maxHealth - 0.0001f) ||
|
||||
(check.block instanceof ConstructBlock && check.<ConstructBuild>bc().cblock == type && check.centerX() == tile.x && check.centerY() == tile.y)) && //same type in construction
|
||||
(check.build instanceof ConstructBuild build && build.cblock == type && check.centerX() == tile.x && check.centerY() == tile.y)) && //same type in construction
|
||||
type.bounds(tile.x, tile.y, Tmp.r1).grow(0.01f).contains(check.block.bounds(check.centerX(), check.centerY(), Tmp.r2))) || //no replacement
|
||||
(type.requiresWater && check.floor().liquidDrop != Liquids.water) //requires water but none found
|
||||
) return false;
|
||||
|
||||
@@ -3,17 +3,15 @@ package mindustry.world;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.blocks.ConstructBlock;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Edges{
|
||||
private static final int maxSize = ConstructBlock.maxSize;
|
||||
private static final int maxRadius = 12;
|
||||
private static Point2[][] edges = new Point2[maxSize][0];
|
||||
private static Point2[][] edgeInside = new Point2[maxSize][0];
|
||||
private static Point2[][] edges = new Point2[maxBlockSize][0];
|
||||
private static Point2[][] edgeInside = new Point2[maxBlockSize][0];
|
||||
private static Vec2[][] polygons = new Vec2[maxRadius * 2][0];
|
||||
|
||||
static{
|
||||
@@ -21,7 +19,7 @@ public class Edges{
|
||||
polygons[i] = Geometry.pixelCircle((i + 1) / 2f);
|
||||
}
|
||||
|
||||
for(int i = 0; i < maxSize; i++){
|
||||
for(int i = 0; i < maxBlockSize; i++){
|
||||
int bot = -(int)(i / 2f) - 1;
|
||||
int top = (int)(i / 2f + 0.5f) + 1;
|
||||
edges[i] = new Point2[(i + 1) * 4];
|
||||
@@ -73,13 +71,13 @@ public class Edges{
|
||||
}
|
||||
|
||||
public static Point2[] getEdges(int size){
|
||||
if(size < 0 || size > maxSize) throw new RuntimeException("Block size must be between 0 and " + maxSize);
|
||||
if(size < 0 || size > maxBlockSize) throw new RuntimeException("Block size must be between 0 and " + maxBlockSize);
|
||||
|
||||
return edges[size - 1];
|
||||
}
|
||||
|
||||
public static Point2[] getInsideEdges(int size){
|
||||
if(size < 0 || size > maxSize) throw new RuntimeException("Block size must be between 0 and " + maxSize);
|
||||
if(size < 0 || size > maxBlockSize) throw new RuntimeException("Block size must be between 0 and " + maxBlockSize);
|
||||
|
||||
return edgeInside[size - 1];
|
||||
}
|
||||
|
||||
@@ -125,13 +125,6 @@ public class Tile implements Position, QuadTreeObject, Displayable{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Convenience method that returns the building of this tile with a cast.
|
||||
* Method name is shortened to prevent conflict. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Building> T bc(){
|
||||
return (T)build;
|
||||
}
|
||||
|
||||
public float worldx(){
|
||||
return x * tilesize;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ import static mindustry.Vars.*;
|
||||
|
||||
/** A block in the process of construction. */
|
||||
public class ConstructBlock extends Block{
|
||||
public static final int maxSize = 16;
|
||||
private static final ConstructBlock[] consBlocks = new ConstructBlock[maxSize];
|
||||
private static final ConstructBlock[] consBlocks = new ConstructBlock[maxBlockSize];
|
||||
|
||||
private static long lastTime = 0;
|
||||
private static int pitchSeq = 0;
|
||||
@@ -46,7 +45,7 @@ public class ConstructBlock extends Block{
|
||||
|
||||
/** Returns a ConstructBlock by size. */
|
||||
public static ConstructBlock get(int size){
|
||||
if(size > maxSize) throw new IllegalArgumentException("No. Don't place ConstructBlock of size greater than " + maxSize);
|
||||
if(size > maxBlockSize) throw new IllegalArgumentException("No. Don't place ConstructBlock of size greater than " + maxBlockSize);
|
||||
return consBlocks[size - 1];
|
||||
}
|
||||
|
||||
@@ -147,6 +146,7 @@ public class ConstructBlock extends Block{
|
||||
*/
|
||||
public Block previous;
|
||||
public Object lastConfig;
|
||||
public boolean wasConstructing;
|
||||
|
||||
@Nullable
|
||||
public Unit lastBuilder;
|
||||
@@ -218,6 +218,7 @@ public class ConstructBlock extends Block{
|
||||
}
|
||||
|
||||
public void construct(Unit builder, @Nullable Building core, float amount, Object config){
|
||||
wasConstructing = true;
|
||||
if(cblock == null){
|
||||
kill();
|
||||
return;
|
||||
@@ -252,6 +253,7 @@ public class ConstructBlock extends Block{
|
||||
}
|
||||
|
||||
public void deconstruct(Unit builder, @Nullable Building core, float amount){
|
||||
wasConstructing = false;
|
||||
float deconstructMultiplier = state.rules.deconstructRefundMultiplier;
|
||||
|
||||
if(builder.isPlayer()){
|
||||
@@ -331,6 +333,7 @@ public class ConstructBlock extends Block{
|
||||
}
|
||||
|
||||
public void setConstruct(Block previous, Block block){
|
||||
wasConstructing = true;
|
||||
this.cblock = block;
|
||||
this.previous = previous;
|
||||
this.accumulator = new float[block.requirements.length];
|
||||
@@ -340,6 +343,7 @@ public class ConstructBlock extends Block{
|
||||
|
||||
public void setDeconstruct(Block previous){
|
||||
if(previous == null) return;
|
||||
wasConstructing = false;
|
||||
this.previous = previous;
|
||||
this.progress = 1f;
|
||||
if(previous.buildCost >= 0.01f){
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ItemBridge extends Block{
|
||||
|
||||
return ((other.block() == tile.block() && tile.block() == this) || (!(tile.block() instanceof ItemBridge) && other.block() == this))
|
||||
&& (other.team() == tile.team() || tile.block() != this)
|
||||
&& (!checkDouble || other.<ItemBridgeBuild>bc().link != tile.pos());
|
||||
&& (!checkDouble || ((ItemBridgeBuild)other.build).link != tile.pos());
|
||||
}
|
||||
|
||||
public Tile findLink(int x, int y){
|
||||
@@ -238,7 +238,7 @@ public class ItemBridge extends Block{
|
||||
while(it.hasNext){
|
||||
int i = it.next();
|
||||
Tile other = world.tile(i);
|
||||
if(!linkValid(tile, other, false) || other.<ItemBridgeBuild>bc().link != tile.pos()){
|
||||
if(!linkValid(tile, other, false) || ((ItemBridgeBuild)other.build).link != tile.pos()){
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,8 +302,7 @@ public class MassDriver extends Block{
|
||||
|
||||
protected boolean shooterValid(Tile other){
|
||||
if(other == null) return true;
|
||||
if(!(other.block() instanceof MassDriver)) return false;
|
||||
MassDriverBuild entity = other.bc();
|
||||
if(!(other.build instanceof MassDriverBuild entity)) return false;
|
||||
return entity.link == tile.pos() && tile.dst(other) <= range;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ public class Sorter extends Block{
|
||||
|
||||
@Override
|
||||
public int minimapColor(Tile tile){
|
||||
return tile.<SorterBuild>bc().sortItem == null ? 0 : tile.<SorterBuild>bc().sortItem.color.rgba();
|
||||
var build = (SorterBuild)tile.build;
|
||||
return build == null || build.sortItem == null ? 0 : build.sortItem.color.rgba();
|
||||
}
|
||||
|
||||
public class SorterBuild extends Building{
|
||||
|
||||
@@ -58,9 +58,8 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void playerSpawn(Tile tile, Player player){
|
||||
if(player == null || tile == null) return;
|
||||
if(player == null || tile == null || !(tile.build instanceof CoreBuild entity)) return;
|
||||
|
||||
CoreBuild entity = tile.bc();
|
||||
CoreBlock block = (CoreBlock)tile.block();
|
||||
Fx.spawn.at(entity);
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ public class UnitBlock extends PayloadAcceptor{
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void unitBlockSpawn(Tile tile){
|
||||
if(!(tile.build instanceof UnitBuild)) return;
|
||||
tile.<UnitBuild>bc().spawned();
|
||||
if(!(tile.build instanceof UnitBuild build)) return;
|
||||
build.spawned();
|
||||
}
|
||||
|
||||
public class UnitBuild extends PayloadAcceptorBuild<UnitPayload>{
|
||||
|
||||
Reference in New Issue
Block a user