Functional desktop schematic placement

This commit is contained in:
Anuken
2019-10-18 00:41:30 -04:00
parent 61d15782d0
commit 30bcfb6d5e
13 changed files with 116 additions and 51 deletions

View File

@@ -104,7 +104,7 @@ public interface BuilderTrait extends Entity, TeamTrait{
if(current.breaking){
entity.deconstruct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
}else{
if(entity.construct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier)){
if(entity.construct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier, current.hasConfig)){
if(current.hasConfig){
Call.onTileConfig(null, tile, current.config);
}
@@ -267,18 +267,26 @@ public interface BuilderTrait extends Entity, TeamTrait{
/** Class for storing build requests. Can be either a place or remove request. */
class BuildRequest{
/** Position and rotation of this request. */
public int x, y, rotation;
/** Block being placed. If null, this is a breaking request.*/
public @Nullable Block block;
/** Whether this is a break request.*/
public boolean breaking;
/** Whether this request comes with a config int. If yes, any blocks placed with this request will not call playerPlaced.*/
public boolean hasConfig;
/** Config int. Not used unless hasConfig is true.*/
public int config;
/** Original position, only used in schematics.*/
public int originalX, originalY;
/** Last progress.*/
public float progress;
/** Whether construction has started for this request.*/
public boolean initialized;
//animation variables
/** Visual scale. Used only for rendering.*/
public float animScale = 0f;
public float animInvalid;
/** This creates a build request. */
public BuildRequest(int x, int y, int rotation, Block block){
@@ -302,6 +310,29 @@ public interface BuilderTrait extends Entity, TeamTrait{
}
public BuildRequest copy(){
BuildRequest copy = new BuildRequest();
copy.x = x;
copy.y = y;
copy.rotation = rotation;
copy.block = block;
copy.breaking = breaking;
copy.hasConfig = hasConfig;
copy.config = config;
copy.originalX = originalX;
copy.originalY = originalY;
copy.progress = progress;
copy.initialized = initialized;
copy.animScale = animScale;
return copy;
}
public BuildRequest original(int x, int y){
originalX = x;
originalY = y;
return this;
}
public Rectangle bounds(Rectangle rect){
if(breaking){
return rect.set(-100f, -100f, 0f, 0f);

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.entities.type;
import io.anuke.mindustry.*;
import io.anuke.mindustry.entities.EntityGroup;
import io.anuke.mindustry.entities.traits.Entity;
@@ -14,6 +15,14 @@ public abstract class BaseEntity implements Entity{
id = lastid++;
}
public int tileX(){
return Vars.world.toTile(x);
}
public int tileY(){
return Vars.world.toTile(y);
}
@Override
public int getID(){
return id;

View File

@@ -236,11 +236,6 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
return 0;
}
/** @return whether the config is a position that should be translated.*/
public boolean posConfig(){
return false;
}
@Override
public void removed(){
if(sound != null){