Implemented multiblock replacement, upgrade-safe building
This commit is contained in:
@@ -101,8 +101,8 @@ public class TileEntity extends Entity{
|
|||||||
Block block = tile.block();
|
Block block = tile.block();
|
||||||
|
|
||||||
block.onDestroyed(tile);
|
block.onDestroyed(tile);
|
||||||
|
|
||||||
world.removeBlock(tile);
|
world.removeBlock(tile);
|
||||||
|
block.afterDestroyed(tile, this);
|
||||||
remove();
|
remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,10 @@ public class Block extends BaseBlock {
|
|||||||
public boolean isAccessible(){
|
public boolean isAccessible(){
|
||||||
return (hasItems && itemCapacity > 0);
|
return (hasItems && itemCapacity > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void afterDestroyed(Tile tile, TileEntity entity){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void onDestroyed(Tile tile){
|
public void onDestroyed(Tile tile){
|
||||||
float x = tile.worldx(), y = tile.worldy();
|
float x = tile.worldx(), y = tile.worldy();
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class Build {
|
|||||||
public static void placeBlock(Team team, int x, int y, Recipe recipe, int rotation){
|
public static void placeBlock(Team team, int x, int y, Recipe recipe, int rotation){
|
||||||
Tile tile = world.tile(x, y);
|
Tile tile = world.tile(x, y);
|
||||||
Block result = recipe.result;
|
Block result = recipe.result;
|
||||||
|
Block previous = tile.block();
|
||||||
|
|
||||||
//just in case
|
//just in case
|
||||||
if(tile == null) return;
|
if(tile == null) return;
|
||||||
@@ -57,7 +58,7 @@ public class Build {
|
|||||||
Block sub = Block.getByName("build" + result.size);
|
Block sub = Block.getByName("build" + result.size);
|
||||||
|
|
||||||
tile.setBlock(sub, rotation);
|
tile.setBlock(sub, rotation);
|
||||||
tile.<BuildEntity>entity().set(recipe);
|
tile.<BuildEntity>entity().set(previous, recipe);
|
||||||
tile.setTeam(team);
|
tile.setTeam(team);
|
||||||
|
|
||||||
if(result.isMultiblock()){
|
if(result.isMultiblock()){
|
||||||
@@ -119,6 +120,10 @@ public class Build {
|
|||||||
if(tile == null || (isSpawnPoint(tile) && (type.solidifes || type.solid))) return false;
|
if(tile == null || (isSpawnPoint(tile) && (type.solidifes || type.solid))) return false;
|
||||||
|
|
||||||
if(type.isMultiblock()){
|
if(type.isMultiblock()){
|
||||||
|
if(type.canReplace(tile.block()) && tile.block().size == type.size){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int offsetx = -(type.size-1)/2;
|
int offsetx = -(type.size-1)/2;
|
||||||
int offsety = -(type.size-1)/2;
|
int offsety = -(type.size-1)/2;
|
||||||
for(int dx = 0; dx < type.size; dx ++){
|
for(int dx = 0; dx < type.size; dx ++){
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ import io.anuke.mindustry.game.Team;
|
|||||||
import io.anuke.mindustry.graphics.Layer;
|
import io.anuke.mindustry.graphics.Layer;
|
||||||
import io.anuke.mindustry.graphics.Shaders;
|
import io.anuke.mindustry.graphics.Shaders;
|
||||||
import io.anuke.mindustry.type.Recipe;
|
import io.anuke.mindustry.type.Recipe;
|
||||||
import io.anuke.mindustry.world.BarType;
|
import io.anuke.mindustry.world.*;
|
||||||
import io.anuke.mindustry.world.Block;
|
|
||||||
import io.anuke.mindustry.world.BlockBar;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
|
||||||
import io.anuke.mindustry.world.blocks.types.modules.InventoryModule;
|
import io.anuke.mindustry.world.blocks.types.modules.InventoryModule;
|
||||||
import io.anuke.ucore.core.Effects;
|
import io.anuke.ucore.core.Effects;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
@@ -56,8 +53,23 @@ public class BuildBlock extends Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Tile tile){
|
public void afterDestroyed(Tile tile, TileEntity e){
|
||||||
|
BuildEntity entity = (BuildEntity)e;
|
||||||
|
|
||||||
|
if(entity.previous.update || entity.previous.solid){
|
||||||
|
tile.setBlock(entity.previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Tile tile){
|
||||||
|
BuildEntity entity = tile.entity();
|
||||||
|
|
||||||
|
if(entity.previous.update || entity.previous.solid) {
|
||||||
|
for (TextureRegion region : entity.previous.getBlockIcon()) {
|
||||||
|
Draw.rect(region, tile.drawx(), tile.drawy(), entity.recipe.result.rotate ? tile.getRotation() * 90 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -115,6 +127,7 @@ public class BuildBlock extends Block {
|
|||||||
private double progress = 0;
|
private double progress = 0;
|
||||||
private double[] accumulator;
|
private double[] accumulator;
|
||||||
private boolean updated;
|
private boolean updated;
|
||||||
|
private Block previous;
|
||||||
|
|
||||||
public void addProgress(InventoryModule inventory, double amount){
|
public void addProgress(InventoryModule inventory, double amount){
|
||||||
double maxProgress = amount;
|
double maxProgress = amount;
|
||||||
@@ -147,9 +160,10 @@ public class BuildBlock extends Block {
|
|||||||
return (float)progress;
|
return (float)progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(Recipe recipe){
|
public void set(Block previous, Recipe recipe){
|
||||||
updated = true;
|
updated = true;
|
||||||
this.recipe = recipe;
|
this.recipe = recipe;
|
||||||
|
this.previous = previous;
|
||||||
this.accumulator = new double[recipe.requirements.length];
|
this.accumulator = new double[recipe.requirements.length];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user