diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c79ce649fc..fe38a3a925 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,20 +40,20 @@ In general, if you are using IntelliJ, you should be warned about platform incom #### Use `arc` collections and classes when possible. -Instead of using `java.util.List`, `java.util.HashMap`, and other standard Java collections, use `Array`, `ObjectMap` and other equivalents from `arc.struct`. +Instead of using `java.util.List`, `java.util.HashMap`, and other standard Java collections, use `Seq`, `ObjectMap` and other equivalents from `arc.struct`. Why? Because that's what the rest of the codebase uses, and the standard collections have a lot of cruft and usability issues associated with them. In the rare case that concurrency is required, you may use the standard Java classes for that purpose (e.g. `CopyOnWriteArrayList`). What you'll usually need to change: - `HashSet` -> `ObjectSet` - `HashMap` -> `ObjectMap` -- `List` / `ArrayList` / `Stack` -> `Array` +- `List` / `ArrayList` / `Stack` -> `Seq` - `java.util.Queue` -> `arc.struct.Queue` - *Many others* #### Avoid boxed types (Integer, Boolean) -Never create variables or collections with boxed types `Array` or `ObjectMap`. Use the collections specialized for this task, e.g. `IntArray` and `IntMap`. +Never create variables or collections with boxed types `Seq` or `ObjectMap`. Use the collections specialized for this task, e.g. `IntSeq` and `IntMap`. #### Do not allocate anything if possible. diff --git a/core/src/mindustry/world/blocks/distribution/Conveyor.java b/core/src/mindustry/world/blocks/distribution/Conveyor.java index f38b0d99f7..b0658fd02d 100644 --- a/core/src/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/mindustry/world/blocks/distribution/Conveyor.java @@ -94,24 +94,24 @@ public class Conveyor extends Block implements Autotiler{ public class ConveyorEntity extends Building{ //parallel array data - Item[] ids = new Item[capacity]; - float[] xs = new float[capacity]; - float[] ys = new float[capacity]; + public Item[] ids = new Item[capacity]; + public float[] xs = new float[capacity]; + public float[] ys = new float[capacity]; //amount of items, always < capacity - int len = 0; + public int len = 0; //next entity - @Nullable Building next; - @Nullable ConveyorEntity nextc; + public @Nullable Building next; + public @Nullable ConveyorEntity nextc; //whether the next conveyor's rotation == tile rotation - boolean aligned; + public boolean aligned; - int lastInserted, mid; - float minitem = 1; + public int lastInserted, mid; + public float minitem = 1; - int blendbits, blending; - int blendsclx, blendscly; + public int blendbits, blending; + public int blendsclx, blendscly; - float clogHeat = 0f; + public float clogHeat = 0f; @Override public void draw(){ @@ -350,7 +350,7 @@ public class Conveyor extends Block implements Autotiler{ } - final void add(int o){ + public final void add(int o){ for(int i = Math.max(o + 1, len); i > o; i--){ ids[i] = ids[i - 1]; xs[i] = xs[i - 1]; @@ -360,7 +360,7 @@ public class Conveyor extends Block implements Autotiler{ len++; } - final void remove(int o){ + public final void remove(int o){ for(int i = o; i < len - 1; i++){ ids[i] = ids[i + 1]; xs[i] = xs[i + 1]; diff --git a/core/src/mindustry/world/blocks/distribution/ExtendingItemBridge.java b/core/src/mindustry/world/blocks/distribution/ExtendingItemBridge.java index a4786217b3..a1ace75eb0 100644 --- a/core/src/mindustry/world/blocks/distribution/ExtendingItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ExtendingItemBridge.java @@ -15,7 +15,7 @@ public class ExtendingItemBridge extends ItemBridge{ super(name); hasItems = true; } - + public class ExtendingItemBridgeEntity extends ItemBridgeEntity{ @Override public void draw(){ diff --git a/core/src/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/mindustry/world/blocks/distribution/ItemBridge.java index 3491f5b3ea..9c926c3450 100644 --- a/core/src/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ItemBridge.java @@ -357,7 +357,7 @@ public class ItemBridge extends Block{ return liquids.get(liquid) + amount < liquidCapacity && (liquids.current() == liquid || liquids.get(liquids.current()) < 0.2f); } - private boolean linked(Building source){ + protected boolean linked(Building source){ return source instanceof ItemBridgeEntity && linkValid(source.tile(), tile) && ((ItemBridgeEntity)source).link == pos(); } diff --git a/core/src/mindustry/world/blocks/distribution/Junction.java b/core/src/mindustry/world/blocks/distribution/Junction.java index 4c497d1634..cf4d7012b0 100644 --- a/core/src/mindustry/world/blocks/distribution/Junction.java +++ b/core/src/mindustry/world/blocks/distribution/Junction.java @@ -27,7 +27,7 @@ public class Junction extends Block{ } public class JunctionEntity extends Building{ - DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity); + public DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity); @Override public int acceptStack(Item item, int amount, Teamc source){ diff --git a/core/src/mindustry/world/blocks/distribution/MassDriver.java b/core/src/mindustry/world/blocks/distribution/MassDriver.java index b61f57f741..1248dab005 100644 --- a/core/src/mindustry/world/blocks/distribution/MassDriver.java +++ b/core/src/mindustry/world/blocks/distribution/MassDriver.java @@ -86,13 +86,13 @@ public class MassDriver extends Block{ } public class MassDriverEntity extends Building{ - int link = -1; - float rotation = 90; - float reload = 0f; - DriverState state = DriverState.idle; - OrderedSet waitingShooters = new OrderedSet<>(); + public int link = -1; + public float rotation = 90; + public float reload = 0f; + public DriverState state = DriverState.idle; + public OrderedSet waitingShooters = new OrderedSet<>(); - Tile currentShooter(){ + public Tile currentShooter(){ return waitingShooters.isEmpty() ? null : waitingShooters.first(); } @@ -322,7 +322,7 @@ public class MassDriver extends Block{ } } - enum DriverState{ + public enum DriverState{ idle, //nothing is shooting at this mass driver and it does not have any target accepting, //currently getting shot at, unload items shooting, diff --git a/core/src/mindustry/world/blocks/distribution/OverflowGate.java b/core/src/mindustry/world/blocks/distribution/OverflowGate.java index 01462261f6..58103915be 100644 --- a/core/src/mindustry/world/blocks/distribution/OverflowGate.java +++ b/core/src/mindustry/world/blocks/distribution/OverflowGate.java @@ -31,9 +31,9 @@ public class OverflowGate extends Block{ } public class OverflowGateEntity extends Building{ - Item lastItem; - Tile lastInput; - float time; + public Item lastItem; + public Tile lastInput; + public float time; @Override public int acceptStack(Item item, int amount, Teamc source){ diff --git a/core/src/mindustry/world/blocks/distribution/PayloadConveyor.java b/core/src/mindustry/world/blocks/distribution/PayloadConveyor.java index c19e53efb5..72dc5c7050 100644 --- a/core/src/mindustry/world/blocks/distribution/PayloadConveyor.java +++ b/core/src/mindustry/world/blocks/distribution/PayloadConveyor.java @@ -136,7 +136,7 @@ public class PayloadConveyor extends Block{ super.draw(); } - @Override + @Override public void draw(){ super.draw(); @@ -241,15 +241,14 @@ public class PayloadConveyor extends Block{ } } - boolean blends(int direction){ + protected boolean blends(int direction){ if(direction == rotation){ return !blocked || next != null; - }else{ - return PayloadAcceptor.blends(this, direction); } + return PayloadAcceptor.blends(this, direction); } - TextureRegion clipRegion(Rect bounds, Rect sprite, TextureRegion region){ + protected TextureRegion clipRegion(Rect bounds, Rect sprite, TextureRegion region){ Rect over = Tmp.r3; boolean overlaps = Intersector.intersectRectangles(bounds, sprite, over); @@ -273,11 +272,11 @@ public class PayloadConveyor extends Block{ return out; } - int curStep(){ + public int curStep(){ return (int)((Time.time()) / moveTime); } - float fract(){ + public float fract(){ return interp.apply(progress / moveTime); } } diff --git a/core/src/mindustry/world/blocks/distribution/Router.java b/core/src/mindustry/world/blocks/distribution/Router.java index 2c8c1012f1..15bd106169 100644 --- a/core/src/mindustry/world/blocks/distribution/Router.java +++ b/core/src/mindustry/world/blocks/distribution/Router.java @@ -20,9 +20,9 @@ public class Router extends Block{ } public class RouterEntity extends Building{ - Item lastItem; - Tile lastInput; - float time; + public Item lastItem; + public Tile lastInput; + public float time; @Override public void updateTile(){ @@ -70,7 +70,7 @@ public class Router extends Block{ return result; } - Building getTileTarget(Item item, Tile from, boolean set){ + public Building getTileTarget(Item item, Tile from, boolean set){ int counter = rotation; for(int i = 0; i < proximity.size; i++){ Building other = proximity.get((i + counter) % proximity.size); diff --git a/core/src/mindustry/world/blocks/distribution/Sorter.java b/core/src/mindustry/world/blocks/distribution/Sorter.java index 5596a87fef..f080f67f8c 100644 --- a/core/src/mindustry/world/blocks/distribution/Sorter.java +++ b/core/src/mindustry/world/blocks/distribution/Sorter.java @@ -48,7 +48,7 @@ public class Sorter extends Block{ } public class SorterEntity extends Building{ - @Nullable Item sortItem; + public @Nullable Item sortItem; @Override public void configured(Player player, Object value){ @@ -86,12 +86,12 @@ public class Sorter extends Block{ to.handleItem(this, item); } - boolean isSame(Building other){ - //uncomment code below to prevent sorter/gate chaining + public boolean isSame(Building other){ + // comment code below to allow sorter/gate chaining return other != null && (other.block() instanceof Sorter || other.block() instanceof OverflowGate); } - Building getTileTarget(Item item, Building source, boolean flip){ + public Building getTileTarget(Item item, Building source, boolean flip){ int dir = source.relativeTo(tile.x, tile.y); if(dir == -1) return null; Building to; diff --git a/core/src/mindustry/world/blocks/distribution/StackConveyor.java b/core/src/mindustry/world/blocks/distribution/StackConveyor.java index 6526f973a5..06d5bc7cff 100644 --- a/core/src/mindustry/world/blocks/distribution/StackConveyor.java +++ b/core/src/mindustry/world/blocks/distribution/StackConveyor.java @@ -147,7 +147,7 @@ public class StackConveyor extends Block implements Autotiler{ int[] bits = buildBlending(tile, rotation, null, true); if(bits[0] == 0 && blends(tile, rotation, 0) && !blends(tile, rotation, 2)) state = stateLoad; // a 0 that faces into a conveyor with none behind it if(bits[0] == 0 && !blends(tile, rotation, 0) && blends(tile, rotation, 2)) state = stateUnload; // a 0 that faces into none with a conveyor behind it - + blendprox = 0; for(int i = 0; i < 4; i++){ @@ -219,12 +219,12 @@ public class StackConveyor extends Block implements Autotiler{ return false; // has no moving parts; } - private void poofIn(){ + protected void poofIn(){ link = tile.pos(); Fx.plasticburn.at(this); } - private void poofOut(){ + protected void poofOut(){ Fx.plasticburn.at(this); link = -1; }