mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-05 16:37:38 +07:00
Removed Tile#bc(), use Tile.build instead
This commit is contained in:
parent
5d4b8a43e3
commit
25125f5a9b
@ -67,6 +67,8 @@ public class Vars implements Loadable{
|
||||
public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md";
|
||||
/** list of built-in servers.*/
|
||||
public static final Seq<ServerGroup> defaultServers = Seq.with();
|
||||
/** maximum size of any block, do not change unless you know what you're doing */
|
||||
public static final int maxBlockSize = 14;
|
||||
/** maximum distance between mine and core that supports automatic transferring */
|
||||
public static final float mineTransferRange = 220f;
|
||||
/** max chat message length */
|
||||
|
@ -56,7 +56,7 @@ public class BuilderAI extends AIController{
|
||||
}
|
||||
|
||||
boolean valid =
|
||||
(req.tile() != null && req.tile().build instanceof ConstructBuild && req.tile().<ConstructBuild>bc().cblock == req.block) ||
|
||||
(req.tile() != null && req.tile().build instanceof ConstructBuild cons && cons.cblock == req.block) ||
|
||||
(req.breaking ?
|
||||
Build.validBreak(unit.team(), req.x, req.y) :
|
||||
Build.validPlace(req.block, unit.team(), req.x, req.y, req.rotation));
|
||||
|
@ -4,6 +4,7 @@ import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.gen.*;
|
||||
@ -134,7 +135,7 @@ public class Blocks implements ContentList{
|
||||
|
||||
//Registers build blocks
|
||||
//no reference is needed here since they can be looked up by name later
|
||||
for(int i = 1; i <= ConstructBlock.maxSize; i++){
|
||||
for(int i = 1; i <= Vars.maxBlockSize; i++){
|
||||
new ConstructBlock(i);
|
||||
}
|
||||
|
||||
|
@ -102,13 +102,11 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
|
||||
}
|
||||
|
||||
//if there is no core to build with or no build entity, stop building!
|
||||
if((core == null && !infinite) || !(tile.build instanceof ConstructBuild)){
|
||||
if((core == null && !infinite) || !(tile.build instanceof ConstructBuild entity)){
|
||||
return;
|
||||
}
|
||||
|
||||
//otherwise, update it.
|
||||
ConstructBuild entity = tile.bc();
|
||||
|
||||
if(current.breaking){
|
||||
entity.deconstruct(self(), core, 1f / entity.buildCost * Time.delta * type.buildSpeed * state.rules.buildSpeedMultiplier);
|
||||
}else{
|
||||
@ -182,8 +180,8 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
|
||||
plans.remove(replace);
|
||||
}
|
||||
Tile tile = world.tile(place.x, place.y);
|
||||
if(tile != null && tile.build instanceof ConstructBuild){
|
||||
place.progress = tile.<ConstructBuild>bc().progress;
|
||||
if(tile != null && tile.build instanceof ConstructBuild cons){
|
||||
place.progress = cons.progress;
|
||||
}
|
||||
if(tail){
|
||||
plans.addLast(place);
|
||||
|
@ -201,7 +201,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
|
||||
if(self() instanceof ConstructBuild entity){
|
||||
//update block to reflect the fact that something was being constructed
|
||||
if(entity.cblock != null && entity.cblock.synthetic()){
|
||||
if(entity.cblock != null && entity.cblock.synthetic() && entity.wasConstructing){
|
||||
block = entity.cblock;
|
||||
}else{
|
||||
//otherwise this was a deconstruction that was interrupted, don't want to rebuild that
|
||||
|
@ -516,7 +516,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
|
||||
public boolean requestMatches(BuildPlan request){
|
||||
Tile tile = world.tile(request.x, request.y);
|
||||
return tile != null && tile.block() instanceof ConstructBlock && tile.<ConstructBuild>bc().cblock == request.block;
|
||||
return tile != null && tile.build instanceof ConstructBuild cons && cons.cblock == request.block;
|
||||
}
|
||||
|
||||
public void drawBreaking(int x, int y){
|
||||
|
@ -39,6 +39,8 @@ import mindustry.world.meta.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ContentParser{
|
||||
private static final boolean ignoreUnknownFields = true;
|
||||
@ -250,8 +252,8 @@ public class ContentParser{
|
||||
|
||||
readFields(block, value, true);
|
||||
|
||||
if(block.size > ConstructBlock.maxSize){
|
||||
throw new IllegalArgumentException("Blocks cannot be larger than " + ConstructBlock.maxSize);
|
||||
if(block.size > maxBlockSize){
|
||||
throw new IllegalArgumentException("Blocks cannot be larger than " + maxBlockSize);
|
||||
}
|
||||
|
||||
//make block visible by default if there are requirements and no visibility set
|
||||
|
@ -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>{
|
||||
|
@ -54,7 +54,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||
};
|
||||
|
||||
tile = createFakeTile(0, 0, generator);
|
||||
entity = tile.bc();
|
||||
entity = (ItemLiquidGeneratorBuild)tile.build;
|
||||
}
|
||||
|
||||
/** Tests the consumption and efficiency when being supplied with liquids. */
|
||||
|
@ -137,7 +137,7 @@ public class PowerTests extends PowerTestFixture{
|
||||
assertEquals(0.0f, consumerTile.build.power.status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
if(consumerTile.block().consumes.hasPower()){
|
||||
ConsumePower consumePower = consumerTile.block().consumes.getPower();
|
||||
assertFalse(consumePower.valid(consumerTile.bc()));
|
||||
assertFalse(consumePower.valid(consumerTile.build));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user