mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-22 12:38:05 +07:00
Implemented multiblock replacement, upgrade-safe building
This commit is contained in:
parent
241b86d704
commit
9708d3183f
@ -101,8 +101,8 @@ public class TileEntity extends Entity{
|
||||
Block block = tile.block();
|
||||
|
||||
block.onDestroyed(tile);
|
||||
|
||||
world.removeBlock(tile);
|
||||
block.afterDestroyed(tile, this);
|
||||
remove();
|
||||
}
|
||||
}
|
||||
|
@ -214,6 +214,10 @@ public class Block extends BaseBlock {
|
||||
public boolean isAccessible(){
|
||||
return (hasItems && itemCapacity > 0);
|
||||
}
|
||||
|
||||
public void afterDestroyed(Tile tile, TileEntity entity){
|
||||
|
||||
}
|
||||
|
||||
public void onDestroyed(Tile tile){
|
||||
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){
|
||||
Tile tile = world.tile(x, y);
|
||||
Block result = recipe.result;
|
||||
Block previous = tile.block();
|
||||
|
||||
//just in case
|
||||
if(tile == null) return;
|
||||
@ -57,7 +58,7 @@ public class Build {
|
||||
Block sub = Block.getByName("build" + result.size);
|
||||
|
||||
tile.setBlock(sub, rotation);
|
||||
tile.<BuildEntity>entity().set(recipe);
|
||||
tile.<BuildEntity>entity().set(previous, recipe);
|
||||
tile.setTeam(team);
|
||||
|
||||
if(result.isMultiblock()){
|
||||
@ -119,6 +120,10 @@ public class Build {
|
||||
if(tile == null || (isSpawnPoint(tile) && (type.solidifes || type.solid))) return false;
|
||||
|
||||
if(type.isMultiblock()){
|
||||
if(type.canReplace(tile.block()) && tile.block().size == type.size){
|
||||
return true;
|
||||
}
|
||||
|
||||
int offsetx = -(type.size-1)/2;
|
||||
int offsety = -(type.size-1)/2;
|
||||
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.Shaders;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.BarType;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.types.modules.InventoryModule;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
@ -56,8 +53,23 @@ public class BuildBlock extends Block {
|
||||
}
|
||||
|
||||
@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
|
||||
@ -115,6 +127,7 @@ public class BuildBlock extends Block {
|
||||
private double progress = 0;
|
||||
private double[] accumulator;
|
||||
private boolean updated;
|
||||
private Block previous;
|
||||
|
||||
public void addProgress(InventoryModule inventory, double amount){
|
||||
double maxProgress = amount;
|
||||
@ -147,9 +160,10 @@ public class BuildBlock extends Block {
|
||||
return (float)progress;
|
||||
}
|
||||
|
||||
public void set(Recipe recipe){
|
||||
public void set(Block previous, Recipe recipe){
|
||||
updated = true;
|
||||
this.recipe = recipe;
|
||||
this.previous = previous;
|
||||
this.accumulator = new double[recipe.requirements.length];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user