Build check cleanup
This commit is contained in:
@@ -1753,6 +1753,7 @@ public class Blocks implements ContentList{
|
|||||||
};
|
};
|
||||||
size = 3;
|
size = 3;
|
||||||
consumes.power(1.2f);
|
consumes.power(1.2f);
|
||||||
|
floating = true;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
additiveReconstructor = new Reconstructor("additive-reconstructor"){{
|
additiveReconstructor = new Reconstructor("additive-reconstructor"){{
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ public class Block extends UnlockableContent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canReplace(Block other){
|
public boolean canReplace(Block other){
|
||||||
|
if(other.alwaysReplace) return true;
|
||||||
return (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && size == other.size;
|
return (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && size == other.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,68 +90,37 @@ public class Build{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type.isMultiblock()){
|
if(!type.requiresWater && !contactsShallows(tile.x, tile.y, type) && !type.placeableLiquid){
|
||||||
if(((type.canReplace(tile.block()) || tile.block.alwaysReplace) || (tile.block instanceof ConstructBlock && tile.<ConstructBuild>bc().cblock == type)) &&
|
return false;
|
||||||
type.canPlaceOn(tile, team) && tile.interactable(team)){
|
|
||||||
|
|
||||||
//if the block can be replaced but the sizes differ, check all the spaces around the block to make sure it can fit
|
|
||||||
if(type.size != tile.block().size){
|
|
||||||
int offsetx = -(type.size - 1) / 2;
|
|
||||||
int offsety = -(type.size - 1) / 2;
|
|
||||||
|
|
||||||
//this does not check *all* the conditions for placeability yet
|
|
||||||
for(int dx = 0; dx < type.size; dx++){
|
|
||||||
for(int dy = 0; dy < type.size; dy++){
|
|
||||||
int wx = dx + offsetx + x, wy = dy + offsety + y;
|
|
||||||
|
|
||||||
Tile check = world.tile(wx, wy);
|
|
||||||
if(check == null ||
|
|
||||||
(check.floor().isDeep() && !type.floating && !type.requiresWater && !type.placeableLiquid) ||
|
|
||||||
!check.interactable(team) ||
|
|
||||||
(!check.block.alwaysReplace && check.block != tile.block && !(check.block.size == 1 && type.canReplace(check.block)))) return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//make sure that the new block can fit the old one
|
|
||||||
return type.bounds(x, y, Tmp.r1).grow(0.01f).contains(tile.block.bounds(tile.centerX(), tile.centerY(), Tmp.r2));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!type.requiresWater && !contactsShallows(tile.x, tile.y, type) && !type.placeableLiquid){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!type.canPlaceOn(tile, team)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int offsetx = -(type.size - 1) / 2;
|
|
||||||
int offsety = -(type.size - 1) / 2;
|
|
||||||
for(int dx = 0; dx < type.size; dx++){
|
|
||||||
for(int dy = 0; dy < type.size; dy++){
|
|
||||||
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
|
|
||||||
if(
|
|
||||||
other == null ||
|
|
||||||
!other.block().alwaysReplace ||
|
|
||||||
!other.floor().placeableOn ||
|
|
||||||
(other.floor().isDeep() && !type.floating && !type.requiresWater && !type.placeableLiquid) ||
|
|
||||||
(type.requiresWater && tile.floor().liquidDrop != Liquids.water)
|
|
||||||
){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return tile.interactable(team)
|
|
||||||
&& (contactsShallows(tile.x, tile.y, type) || type.requiresWater || type.placeableLiquid)
|
|
||||||
&& (!tile.floor().isDeep() || type.floating || type.requiresWater || type.placeableLiquid)
|
|
||||||
&& tile.floor().placeableOn
|
|
||||||
&& (!type.requiresWater || tile.floor().liquidDrop == Liquids.water)
|
|
||||||
&& (((type.canReplace(tile.block()) || (tile.block instanceof ConstructBlock && tile.<ConstructBuild>bc().cblock == type))
|
|
||||||
&& !(type == tile.block() && (tile.build != null && rotation == tile.build.rotation) && type.rotate)) || tile.block().alwaysReplace || tile.block() == Blocks.air)
|
|
||||||
&& tile.block().isMultiblock() == type.isMultiblock() && type.canPlaceOn(tile, team);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!type.canPlaceOn(tile, team)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int offsetx = -(type.size - 1) / 2;
|
||||||
|
int offsety = -(type.size - 1) / 2;
|
||||||
|
|
||||||
|
for(int dx = 0; dx < type.size; dx++){
|
||||||
|
for(int dy = 0; dy < type.size; dy++){
|
||||||
|
int wx = dx + offsetx + tile.x, wy = dy + offsety + tile.y;
|
||||||
|
|
||||||
|
Tile check = world.tile(wx, wy);
|
||||||
|
if(
|
||||||
|
check == null || //nothing there
|
||||||
|
(check.floor().isDeep() && !type.floating && !type.requiresWater && !type.placeableLiquid) || //deep water
|
||||||
|
(type == check.block() && check.build != null && rotation == check.build.rotation && type.rotate) || //same block, same rotation
|
||||||
|
!check.interactable(team) || //cannot interact
|
||||||
|
!check.floor().placeableOn || //solid wall
|
||||||
|
!((type.canReplace(check.block()) || //can replace type
|
||||||
|
(check.block instanceof ConstructBlock && check.<ConstructBuild>bc().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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean contactsGround(int x, int y, Block block){
|
public static boolean contactsGround(int x, int y, Block block){
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ public class Wall extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canReplace(Block other){
|
public boolean canReplace(Block other){
|
||||||
return (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && health > other.health && size >= other.size;
|
if(other.alwaysReplace) return true;
|
||||||
|
return (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && other != this && size >= other.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WallBuild extends Building{
|
public class WallBuild extends Building{
|
||||||
|
|||||||
Reference in New Issue
Block a user