Many internal changes

This commit is contained in:
Anuken
2020-03-04 13:32:31 -05:00
parent aeae286273
commit cf31293d7b
30 changed files with 283 additions and 290 deletions

View File

@@ -476,14 +476,20 @@ public class Block extends BlockStorage{
/** Called when arbitrary configuration is applied to a tile. */
public void configured(Tile tile, @Nullable Playerc player, @Nullable Object value){
if(value == null){
//TODO
//tapped(tile, player);
}else if(configurations.containsKey(value.getClass())){
configurations.get(value.getClass()).configured(tile, value);
//null is of type Void.class; anonymous classes use their superclass.
Class<?> type = value == null ? void.class : value.getClass().isAnonymousClass() ? value.getClass().getSuperclass() : value.getClass();
if(configurations.containsKey(type)){
configurations.get(type).configured(tile, value);
}
}
/** Configure when a null value is passed.*/
public void configClear(Cons<Tile> cons){
configurations.put(void.class, (tile, value) -> cons.get(tile));
}
/** Listen for a config by class type. */
public <T> void config(Class<T> type, ConfigHandler<T> config){
configurations.put(type, config);
}
@@ -743,7 +749,7 @@ public class Block extends BlockStorage{
}
public void drawRequestConfigCenter(BuildRequest req, Content content, String region){
public void drawRequestConfigCenter(BuildRequest req, Object content, String region){
Color color = content instanceof Item ? ((Item)content).color : content instanceof Liquid ? ((Liquid)content).color : null;
if(color == null) return;

View File

@@ -1,21 +0,0 @@
package mindustry.world;
/** Methods for a packed position 'struct', contained in an int. */
public class Pos{
public static final int invalid = get(-1, -1);
/** Returns packed position from an x/y position. The values must be within short limits. */
public static int get(int x, int y){
return (((short)x) << 16) | (((short)y) & 0xFFFF);
}
/** Returns the x component of a position. */
public static short x(int pos){
return (short)(pos >>> 16);
}
/** Returns the y component of a position. */
public static short y(int pos){
return (short)(pos & 0xFFFF);
}
}

View File

@@ -50,9 +50,9 @@ public class Tile implements Position{
this(x, y, content.block(floor), content.block(overlay), content.block(wall));
}
/** Returns this tile's position as a {@link Pos}. */
/** Returns this tile's position as a packed point. */
public int pos(){
return Pos.get(x, y);
return Point2.pack(x, y);
}
public byte relativeTo(Tile tile){

View File

@@ -1,6 +1,7 @@
package mindustry.world;
import arc.func.*;
import arc.math.geom.*;
import arc.util.ArcAnnotate.*;
import java.util.*;
@@ -61,7 +62,7 @@ public class Tiles implements Iterable<Tile>{
/** @return a tile at an int position (not equivalent to geti) */
public @Nullable Tile getp(int pos){
return get(Pos.x(pos), Pos.y(pos));
return get(Point2.x(pos), Point2.y(pos));
}
@Override

View File

@@ -3,6 +3,7 @@ package mindustry.world.blocks;
import arc.Core;
import arc.graphics.g2d.*;
import arc.math.Mathf;
import arc.math.geom.*;
import mindustry.graphics.CacheLayer;
import mindustry.world.*;
@@ -25,7 +26,7 @@ public class StaticWall extends Rock{
int rx = tile.x / 2 * 2;
int ry = tile.y / 2 * 2;
if(Core.atlas.isFound(large) && eq(rx, ry) && Mathf.randomSeed(Pos.get(rx, ry)) < 0.5){
if(Core.atlas.isFound(large) && eq(rx, ry) && Mathf.randomSeed(Point2.pack(rx, ry)) < 0.5){
Draw.rect(split[tile.x % 2][1 - tile.y % 2], tile.worldx(), tile.worldy());
}else if(variants > 0){
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());

View File

@@ -1,20 +1,17 @@
package mindustry.world.blocks.defense;
import arc.*;
import arc.util.io.*;
import mindustry.annotations.Annotations.*;
import arc.Graphics.*;
import arc.Graphics.Cursor.*;
import arc.graphics.g2d.*;
import arc.math.geom.*;
import arc.util.io.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.world.*;
import java.io.*;
import static mindustry.Vars.*;
import static mindustry.Vars.pathfinder;
public class Door extends Wall{
protected final static Rect rect = new Rect();
@@ -31,23 +28,19 @@ public class Door extends Wall{
solidifes = true;
consumesTap = true;
entityType = DoorEntity::new;
}
@Remote(called = Loc.server)
public static void onDoorToggle(Playerc player, Tile tile, boolean open){
DoorEntity entity = tile.ent();
if(entity != null){
config(Boolean.class, (tile, open) -> {
DoorEntity entity = tile.ent();
entity.open = open;
Door door = (Door)tile.block();
pathfinder.updateTile(tile);
if(!entity.open){
door.openfx.at(tile.drawx(), tile.drawy());
openfx.at(tile.drawx(), tile.drawy());
}else{
door.closefx.at(tile.drawx(), tile.drawy());
closefx.at(tile.drawx(), tile.drawy());
}
Sounds.door.at(tile);
}
});
}
@Override
@@ -86,12 +79,17 @@ public class Door extends Wall{
return;
}
Call.onDoorToggle(null, tile, !entity.open);
tile.configure(!entity.open);
}
public class DoorEntity extends TileEntity{
public boolean open = false;
@Override
public Boolean config(){
return open;
}
@Override
public void write(Writes write){
super.write(write);

View File

@@ -1,23 +1,21 @@
package mindustry.world.blocks.distribution;
import arc.*;
import arc.struct.*;
import arc.struct.IntSet.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.struct.IntSet.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.*;
public class ItemBridge extends Block{
@@ -27,7 +25,7 @@ public class ItemBridge extends Block{
public TextureRegion endRegion, bridgeRegion, arrowRegion;
private static BuildRequest otherReq;
private static int lastPlaced = Pos.invalid;
private static int lastPlaced = -1;
public ItemBridge(String name){
super(name);
@@ -43,6 +41,7 @@ public class ItemBridge extends Block{
group = BlockGroup.transportation;
entityType = ItemBridgeEntity::new;
config(Point2.class, (tile, i) -> tile.<ItemBridgeEntity>ent().link = i.pack());
config(Integer.class, (tile, i) -> tile.<ItemBridgeEntity>ent().link = i);
}
@@ -59,7 +58,7 @@ public class ItemBridge extends Block{
public void drawRequestConfigTop(BuildRequest req, Eachable<BuildRequest> list){
otherReq = null;
list.each(other -> {
if(other.block == this && req.config == Pos.get(other.x, other.y)){
if(other.block == this && req.config instanceof Point2 && ((Point2)req.config).equals(other.x, other.y)){
otherReq = other;
}
});
@@ -87,7 +86,7 @@ public class ItemBridge extends Block{
}
public Tile findLink(int x, int y){
if(world.tile(x, y) != null && linkValid(world.tile(x, y), world.tile(lastPlaced)) && lastPlaced != Pos.get(x, y)){
if(world.tile(x, y) != null && linkValid(world.tile(x, y), world.tile(lastPlaced)) && lastPlaced != Point2.pack(x, y)){
return world.tile(lastPlaced);
}
return null;
@@ -152,7 +151,7 @@ public class ItemBridge extends Block{
if(linkValid(tile, other)){
if(entity.link == other.pos()){
tile.configure(Pos.invalid);
tile.configure(-1);
}else{
tile.configure(other.pos());
}
@@ -283,7 +282,7 @@ public class ItemBridge extends Block{
while(it.hasNext){
int v = it.next();
if(tile.absoluteRelativeTo(Pos.x(v), Pos.y(v)) == i){
if(tile.absoluteRelativeTo(Point2.x(v), Point2.y(v)) == i){
return false;
}
}
@@ -328,7 +327,7 @@ public class ItemBridge extends Block{
while(it.hasNext){
int v = it.next();
if(tile.absoluteRelativeTo(Pos.x(v), Pos.y(v)) == i){
if(tile.absoluteRelativeTo(Point2.x(v), Point2.y(v)) == i){
return false;
}
}
@@ -359,7 +358,7 @@ public class ItemBridge extends Block{
}
public static class ItemBridgeEntity extends TileEntity{
public int link = Pos.invalid;
public int link = -1;
public IntSet incoming = new IntSet();
public float uptime;
public float time;
@@ -367,8 +366,8 @@ public class ItemBridge extends Block{
public float cycleSpeed = 1f;
@Override
public Object config(){
return link;
public Point2 config(){
return Point2.unpack(link);
}
@Override

View File

@@ -1,9 +1,10 @@
package mindustry.world.blocks.distribution;
import arc.*;
import arc.struct.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import arc.util.pooling.Pool.*;
@@ -15,8 +16,6 @@ import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import java.io.*;
import static mindustry.Vars.*;
public class MassDriver extends Block{
@@ -42,11 +41,9 @@ public class MassDriver extends Block{
hasPower = true;
outlineIcon = true;
entityType = MassDriverEntity::new;
}
@Override
public void configured(Tile tile, Playerc player, Object value){
tile.<MassDriverEntity>ent().link = value;
config(Point2.class, (tile, point) -> tile.<MassDriverEntity>ent().link = point.pack());
config(Integer.class, (tile, point) -> tile.<MassDriverEntity>ent().link = point);
}
@Override
@@ -327,8 +324,8 @@ public class MassDriver extends Block{
}
@Override
public int config(){
return link;
public Point2 config(){
return Point2.unpack(link);
}
@Override

View File

@@ -136,7 +136,7 @@ public class OverflowGate extends Block{
@Override
public void write(Writes write){
write.i(lastInput == null ? Pos.invalid : lastInput.pos());
write.i(lastInput == null ? -1 : lastInput.pos());
}
@Override

View File

@@ -6,15 +6,13 @@ import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.*;
public class Sorter extends Block{
@@ -32,6 +30,7 @@ public class Sorter extends Block{
entityType = SorterEntity::new;
config(Item.class, (tile, item) -> tile.<SorterEntity>ent().sortItem = item);
configClear(tile -> tile.<SorterEntity>ent().sortItem = null);
}
@Override
@@ -48,7 +47,8 @@ public class Sorter extends Block{
@Override
public void configured(Tile tile, Playerc player, Object value){
tile.<SorterEntity>ent().sortItem = (Item)value;
super.configured(tile, player, value);
if(!headless){
renderer.minimap.update(tile);
}
@@ -139,25 +139,17 @@ public class Sorter extends Block{
@Override
public void buildConfiguration(Tile tile, Table table){
SorterEntity entity = tile.ent();
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> {
lastItem = item;
tile.configure(item == null ? -1 : item.id);
});
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> tile.configure(lastItem = item));
}
public class SorterEntity extends TileEntity{
@Nullable Item sortItem;
@Override
public Object config(){
public Item config(){
return sortItem;
}
@Override
public void setConfig(Object config){
sortItem = (Item)config;
}
@Override
public byte version(){
return 2;

View File

@@ -10,8 +10,6 @@ import arc.scene.ui.layout.*;
import arc.util.*;
import arc.util.io.*;
import arc.util.pooling.*;
import mindustry.annotations.Annotations.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.net.*;
import mindustry.ui.*;
@@ -21,8 +19,9 @@ import mindustry.world.*;
import static mindustry.Vars.*;
public class MessageBlock extends Block{
protected static int maxTextLength = 220;
protected static int maxNewlines = 24;
//don't change this too much unless you want to run into issues with packet sizes
public int maxTextLength = 220;
public int maxNewlines = 24;
public MessageBlock(String name){
super(name);
@@ -30,40 +29,32 @@ public class MessageBlock extends Block{
solid = true;
destructible = true;
entityType = MessageBlockEntity::new;
}
@Remote(targets = Loc.both, called = Loc.both, forward = true)
public static void setMessageBlockText(Playerc player, Tile tile, String text){
if(!Units.canInteract(player, tile)) return;
if(net.server() && text.length() > maxTextLength){
throw new ValidateException(player, "Player has gone above text limit.");
}
config(String.class, (tile, text) -> {
if(net.server() && text.length() > maxTextLength){
throw new ValidateException(player, "Player has gone above text limit.");
}
//can be broken while a player is typing
if(!(tile.block() instanceof MessageBlock)){
return;
}
MessageBlockEntity entity = tile.ent();
StringBuilder result = new StringBuilder(text.length());
text = text.trim();
int count = 0;
for(int i = 0; i < text.length(); i++){
char c = text.charAt(i);
if(c == '\n' || c == '\r'){
count ++;
if(count <= maxNewlines){
result.append('\n');
StringBuilder result = new StringBuilder(text.length());
text = text.trim();
int count = 0;
for(int i = 0; i < text.length(); i++){
char c = text.charAt(i);
if(c == '\n' || c == '\r'){
count ++;
if(count <= maxNewlines){
result.append('\n');
}
}else{
result.append(c);
}
}else{
result.append(c);
}
}
MessageBlockEntity entity = tile.ent();
if(entity != null){
entity.message = result.toString();
entity.lines = entity.message.split("\n");
}
});
}
@Override
@@ -102,9 +93,7 @@ public class MessageBlock extends Block{
text = entity.message;
multiline = true;
maxLength = maxTextLength;
accepted = out -> {
Call.setMessageBlockText(player, tile, out);
};
accepted = tile::configure;
}});
}else{
FloatingDialog dialog = new FloatingDialog("$editmessage");
@@ -124,11 +113,11 @@ public class MessageBlock extends Block{
});
a.setMaxLength(maxTextLength);
dialog.buttons.addButton("$ok", () -> {
Call.setMessageBlockText(player, tile, a.getText());
tile.configure(a.getText());
dialog.hide();
}).size(130f, 60f);
dialog.update(() -> {
if(!entity.isValid()){
if(tile.block() != this){
dialog.hide();
}
});
@@ -148,6 +137,11 @@ public class MessageBlock extends Block{
public String message = "";
public String[] lines = {""};
@Override
public String config(){
return message;
}
@Override
public void write(Writes write){
super.write(write);

View File

@@ -9,8 +9,6 @@ import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import java.io.*;
import static mindustry.Vars.*;
public class LightBlock extends Block{
@@ -27,6 +25,8 @@ public class LightBlock extends Block{
topRegion = reg("-top");
configurable = true;
entityType = LightEntity::new;
config(Integer.class, (tile, value) -> tile.<LightEntity>ent().color = value);
}
@Override
@@ -61,11 +61,6 @@ public class LightBlock extends Block{
}).size(40f);
}
@Override
public void configured(Tile tile, Playerc player, Object value){
tile.<LightEntity>ent().color = value;
}
@Override
public void drawLight(Tile tile){
LightEntity entity = tile.ent();
@@ -76,7 +71,7 @@ public class LightBlock extends Block{
public int color = Pal.accent.rgba();
@Override
public int config(){
public Integer config(){
return color;
}

View File

@@ -35,45 +35,52 @@ public class PowerNode extends PowerBlock{
configurable = true;
consumesPower = false;
outputsPower = false;
}
entityType = PowerNodeEntity::new;
@Override
public void configured(Tile tile, Playerc player, Object value){
Tilec entity = tile.entity;
Tile other = world.tile(value);
boolean contains = entity.power().links.contains(value), valid = other != null && other.entity != null && other.entity.power() != null;
config(Integer.class, (tile, value) -> {
Tilec entity = tile.entity;
Tile other = world.tile(value);
boolean contains = entity.power().links.contains(value), valid = other != null && other.entity != null && other.entity.power() != null;
if(contains){
//unlink
entity.power().links.removeValue(value);
if(valid) other.entity.power().links.removeValue(tile.pos());
if(contains){
//unlink
entity.power().links.removeValue(value);
if(valid) other.entity.power().links.removeValue(tile.pos());
PowerGraph newgraph = new PowerGraph();
PowerGraph newgraph = new PowerGraph();
//reflow from this point, covering all tiles on this side
newgraph.reflow(tile);
//reflow from this point, covering all tiles on this side
newgraph.reflow(tile);
if(valid && other.entity.power().graph != newgraph){
//create new graph for other end
PowerGraph og = new PowerGraph();
//reflow from other end
og.reflow(other);
}
}else if(linkValid(tile, other) && valid && entity.power().links.size < maxNodes){
if(!entity.power().links.contains(other.pos())){
entity.power().links.add(other.pos());
}
if(other.getTeamID() == tile.getTeamID()){
if(!other.entity.power().links.contains(tile.pos())){
other.entity.power().links.add(tile.pos());
if(valid && other.entity.power().graph != newgraph){
//create new graph for other end
PowerGraph og = new PowerGraph();
//reflow from other end
og.reflow(other);
}
}
}else if(linkValid(tile, other) && valid && entity.power().links.size < maxNodes){
entity.power().graph.add(other.entity.power().graph);
}
if(!entity.power().links.contains(other.pos())){
entity.power().links.add(other.pos());
}
if(other.getTeamID() == tile.getTeamID()){
if(!other.entity.power().links.contains(tile.pos())){
other.entity.power().links.add(tile.pos());
}
}
entity.power().graph.add(other.entity.power().graph);
}
});
config(Point2[].class, (tile, value) -> {
tile.entity.power().links.clear();
for(Point2 p : value){
tile.entity.power().links.add(p.pack());
}
});
}
@Override
@@ -360,4 +367,16 @@ public class PowerNode extends PowerBlock{
return false;
});
}
public class PowerNodeEntity extends TileEntity{
@Override
public Point2[] config(){
Point2[] out = new Point2[power.links.size];
for(int i = 0; i < out.length; i++){
out[i] = Point2.unpack(power.links.get(i));
}
return out;
}
}
}

View File

@@ -5,15 +5,13 @@ import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.content;
public class ItemSource extends Block{
@@ -27,17 +25,15 @@ public class ItemSource extends Block{
group = BlockGroup.transportation;
configurable = true;
entityType = ItemSourceEntity::new;
}
@Override
public void configured(Tile tile, Playerc player, Object value){
tile.<ItemSourceEntity>ent().outputItem = content.item(value);
config(Item.class, (tile, item) -> tile.<ItemSourceEntity>ent().outputItem = item);
configClear(tile -> tile.<ItemSourceEntity>ent().outputItem = null);
}
@Override
public void playerPlaced(Tile tile){
if(lastItem != null){
Core.app.post(() -> tile.configure(lastItem.id));
Core.app.post(() -> tile.configure(lastItem));
}
}
@@ -49,7 +45,7 @@ public class ItemSource extends Block{
@Override
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
drawRequestConfigCenter(req, content.item(req.config), "center");
drawRequestConfigCenter(req, req.config, "center");
}
@Override
@@ -82,10 +78,7 @@ public class ItemSource extends Block{
@Override
public void buildConfiguration(Tile tile, Table table){
ItemSourceEntity entity = tile.ent();
ItemSelection.buildTable(table, content.items(), () -> entity.outputItem, item -> {
lastItem = item;
tile.configure(item == null ? -1 : item.id);
});
ItemSelection.buildTable(table, content.items(), () -> entity.outputItem, item -> tile.configure(lastItem = item));
}
@Override
@@ -97,8 +90,8 @@ public class ItemSource extends Block{
Item outputItem;
@Override
public int config(){
return outputItem == null ? -1 : outputItem.id;
public Item config(){
return outputItem;
}
@Override

View File

@@ -6,14 +6,13 @@ import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.ctype.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import java.io.*;
import static mindustry.Vars.content;
public class LiquidSource extends Block{
@@ -29,13 +28,14 @@ public class LiquidSource extends Block{
outputsLiquid = true;
entityType = LiquidSourceEntity::new;
config();
config(Liquid.class, (tile, l) -> tile.<LiquidSourceEntity>ent().source = l);
configClear(tile -> tile.<LiquidSourceEntity>ent().source = null);
}
@Override
public void playerPlaced(Tile tile){
if(lastLiquid != null){
Core.app.post(() -> tile.configure(lastLiquid.id));
Core.app.post(() -> tile.configure(lastLiquid));
}
}
@@ -60,7 +60,7 @@ public class LiquidSource extends Block{
@Override
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
drawRequestConfigCenter(req, content.liquid(req.config), "center");
drawRequestConfigCenter(req, (Content)req.config, "center");
}
@Override
@@ -80,22 +80,14 @@ public class LiquidSource extends Block{
public void buildConfiguration(Tile tile, Table table){
LiquidSourceEntity entity = tile.ent();
ItemSelection.buildTable(table, content.liquids(), () -> entity.source, liquid -> {
lastLiquid = liquid;
tile.configure(liquid == null ? -1 : liquid.id);
});
}
@Override
public void configured(Tile tile, Playerc player, Object value){
tile.<LiquidSourceEntity>ent().source = value == -1 ? null : content.liquid(value);
ItemSelection.buildTable(table, content.liquids(), () -> entity.source, liquid -> tile.configure(lastLiquid = liquid));
}
class LiquidSourceEntity extends TileEntity{
public @Nullable Liquid source = null;
@Override
public Object config(){
public Liquid config(){
return source;
}

View File

@@ -5,14 +5,12 @@ import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import java.io.*;
import static mindustry.Vars.content;
public class Unloader extends Block{
@@ -29,11 +27,18 @@ public class Unloader extends Block{
hasItems = true;
configurable = true;
entityType = UnloaderEntity::new;
config(Item.class, (tile, item) -> {
tile.entity.items().clear();
tile.<UnloaderEntity>ent().sortItem = item;
});
configClear(tile -> tile.<UnloaderEntity>ent().sortItem = null);
}
@Override
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
drawRequestConfigCenter(req, content.item(req.config), "unloader-center");
drawRequestConfigCenter(req, (Item)req.config, "unloader-center");
}
@Override
@@ -50,16 +55,10 @@ public class Unloader extends Block{
@Override
public void playerPlaced(Tile tile){
if(lastItem != null){
tile.configure(lastItem.id);
tile.configure(lastItem);
}
}
@Override
public void configured(Tile tile, Playerc player, Object value){
tile.entity.items().clear();
tile.<UnloaderEntity>ent().sortItem = content.item(value);
}
@Override
public void update(Tile tile){
UnloaderEntity entity = tile.ent();
@@ -123,19 +122,15 @@ public class Unloader extends Block{
@Override
public void buildConfiguration(Tile tile, Table table){
UnloaderEntity entity = tile.ent();
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> {
lastItem = item;
tile.configure(item == null ? -1 : item.id);
});
ItemSelection.buildTable(table, content.items(), () -> tile.<UnloaderEntity>ent().sortItem, item -> tile.configure(lastItem = item));
}
public static class UnloaderEntity extends TileEntity{
public Item sortItem = null;
@Override
public int config(){
return sortItem == null ? -1 : sortItem.id;
public Item config(){
return sortItem;
}
@Override

View File

@@ -11,16 +11,14 @@ import arc.util.*;
import arc.util.io.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.*;
public class CommandCenter extends Block{
@@ -37,6 +35,21 @@ public class CommandCenter extends Block{
solid = true;
configurable = true;
entityType = CommandCenterEntity::new;
config(Integer.class, (tile, value) -> {
UnitCommand command = UnitCommand.all[value];
((CommandCenter)tile.block()).effect.at(tile);
for(Tile center : indexer.getAllied(tile.team(), BlockFlag.comandCenter)){
if(center.block() instanceof CommandCenter){
CommandCenterEntity entity = center.ent();
entity.command = command;
}
}
Groups.unit.each(t -> t.team() == tile.team(), u -> u.controller().command(command));
Events.fire(new CommandIssueEvent(tile, command));
});
}
@Override
@@ -102,27 +115,11 @@ public class CommandCenter extends Block{
table.label(() -> entity.command.localized()).style(Styles.outlineLabel).center().growX().get().setAlignment(Align.center);
}
@Override
public void configured(Tile tile, Playerc player, Object value){
UnitCommand command = UnitCommand.all[value];
((CommandCenter)tile.block()).effect.at(tile);
for(Tile center : indexer.getAllied(tile.team(), BlockFlag.comandCenter)){
if(center.block() instanceof CommandCenter){
CommandCenterEntity entity = center.ent();
entity.command = command;
}
}
Groups.unit.each(t -> t.team() == tile.team(), u -> u.controller().command(command));
Events.fire(new CommandIssueEvent(tile, command));
}
public class CommandCenterEntity extends TileEntity{
public UnitCommand command = UnitCommand.attack;
@Override
public int config(){
public Integer config(){
return command.ordinal();
}