From 0ed21a1d5f9d72c7caff17caea3b22919ab07088 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 17 Mar 2020 11:51:33 -0400 Subject: [PATCH] Bugfixes, cleanup / Created stub processor class --- core/src/mindustry/editor/EditorTile.java | 32 ++++------------ core/src/mindustry/entities/def/TileComp.java | 20 ++++------ core/src/mindustry/input/InputHandler.java | 1 + core/src/mindustry/world/Tile.java | 4 ++ .../blocks/defense/turrets/BurstTurret.java | 3 +- .../world/blocks/logic/ProcessorBlock.java | 37 +++++++++++++++++++ 6 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 core/src/mindustry/world/blocks/logic/ProcessorBlock.java diff --git a/core/src/mindustry/editor/EditorTile.java b/core/src/mindustry/editor/EditorTile.java index d15a710f64..b53e951e75 100644 --- a/core/src/mindustry/editor/EditorTile.java +++ b/core/src/mindustry/editor/EditorTile.java @@ -41,20 +41,6 @@ public class EditorTile extends Tile{ super.setFloor(type); } - @Override - public void setBlock(Block type){ - if(state.is(State.playing)){ - super.setBlock(type); - return; - } - - if(block == type) return; - op(OpType.block, block.id); - if(rotation != 0) op(OpType.rotation, rotation); - if(team() != Team.derelict) op(OpType.team, team().id); - super.setBlock(type); - } - @Override public void setBlock(Block type, Team team, int rotation){ if(state.is(State.playing)){ @@ -62,9 +48,10 @@ public class EditorTile extends Tile{ return; } - setBlock(type); - setTeam(team); - rotation(rotation); + op(OpType.block, block.id); + if(rotation != 0) op(OpType.rotation, (byte)rotation); + if(team() != Team.derelict) op(OpType.team, team().id); + super.setBlock(type, team, rotation); } @Override @@ -93,20 +80,15 @@ public class EditorTile extends Tile{ @Override public void setOverlay(Block overlay){ - setOverlayID(overlay.id); - } - - @Override - public void setOverlayID(short overlay){ if(state.is(State.playing)){ - super.setOverlayID(overlay); + super.setOverlay(overlay); return; } if(floor.isLiquid) return; - if(overlayID() == overlay) return; + if(overlay() == overlay) return; op(OpType.overlay, this.overlay.id); - super.setOverlayID(overlay); + super.setOverlay(overlay); } @Override diff --git a/core/src/mindustry/entities/def/TileComp.java b/core/src/mindustry/entities/def/TileComp.java index 3a757281ed..4ae1b85ab0 100644 --- a/core/src/mindustry/entities/def/TileComp.java +++ b/core/src/mindustry/entities/def/TileComp.java @@ -421,10 +421,8 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{ for(int i = 0; i < proximity.size; i++){ incrementDump(proximity.size); Tilec other = proximity.get((i + dump) % proximity.size); - //TODO fix position - Tilec in = Edges.getFacingEdge(tile(), other.tile()).entity; - if(other.team() == team() && other.acceptItem(in, item) && canDump(other, item)){ - other.handleItem(in, item); + if(other.team() == team() && other.acceptItem(this, item) && canDump(other, item)){ + other.handleItem(this, item); return; } } @@ -451,24 +449,22 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{ for(int i = 0; i < proximity.size; i++){ Tilec other = proximity.get((i + dump) % proximity.size); - //TODO fix position - Tilec in = Edges.getFacingEdge(tile, other.tile()).entity; if(todump == null){ for(int ii = 0; ii < content.items().size; ii++){ Item item = content.item(ii); - if(other.team() == team() && items.has(item) && other.acceptItem(in, item) && canDump(other, item)){ - other.handleItem(in, item); + if(other.team() == team() && items.has(item) && other.acceptItem(this, item) && canDump(other, item)){ + other.handleItem(this, item); items.remove(item, 1); incrementDump(proximity.size); return true; } } }else{ - if(other.team() == team() && other.acceptItem(in, todump) && canDump(other, todump)){ - other.handleItem(in, todump); + if(other.team() == team() && other.acceptItem(this, todump) && canDump(other, todump)){ + other.handleItem(this, todump); items.remove(todump, 1); incrementDump(proximity.size); return true; @@ -798,10 +794,10 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{ /** * Called when another tile is tapped while this block is selected. - * Returns whether or not this block should be deselected. + * @return whether or not this block should be deselected. */ public boolean onConfigureTileTapped(Tilec other){ - return tile != other; + return this != other; } /** Returns whether this config menu should show when the specified player taps it. */ diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 5302f76f0a..204f81b257 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -570,6 +570,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ boolean tileTapped(@Nullable Tilec tile){ if(tile == null){ frag.inv.hide(); + frag.config.hideConfig(); return false; } boolean consumed = false, showedInventory = false; diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index 0fcf35e39d..d1f0262721 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -497,6 +497,10 @@ public class Tile implements Position{ other.entity = null; } other.block = Blocks.air; + + //manually call changed event + other.updateOcclusion(); + world.notifyChanged(other); } } } diff --git a/core/src/mindustry/world/blocks/defense/turrets/BurstTurret.java b/core/src/mindustry/world/blocks/defense/turrets/BurstTurret.java index 103287c712..ab2ade3693 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/BurstTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/BurstTurret.java @@ -21,8 +21,7 @@ public class BurstTurret extends ItemTurret{ for(int i = 0; i < shots; i++){ Time.run(burstSpacing * i, () -> { - if(!(tile.entity instanceof TurretEntity) || - !hasAmmo()) return; + if(!(tile.entity instanceof TurretEntity) || !hasAmmo()) return; recoil = recoilAmount; diff --git a/core/src/mindustry/world/blocks/logic/ProcessorBlock.java b/core/src/mindustry/world/blocks/logic/ProcessorBlock.java new file mode 100644 index 0000000000..e1b4834c58 --- /dev/null +++ b/core/src/mindustry/world/blocks/logic/ProcessorBlock.java @@ -0,0 +1,37 @@ +package mindustry.world.blocks.logic; + +import arc.scene.ui.layout.*; +import arc.struct.*; +import mindustry.gen.*; +import mindustry.world.*; + +public class ProcessorBlock extends Block{ + + public ProcessorBlock(String name){ + super(name); + configurable = true; + } + + public class ProcessorEntity extends TileEntity{ + //all tiles in the block network - does not include itself + Array network = new Array<>(); + + @Override + public boolean onConfigureTileTapped(Tilec other){ + if(other == this) return true; + + if(!network.contains(other)){ + network.add(other); + }else{ + network.remove(other); + } + return false; + } + + @Override + public void buildConfiguration(Table table){ + super.buildConfiguration(table); + } + } + +}