From a942ed2cad745de978abb71067279ef1f390105e Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 3 Feb 2020 20:24:49 -0500 Subject: [PATCH] More cleanup --- .../mindustry/annotations/Annotations.java | 7 + .../mindustry/annotations/BaseProcessor.java | 2 +- .../annotations/impl/EntityProcess.java | 13 +- .../java/main/mindustry/gen/Call.java | 1145 +++++++++++++++++ core/src/mindustry/Vars.java | 34 - core/src/mindustry/ai/BlockIndexer.java | 29 +- core/src/mindustry/ai/WaveSpawner.java | 6 +- core/src/mindustry/content/Blocks.java | 9 +- core/src/mindustry/content/Bullets.java | 23 +- core/src/mindustry/core/Control.java | 11 +- core/src/mindustry/core/Logic.java | 22 +- core/src/mindustry/core/NetClient.java | 2 +- core/src/mindustry/core/NetServer.java | 5 +- core/src/mindustry/core/Renderer.java | 10 +- core/src/mindustry/editor/EditorTile.java | 6 +- core/src/mindustry/entities/Damage.java | 4 +- core/src/mindustry/entities/Effect.java | 4 + core/src/mindustry/entities/Entities.java | 33 - .../mindustry/entities/EntityCollisions.java | 66 +- core/src/mindustry/entities/EntityGroup.java | 178 +-- core/src/mindustry/entities/Predict.java | 2 +- core/src/mindustry/entities/Units.java | 42 +- .../entities/bullet/ArtilleryBulletType.java | 5 +- .../entities/bullet/BasicBulletType.java | 4 +- .../mindustry/entities/bullet/BulletType.java | 96 +- .../entities/bullet/FlakBulletType.java | 4 +- .../entities/bullet/HealBulletType.java | 8 +- .../entities/bullet/LaserBulletType.java | 6 +- .../entities/bullet/LightningBulletType.java | 6 +- .../entities/bullet/LiquidBulletType.java | 9 +- .../entities/bullet/MassDriverBolt.java | 10 +- .../entities/bullet/MissileBulletType.java | 3 +- .../mindustry/entities/def/EntityComps.java | 417 +++--- .../mindustry/entities/def/EntityDefs.java | 3 + .../entities/def/EntityGroupDefs.java | 4 + core/src/mindustry/entities/effect/Fire.java | 4 +- .../entities/effect/GroundEffectEntity.java | 2 +- .../entities/effect/ItemTransfer.java | 4 +- .../mindustry/entities/effect/Lightning.java | 1 - .../src/mindustry/entities/type/BaseUnit.java | 350 ----- core/src/mindustry/entities/type/Bullet.java | 322 ----- core/src/mindustry/entities/type/Player.java | 12 +- .../type/{TileEntity.java => Tilec.java} | 10 +- .../entities/type/base/BuilderDrone.java | 4 +- .../entities/type/base/GroundUnit.java | 5 +- .../entities/type/base/MinerDrone.java | 10 +- .../entities/type/base/RepairDrone.java | 6 +- .../mindustry/entities/units/UnitDrops.java | 5 +- core/src/mindustry/game/Saves.java | 2 +- core/src/mindustry/game/SpawnGroup.java | 1 - core/src/mindustry/game/Teams.java | 4 +- core/src/mindustry/game/Tutorial.java | 4 +- .../src/mindustry/graphics/BlockRenderer.java | 2 +- core/src/mindustry/input/InputHandler.java | 4 +- core/src/mindustry/input/MobileInput.java | 11 +- core/src/mindustry/io/TypeIO.java | 3 +- .../io/versions/LegacyTypeTable.java | 1 - .../maps/generators/MapGenerator.java | 2 +- core/src/mindustry/net/Administration.java | 2 +- core/src/mindustry/type/Weapon.java | 9 - core/src/mindustry/ui/dialogs/JoinDialog.java | 2 +- .../ui/fragments/BlockInventoryFragment.java | 14 +- .../ui/fragments/PlacementFragment.java | 6 +- core/src/mindustry/world/Block.java | 87 +- core/src/mindustry/world/BlockStorage.java | 60 +- core/src/mindustry/world/CachedTile.java | 4 +- core/src/mindustry/world/Tile.java | 40 +- core/src/mindustry/world/TileData.java | 4 + .../mindustry/world/blocks/BuildBlock.java | 7 +- .../mindustry/world/blocks/LiquidBlock.java | 2 +- .../world/blocks/defense/DeflectorWall.java | 10 +- .../mindustry/world/blocks/defense/Door.java | 6 +- .../world/blocks/defense/ForceProjector.java | 8 +- .../world/blocks/defense/MendProjector.java | 10 +- .../blocks/defense/OverdriveProjector.java | 10 +- .../world/blocks/defense/ShockMine.java | 2 +- .../world/blocks/defense/SurgeWall.java | 5 +- .../defense/turrets/ArtilleryTurret.java | 1 - .../blocks/defense/turrets/CooledTurret.java | 8 +- .../blocks/defense/turrets/ItemTurret.java | 2 +- .../blocks/defense/turrets/LaserTurret.java | 8 +- .../blocks/defense/turrets/LiquidTurret.java | 28 +- .../blocks/defense/turrets/PowerTurret.java | 2 +- .../world/blocks/defense/turrets/Turret.java | 11 +- .../distribution/BufferedItemBridge.java | 6 +- .../world/blocks/distribution/Conveyor.java | 6 +- .../world/blocks/distribution/ItemBridge.java | 16 +- .../world/blocks/distribution/Junction.java | 4 +- .../world/blocks/distribution/MassDriver.java | 25 +- .../blocks/distribution/OverflowGate.java | 14 +- .../world/blocks/distribution/Router.java | 14 +- .../world/blocks/distribution/Sorter.java | 2 +- .../world/blocks/liquid/Conduit.java | 12 +- .../world/blocks/liquid/LiquidBridge.java | 6 +- .../blocks/liquid/LiquidExtendingBridge.java | 6 +- .../world/blocks/liquid/LiquidRouter.java | 6 +- .../world/blocks/logic/MessageBlock.java | 3 +- .../blocks/power/ConditionalConsumePower.java | 8 +- .../world/blocks/power/ImpactReactor.java | 6 +- .../blocks/power/ItemLiquidGenerator.java | 20 +- .../world/blocks/power/LightBlock.java | 3 +- .../world/blocks/power/NuclearReactor.java | 16 +- .../world/blocks/power/PowerDiode.java | 6 +- .../world/blocks/power/PowerGenerator.java | 4 +- .../world/blocks/power/PowerGraph.java | 28 +- .../world/blocks/power/PowerNode.java | 62 +- .../world/blocks/production/Cultivator.java | 4 +- .../world/blocks/production/Drill.java | 22 +- .../world/blocks/production/Fracker.java | 10 +- .../blocks/production/GenericCrafter.java | 19 +- .../world/blocks/production/Incinerator.java | 9 +- .../blocks/production/LiquidConverter.java | 10 +- .../world/blocks/production/Pump.java | 16 +- .../world/blocks/production/Separator.java | 14 +- .../world/blocks/production/SolidPump.java | 19 +- .../world/blocks/sandbox/ItemSource.java | 6 +- .../world/blocks/sandbox/LiquidSource.java | 7 +- .../world/blocks/storage/CoreBlock.java | 27 +- .../world/blocks/storage/LaunchPad.java | 17 +- .../world/blocks/storage/StorageBlock.java | 20 +- .../world/blocks/storage/Unloader.java | 26 +- .../world/blocks/units/CommandCenter.java | 3 +- .../mindustry/world/blocks/units/MechPad.java | 9 +- .../world/blocks/units/RepairPoint.java | 8 +- .../world/blocks/units/UnitFactory.java | 6 +- .../mindustry/world/consumers/Consume.java | 8 +- .../world/consumers/ConsumeItemFilter.java | 14 +- .../world/consumers/ConsumeItems.java | 12 +- .../world/consumers/ConsumeLiquid.java | 8 +- .../world/consumers/ConsumeLiquidBase.java | 4 +- .../world/consumers/ConsumeLiquidFilter.java | 12 +- .../world/consumers/ConsumePower.java | 18 +- .../mindustry/world/consumers/Consumers.java | 4 +- core/src/mindustry/world/meta/BlockBars.java | 8 +- .../world/modules/ConsumeModule.java | 6 +- .../src/mindustry/desktop/steam/SStats.java | 4 +- tests/src/test/java/ApplicationTests.java | 24 +- .../test/java/power/DirectConsumerTests.java | 6 +- .../java/power/ItemLiquidGeneratorTests.java | 10 +- .../src/test/java/power/PowerTestFixture.java | 12 +- tests/src/test/java/power/PowerTests.java | 12 +- 141 files changed, 2213 insertions(+), 1819 deletions(-) create mode 100644 core/build/generated/sources/annotationProcessor/java/main/mindustry/gen/Call.java delete mode 100755 core/src/mindustry/entities/Entities.java create mode 100644 core/src/mindustry/entities/def/EntityGroupDefs.java delete mode 100644 core/src/mindustry/entities/type/BaseUnit.java delete mode 100644 core/src/mindustry/entities/type/Bullet.java rename core/src/mindustry/entities/type/{TileEntity.java => Tilec.java} (97%) create mode 100644 core/src/mindustry/world/TileData.java diff --git a/annotations/src/main/java/mindustry/annotations/Annotations.java b/annotations/src/main/java/mindustry/annotations/Annotations.java index d16495cb78..79d88c068a 100644 --- a/annotations/src/main/java/mindustry/annotations/Annotations.java +++ b/annotations/src/main/java/mindustry/annotations/Annotations.java @@ -24,6 +24,13 @@ public class Annotations{ public @interface BaseComponent{ } + /** Creates a group that only examines entities that have all the components listed. */ + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.SOURCE) + public @interface GroupDef{ + Class[] value(); + } + /** Indicates an entity definition. */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.SOURCE) diff --git a/annotations/src/main/java/mindustry/annotations/BaseProcessor.java b/annotations/src/main/java/mindustry/annotations/BaseProcessor.java index 57d3be2d9c..db998ea889 100644 --- a/annotations/src/main/java/mindustry/annotations/BaseProcessor.java +++ b/annotations/src/main/java/mindustry/annotations/BaseProcessor.java @@ -116,7 +116,7 @@ public abstract class BaseProcessor extends AbstractProcessor{ this.env = roundEnv; try{ process(roundEnv); - }catch(Exception e){ + }catch(Throwable e){ e.printStackTrace(); throw new RuntimeException(e); } diff --git a/annotations/src/main/java/mindustry/annotations/impl/EntityProcess.java b/annotations/src/main/java/mindustry/annotations/impl/EntityProcess.java index 42b52d7eab..b4b89b22c7 100644 --- a/annotations/src/main/java/mindustry/annotations/impl/EntityProcess.java +++ b/annotations/src/main/java/mindustry/annotations/impl/EntityProcess.java @@ -50,6 +50,7 @@ public class EntityProcess extends BaseProcessor{ //create component interfaces for(Stype component : allComponents){ + Log.info("&yGenerating interface for " + component); TypeSpec.Builder inter = TypeSpec.interfaceBuilder(interfaceName(component)).addModifiers(Modifier.PUBLIC).addAnnotation(EntityInterface.class); //implement extra interfaces these components may have, e.g. position @@ -66,7 +67,7 @@ public class EntityProcess extends BaseProcessor{ for(Svar field : component.fields().select(e -> !e.is(Modifier.STATIC) && !e.is(Modifier.PRIVATE) && !e.is(Modifier.TRANSIENT))){ String cname = Strings.capitalize(field.name()); //getter - inter.addMethod(MethodSpec.methodBuilder("get" + cname).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).returns(field.tname()).build()); + inter.addMethod(MethodSpec.methodBuilder((field.mirror().toString().equals("boolean") ? "is" : "get") + cname).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).returns(field.tname()).build()); //setter if(!field.is(Modifier.FINAL)) inter.addMethod(MethodSpec.methodBuilder("set" + cname).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).addParameter(field.tname(), field.name()).build()); } @@ -144,7 +145,7 @@ public class EntityProcess extends BaseProcessor{ boolean writeBlock = first.ret().toString().equals("void") && entry.value.size > 1; if((entry.value.first().is(Modifier.ABSTRACT) || entry.value.first().is(Modifier.NATIVE)) && entry.value.size == 1){ - err(entry.value.first().up().getSimpleName() + " declares an abstract method. This method must be implemented in another component", entry.value.first()); + err(entry.value.first().up().getSimpleName() + "#" + entry.value.first() + " is an abstract method and must be implemented in some component", type); } for(Smethod elem : entry.value){ @@ -208,11 +209,11 @@ public class EntityProcess extends BaseProcessor{ for(Smethod method : inter.methods()){ if(method.name().length() <= 3) continue; - String var = Strings.camelize(method.name().substring(3)); + String var = Strings.camelize(method.name().substring(method.name().startsWith("is") ? 2 : 3)); //make sure it's a real variable if(!Array.with(def.builder.fieldSpecs).contains(f -> f.name.equals(var))) continue; - if(method.name().startsWith("get")){ + if(method.name().startsWith("get") || method.name().startsWith("is")){ def.builder.addMethod(MethodSpec.overriding(method.e).addStatement("return " + var).build()); }else if(method.name().startsWith("set")){ def.builder.addMethod(MethodSpec.overriding(method.e).addStatement("this." + var + " = " + var).build()); @@ -261,6 +262,8 @@ public class EntityProcess extends BaseProcessor{ ObjectSet out = new ObjectSet<>(); //add base component interfaces out.addAll(component.interfaces().select(this::isCompInterface).map(this::interfaceToComp)); + //remove self interface + out.remove(component); //out now contains the base dependencies; finish constructing the tree ObjectSet result = new ObjectSet<>(); @@ -273,6 +276,8 @@ public class EntityProcess extends BaseProcessor{ result.addAll(baseComponents); } + //remove it again just in case + out.remove(component); componentDependencies.put(component, result.asArray()); } diff --git a/core/build/generated/sources/annotationProcessor/java/main/mindustry/gen/Call.java b/core/build/generated/sources/annotationProcessor/java/main/mindustry/gen/Call.java new file mode 100644 index 0000000000..6ac4f59eff --- /dev/null +++ b/core/build/generated/sources/annotationProcessor/java/main/mindustry/gen/Call.java @@ -0,0 +1,1145 @@ +package mindustry.gen; + +import arc.graphics.Color; +import java.lang.String; +import java.nio.ByteBuffer; +import mindustry.entities.bullet.BulletType; +import mindustry.entities.type.Player; +import mindustry.entities.units.BuildRequest; +import mindustry.game.Rules; +import mindustry.game.Team; +import mindustry.net.Administration; +import mindustry.net.NetConnection; +import mindustry.net.Packets; +import mindustry.type.Item; +import mindustry.world.Block; +import mindustry.world.Tile; + +/** + * Autogenerated file. Do not modify! + */ +public class Call { + private static final ByteBuffer TEMP_BUFFER = ByteBuffer.allocate(4096); + + public static synchronized void beginBreak(Team team, int x, int y) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.Build.beginBreak(team, x, y); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)0; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, team); + TEMP_BUFFER.putInt(x); + TEMP_BUFFER.putInt(y); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void beginPlace(Team team, int x, int y, Block result, int rotation) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.Build.beginPlace(team, x, y, result, rotation); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)1; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, team); + TEMP_BUFFER.putInt(x); + TEMP_BUFFER.putInt(y); + mindustry.io.TypeIO.writeBlock(TEMP_BUFFER, result); + TEMP_BUFFER.putInt(rotation); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void connectConfirm() { + if(mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)2; + TEMP_BUFFER.position(0); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void createBullet(BulletType type, Team team, float x, float y, + float angle, float velocityScl, float lifetimeScl) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.entities.bullet.BulletType.createBullet(type, team, x, y, angle, velocityScl, lifetimeScl); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)3; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeBulletType(TEMP_BUFFER, type); + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, team); + TEMP_BUFFER.putFloat(x); + TEMP_BUFFER.putFloat(y); + TEMP_BUFFER.putFloat(angle); + TEMP_BUFFER.putFloat(velocityScl); + TEMP_BUFFER.putFloat(lifetimeScl); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void createLighting(int seed, Team team, Color color, float damage, + float x, float y, float rotation, int length) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.entities.effect.Lightning.createLighting(seed, team, color, damage, x, y, rotation, length); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)4; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putInt(seed); + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, team); + mindustry.io.TypeIO.writeColor(TEMP_BUFFER, color); + TEMP_BUFFER.putFloat(damage); + TEMP_BUFFER.putFloat(x); + TEMP_BUFFER.putFloat(y); + TEMP_BUFFER.putFloat(rotation); + TEMP_BUFFER.putInt(length); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void dropItem(float angle) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.input.InputHandler.dropItem(mindustry.Vars.player, angle); + } + if(mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)5; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putFloat(angle); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void launchZone() { + mindustry.core.Logic.launchZone(); + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)6; + TEMP_BUFFER.position(0); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onAdminRequest(Player other, Packets.AdminAction action) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.core.NetServer.onAdminRequest(mindustry.Vars.player, other, action); + } + if(mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)7; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, other); + mindustry.io.TypeIO.writeAction(TEMP_BUFFER, action); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onBlockSnapshot(short amount, short dataLen, byte[] data) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)2; + packet.type = (byte)8; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putShort(amount); + TEMP_BUFFER.putShort(dataLen); + mindustry.io.TypeIO.writeBytes(TEMP_BUFFER, data); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void onBlockSnapshot(NetConnection playerConnection, short amount, + short dataLen, byte[] data) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)2; + packet.type = (byte)8; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putShort(amount); + TEMP_BUFFER.putShort(dataLen); + mindustry.io.TypeIO.writeBytes(TEMP_BUFFER, data); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void onClientShapshot(int snapshotID, float x, float y, float pointerX, + float pointerY, float rotation, float baseRotation, float xVelocity, float yVelocity, + Tile mining, boolean boosting, boolean shooting, boolean chatting, boolean building, + BuildRequest[] requests, float viewX, float viewY, float viewWidth, float viewHeight) { + if(mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)9; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putInt(snapshotID); + TEMP_BUFFER.putFloat(x); + TEMP_BUFFER.putFloat(y); + TEMP_BUFFER.putFloat(pointerX); + TEMP_BUFFER.putFloat(pointerY); + TEMP_BUFFER.putFloat(rotation); + TEMP_BUFFER.putFloat(baseRotation); + TEMP_BUFFER.putFloat(xVelocity); + TEMP_BUFFER.putFloat(yVelocity); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, mining); + TEMP_BUFFER.put(boosting ? (byte)1 : 0); + TEMP_BUFFER.put(shooting ? (byte)1 : 0); + TEMP_BUFFER.put(chatting ? (byte)1 : 0); + TEMP_BUFFER.put(building ? (byte)1 : 0); + mindustry.io.TypeIO.writeRequests(TEMP_BUFFER, requests); + TEMP_BUFFER.putFloat(viewX); + TEMP_BUFFER.putFloat(viewY); + TEMP_BUFFER.putFloat(viewWidth); + TEMP_BUFFER.putFloat(viewHeight); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void onConnect(NetConnection playerConnection, String ip, int port) { + if(mindustry.Vars.net.client() || !mindustry.Vars.net.active()) { + mindustry.core.NetClient.onConnect(ip, port); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)10; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, ip); + TEMP_BUFFER.putInt(port); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onConstructFinish(Tile tile, Block block, int builderID, + byte rotation, Team team, boolean skipConfig) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.blocks.BuildBlock.onConstructFinish(tile, block, builderID, rotation, team, skipConfig); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)11; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + mindustry.io.TypeIO.writeBlock(TEMP_BUFFER, block); + TEMP_BUFFER.putInt(builderID); + TEMP_BUFFER.put(rotation); + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, team); + TEMP_BUFFER.put(skipConfig ? (byte)1 : 0); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onDeconstructFinish(Tile tile, Block block, int builderID) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.blocks.BuildBlock.onDeconstructFinish(tile, block, builderID); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)12; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + mindustry.io.TypeIO.writeBlock(TEMP_BUFFER, block); + TEMP_BUFFER.putInt(builderID); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onDoorToggle(Player player, Tile tile, boolean open) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.blocks.defense.Door.onDoorToggle(player, tile, open); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)13; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + TEMP_BUFFER.put(open ? (byte)1 : 0); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onEntitySnapshot(NetConnection playerConnection, byte groupID, + short amount, short dataLen, byte[] data) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)2; + packet.type = (byte)14; + TEMP_BUFFER.position(0); + TEMP_BUFFER.put(groupID); + TEMP_BUFFER.putShort(amount); + TEMP_BUFFER.putShort(dataLen); + mindustry.io.TypeIO.writeBytes(TEMP_BUFFER, data); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void onGameOver(Team winner) { + mindustry.core.Logic.onGameOver(winner); + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)15; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, winner); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onInfoMessage(String message) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)16; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, message); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onInfoMessage(NetConnection playerConnection, String message) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)16; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, message); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onInfoToast(String message, float duration) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)17; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, message); + TEMP_BUFFER.putFloat(duration); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onInfoToast(NetConnection playerConnection, String message, + float duration) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)17; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, message); + TEMP_BUFFER.putFloat(duration); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onKick(NetConnection playerConnection, String reason) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)1; + packet.type = (byte)18; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, reason); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onKick(NetConnection playerConnection, + Packets.KickReason reason) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)1; + packet.type = (byte)19; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeKick(TEMP_BUFFER, reason); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onMechFactoryDone(Tile tile) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.blocks.units.MechPad.onMechFactoryDone(tile); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)20; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onMechFactoryTap(Player player, Tile tile) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.blocks.units.MechPad.onMechFactoryTap(player, tile); + } + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)21; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onPing(long time) { + if(mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)22; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putLong(time); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onPingResponse(NetConnection playerConnection, long time) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)23; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putLong(time); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onPlayerDeath(Player player) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.entities.type.Player.onPlayerDeath(player); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)24; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onPlayerDisconnect(int playerid) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)25; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putInt(playerid); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onPositionSet(NetConnection playerConnection, float x, float y) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)26; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putFloat(x); + TEMP_BUFFER.putFloat(y); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onPuddleRemoved(int puddleid) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.entities.effect.Puddle.onPuddleRemoved(puddleid); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)27; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putInt(puddleid); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onRemoveFire(int fid) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)28; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putInt(fid); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onSetRules(Rules rules) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)29; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeRules(TEMP_BUFFER, rules); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onSetRules(NetConnection playerConnection, Rules rules) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)29; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeRules(TEMP_BUFFER, rules); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onStateSnapshot(NetConnection playerConnection, float waveTime, + int wave, int enemies, short coreDataLen, byte[] coreData) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)2; + packet.type = (byte)30; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putFloat(waveTime); + TEMP_BUFFER.putInt(wave); + TEMP_BUFFER.putInt(enemies); + TEMP_BUFFER.putShort(coreDataLen); + mindustry.io.TypeIO.writeBytes(TEMP_BUFFER, coreData); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void onTileConfig(Player player, Tile tile, int value) { + mindustry.input.InputHandler.onTileConfig(player, tile, value); + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)31; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + TEMP_BUFFER.putInt(value); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + static synchronized void onTileConfig__forward(NetConnection exceptConnection, Player player, + Tile tile, int value) { + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)31; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + TEMP_BUFFER.putInt(value); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.sendExcept(exceptConnection, packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onTileDamage(Tile tile, float health) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.entities.type.Tilec__.onTileDamage(tile, health); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)32; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + TEMP_BUFFER.putFloat(health); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void onTileDestroyed(Tile tile) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.entities.type.Tilec__.onTileDestroyed(tile); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)33; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onTileTapped(Player player, Tile tile) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.input.InputHandler.onTileTapped(player, tile); + } + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)34; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + static synchronized void onTileTapped__forward(NetConnection exceptConnection, Player player, + Tile tile) { + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)34; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onTraceInfo(NetConnection playerConnection, Player player, + Administration.TraceInfo info) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)35; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + mindustry.io.TypeIO.writeTraceInfo(TEMP_BUFFER, info); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onUnitDeath(BaseUnit unit) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.entities.type.BaseUnit.onUnitDeath(unit); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)36; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeBaseUnit(TEMP_BUFFER, unit); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onUnitFactorySpawn(Tile tile, int spawns) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.blocks.units.UnitFactory.onUnitFactorySpawn(tile, spawns); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)37; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + TEMP_BUFFER.putInt(spawns); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onUnitRespawn(Tile tile, Player player) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.blocks.storage.CoreBlock.onUnitRespawn(tile, player); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)38; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onWorldDataBegin() { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)39; + TEMP_BUFFER.position(0); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void onWorldDataBegin(NetConnection playerConnection) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)39; + TEMP_BUFFER.position(0); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void removeQueueBlock(NetConnection playerConnection, int x, int y, + boolean breaking) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)40; + TEMP_BUFFER.position(0); + TEMP_BUFFER.putInt(x); + TEMP_BUFFER.putInt(y); + TEMP_BUFFER.put(breaking ? (byte)1 : 0); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void removeTile(Tile tile) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.Tile.removeTile(tile); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)41; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void removeUnitEditor(Player player, BaseUnit unit) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.ui.fragments.HudFragment.removeUnitEditor(player, unit); + } + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)42; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeBaseUnit(TEMP_BUFFER, unit); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + static synchronized void removeUnitEditor__forward(NetConnection exceptConnection, Player player, + BaseUnit unit) { + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)42; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeBaseUnit(TEMP_BUFFER, unit); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void requestItem(Player player, Tile tile, Item item, int amount) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.ui.fragments.BlockInventoryFragment.requestItem(player, tile, item, amount); + } + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)43; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + mindustry.io.TypeIO.writeItem(TEMP_BUFFER, item); + TEMP_BUFFER.putInt(amount); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + static synchronized void requestItem__forward(NetConnection exceptConnection, Player player, + Tile tile, Item item, int amount) { + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)43; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + mindustry.io.TypeIO.writeItem(TEMP_BUFFER, item); + TEMP_BUFFER.putInt(amount); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void rotateBlock(Player player, Tile tile, boolean direction) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.input.InputHandler.rotateBlock(player, tile, direction); + } + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)44; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + TEMP_BUFFER.put(direction ? (byte)1 : 0); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + static synchronized void rotateBlock__forward(NetConnection exceptConnection, Player player, + Tile tile, boolean direction) { + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)44; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + TEMP_BUFFER.put(direction ? (byte)1 : 0); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.udp); + } + } + + public static synchronized void sendChatMessage(String message) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.core.NetClient.sendChatMessage(mindustry.Vars.player, message); + } + if(mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)45; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, message); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void sendMessage(String message) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.core.NetClient.sendMessage(message); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)46; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, message); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void sendMessage(String message, String sender, Player playersender) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)47; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, message); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, sender); + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, playersender); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void sendMessage(NetConnection playerConnection, String message, + String sender, Player playersender) { + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)47; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, message); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, sender); + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, playersender); + packet.writeLength = TEMP_BUFFER.position(); + playerConnection.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void setMessageBlockText(Player player, Tile tile, String text) { + mindustry.world.blocks.logic.MessageBlock.setMessageBlockText(player, tile, text); + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)48; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, text); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + static synchronized void setMessageBlockText__forward(NetConnection exceptConnection, + Player player, Tile tile, String text) { + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)48; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + mindustry.io.TypeIO.writeString(TEMP_BUFFER, text); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.sendExcept(exceptConnection, packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void setPlayerTeamEditor(Player player, Team team) { + mindustry.ui.fragments.HudFragment.setPlayerTeamEditor(player, team); + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)49; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, team); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + static synchronized void setPlayerTeamEditor__forward(NetConnection exceptConnection, + Player player, Team team) { + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)49; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, team); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.sendExcept(exceptConnection, packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void setTile(Tile tile, Block block, Team team, int rotation) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.world.Tile.setTile(tile, block, team, rotation); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)50; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + mindustry.io.TypeIO.writeBlock(TEMP_BUFFER, block); + mindustry.io.TypeIO.writeTeam(TEMP_BUFFER, team); + TEMP_BUFFER.putInt(rotation); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void transferInventory(Player player, Tile tile) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.input.InputHandler.transferInventory(player, tile); + } + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)52; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + static synchronized void transferInventory__forward(NetConnection exceptConnection, Player player, + Tile tile) { + if(mindustry.Vars.net.server() || mindustry.Vars.net.client()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)52; + TEMP_BUFFER.position(0); + if(mindustry.Vars.net.server()) { + mindustry.io.TypeIO.writePlayer(TEMP_BUFFER, player); + } + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.tcp); + } + } + + public static synchronized void transferItemTo(Item item, int amount, float x, float y, + Tile tile) { + if(mindustry.Vars.net.server() || !mindustry.Vars.net.active()) { + mindustry.entities.effect.ItemTransfer.transferItemTo(item, amount, x, y, tile); + } + if(mindustry.Vars.net.server()) { + mindustry.net.Packets.InvokePacket packet = arc.util.pooling.Pools.obtain(mindustry.net.Packets.InvokePacket.class, mindustry.net.Packets.InvokePacket::new); + packet.writeBuffer = TEMP_BUFFER; + packet.priority = (byte)0; + packet.type = (byte)54; + TEMP_BUFFER.position(0); + mindustry.io.TypeIO.writeItem(TEMP_BUFFER, item); + TEMP_BUFFER.putInt(amount); + TEMP_BUFFER.putFloat(x); + TEMP_BUFFER.putFloat(y); + mindustry.io.TypeIO.writeTile(TEMP_BUFFER, tile); + packet.writeLength = TEMP_BUFFER.position(); + mindustry.Vars.net.send(packet, mindustry.net.Net.SendMode.udp); + } + } +} diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index c137395f84..897db14689 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -13,9 +13,6 @@ import arc.util.io.*; import mindustry.ai.*; import mindustry.core.*; import mindustry.entities.*; -import mindustry.entities.effect.*; -import mindustry.entities.traits.*; -import mindustry.entities.type.*; import mindustry.game.*; import mindustry.game.EventType.*; import mindustry.gen.*; @@ -24,7 +21,6 @@ import mindustry.maps.*; import mindustry.mod.*; import mindustry.net.Net; import mindustry.net.*; -import mindustry.world.blocks.defense.ForceProjector.*; import java.io.*; import java.nio.charset.*; @@ -178,17 +174,6 @@ public class Vars implements Loadable{ public static NetServer netServer; public static NetClient netClient; - public static Entities entities; - public static EntityGroup playerGroup; - public static EntityGroup tileGroup; - public static EntityGroup bulletGroup; - public static EntityGroup effectGroup; - public static EntityGroup groundEffectGroup; - public static EntityGroup shieldGroup; - public static EntityGroup puddleGroup; - public static EntityGroup fireGroup; - public static EntityGroup unitGroup; - public static Unitc player; @Override @@ -234,25 +219,6 @@ public class Vars implements Loadable{ indexer = new BlockIndexer(); pathfinder = new Pathfinder(); - entities = new Entities(); - playerGroup = entities.add(Player.class).enableMapping(); - tileGroup = entities.add(TileEntity.class, false); - bulletGroup = entities.add(Bullet.class).enableMapping(); - effectGroup = entities.add(EffectEntity.class, false); - groundEffectGroup = entities.add(DrawTrait.class, false); - puddleGroup = entities.add(Puddle.class).enableMapping(); - shieldGroup = entities.add(ShieldEntity.class, false); - fireGroup = entities.add(Fire.class).enableMapping(); - unitGroup = entities.add(BaseUnit.class).enableMapping(); - - for(EntityGroup group : entities.all()){ - group.setRemoveListener(entity -> { - if(entity instanceof SyncTrait && net.client()){ - netClient.addRemovedEntity((entity).getID()); - } - }); - } - state = new GameState(); data = new GlobalData(); diff --git a/core/src/mindustry/ai/BlockIndexer.java b/core/src/mindustry/ai/BlockIndexer.java index 050d73da19..b3a414c15c 100644 --- a/core/src/mindustry/ai/BlockIndexer.java +++ b/core/src/mindustry/ai/BlockIndexer.java @@ -7,10 +7,9 @@ import arc.math.geom.*; import arc.struct.*; import arc.util.*; import mindustry.content.*; -import mindustry.entities.traits.*; -import mindustry.entities.type.*; import mindustry.game.EventType.*; import mindustry.game.*; +import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; import mindustry.world.blocks.*; @@ -164,8 +163,8 @@ public class BlockIndexer{ return flagMap[team.id][type.ordinal()]; } - public boolean eachBlock(TeamTrait trait, float range, Boolf pred, Cons cons){ - return eachBlock(trait.getTeam(), trait.getX(), trait.getY(), range, pred, cons); + public boolean eachBlock(Teamc team, float range, Boolf pred, Cons cons){ + return eachBlock(team.getTeam(), team.getX(), team.getY(), range, pred, cons); } public boolean eachBlock(Team team, float wx, float wy, float range, Boolf pred, Cons cons){ @@ -213,20 +212,20 @@ public class BlockIndexer{ return returnArray; } - public void notifyTileDamaged(TileEntity entity){ + public void notifyTileDamaged(Tilec entity){ if(damagedTiles[(int)entity.getTeam().id] == null){ damagedTiles[(int)entity.getTeam().id] = new ObjectSet<>(); } ObjectSet set = damagedTiles[(int)entity.getTeam().id]; - set.add(entity.tile); + set.add(entity.getTile()); } - public TileEntity findEnemyTile(Team team, float x, float y, float range, Boolf pred){ + public Tilec findEnemyTile(Team team, float x, float y, float range, Boolf pred){ for(Team enemy : activeTeams){ if(!team.isEnemy(enemy)) continue; - TileEntity entity = indexer.findTile(enemy, x, y, range, pred, true); + Tilec entity = indexer.findTile(enemy, x, y, range, pred, true); if(entity != null){ return entity; } @@ -235,12 +234,12 @@ public class BlockIndexer{ return null; } - public TileEntity findTile(Team team, float x, float y, float range, Boolf pred){ + public Tilec findTile(Team team, float x, float y, float range, Boolf pred){ return findTile(team, x, y, range, pred, false); } - public TileEntity findTile(Team team, float x, float y, float range, Boolf pred, boolean usePriority){ - TileEntity closest = null; + public Tilec findTile(Team team, float x, float y, float range, Boolf pred, boolean usePriority){ + Tilec closest = null; float dst = 0; float range2 = range*range; @@ -258,14 +257,14 @@ public class BlockIndexer{ if(other.entity == null || other.getTeam() != team || !pred.get(other) || !other.block().targetable) continue; - TileEntity e = other.entity; + Tilec e = other.entity; - float ndst = Mathf.dst2(x, y, e.x, e.y); + float ndst = e.dst2(x, y); if(ndst < range2 && (closest == null || //this one is closer, and it is at least of equal priority - (ndst < dst && (!usePriority || closest.block.priority.ordinal() <= e.block.priority.ordinal())) || + (ndst < dst && (!usePriority || closest.getBlock().priority.ordinal() <= e.getBlock().priority.ordinal())) || //priority is used, and new block has higher priority regardless of range - (usePriority && closest.block.priority.ordinal() < e.block.priority.ordinal()))){ + (usePriority && closest.getBlock().priority.ordinal() < e.getBlock().priority.ordinal()))){ dst = ndst; closest = e; } diff --git a/core/src/mindustry/ai/WaveSpawner.java b/core/src/mindustry/ai/WaveSpawner.java index 4693da996a..3a0de5c0f3 100644 --- a/core/src/mindustry/ai/WaveSpawner.java +++ b/core/src/mindustry/ai/WaveSpawner.java @@ -87,8 +87,8 @@ public class WaveSpawner{ } if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam) && !state.teams.playerCores().isEmpty()){ - TileEntity firstCore = state.teams.playerCores().first(); - for(TileEntity core : state.rules.waveTeam.cores()){ + Tilec firstCore = state.teams.playerCores().first(); + for(Tilec core : state.rules.waveTeam.cores()){ Tmp.v1.set(firstCore).sub(core.x, core.y).limit(coreMargin + core.block.size*tilesize); cons.accept(core.x + Tmp.v1.x, core.y + Tmp.v1.y, false); } @@ -104,7 +104,7 @@ public class WaveSpawner{ } if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam)){ - for(TileEntity core : state.teams.get(state.rules.waveTeam).cores){ + for(Tilec core : state.teams.get(state.rules.waveTeam).cores){ cons.get(core.x, core.y); } } diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index a4644312c4..9ffcd10858 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -10,7 +10,6 @@ import mindustry.*; import mindustry.ctype.*; import mindustry.entities.*; import mindustry.entities.bullet.*; -import mindustry.entities.type.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.type.*; @@ -585,7 +584,7 @@ public class Blocks implements ContentList{ drawIcons = () -> new TextureRegion[]{Core.atlas.find(name + "-bottom"), Core.atlas.find(name + "-top")}; drawer = tile -> { - LiquidModule mod = tile.entity.liquids; + LiquidModule mod = tile.entity.getLiquids(); int rotation = rotate ? tile.rotation() * 90 : 0; @@ -681,7 +680,7 @@ public class Blocks implements ContentList{ Draw.rect(region, tile.drawx(), tile.drawy()); Draw.rect(reg(frameRegions[(int)Mathf.absin(entity.totalProgress, 5f, 2.999f)]), tile.drawx(), tile.drawy()); - Draw.color(Color.clear, tile.entity.liquids.current().color, tile.entity.liquids.total() / liquidCapacity); + Draw.color(Color.clear, tile.entity.getLiquids().current().color, tile.entity.getLiquids().total() / liquidCapacity); Draw.rect(reg(liquidRegion), tile.drawx(), tile.drawy()); Draw.color(); Draw.rect(reg(topRegion), tile.drawx(), tile.drawy()); @@ -1536,14 +1535,14 @@ public class Blocks implements ContentList{ } @Override - public void init(mindustry.entities.type.Bullet b){ + public void init(Bulletc b){ for(int i = 0; i < rays; i++){ Damage.collideLine(b, b.getTeam(), hitEffect, b.x, b.y, b.rot(), rayLength - Math.abs(i - (rays / 2)) * 20f); } } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ super.draw(b); Draw.color(Color.white, Pal.lancerLaser, b.fin()); //Draw.alpha(b.fout()); diff --git a/core/src/mindustry/content/Bullets.java b/core/src/mindustry/content/Bullets.java index 54125a0062..0462133eda 100644 --- a/core/src/mindustry/content/Bullets.java +++ b/core/src/mindustry/content/Bullets.java @@ -9,6 +9,7 @@ import mindustry.entities.*; import mindustry.entities.bullet.*; import mindustry.entities.effect.*; import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.graphics.*; import mindustry.world.*; @@ -410,19 +411,19 @@ public class Bullets implements ContentList{ } @Override - public void init(Bullet b){ + public void init(Bulletc b){ b.velocity().setLength(0.6f + Mathf.random(2f)); } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ Draw.color(Pal.lightFlame, Pal.darkFlame, Color.gray, b.fin()); Fill.circle(b.x, b.y, 3f * b.fout()); Draw.reset(); } @Override - public void update(Bullet b){ + public void update(Bulletc b){ if(Mathf.chance(0.04 * Time.delta())){ Tile tile = world.tileWorld(b.x, b.y); if(tile != null){ @@ -461,7 +462,7 @@ public class Bullets implements ContentList{ } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ } }; @@ -480,7 +481,7 @@ public class Bullets implements ContentList{ } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ } }; @@ -510,7 +511,7 @@ public class Bullets implements ContentList{ } @Override - public void update(Bullet b){ + public void update(Bulletc b){ if(b.timer.get(1, 5f)){ Damage.collideLine(b, b.getTeam(), hitEffect, b.x, b.y, b.rot(), length, true); } @@ -518,7 +519,7 @@ public class Bullets implements ContentList{ } @Override - public void hit(Bullet b, float hitx, float hity){ + public void hit(Bulletc b, float hitx, float hity){ hitEffect.at(colors[2], hitx, hity); if(Mathf.chance(0.4)){ Fire.create(world.tileWorld(hitx + Mathf.range(5f), hity + Mathf.range(5f))); @@ -526,7 +527,7 @@ public class Bullets implements ContentList{ } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ float baseLen = (length) * b.fout(); Lines.lineAngle(b.x, b.y, b.rot(), baseLen); @@ -581,11 +582,11 @@ public class Bullets implements ContentList{ } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ } @Override - public void init(Bullet b){ + public void init(Bulletc b){ Lightning.create(b.getTeam(), Pal.lancerLaser, damage * (b.getOwner() instanceof Player ? state.rules.playerDamageMultiplier : 1f), b.x, b.y, b.rot(), 30); } }; @@ -634,7 +635,7 @@ public class Bullets implements ContentList{ } @Override - public void hit(Bullet b, float x, float y){ + public void hit(Bulletc b, float x, float y){ super.hit(b, x, y); for(int i = 0; i < 3; i++){ diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index 15bb03532d..231b249c65 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -14,6 +14,7 @@ import mindustry.content.*; import mindustry.core.GameState.*; import mindustry.entities.*; import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.game.EventType.*; import mindustry.game.*; import mindustry.gen.*; @@ -163,7 +164,7 @@ public class Control implements ApplicationListener, Loadable{ }); Events.on(Trigger.newGame, () -> { - TileEntity core = player.getClosestCore(); + Tilec core = player.getClosestCore(); if(core == null) return; @@ -256,7 +257,7 @@ public class Control implements ApplicationListener, Loadable{ world.loadGenerator(zone.generator); zone.rules.get(state.rules); state.rules.zone = zone; - for(TileEntity core : state.teams.playerCores()){ + for(Tilec core : state.teams.playerCores()){ for(ItemStack stack : zone.getStartingItems()){ core.items.add(stack.item, stack.amount); } @@ -305,12 +306,12 @@ public class Control implements ApplicationListener, Loadable{ zone.rules.get(state.rules); state.rules.zone = zone; - for(TileEntity core : state.teams.playerCores()){ + for(Tilec core : state.teams.playerCores()){ for(ItemStack stack : zone.getStartingItems()){ core.items.add(stack.item, stack.amount); } } - TileEntity core = state.teams.playerCores().first(); + Tilec core = state.teams.playerCores().first(); core.items.clear(); logic.play(); @@ -434,7 +435,7 @@ public class Control implements ApplicationListener, Loadable{ input.update(); if(world.isZone()){ - for(TileEntity tile : state.teams.cores(player.getTeam())){ + for(Tilec tile : state.teams.cores(player.getTeam())){ for(Item item : content.items()){ if(tile.items.has(item)){ data.unlockContent(item); diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 3a3c0315e6..6c47c616ae 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -6,8 +6,8 @@ import mindustry.annotations.Annotations.*; import mindustry.content.*; import mindustry.core.GameState.*; import mindustry.ctype.*; -import mindustry.entities.*; import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.game.EventType.*; import mindustry.game.*; import mindustry.game.Teams.*; @@ -16,7 +16,6 @@ import mindustry.type.*; import mindustry.world.*; import mindustry.world.blocks.*; import mindustry.world.blocks.BuildBlock.*; -import mindustry.world.blocks.power.*; import java.util.*; @@ -109,10 +108,10 @@ public class Logic implements ApplicationListener{ if(!world.isZone()){ for(TeamData team : state.teams.getActive()){ if(team.hasCore()){ - TileEntity entity = team.core(); - entity.items.clear(); + Tilec entity = team.core(); + entity.getItems().clear(); for(ItemStack stack : state.rules.loadout){ - entity.items.add(stack.item, stack.amount); + entity.getItems().add(stack.item, stack.amount); } } } @@ -129,8 +128,6 @@ public class Logic implements ApplicationListener{ entities.clear(); Time.clear(); - TileEntity.sleepingEntities = 0; - Events.fire(new ResetEvent()); } @@ -176,7 +173,7 @@ public class Logic implements ApplicationListener{ ui.hudfrag.showLaunch(); } - for(TileEntity tile : state.teams.playerCores()){ + for(Tilec tile : state.teams.playerCores()){ Fx.launch.at(tile); } @@ -185,12 +182,12 @@ public class Logic implements ApplicationListener{ } Time.runTask(30f, () -> { - for(TileEntity entity : state.teams.playerCores()){ + for(Tilec entity : state.teams.playerCores()){ for(Item item : content.items()){ - data.addItem(item, entity.items.get(item)); - Events.fire(new LaunchItemEvent(item, entity.items.get(item))); + data.addItem(item, entity.getItems().get(item)); + Events.fire(new LaunchItemEvent(item, entity.getItems().get(item))); } - entity.tile.remove(); + entity.getTile().remove(); } state.launched = true; state.gameOver = true; @@ -257,7 +254,6 @@ public class Logic implements ApplicationListener{ if(!state.isEditor()){ //bulletGroup collisions.collideGroups(bulletGroup, unitGroup); - collisions.collideGroups(bulletGroup, playerGroup); } } diff --git a/core/src/mindustry/core/NetClient.java b/core/src/mindustry/core/NetClient.java index ee52e41588..14b9fc28eb 100644 --- a/core/src/mindustry/core/NetClient.java +++ b/core/src/mindustry/core/NetClient.java @@ -420,7 +420,7 @@ public class NetClient implements ApplicationListener{ Tile tile = world.tile(pos); if(tile != null && tile.entity != null){ - tile.entity.items.read(input); + tile.entity.getItems().read(input); }else{ new ItemModule().read(input); } diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index 82f77c30b9..6cf798e2dd 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -14,6 +14,7 @@ import mindustry.core.GameState.*; import mindustry.entities.*; import mindustry.entities.traits.*; import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.entities.units.*; import mindustry.net.Administration; import mindustry.game.EventType.*; @@ -688,7 +689,7 @@ public class NetServer implements ApplicationListener{ syncStream.reset(); short sent = 0; - for(TileEntity entity : tileGroup.all()){ + for(Tilec entity : tileGroup.all()){ if(!entity.block.sync) continue; sent ++; @@ -719,7 +720,7 @@ public class NetServer implements ApplicationListener{ for(CoreEntity entity : cores){ dataStream.writeInt(entity.tile.pos()); - entity.items.write(dataStream); + entity.getItems().write(dataStream); } dataStream.close(); diff --git a/core/src/mindustry/core/Renderer.java b/core/src/mindustry/core/Renderer.java index d9e03e58e8..f728f2ef31 100644 --- a/core/src/mindustry/core/Renderer.java +++ b/core/src/mindustry/core/Renderer.java @@ -80,7 +80,7 @@ public class Renderer implements ApplicationListener{ Vec2 position = Tmp.v3.set(player); if(player.isDead()){ - TileEntity core = player.getClosestCore(); + Tilec core = player.getClosestCore(); if(core != null){ if(player.spawner == null){ camera.position.lerpDelta(core.x, core.y, 0.08f); @@ -279,23 +279,23 @@ public class Renderer implements ApplicationListener{ private void drawLanding(){ if(landTime > 0 && player.getClosestCore() != null){ float fract = landTime / Fx.coreLand.lifetime; - TileEntity entity = player.getClosestCore(); + Tilec entity = player.getClosestCore(); TextureRegion reg = entity.block.icon(Cicon.full); float scl = Scl.scl(4f) / camerascale; float s = reg.getWidth() * Draw.scl * scl * 4f * fract; Draw.color(Pal.lightTrail); - Draw.rect("circle-shadow", entity.x, entity.y, s, s); + Draw.rect("circle-shadow", entity.getX(), entity.getY(), s, s); Angles.randLenVectors(1, (1f- fract), 100, 1000f * scl * (1f-fract), (x, y, fin, fout) -> { Lines.stroke(scl * fin); - Lines.lineAngle(entity.x + x, entity.y + y, Mathf.angle(x, y), (fin * 20 + 1f) * scl); + Lines.lineAngle(entity.getX() + x, entity.getY() + y, Mathf.angle(x, y), (fin * 20 + 1f) * scl); }); Draw.color(); Draw.mixcol(Color.white, fract); - Draw.rect(reg, entity.x, entity.y, reg.getWidth() * Draw.scl * scl, reg.getHeight() * Draw.scl * scl, fract * 135f); + Draw.rect(reg, entity.getX(), entity.getY(), reg.getWidth() * Draw.scl * scl, reg.getHeight() * Draw.scl * scl, fract * 135f); Draw.reset(); } diff --git a/core/src/mindustry/editor/EditorTile.java b/core/src/mindustry/editor/EditorTile.java index 6a2829b098..d9a48d625e 100644 --- a/core/src/mindustry/editor/EditorTile.java +++ b/core/src/mindustry/editor/EditorTile.java @@ -141,9 +141,9 @@ public class EditorTile extends Tile{ if(block.hasEntity()){ entity = block.newEntity().init(this, false); entity.cons = new ConsumeModule(entity); - if(block.hasItems) entity.items = new ItemModule(); - if(block.hasLiquids) entity.liquids = new LiquidModule(); - if(block.hasPower) entity.power = new PowerModule(); + if(block.hasItems) entity.getItems() = new ItemModule(); + if(block.hasLiquids) entity.getLiquids() = new LiquidModule(); + if(block.hasPower) entity.getPower() = new PowerModule(); } } diff --git a/core/src/mindustry/entities/Damage.java b/core/src/mindustry/entities/Damage.java index 0a8612d31a..b3d4d78d89 100644 --- a/core/src/mindustry/entities/Damage.java +++ b/core/src/mindustry/entities/Damage.java @@ -181,10 +181,10 @@ public class Damage{ if(entity.getTeam() == team || entity.dst(x, y) > radius){ return; } - float amount = calculateDamage(x, y, entity.x, entity.y, radius, damage); + float amount = calculateDamage(x, y, entity.getX(), entity.getY(), radius, damage); entity.damage(amount); //TODO better velocity displacement - float dst = tr.set(entity.x - x, entity.y - y).len(); + float dst = tr.set(entity.getX() - x, entity.getY() - y).len(); entity.velocity().add(tr.setLength((1f - dst / radius) * 2f / entity.mass())); if(complete && damage >= 9999999f && entity == player){ diff --git a/core/src/mindustry/entities/Effect.java b/core/src/mindustry/entities/Effect.java index 5b56575424..a09e0c81ca 100644 --- a/core/src/mindustry/entities/Effect.java +++ b/core/src/mindustry/entities/Effect.java @@ -47,6 +47,10 @@ public class Effect{ Effects.createEffect(this, x, y, rotation, color, null); } + public void at(float x, float y, Color color){ + Effects.createEffect(this, x, y, 0, color, null); + } + public void at(float x, float y, float rotation, Color color, Object data){ Effects.createEffect(this, x, y, rotation, color, data); } diff --git a/core/src/mindustry/entities/Entities.java b/core/src/mindustry/entities/Entities.java deleted file mode 100755 index 022af6b95d..0000000000 --- a/core/src/mindustry/entities/Entities.java +++ /dev/null @@ -1,33 +0,0 @@ -package mindustry.entities; - -import arc.struct.*; -import mindustry.entities.traits.*; - -/** Simple container for managing entity groups.*/ -public class Entities{ - private final Array> groupArray = new Array<>(); - - public void clear(){ - for(EntityGroup group : groupArray){ - group.clear(); - } - } - - public EntityGroup get(int id){ - return groupArray.get(id); - } - - public Array> all(){ - return groupArray; - } - - public EntityGroup add(Class type){ - return add(type, true); - } - - public EntityGroup add(Class type, boolean useTree){ - EntityGroup group = new EntityGroup<>(groupArray.size, type, useTree); - groupArray.add(group); - return group; - } -} diff --git a/core/src/mindustry/entities/EntityCollisions.java b/core/src/mindustry/entities/EntityCollisions.java index 19ff0c7f1f..b5d776c78e 100644 --- a/core/src/mindustry/entities/EntityCollisions.java +++ b/core/src/mindustry/entities/EntityCollisions.java @@ -3,6 +3,7 @@ package mindustry.entities; import arc.struct.Array; import arc.math.Mathf; import arc.math.geom.*; +import mindustry.gen.*; import mindustry.world.Tile; import static mindustry.Vars.tilesize; @@ -22,9 +23,9 @@ public class EntityCollisions{ private Rect r2 = new Rect(); //entity collisions - private Array arrOut = new Array<>(); + private Array arrOut = new Array<>(); - public void move(SolidTrait entity, float deltax, float deltay){ + public void move(Hitboxc entity, float deltax, float deltay){ boolean movedx = false; @@ -53,8 +54,7 @@ public class EntityCollisions{ } } - public void moveDelta(SolidTrait entity, float deltax, float deltay, boolean x){ - + public void moveDelta(Hitboxc entity, float deltax, float deltay, boolean x){ Rect rect = r1; entity.hitboxTile(rect); entity.hitboxTile(r2); @@ -66,7 +66,7 @@ public class EntityCollisions{ for(int dx = -r; dx <= r; dx++){ for(int dy = -r; dy <= r; dy++){ int wx = dx + tilex, wy = dy + tiley; - if(solid(wx, wy) && entity.collidesGrid(wx, wy)){ + if(solid(wx, wy)){ tmp.setSize(tilesize).setCenter(wx * tilesize, wy * tilesize); if(tmp.overlaps(rect)){ @@ -106,18 +106,16 @@ public class EntityCollisions{ } @SuppressWarnings("unchecked") - public void updatePhysics(EntityGroup group){ + public void updatePhysics(EntityGroup group){ QuadTree tree = group.tree(); tree.clear(); - for(Entity entity : group.all()){ - if(entity instanceof SolidTrait){ - SolidTrait s = (SolidTrait)entity; - s.lastPosition().set(s.getX(), s.getY()); - tree.insert(s); - } - } + group.each(s -> { + s.setLastX(s.getX()); + s.setLastY(s.getY()); + tree.insert(s); + }); } private static boolean solid(int x, int y){ @@ -125,25 +123,22 @@ public class EntityCollisions{ return tile != null && tile.solid(); } - private void checkCollide(Entity entity, Entity other){ - - SolidTrait a = (SolidTrait)entity; - SolidTrait b = (SolidTrait)other; + private void checkCollide(Hitboxc a, Hitboxc b){ a.hitbox(this.r1); b.hitbox(this.r2); - r1.x += (a.lastPosition().x - a.getX()); - r1.y += (a.lastPosition().y - a.getY()); - r2.x += (b.lastPosition().x - b.getX()); - r2.y += (b.lastPosition().y - b.getY()); + r1.x += (a.getLastX() - a.getX()); + r1.y += (a.getLastY() - a.getY()); + r2.x += (b.getLastX() - b.getX()); + r2.y += (b.getLastY() - b.getY()); - float vax = a.getX() - a.lastPosition().x; - float vay = a.getY() - a.lastPosition().y; - float vbx = b.getX() - b.lastPosition().x; - float vby = b.getY() - b.lastPosition().y; + float vax = a.getX() - a.getLastX(); + float vay = a.getY() - a.getLastY(); + float vbx = b.getX() - b.getLastX(); + float vby = b.getY() - b.getLastY(); - if(a != b && a.collides(b) && b.collides(a)){ + if(a != b && a.collides(b)){ l1.set(a.getX(), a.getY()); boolean collide = r1.overlaps(r2) || collide(r1.x, r1.y, r1.width, r1.height, vax, vay, r2.x, r2.y, r2.width, r2.height, vbx, vby, l1); @@ -205,17 +200,12 @@ public class EntityCollisions{ } @SuppressWarnings("unchecked") - public void collideGroups(EntityGroup groupa, EntityGroup groupb){ - - for(Entity entity : groupa.all()){ - if(!(entity instanceof SolidTrait)) - continue; - - SolidTrait solid = (SolidTrait)entity; + public void collideGroups(EntityGroup groupa, EntityGroup groupb){ + groupa.each(solid -> { solid.hitbox(r1); - r1.x += (solid.lastPosition().x - solid.getX()); - r1.y += (solid.lastPosition().y - solid.getY()); + r1.x += (solid.getLastX() - solid.getX()); + r1.y += (solid.getLastY() - solid.getY()); solid.hitbox(r2); r2.merge(r1); @@ -223,12 +213,12 @@ public class EntityCollisions{ arrOut.clear(); groupb.tree().getIntersect(arrOut, r2); - for(SolidTrait sc : arrOut){ + for(Hitboxc sc : arrOut){ sc.hitbox(r1); if(r2.overlaps(r1)){ - checkCollide(entity, sc); + checkCollide(solid, sc); } } - } + }); } } diff --git a/core/src/mindustry/entities/EntityGroup.java b/core/src/mindustry/entities/EntityGroup.java index 24c3f0e4f0..fe1954bc4f 100644 --- a/core/src/mindustry/entities/EntityGroup.java +++ b/core/src/mindustry/entities/EntityGroup.java @@ -1,39 +1,26 @@ package mindustry.entities; -import arc.*; -import arc.struct.*; import arc.func.*; -import arc.graphics.*; import arc.math.geom.*; -import mindustry.entities.traits.*; +import arc.struct.*; +import mindustry.gen.*; -import java.util.*; - -import static mindustry.Vars.collisions; +import static mindustry.Vars.*; /** Represents a group of a certain type of entity.*/ @SuppressWarnings("unchecked") -public class EntityGroup implements Iterable{ +public class EntityGroup{ private final boolean useTree; - private final int id; - private final Class type; - private final Array entityArray = new Array<>(false, 32); - private final Array entitiesToRemove = new Array<>(false, 32); - private final Array entitiesToAdd = new Array<>(false, 32); + private final Array array = new Array<>(false, 32); private final Array intersectArray = new Array<>(); private final Rect intersectRect = new Rect(); private IntMap map; private QuadTree tree; - private Cons removeListener; - private Cons addListener; - private final Rect viewport = new Rect(); - private int count = 0; + private int index; - public EntityGroup(int id, Class type, boolean useTree){ + public EntityGroup(boolean useTree){ this.useTree = useTree; - this.id = id; - this.type = type; if(useTree){ tree = new QuadTree<>(new Rect(0, 0, 0, 0)); @@ -41,42 +28,18 @@ public class EntityGroup implements Iterable{ } public void update(){ - updateEvents(); if(useTree()){ - collisions.updatePhysics(this); + collisions.updatePhysics((EntityGroup)this); } - for(Entity e : all()){ - e.update(); - } + each(Entityc::update); } - public int countInBounds(){ - count = 0; - draw(e -> true, e -> count++); - return count; - } - - public void draw(){ - draw(e -> true); - } - - public void draw(Boolf toDraw){ - draw(toDraw, t -> ((DrawTrait)t).draw()); - } - - public void draw(Boolf toDraw, Cons cons){ - Camera cam = Core.camera; - viewport.set(cam.position.x - cam.width / 2, cam.position.y - cam.height / 2, cam.width, cam.height); - - for(Entity e : all()){ - if(!(e instanceof DrawTrait) || !toDraw.get((T)e) || !e.isAdded()) continue; - DrawTrait draw = (DrawTrait)e; - - if(viewport.overlaps(draw.getX() - draw.drawSize()/2f, draw.getY() - draw.drawSize()/2f, draw.drawSize(), draw.drawSize())){ - cons.get((T)e); - } + public void each(Cons cons){ + T[] items = array.items; + for(index = 0; index < array.size; index++){ + cons.get(items[index]); } } @@ -84,14 +47,6 @@ public class EntityGroup implements Iterable{ return useTree; } - public void setRemoveListener(Cons removeListener){ - this.removeListener = removeListener; - } - - public void setAddListener(Cons addListener){ - this.addListener = addListener; - } - public EntityGroup enableMapping(){ map = new IntMap<>(); return this; @@ -101,40 +56,6 @@ public class EntityGroup implements Iterable{ return map != null; } - public Class getType(){ - return type; - } - - public int getID(){ - return id; - } - - public void updateEvents(){ - - for(T e : entitiesToAdd){ - if(e == null) - continue; - entityArray.add(e); - e.added(); - - if(map != null){ - map.put(e.getID(), e); - } - } - - entitiesToAdd.clear(); - - for(T e : entitiesToRemove){ - entityArray.removeValue(e, true); - if(map != null){ - map.remove(e.getID()); - } - e.removed(); - } - - entitiesToRemove.clear(); - } - public T getByID(int id){ if(map == null) throw new RuntimeException("Mapping is not enabled for group " + id + "!"); return map.get(id); @@ -145,16 +66,6 @@ public class EntityGroup implements Iterable{ T t = map.get(id); if(t != null){ //remove if present in map already remove(t); - }else{ //maybe it's being queued? - for(T check : entitiesToAdd){ - if(check.getID() == id){ //if it is indeed queued, remove it - entitiesToAdd.removeValue(check, true); - if(removeListener != null){ - removeListener.get(check); - } - break; - } - } } } @@ -187,81 +98,46 @@ public class EntityGroup implements Iterable{ } public boolean isEmpty(){ - return entityArray.size == 0; + return array.size == 0; } public int size(){ - return entityArray.size; + return array.size; } public int count(Boolf pred){ - int count = 0; - for(int i = 0; i < entityArray.size; i++){ - if(pred.get(entityArray.get(i))) count++; - } - return count; + return array.count(pred); } public void add(T type){ if(type == null) throw new RuntimeException("Cannot add a null entity!"); - if(type.getGroup() != null) return; - type.setGroup(this); - entitiesToAdd.add(type); + array.add(type); if(mappingEnabled()){ - map.put(type.getID(), type); - } - - if(addListener != null){ - addListener.get(type); + map.put(type.getId(), type); } } public void remove(T type){ if(type == null) throw new RuntimeException("Cannot remove a null entity!"); - type.setGroup(null); - entitiesToRemove.add(type); + int idx = array.indexOf(type, true); + if(idx != -1){ + array.remove(idx); - if(removeListener != null){ - removeListener.get(type); + //fix iteration index when removing + if(index >= idx){ + index --; + } } } public void clear(){ - for(T entity : entityArray){ - entity.removed(); - entity.setGroup(null); - } - - for(T entity : entitiesToAdd) - entity.setGroup(null); - - for(T entity : entitiesToRemove) - entity.setGroup(null); - - entitiesToAdd.clear(); - entitiesToRemove.clear(); - entityArray.clear(); + array.clear(); if(map != null) map.clear(); } public T find(Boolf pred){ - - for(int i = 0; i < entityArray.size; i++){ - if(pred.get(entityArray.get(i))) return entityArray.get(i); - } - - return null; - } - - /** Returns the array for iteration. */ - public Array all(){ - return entityArray; - } - - @Override - public Iterator iterator(){ - return entityArray.iterator(); + return array.find(pred); } } diff --git a/core/src/mindustry/entities/Predict.java b/core/src/mindustry/entities/Predict.java index c541771829..32a812ac8f 100644 --- a/core/src/mindustry/entities/Predict.java +++ b/core/src/mindustry/entities/Predict.java @@ -54,7 +54,7 @@ public class Predict{ /** * See {@link #intercept(float, float, float, float, float, float, float)}. */ - public static Vec2 intercept(TargetTrait src, TargetTrait dst, float v){ + public static Vec2 intercept(Teamc src, Teamc dst, float v){ return intercept(src.getX(), src.getY(), dst.getX(), dst.getY(), dst.getTargetVelocityX() - src.getTargetVelocityX()/(2f*Time.delta()), dst.getTargetVelocityY() - src.getTargetVelocityY()/(2f*Time.delta()), v); } diff --git a/core/src/mindustry/entities/Units.java b/core/src/mindustry/entities/Units.java index dd1d899d80..9c8b0989b5 100644 --- a/core/src/mindustry/entities/Units.java +++ b/core/src/mindustry/entities/Units.java @@ -5,6 +5,7 @@ import arc.math.*; import arc.math.geom.*; import mindustry.entities.type.*; import mindustry.game.*; +import mindustry.gen.*; import mindustry.world.*; import static mindustry.Vars.*; @@ -30,17 +31,17 @@ public class Units{ * @param range The maximum distance from the target X/Y the targeter can be for it to be valid * @return whether the target is invalid */ - public static boolean invalidateTarget(TargetTrait target, Team team, float x, float y, float range){ + public static boolean invalidateTarget(Teamc target, Team team, float x, float y, float range){ return target == null || (range != Float.MAX_VALUE && !target.withinDst(x, y, range)) || target.getTeam() == team || !target.isValid(); } - /** See {@link #invalidateTarget(TargetTrait, Team, float, float, float)} */ - public static boolean invalidateTarget(TargetTrait target, Team team, float x, float y){ + /** See {@link #invalidateTarget(Teamc, Team, float, float, float)} */ + public static boolean invalidateTarget(Teamc target, Team team, float x, float y){ return invalidateTarget(target, team, x, y, Float.MAX_VALUE); } - /** See {@link #invalidateTarget(TargetTrait, Team, float, float, float)} */ - public static boolean invalidateTarget(TargetTrait target, Unitc targeter){ + /** See {@link #invalidateTarget(Teamc, Team, float, float, float)} */ + public static boolean invalidateTarget(Teamc target, Unitc targeter){ return invalidateTarget(target, targeter.getTeam(), targeter.x, targeter.y, targeter.getWeapon().bullet.range()); } @@ -68,35 +69,35 @@ public class Units{ } /** Returns the neareset damaged tile. */ - public static TileEntity findDamagedTile(Team team, float x, float y){ + public static Tilec findDamagedTile(Team team, float x, float y){ Tile tile = Geometry.findClosest(x, y, indexer.getDamaged(team)); return tile == null ? null : tile.entity; } /** Returns the neareset ally tile in a range. */ - public static TileEntity findAllyTile(Team team, float x, float y, float range, Boolf pred){ + public static Tilec findAllyTile(Team team, float x, float y, float range, Boolf pred){ return indexer.findTile(team, x, y, range, pred); } /** Returns the neareset enemy tile in a range. */ - public static TileEntity findEnemyTile(Team team, float x, float y, float range, Boolf pred){ + public static Tilec findEnemyTile(Team team, float x, float y, float range, Boolf pred){ if(team == Team.derelict) return null; return indexer.findEnemyTile(team, x, y, range, pred); } /** Returns the closest target enemy. First, units are checked, then tile entities. */ - public static TargetTrait closestTarget(Team team, float x, float y, float range){ + public static Teamc closestTarget(Team team, float x, float y, float range){ return closestTarget(team, x, y, range, Unitc::isValid); } /** Returns the closest target enemy. First, units are checked, then tile entities. */ - public static TargetTrait closestTarget(Team team, float x, float y, float range, Boolf unitPred){ + public static Teamc closestTarget(Team team, float x, float y, float range, Boolf unitPred){ return closestTarget(team, x, y, range, unitPred, t -> true); } /** Returns the closest target enemy. First, units are checked, then tile entities. */ - public static TargetTrait closestTarget(Team team, float x, float y, float range, Boolf unitPred, Boolf tilePred){ + public static Teamc closestTarget(Team team, float x, float y, float range, Boolf unitPred, Boolf tilePred){ if(team == Team.derelict) return null; Unitc unit = closestEnemy(team, x, y, range, unitPred); @@ -152,11 +153,6 @@ public class Units{ cons.get(u); } }); - playerGroup.intersect(x, y, width, height, player -> { - if(player.getTeam() == team){ - cons.get(player); - } - }); } /** Iterates over all units in a circle around this position. */ @@ -166,18 +162,11 @@ public class Units{ cons.get(unit); } }); - - playerGroup.intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> { - if(unit.getTeam() == team && unit.withinDst(x, y, radius)){ - cons.get(unit); - } - }); } /** Iterates over all units in a rectangle. */ public static void nearby(float x, float y, float width, float height, Cons cons){ unitGroup.intersect(x, y, width, height, cons); - playerGroup.intersect(x, y, width, height, cons); } /** Iterates over all units in a rectangle. */ @@ -192,12 +181,6 @@ public class Units{ cons.get(u); } }); - - playerGroup.intersect(x, y, width, height, player -> { - if(team.isEnemy(player.getTeam())){ - cons.get(player); - } - }); } /** Iterates over all units that are enemies of this team. */ @@ -208,7 +191,6 @@ public class Units{ /** Iterates over all units. */ public static void all(Cons cons){ unitGroup.all().each(cons); - playerGroup.all().each(cons); } public static void each(Team team, Cons cons){ diff --git a/core/src/mindustry/entities/bullet/ArtilleryBulletType.java b/core/src/mindustry/entities/bullet/ArtilleryBulletType.java index 17bbc85d89..18888ad538 100644 --- a/core/src/mindustry/entities/bullet/ArtilleryBulletType.java +++ b/core/src/mindustry/entities/bullet/ArtilleryBulletType.java @@ -3,7 +3,6 @@ package mindustry.entities.bullet; import arc.graphics.g2d.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.type.Bullet; import mindustry.gen.*; //TODO scale velocity depending on fslope() @@ -24,7 +23,7 @@ public class ArtilleryBulletType extends BasicBulletType{ } @Override - public void update(Bullet b){ + public void update(Bulletc b){ super.update(b); if(b.timer.get(0, 3 + b.fslope() * 2f)){ @@ -33,7 +32,7 @@ public class ArtilleryBulletType extends BasicBulletType{ } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ float baseScale = 0.7f; float scale = (baseScale + b.fslope() * (1f - baseScale)); diff --git a/core/src/mindustry/entities/bullet/BasicBulletType.java b/core/src/mindustry/entities/bullet/BasicBulletType.java index 44588dedf4..6a71cd9538 100644 --- a/core/src/mindustry/entities/bullet/BasicBulletType.java +++ b/core/src/mindustry/entities/bullet/BasicBulletType.java @@ -4,7 +4,7 @@ import arc.Core; import arc.graphics.Color; import arc.graphics.g2d.Draw; import arc.graphics.g2d.TextureRegion; -import mindustry.entities.type.Bullet; +import mindustry.gen.*; import mindustry.graphics.Pal; /** An extended BulletType for most ammo-based bullets shot from turrets and units. */ @@ -34,7 +34,7 @@ public class BasicBulletType extends BulletType{ } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ float height = bulletHeight * ((1f - bulletShrink) + bulletShrink * b.fout()); Draw.color(backColor); diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index f9e6e120f5..a2f815b4fd 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -2,13 +2,16 @@ package mindustry.entities.bullet; import arc.audio.*; import arc.math.*; +import arc.math.geom.*; +import arc.util.*; +import arc.util.pooling.*; +import mindustry.annotations.Annotations.*; import mindustry.content.*; import mindustry.ctype.*; import mindustry.entities.*; -import mindustry.entities.Effects.*; import mindustry.entities.effect.*; -import mindustry.entities.traits.*; import mindustry.entities.type.*; +import mindustry.game.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.type.*; @@ -97,20 +100,20 @@ public abstract class BulletType extends Content{ return speed * lifetime * (1f - drag); } - public boolean collides(Bullet bullet, Tile tile){ + public boolean collides(Bulletc bullet, Tile tile){ return true; } - public void hitTile(Bullet b, Tile tile){ + public void hitTile(Bulletc b, Tile tile){ hit(b); } - public void hit(Bullet b){ - hit(b, b.x, b.y); + public void hit(Bulletc b){ + hit(b, b.getX(), b.getY()); } - public void hit(Bullet b, float x, float y){ - hitEffect.at(x, y, b.rot()); + public void hit(Bulletc b, float x, float y){ + hitEffect.at(x, y, b.getRotation()); hitSound.at(b); Effects.shake(hitShake, hitShake, b); @@ -119,7 +122,7 @@ public abstract class BulletType extends Content{ for(int i = 0; i < fragBullets; i++){ float len = Mathf.random(1f, 7f); float a = Mathf.random(360f); - Bullet.create(fragBullet, b, x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a, Mathf.random(fragVelocityMin, fragVelocityMax)); + fragBullet.create(b, x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a, Mathf.random(fragVelocityMin, fragVelocityMax)); } } @@ -132,8 +135,8 @@ public abstract class BulletType extends Content{ } } - public void despawned(Bullet b){ - despawnEffect.at(b.x, b.y, b.rot()); + public void despawned(Bulletc b){ + despawnEffect.at(b.getX(), b.getY(), b.getRotation()); hitSound.at(b); if(fragBullet != null || splashDamageRadius > 0){ @@ -145,23 +148,23 @@ public abstract class BulletType extends Content{ } } - public void draw(Bullet b){ + public void draw(Bulletc b){ } - public void init(Bullet b){ - if(killShooter && b.getOwner() instanceof HealthTrait){ - ((HealthTrait)b.getOwner()).kill(); + public void init(Bulletc b){ + if(killShooter && b.getOwner() instanceof Healthc){ + ((Healthc)b.getOwner()).kill(); } if(instantDisappear){ - b.time(lifetime); + b.setTime(lifetime); } } - public void update(Bullet b){ + public void update(Bulletc b){ if(homingPower > 0.0001f){ - TargetTrait target = Units.closestTarget(b.getTeam(), b.x, b.y, homingRange, e -> !e.isFlying() || collidesAir); + Teamc target = Units.closestTarget(b.getTeam(), b.x, b.y, homingRange, e -> !e.isFlying() || collidesAir); if(target != null){ b.velocity().setAngle(Mathf.slerpDelta(b.velocity().angle(), b.angleTo(target), 0.08f)); } @@ -172,4 +175,61 @@ public abstract class BulletType extends Content{ public ContentType getContentType(){ return ContentType.bullet; } + + //TODO change 'create' to 'at' + + public Bulletc create(Teamc owner, float x, float y, float angle){ + return create(owner, owner.getTeam(), x, y, angle); + } + + public Bulletc create(Entityc owner, Team team, float x, float y, float angle){ + return create(owner, team, x, y, angle, 1f); + } + + public Bulletc create(Entityc owner, Team team, float x, float y, float angle, float velocityScl){ + return create(owner, team, x, y, angle, velocityScl, 1f, null); + } + + public Bulletc create(Entityc owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl){ + return create(owner, team, x, y, angle, velocityScl, lifetimeScl, null); + } + + public Bulletc create(Entityc owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Object data){ + + + //TODO implement + return null; + /* + Bullet bullet = Pools.obtain(Bullet.class, Bullet::new); + bullet.type = type; + bullet.owner = owner; + bullet.data = data; + + bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl); + if(type.keepVelocity){ + bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).velocity() : Vec2.ZERO); + } + + bullet.team = team; + bullet.type = type; + bullet.lifeScl = lifetimeScl; + + bullet.set(x - bullet.velocity.x * Time.delta(), y - bullet.velocity.y * Time.delta()); + bullet.add(); + + return bullet;*/ + } + + public Bulletc create(Bulletc parent, float x, float y, float angle){ + return create(parent.getOwner(), parent.getTeam(), x, y, angle); + } + + public Bulletc create(Bulletc parent, float x, float y, float angle, float velocityScl){ + return create(parent.getOwner(), parent.getTeam(), x, y, angle, velocityScl); + } + + @Remote(called = Loc.server, unreliable = true) + public static void createBullet(BulletType type, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl){ + type.create(null, team, x, y, angle, velocityScl, lifetimeScl, null); + } } diff --git a/core/src/mindustry/entities/bullet/FlakBulletType.java b/core/src/mindustry/entities/bullet/FlakBulletType.java index ead19859cc..4eb4c4bac1 100644 --- a/core/src/mindustry/entities/bullet/FlakBulletType.java +++ b/core/src/mindustry/entities/bullet/FlakBulletType.java @@ -4,7 +4,7 @@ import arc.math.geom.Rect; import arc.util.Time; import mindustry.content.Fx; import mindustry.entities.Units; -import mindustry.entities.type.Bullet; +import mindustry.gen.*; public class FlakBulletType extends BasicBulletType{ protected static Rect rect = new Rect(); @@ -24,7 +24,7 @@ public class FlakBulletType extends BasicBulletType{ } @Override - public void update(Bullet b){ + public void update(Bulletc b){ super.update(b); if(b.getData() instanceof Integer) return; diff --git a/core/src/mindustry/entities/bullet/HealBulletType.java b/core/src/mindustry/entities/bullet/HealBulletType.java index 08bb7e51a9..da5171ec89 100644 --- a/core/src/mindustry/entities/bullet/HealBulletType.java +++ b/core/src/mindustry/entities/bullet/HealBulletType.java @@ -3,7 +3,7 @@ package mindustry.entities.bullet; import arc.graphics.*; import arc.graphics.g2d.*; import mindustry.content.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.graphics.*; import mindustry.world.*; import mindustry.world.blocks.*; @@ -28,12 +28,12 @@ public class HealBulletType extends BulletType{ } @Override - public boolean collides(Bullet b, Tile tile){ + public boolean collides(Bulletc b, Tile tile){ return tile.getTeam() != b.getTeam() || tile.entity.healthf() < 1f; } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ Draw.color(backColor); Lines.stroke(bulletWidth); Lines.lineAngleCenter(b.x, b.y, b.rot(), bulletHeight); @@ -43,7 +43,7 @@ public class HealBulletType extends BulletType{ } @Override - public void hitTile(Bullet b, Tile tile){ + public void hitTile(Bulletc b, Tile tile){ super.hit(b); tile = tile.link(); diff --git a/core/src/mindustry/entities/bullet/LaserBulletType.java b/core/src/mindustry/entities/bullet/LaserBulletType.java index 72358543cf..3b902cafe6 100644 --- a/core/src/mindustry/entities/bullet/LaserBulletType.java +++ b/core/src/mindustry/entities/bullet/LaserBulletType.java @@ -6,7 +6,7 @@ import arc.math.*; import arc.util.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.graphics.*; public class LaserBulletType extends BulletType{ @@ -40,12 +40,12 @@ public class LaserBulletType extends BulletType{ } @Override - public void init(Bullet b){ + public void init(Bulletc b){ Damage.collideLine(b, b.getTeam(), hitEffect, b.x, b.y, b.rot(), length); } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ float f = Mathf.curve(b.fin(), 0f, 0.2f); float baseLen = length * f; float cwidth = width; diff --git a/core/src/mindustry/entities/bullet/LightningBulletType.java b/core/src/mindustry/entities/bullet/LightningBulletType.java index 3edbed8b96..d5bcaafa57 100644 --- a/core/src/mindustry/entities/bullet/LightningBulletType.java +++ b/core/src/mindustry/entities/bullet/LightningBulletType.java @@ -3,7 +3,7 @@ package mindustry.entities.bullet; import arc.graphics.*; import mindustry.content.*; import mindustry.entities.effect.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.graphics.*; public class LightningBulletType extends BulletType{ @@ -20,11 +20,11 @@ public class LightningBulletType extends BulletType{ } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ } @Override - public void init(Bullet b){ + public void init(Bulletc b){ Lightning.create(b.getTeam(), lightningColor, damage, b.x, b.y, b.rot(), lightningLength); } } diff --git a/core/src/mindustry/entities/bullet/LiquidBulletType.java b/core/src/mindustry/entities/bullet/LiquidBulletType.java index 09cc19117c..d73d0d90ad 100644 --- a/core/src/mindustry/entities/bullet/LiquidBulletType.java +++ b/core/src/mindustry/entities/bullet/LiquidBulletType.java @@ -5,9 +5,8 @@ import arc.graphics.g2d.*; import arc.math.geom.*; import arc.util.ArcAnnotate.*; import mindustry.content.*; -import mindustry.entities.*; import mindustry.entities.effect.*; -import mindustry.entities.type.Bullet; +import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; @@ -45,7 +44,7 @@ public class LiquidBulletType extends BulletType{ } @Override - public void update(Bullet b){ + public void update(Bulletc b){ super.update(b); if(liquid.canExtinguish()){ @@ -59,14 +58,14 @@ public class LiquidBulletType extends BulletType{ } @Override - public void draw(Bullet b){ + public void draw(Bulletc b){ Draw.color(liquid.color, Color.white, b.fout() / 100f); Fill.circle(b.x, b.y, 0.5f + b.fout() * 2.5f); } @Override - public void hit(Bullet b, float hitx, float hity){ + public void hit(Bulletc b, float hitx, float hity){ hitEffect.at(liquid.color, hitx, hity); Puddle.deposit(world.tileWorld(hitx, hity), liquid, puddleSize); diff --git a/core/src/mindustry/entities/bullet/MassDriverBolt.java b/core/src/mindustry/entities/bullet/MassDriverBolt.java index e415155e27..3316c86bb1 100644 --- a/core/src/mindustry/entities/bullet/MassDriverBolt.java +++ b/core/src/mindustry/entities/bullet/MassDriverBolt.java @@ -5,7 +5,7 @@ import arc.graphics.g2d.Draw; import arc.math.Angles; import arc.math.Mathf; import mindustry.content.Fx; -import mindustry.entities.type.Bullet; +import mindustry.gen.*; import mindustry.graphics.Pal; import mindustry.world.blocks.distribution.MassDriver.DriverBulletData; @@ -23,7 +23,7 @@ public class MassDriverBolt extends BulletType{ } @Override - public void draw(mindustry.entities.type.Bullet b){ + public void draw(Bulletc b){ float w = 11f, h = 13f; Draw.color(Pal.bulletYellowBack); @@ -36,7 +36,7 @@ public class MassDriverBolt extends BulletType{ } @Override - public void update(mindustry.entities.type.Bullet b){ + public void update(Bulletc b){ //data MUST be an instance of DriverBulletData if(!(b.getData() instanceof DriverBulletData)){ hit(b); @@ -82,7 +82,7 @@ public class MassDriverBolt extends BulletType{ } @Override - public void despawned(mindustry.entities.type.Bullet b){ + public void despawned(Bulletc b){ super.despawned(b); if(!(b.getData() instanceof DriverBulletData)) return; @@ -99,7 +99,7 @@ public class MassDriverBolt extends BulletType{ } @Override - public void hit(Bullet b, float hitx, float hity){ + public void hit(Bulletc b, float hitx, float hity){ super.hit(b, hitx, hity); despawned(b); } diff --git a/core/src/mindustry/entities/bullet/MissileBulletType.java b/core/src/mindustry/entities/bullet/MissileBulletType.java index d16baecf36..81a35982b3 100644 --- a/core/src/mindustry/entities/bullet/MissileBulletType.java +++ b/core/src/mindustry/entities/bullet/MissileBulletType.java @@ -4,7 +4,6 @@ import arc.graphics.Color; import arc.math.Mathf; import arc.util.Time; import mindustry.content.Fx; -import mindustry.entities.type.Bullet; import mindustry.gen.*; import mindustry.graphics.Pal; @@ -27,7 +26,7 @@ public class MissileBulletType extends BasicBulletType{ } @Override - public void update(Bullet b){ + public void update(Bulletc b){ super.update(b); if(Mathf.chance(Time.delta() * 0.2)){ diff --git a/core/src/mindustry/entities/def/EntityComps.java b/core/src/mindustry/entities/def/EntityComps.java index 38ef607c0e..eb4dc46642 100644 --- a/core/src/mindustry/entities/def/EntityComps.java +++ b/core/src/mindustry/entities/def/EntityComps.java @@ -5,6 +5,7 @@ import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; +import arc.math.geom.QuadTree.*; import arc.scene.ui.layout.*; import arc.struct.Bits; import arc.struct.Queue; @@ -19,7 +20,6 @@ import mindustry.ctype.*; import mindustry.entities.*; import mindustry.entities.bullet.*; import mindustry.entities.effect.*; -import mindustry.entities.type.*; import mindustry.entities.units.*; import mindustry.game.EventType.*; import mindustry.game.*; @@ -31,18 +31,19 @@ import mindustry.ui.*; import mindustry.world.*; import mindustry.world.blocks.*; import mindustry.world.blocks.BuildBlock.*; +import mindustry.world.consumers.*; +import mindustry.world.modules.*; import java.io.*; import java.util.*; import static mindustry.Vars.*; -import static mindustry.entities.traits.BuilderTrait.BuildDataStatic.tmptr; @SuppressWarnings("unused") public class EntityComps{ @Component - abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc{ + abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc{ UnitDef type; UnitController controller; @@ -138,8 +139,8 @@ public class EntityComps{ } @Component - abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc{ - private boolean supressCollision, supressOnce, deflected; + abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc{ + private float lifeScl; Object data; BulletType type; @@ -148,196 +149,91 @@ public class EntityComps{ return type.damage; } - public void init(){ - //TODO - type.init((Bulletc)this); + public void add(){ + type.init(this); + + setDrag(type.drag); + setHitSize(type.hitSize); + setLifetime(lifeScl * type.lifetime); } public void remove(){ - //TODO - type.despawned((Bulletc)this); + type.despawned(this); } public float getLifetime(){ return type.lifetime; } - void deflect(){ - supressCollision = true; - supressOnce = true; - deflected = true; - } - - public boolean isDeflected(){ - return deflected; - } - public float damageMultiplier(){ - if(owner instanceof Unitc){ - return ((Unitc)owner).getDamageMultipler(); + if(getOwner() instanceof Unitc){ + return ((Unitc)getOwner()).getDamageMultiplier(); } return 1f; } - @Override - public void killed(Entity other){ - if(owner instanceof KillerTrait){ - ((KillerTrait)owner).killed(other); - } - } - - @Override public void absorb(){ - supressCollision = true; + //TODO remove(); } - @Override - public float drawSize(){ + public float clipSize(){ return type.drawSize; } - @Override public float damage(){ - if(owner instanceof Lightning && data instanceof Float){ - return (Float)data; - } return type.damage * damageMultiplier(); } - @Override - public Team getTeam(){ - return team; - } - - @Override - public float getShieldDamage(){ - return Math.max(damage(), type.splashDamage); - } - - @Override - public boolean collides(SolidTrait other){ - return type.collides && (other != owner && !(other instanceof DamageTrait)) && !supressCollision && !(other instanceof Unitc && ((Unitc)other).isFlying() && !type.collidesAir); - } - - @Override - public void collision(SolidTrait other, float x, float y){ + public void collision(Hitboxc other, float x, float y){ if(!type.pierce) remove(); type.hit(this, x, y); if(other instanceof Unitc){ Unitc unit = (Unitc)other; - unit.velocity().add(Tmp.v3.set(other.getX(), other.getY()).sub(x, y).setLength(type.knockback / unit.mass())); - unit.applyEffect(type.status, type.statusDuration); + unit.getVel().add(Tmp.v3.set(other.getX(), other.getY()).sub(x, y).setLength(type.knockback / unit.getMass())); + unit.apply(type.status, type.statusDuration); } } - @Override public void update(){ type.update(this); - x += velocity.x * Time.delta(); - y += velocity.y * Time.delta(); - - velocity.scl(Mathf.clamp(1f - type.drag * Time.delta())); - - time += Time.delta() * 1f / (lifeScl); - time = Mathf.clamp(time, 0, type.lifetime); - - if(time >= type.lifetime){ - if(!supressCollision) type.despawned(this); - remove(); - } - - if(type.hitTiles && collidesTiles() && !supressCollision && initialized){ - world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> { + if(type.hitTiles){ + world.raycastEach(world.toTile(getLastX()), world.toTile(getLastY()), tileX(), tileY(), (x, y) -> { Tile tile = world.ltile(x, y); if(tile == null) return false; - if(tile.entity != null && tile.entity.collide(this) && type.collides(this, tile) && !tile.entity.isDead() && (type.collidesTeam || tile.getTeam() != team)){ - if(tile.getTeam() != team){ + if(tile.entity != null && tile.entity.collide(this) && type.collides(this, tile) && !tile.entity.isDead() && (type.collidesTeam || tile.getTeam() != getTeam())){ + if(tile.getTeam() != getTeam()){ tile.entity.collision(this); } - if(!supressCollision){ - type.hitTile(this, tile); - remove(); - } - + type.hitTile(this, tile); + remove(); return true; } return false; }); } - - if(supressOnce){ - supressCollision = false; - supressOnce = false; - } - - initialized = true; } - @Override - public void reset(){ - type = null; - owner = null; - velocity.setZero(); - time = 0f; - timer.clear(); - lifeScl = 1f; - team = null; - data = null; - supressCollision = false; - supressOnce = false; - deflected = false; - initialized = false; - } - - @Override - public void hitbox(Rect rect){ - rect.setSize(type.hitSize).setCenter(x, y); - } - - @Override - public void hitboxTile(Rect rect){ - rect.setSize(type.hitSize).setCenter(x, y); - } - - @Override public void draw(){ type.draw(this); - renderer.lights.add(x, y, 16f, Pal.powerLight, 0.3f); - } - - @Override - public float fin(){ - return time / type.lifetime; - } - - @Override - public Vec2 velocity(){ - return velocity; - } - - public void velocity(float speed, float angle){ - velocity.set(0, speed).setAngle(angle); - } - - public void limit(float f){ - velocity.limit(f); + //TODO refactor + renderer.lights.add(getX(), getY(), 16f, Pal.powerLight, 0.3f); } /** Sets the bullet's rotation in degrees. */ - public void rot(float angle){ - velocity.setAngle(angle); + public void setRotation(float angle){ + getVel().setAngle(angle); } /** @return the bullet's rotation. */ - public float rot(){ - float angle = Mathf.atan2(velocity.x, velocity.y) * Mathf.radiansToDegrees; + public float getRotation(){ + float angle = Mathf.atan2(getVel().x, getVel().y) * Mathf.radiansToDegrees; if(angle < 0) angle += 360; return angle; } @@ -491,17 +387,218 @@ public class EntityComps{ } @Component - abstract class TileComp implements Posc, Teamc{ + static abstract class TileComp implements Posc, Teamc, Healthc, Tilec{ + static final float timeToSleep = 60f * 1; + static final ObjectSet tmpTiles = new ObjectSet<>(); + static int sleepingEntities = 0; + Tile tile; + Block block; + Array proximity = new Array<>(8); + + PowerModule power; + ItemModule items; + LiquidModule liquids; + ConsumeModule cons; + + private Interval timer; + private float timeScale = 1f, timeScaleDuration; + + private @Nullable SoundLoop sound; + + private boolean sleeping; + private float sleepTime; + + /** Sets this tile entity data to this tile, and adds it if necessary. */ + public Tilec init(Tile tile, boolean shouldAdd){ + this.tile = tile; + this.block = tile.block(); + + set(tile.drawx(), tile.drawy()); + if(block.activeSound != Sounds.none){ + sound = new SoundLoop(block.activeSound, block.activeSoundVolume); + } + + setHealth(block.health); + setMaxHealth(block.health); + timer = new Interval(block.timers); + + if(shouldAdd){ + add(); + } + + return this; + } + + public float getTimeScale(){ + return timeScale; + } + + public boolean consValid(){ + return cons.valid(); + } + + public void consume(){ + cons.trigger(); + } + + public boolean timer(int id, float time){ + return timer.get(id, time); + } + + /** Scaled delta. */ + public float delta(){ + return Time.delta() * timeScale; + } + + /** Base efficiency. If this entity has non-buffered power, returns the power %, otherwise returns 1. */ + public float efficiency(){ + return power != null && (block.consumes.has(ConsumeType.power) && !block.consumes.getPower().buffered) ? power.status : 1f; + } + + /** Call when nothing is happening to the entity. This increments the internal sleep timer. */ + public void sleep(){ + sleepTime += Time.delta(); + if(!sleeping && sleepTime >= timeToSleep){ + remove(); + sleeping = true; + sleepingEntities++; + } + } + + /** Call when this entity is updating. This wakes it up. */ + public void noSleep(){ + sleepTime = 0f; + if(sleeping){ + add(); + sleeping = false; + sleepingEntities--; + } + } + + /** Returns the version of this TileEntity IO code.*/ + public byte version(){ + return 0; + } + + public boolean collide(Bulletc other){ + return true; + } + + public void collision(Bulletc other){ + block.handleBulletHit(this, other); + } + + //TODO Implement damage! + + public void removeFromProximity(){ + block.onProximityRemoved(tile); + + Point2[] nearby = Edges.getEdges(block.size); + for(Point2 point : nearby){ + Tile other = world.ltile(tile.x + point.x, tile.y + point.y); + //remove this tile from all nearby tile's proximities + if(other != null){ + other.block().onProximityUpdate(other); + + if(other.entity != null){ + other.entity.getProximity().remove(tile, true); + } + } + } + } + + public void updateProximity(){ + tmpTiles.clear(); + proximity.clear(); + + Point2[] nearby = Edges.getEdges(block.size); + for(Point2 point : nearby){ + Tile other = world.ltile(tile.x + point.x, tile.y + point.y); + + if(other == null) continue; + if(other.entity == null || !(other.interactable(tile.getTeam()))) continue; + + //add this tile to proximity of nearby tiles + if(!other.entity.getProximity().contains(tile, true)){ + other.entity.getProximity().add(tile); + } + + tmpTiles.add(other); + } + + //using a set to prevent duplicates + for(Tile tile : tmpTiles){ + proximity.add(tile); + } + + block.onProximityAdded(tile); + block.onProximityUpdate(tile); + + for(Tile other : tmpTiles){ + other.block().onProximityUpdate(other); + } + } + + public Array proximity(){ + return proximity; + } + + /** Tile configuration. Defaults to 0. Used for block rebuilding. */ + public int config(){ + return 0; + } + + public void remove(){ + if(sound != null){ + sound.stop(); + } + } + + public void killed(){ + Events.fire(new BlockDestroyEvent(tile)); + block.breakSound.at(tile); + block.onDestroyed(tile); + tile.remove(); + } + + public void update(){ + timeScaleDuration -= Time.delta(); + if(timeScaleDuration <= 0f || !block.canOverdrive){ + timeScale = 1f; + } + + if(sound != null){ + sound.update(getX(), getY(), block.shouldActiveSound(tile)); + } + + if(block.idleSound != Sounds.none && block.shouldIdleSound(tile)){ + loops.play(block.idleSound, this, block.idleSoundVolume); + } + + block.update(tile); + + if(liquids != null){ + liquids.update(); + } + + if(cons != null){ + cons.update(); + } + + if(power != null){ + power.graph.update(); + } + } } @Component - abstract class TeamComp implements Posc{ + abstract class TeamComp implements Posc, Healthc{ transient float x, y; Team team = Team.sharded; - public @Nullable TileEntity getClosestCore(){ + public @Nullable Tilec getClosestCore(){ return state.teams.closestCore(x, y, team); } } @@ -838,14 +935,14 @@ public class EntityComps{ } void updateMining(){ - TileEntity core = getClosestCore(); + Tilec core = getClosestCore(); if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && dst(core) < mineTransferRange){ - int accepted = core.tile.block().acceptStack(item(), getStack().amount, core.tile, this); + int accepted = core.getTile().block().acceptStack(item(), getStack().amount, core.getTile(), this); if(accepted > 0){ Call.transferItemTo(item(), accepted, mineTile.worldx() + Mathf.range(tilesize / 2f), - mineTile.worldy() + Mathf.range(tilesize / 2f), core.tile); + mineTile.worldy() + Mathf.range(tilesize / 2f), core.getTile()); clearItem(); } } @@ -859,10 +956,10 @@ public class EntityComps{ if(Mathf.chance(Time.delta() * (0.06 - item.hardness * 0.01) * getMiningSpeed())){ - if(dst(core) < mineTransferRange && core.tile.block().acceptStack(item, 1, core.tile, this) == 1 && offloadImmediately()){ + if(dst(core) < mineTransferRange && core.getTile().block().acceptStack(item, 1, core.getTile(), this) == 1 && offloadImmediately()){ Call.transferItemTo(item, 1, mineTile.worldx() + Mathf.range(tilesize / 2f), - mineTile.worldy() + Mathf.range(tilesize / 2f), core.tile); + mineTile.worldy() + Mathf.range(tilesize / 2f), core.getTile()); }else if(acceptsItem(item)){ //this is clientside, since items are synced anyway ItemTransfer.transferItemToUnit(item, @@ -927,7 +1024,7 @@ public class EntityComps{ } } - TileEntity core = getClosestCore(); + Tilec core = getClosestCore(); //nothing to build. if(buildRequest() == null) return; @@ -996,10 +1093,10 @@ public class EntityComps{ } /** @return whether this request should be skipped, in favor of the next one. */ - boolean shouldSkip(BuildRequest request, @Nullable TileEntity core){ + boolean shouldSkip(BuildRequest request, @Nullable Tilec core){ //requests that you have at least *started* are considered if(state.rules.infiniteResources || request.breaking || !request.initialized || core == null) return false; - return request.stuck && !core.items.has(request.block.requirements); + return request.stuck && !core.getItems().has(request.block.requirements); } void removeBuild(int x, int y, boolean breaking){ @@ -1163,7 +1260,7 @@ public class EntityComps{ } @Component - abstract class HitboxComp implements Posc{ + abstract class HitboxComp implements Posc, QuadTreeObject{ transient float x, y; float hitSize; @@ -1178,7 +1275,7 @@ public class EntityComps{ lastY = y; } - void collision(Hitboxc other){ + void collision(Hitboxc other, float x, float y){ } @@ -1194,6 +1291,15 @@ public class EntityComps{ return Intersector.overlapsRect(x - hitSize/2f, y - hitSize/2f, hitSize, hitSize, other.getX() - other.getHitSize()/2f, other.getY() - other.getHitSize()/2f, other.getHitSize(), other.getHitSize()); } + + public void hitbox(Rect rect){ + rect.setCentered(x, y, hitSize, hitSize); + } + + public void hitboxTile(Rect rect){ + float scale = 0.6f; + rect.setCentered(x, y, hitSize * scale, hitSize * scale); + } } @Component @@ -1201,9 +1307,9 @@ public class EntityComps{ private Array statuses = new Array<>(); private Bits applied = new Bits(content.getBy(ContentType.status).size); - private float speedMultiplier; - private float damageMultiplier; - private float armorMultiplier; + float speedMultiplier; + float damageMultiplier; + float armorMultiplier; /** @return damage taken based on status armor multipliers */ float getDamage(float amount){ @@ -1329,10 +1435,11 @@ public class EntityComps{ @Component @BaseComponent class EntityComp{ + private boolean added; int id; boolean isAdded(){ - return true; + return added; } void init(){} @@ -1340,11 +1447,11 @@ public class EntityComps{ void update(){} void remove(){ - + added = false; } void add(){ - + added = true; } boolean isLocal(){ diff --git a/core/src/mindustry/entities/def/EntityDefs.java b/core/src/mindustry/entities/def/EntityDefs.java index d538cec4a8..ed68dca6e5 100644 --- a/core/src/mindustry/entities/def/EntityDefs.java +++ b/core/src/mindustry/entities/def/EntityDefs.java @@ -7,4 +7,7 @@ class EntityDefs{ @EntityDef({BulletComp.class, VelComp.class, TimedComp.class}) class BulletDef{} + + @EntityDef({TileComp.class}) + class TileDef{} } diff --git a/core/src/mindustry/entities/def/EntityGroupDefs.java b/core/src/mindustry/entities/def/EntityGroupDefs.java new file mode 100644 index 0000000000..1a654e2eca --- /dev/null +++ b/core/src/mindustry/entities/def/EntityGroupDefs.java @@ -0,0 +1,4 @@ +package mindustry.entities.def; + +public class EntityGroupDefs{ +} diff --git a/core/src/mindustry/entities/effect/Fire.java b/core/src/mindustry/entities/effect/Fire.java index 2d5ac2e0d1..64e78ef540 100644 --- a/core/src/mindustry/entities/effect/Fire.java +++ b/core/src/mindustry/entities/effect/Fire.java @@ -8,7 +8,7 @@ import arc.math.geom.*; import arc.util.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.game.EventType.*; import mindustry.game.*; import mindustry.gen.*; @@ -119,7 +119,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait{ return; } - TileEntity entity = tile.link().entity; + Tilec entity = tile.link().entity; boolean damage = entity != null; float flammability = baseFlammability + puddleFlammability; diff --git a/core/src/mindustry/entities/effect/GroundEffectEntity.java b/core/src/mindustry/entities/effect/GroundEffectEntity.java index 22568f70a2..3e15448c6e 100644 --- a/core/src/mindustry/entities/effect/GroundEffectEntity.java +++ b/core/src/mindustry/entities/effect/GroundEffectEntity.java @@ -4,7 +4,7 @@ import arc.math.Mathf; import arc.util.Time; import mindustry.Vars; import mindustry.entities.Effects; -import mindustry.entities.Effects.Effect; +import mindustry.entities.*; import mindustry.entities.Effects.EffectRenderer; import mindustry.world.Tile; diff --git a/core/src/mindustry/entities/effect/ItemTransfer.java b/core/src/mindustry/entities/effect/ItemTransfer.java index 85beec2b3e..f40f3267b1 100644 --- a/core/src/mindustry/entities/effect/ItemTransfer.java +++ b/core/src/mindustry/entities/effect/ItemTransfer.java @@ -42,11 +42,11 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{ @Remote(called = Loc.server, unreliable = true) public static void transferItemTo(Item item, int amount, float x, float y, Tile tile){ - if(tile == null || tile.entity == null || tile.entity.items == null) return; + if(tile == null || tile.entity == null || tile.entity.getItems() == null) return; for(int i = 0; i < Mathf.clamp(amount / 3, 1, 8); i++){ Time.run(i * 3, () -> create(item, x, y, tile, () -> {})); } - tile.entity.items.add(item, amount); + tile.entity.getItems().add(item, amount); } public static void create(Item item, float fromx, float fromy, Position to, Runnable done){ diff --git a/core/src/mindustry/entities/effect/Lightning.java b/core/src/mindustry/entities/effect/Lightning.java index 78447a9f1a..05ae5bff73 100644 --- a/core/src/mindustry/entities/effect/Lightning.java +++ b/core/src/mindustry/entities/effect/Lightning.java @@ -12,7 +12,6 @@ import arc.util.pooling.Pools; import mindustry.content.Bullets; import mindustry.entities.EntityGroup; import mindustry.entities.Units; -import mindustry.entities.type.Bullet; import mindustry.game.Team; import mindustry.gen.Call; import mindustry.graphics.Pal; diff --git a/core/src/mindustry/entities/type/BaseUnit.java b/core/src/mindustry/entities/type/BaseUnit.java deleted file mode 100644 index cc36369e95..0000000000 --- a/core/src/mindustry/entities/type/BaseUnit.java +++ /dev/null @@ -1,350 +0,0 @@ -package mindustry.entities.type; - -import arc.*; -import mindustry.annotations.Annotations.*; -import arc.graphics.g2d.*; -import arc.math.*; -import arc.math.geom.*; -import arc.util.*; -import arc.util.ArcAnnotate.*; -import mindustry.*; -import mindustry.content.*; -import mindustry.ctype.ContentType; -import mindustry.entities.*; -import mindustry.entities.units.*; -import mindustry.game.EventType.*; -import mindustry.game.*; -import mindustry.gen.*; -import mindustry.type.*; -import mindustry.type.TypeID; -import mindustry.ui.Cicon; -import mindustry.world.*; -import mindustry.world.blocks.*; -import mindustry.world.blocks.defense.DeflectorWall.*; -import mindustry.world.blocks.units.CommandCenter.*; -import mindustry.world.blocks.units.UnitFactory.*; -import mindustry.world.meta.*; - -import java.io.*; - -import static mindustry.Vars.*; - -/** Base class for AI units. */ -public abstract class BaseUnit extends Unitc implements ShooterTrait{ - protected static int timerIndex = 0; - - protected static final int timerTarget = timerIndex++; - protected static final int timerTarget2 = timerIndex++; - - protected boolean loaded; - protected UnitDef type; - protected Interval timer = new Interval(5); - protected StateMachine state = new StateMachine(); - protected TargetTrait target; - - protected int spawner = noSpawner; - - /** internal constructor used for deserialization, DO NOT USE */ - public BaseUnit(){ - } - - @Remote(called = Loc.server) - public static void onUnitDeath(BaseUnit unit){ - if(unit == null) return; - - if(net.server() || !net.active()){ - UnitDrops.dropItems(unit); - } - - unit.onSuperDeath(); - unit.type.deathSound.at(unit); - - //visual only. - if(net.client()){ - Tile tile = world.tile(unit.spawner); - if(tile != null){ - tile.block().unitRemoved(tile, unit); - } - - unit.spawner = noSpawner; - } - - //must run afterwards so the unit's group is not null when sending the removal packet - Core.app.post(unit::remove); - } - - @Override - public TypeID getTypeID(){ - return type.typeID; - } - - @Override - public void onHit(SolidTrait entity){ - if(entity instanceof Bullet && ((Bullet)entity).getOwner() instanceof DeflectorEntity && player != null && getTeam() != player.getTeam()){ - Core.app.post(() -> { - if(isDead()){ - Events.fire(Trigger.phaseDeflectHit); - } - }); - } - } - - public @Nullable - Tile getSpawner(){ - return world.tile(spawner); - } - - public boolean isCommanded(){ - return indexer.getAllied(team, BlockFlag.comandCenter).size != 0 && indexer.getAllied(team, BlockFlag.comandCenter).first().entity instanceof CommandCenterEntity; - } - - public @Nullable UnitCommand getCommand(){ - if(isCommanded()){ - return indexer.getAllied(team, BlockFlag.comandCenter).first().ent().command; - } - return null; - } - - /**Called when a command is recieved from the command center.*/ - public void onCommand(UnitCommand command){ - - } - - /** Initialize the type and team of this unit. Only call once! */ - public void init(UnitDef type, Team team){ - if(this.type != null) throw new RuntimeException("This unit is already initialized!"); - - this.type = type; - this.team = team; - } - - /** @return whether this unit counts toward the enemy amount in the wave UI. */ - public boolean countsAsEnemy(){ - return true; - } - - public void setSpawner(Tile tile){ - this.spawner = tile.pos(); - } - - public void rotate(float angle){ - rotation = Mathf.slerpDelta(rotation, angle, type.rotateSpeed); - } - - public boolean targetHasFlag(BlockFlag flag){ - return (target instanceof TileEntity && ((TileEntity)target).tile.block().flags.contains(flag)) || - (target instanceof Tile && ((Tile)target).block().flags.contains(flag)); - } - - public void setState(UnitState state){ - this.state.set(state); - } - - public boolean retarget(){ - return timer.get(timerTarget, 20); - } - - /** Only runs when the unit has a target. */ - public void behavior(){ - - } - - public void updateTargeting(){ - if(target == null || (target instanceof Unitc && (target.isDead() || target.getTeam() == team)) - || (target instanceof TileEntity && ((TileEntity)target).tile.entity == null)){ - target = null; - } - } - - public void targetClosestAllyFlag(BlockFlag flag){ - Tile target = Geometry.findClosest(x, y, indexer.getAllied(team, flag)); - if(target != null) this.target = target.entity; - } - - public void targetClosestEnemyFlag(BlockFlag flag){ - Tile target = Geometry.findClosest(x, y, indexer.getEnemy(team, flag)); - if(target != null) this.target = target.entity; - } - - public void targetClosest(){ - TargetTrait newTarget = Units.closestTarget(team, x, y, type.range, u -> type.targetAir || !u.isFlying()); - if(newTarget != null){ - target = newTarget; - } - } - - public @Nullable Tile getClosest(BlockFlag flag){ - return Geometry.findClosest(x, y, indexer.getAllied(team, flag)); - } - - public @Nullable Tile getClosestSpawner(){ - return Geometry.findClosest(x, y, Vars.spawner.getGroundSpawns()); - } - - public @Nullable TileEntity getClosestEnemyCore(){ - return Vars.state.teams.closestEnemyCore(x, y, team); - } - - public UnitState getStartState(){ - return null; - } - - public boolean isBoss(){ - return hasEffect(StatusEffects.boss); - } - - @Override - public float getDamageMultipler(){ - return status.getDamageMultiplier() * Vars.state.rules.unitDamageMultiplier; - } - - @Override - public TextureRegion getIconRegion(){ - return type.icon(Cicon.full); - } - - @Override - public void interpolate(){ - super.interpolate(); - - if(interpolator.values.length > 0){ - rotation = interpolator.values[0]; - } - } - - @Override - public float maxHealth(){ - return type.health * Vars.state.rules.unitHealthMultiplier; - } - - @Override - public void update(){ - if(isDead()){ - //dead enemies should get immediately removed - remove(); - return; - } - - hitTime -= Time.delta(); - - if(net.client()){ - interpolate(); - status.update(this); - return; - } - - if(!isFlying() && (world.tileWorld(x, y) != null && !(world.tileWorld(x, y).block() instanceof BuildBlock) && world.tileWorld(x, y).solid())){ - kill(); - } - - avoidOthers(); - - if(spawner != noSpawner && (world.tile(spawner) == null || !(world.tile(spawner).entity instanceof UnitFactoryEntity))){ - kill(); - } - - updateTargeting(); - - state.update(); - updateVelocityStatus(); - - if(target != null) behavior(); - - if(!isFlying()){ - clampPosition(); - } - } - - @Override - public void draw(){ - - } - - @Override - public void removed(){ - super.removed(); - Tile tile = world.tile(spawner); - if(tile != null && !net.client()){ - tile.block().unitRemoved(tile, this); - } - - spawner = noSpawner; - } - - @Override - public float drawSize(){ - return type.hitsize * 10; - } - - @Override - public void onDeath(){ - Call.onUnitDeath(this); - } - - @Override - public void added(){ - state.set(getStartState()); - - if(!loaded){ - health(maxHealth()); - } - - if(isCommanded()){ - onCommand(getCommand()); - } - } - - @Override - public EntityGroup targetGroup(){ - return unitGroup; - } - - @Override - public byte version(){ - return 0; - } - - @Override - public void writeSave(DataOutput stream) throws IOException{ - super.writeSave(stream); - stream.writeByte(type.id); - stream.writeInt(spawner); - } - - @Override - public void readSave(DataInput stream, byte version) throws IOException{ - super.readSave(stream, version); - loaded = true; - byte type = stream.readByte(); - this.spawner = stream.readInt(); - - this.type = content.getByID(ContentType.unit, type); - add(); - } - - @Override - public void write(DataOutput data) throws IOException{ - super.writeSave(data); - data.writeByte(type.id); - data.writeInt(spawner); - } - - @Override - public void read(DataInput data) throws IOException{ - float lastx = x, lasty = y, lastrot = rotation; - - super.readSave(data, version()); - - this.type = content.getByID(ContentType.unit, data.readByte()); - this.spawner = data.readInt(); - - interpolator.read(lastx, lasty, x, y, rotation); - rotation = lastrot; - x = lastx; - y = lasty; - } - - public void onSuperDeath(){ - super.onDeath(); - } -} \ No newline at end of file diff --git a/core/src/mindustry/entities/type/Bullet.java b/core/src/mindustry/entities/type/Bullet.java deleted file mode 100644 index a4f6a2bfdf..0000000000 --- a/core/src/mindustry/entities/type/Bullet.java +++ /dev/null @@ -1,322 +0,0 @@ -package mindustry.entities.type; - -import mindustry.annotations.Annotations.*; -import arc.math.*; -import arc.math.geom.*; -import arc.util.*; -import arc.util.pooling.Pool.*; -import arc.util.pooling.*; -import mindustry.entities.*; -import mindustry.entities.bullet.*; -import mindustry.entities.effect.*; -import mindustry.game.*; -import mindustry.graphics.*; -import mindustry.world.*; - -import static mindustry.Vars.*; - -public class Bullet extends SolidEntity implements DamageTrait, Scaled, Poolable, DrawTrait, VelocityTrait, TimeTrait, TeamTrait, AbsorbTrait{ - public Interval timer = new Interval(3); - - private float lifeScl; - private Team team; - private Object data; - private boolean supressCollision, supressOnce, initialized, deflected; - - protected BulletType type; - protected Entity owner; - protected float time; - - /** Internal use only! */ - public Bullet(){ - } - - public static Bullet create(BulletType type, TeamTrait owner, float x, float y, float angle){ - return create(type, owner, owner.getTeam(), x, y, angle); - } - - public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle){ - return create(type, owner, team, x, y, angle, 1f); - } - - public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl){ - return create(type, owner, team, x, y, angle, velocityScl, 1f, null); - } - - public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl){ - return create(type, owner, team, x, y, angle, velocityScl, lifetimeScl, null); - } - - public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Object data){ - Bullet bullet = Pools.obtain(Bullet.class, Bullet::new); - bullet.type = type; - bullet.owner = owner; - bullet.data = data; - - bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl); - if(type.keepVelocity){ - bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).velocity() : Vec2.ZERO); - } - - bullet.team = team; - bullet.type = type; - bullet.lifeScl = lifetimeScl; - - bullet.set(x - bullet.velocity.x * Time.delta(), y - bullet.velocity.y * Time.delta()); - bullet.add(); - - return bullet; - } - - public static Bullet create(BulletType type, Bullet parent, float x, float y, float angle){ - return create(type, parent.owner, parent.team, x, y, angle); - } - - public static Bullet create(BulletType type, Bullet parent, float x, float y, float angle, float velocityScl){ - return create(type, parent.owner, parent.team, x, y, angle, velocityScl); - } - - @Remote(called = Loc.server, unreliable = true) - public static void createBullet(BulletType type, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl){ - create(type, null, team, x, y, angle, velocityScl, lifetimeScl, null); - } - - public Entity getOwner(){ - return owner; - } - - public boolean collidesTiles(){ - return type.collidesTiles; - } - - public void deflect(){ - supressCollision = true; - supressOnce = true; - deflected = true; - } - - public boolean isDeflected(){ - return deflected; - } - - public BulletType getBulletType(){ - return type; - } - - public void resetOwner(Entity entity, Team team){ - this.owner = entity; - this.team = team; - } - - public void scaleTime(float add){ - time += add; - } - - public Object getData(){ - return data; - } - - public void setData(Object data){ - this.data = data; - } - - public float damageMultiplier(){ - if(owner instanceof Unitc){ - return ((Unitc)owner).getDamageMultipler(); - } - return 1f; - } - - @Override - public void killed(Entity other){ - if(owner instanceof KillerTrait){ - ((KillerTrait)owner).killed(other); - } - } - - @Override - public void absorb(){ - supressCollision = true; - remove(); - } - - @Override - public float drawSize(){ - return type.drawSize; - } - - @Override - public float damage(){ - if(owner instanceof Lightning && data instanceof Float){ - return (Float)data; - } - return type.damage * damageMultiplier(); - } - - @Override - public Team getTeam(){ - return team; - } - - @Override - public float getShieldDamage(){ - return Math.max(damage(), type.splashDamage); - } - - @Override - public boolean collides(SolidTrait other){ - return type.collides && (other != owner && !(other instanceof DamageTrait)) && !supressCollision && !(other instanceof Unitc && ((Unitc)other).isFlying() && !type.collidesAir); - } - - @Override - public void collision(SolidTrait other, float x, float y){ - if(!type.pierce) remove(); - type.hit(this, x, y); - - if(other instanceof Unitc){ - Unitc unit = (Unitc)other; - unit.velocity().add(Tmp.v3.set(other.getX(), other.getY()).sub(x, y).setLength(type.knockback / unit.mass())); - unit.applyEffect(type.status, type.statusDuration); - } - } - - @Override - public void update(){ - type.update(this); - - x += velocity.x * Time.delta(); - y += velocity.y * Time.delta(); - - velocity.scl(Mathf.clamp(1f - type.drag * Time.delta())); - - time += Time.delta() * 1f / (lifeScl); - time = Mathf.clamp(time, 0, type.lifetime); - - if(time >= type.lifetime){ - if(!supressCollision) type.despawned(this); - remove(); - } - - if(type.hitTiles && collidesTiles() && !supressCollision && initialized){ - world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> { - - Tile tile = world.ltile(x, y); - if(tile == null) return false; - - if(tile.entity != null && tile.entity.collide(this) && type.collides(this, tile) && !tile.entity.isDead() && (type.collidesTeam || tile.getTeam() != team)){ - if(tile.getTeam() != team){ - tile.entity.collision(this); - } - - if(!supressCollision){ - type.hitTile(this, tile); - remove(); - } - - return true; - } - - return false; - }); - } - - if(supressOnce){ - supressCollision = false; - supressOnce = false; - } - - initialized = true; - } - - @Override - public void reset(){ - type = null; - owner = null; - velocity.setZero(); - time = 0f; - timer.clear(); - lifeScl = 1f; - team = null; - data = null; - supressCollision = false; - supressOnce = false; - deflected = false; - initialized = false; - } - - @Override - public void hitbox(Rect rect){ - rect.setSize(type.hitSize).setCenter(x, y); - } - - @Override - public void hitboxTile(Rect rect){ - rect.setSize(type.hitSize).setCenter(x, y); - } - - @Override - public float lifetime(){ - return type.lifetime; - } - - @Override - public void time(float time){ - this.time = time; - } - - @Override - public float time(){ - return time; - } - - @Override - public void removed(){ - Pools.free(this); - } - - @Override - public EntityGroup targetGroup(){ - return bulletGroup; - } - - @Override - public void added(){ - type.init(this); - } - - @Override - public void draw(){ - type.draw(this); - renderer.lights.add(x, y, 16f, Pal.powerLight, 0.3f); - } - - @Override - public float fin(){ - return time / type.lifetime; - } - - @Override - public Vec2 velocity(){ - return velocity; - } - - public void velocity(float speed, float angle){ - velocity.set(0, speed).setAngle(angle); - } - - public void limit(float f){ - velocity.limit(f); - } - - /** Sets the bullet's rotation in degrees. */ - public void rot(float angle){ - velocity.setAngle(angle); - } - - /** @return the bullet's rotation. */ - public float rot(){ - float angle = Mathf.atan2(velocity.x, velocity.y) * Mathf.radiansToDegrees; - if(angle < 0) angle += 360; - return angle; - } -} diff --git a/core/src/mindustry/entities/type/Player.java b/core/src/mindustry/entities/type/Player.java index be335b3d9c..7acedffef0 100644 --- a/core/src/mindustry/entities/type/Player.java +++ b/core/src/mindustry/entities/type/Player.java @@ -59,8 +59,8 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{ public @Nullable NetConnection con; public boolean isLocal = false; public Interval timer = new Interval(6); - public TargetTrait target; - public TargetTrait moveTarget; + public Teamc target; + public Teamc moveTarget; public @Nullable String lastText; public float textFadeTime; @@ -604,7 +604,7 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{ protected void updateTouch(){ if(Units.invalidateTarget(target, this) && - !(target instanceof TileEntity && ((TileEntity)target).damaged() && target.isValid() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range && !(((TileEntity)target).block instanceof BuildBlock))){ + !(target instanceof Tilec && ((Tilec)target).damaged() && target.isValid() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range && !(((Tilec)target).block instanceof BuildBlock))){ target = null; } @@ -619,7 +619,7 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{ if(moveTarget != null && !moveTarget.isDead()){ targetX = moveTarget.getX(); targetY = moveTarget.getY(); - boolean tapping = moveTarget instanceof TileEntity && moveTarget.getTeam() == team; + boolean tapping = moveTarget instanceof Tilec && moveTarget.getTeam() == team; attractDst = 0f; if(tapping){ @@ -628,7 +628,7 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{ if(dst(moveTarget) <= 2f * Time.delta()){ if(tapping && !isDead()){ - Tile tile = ((TileEntity)moveTarget).tile; + Tile tile = ((Tilec)moveTarget).tile; tile.block().tapped(tile, this); } @@ -695,7 +695,7 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{ setMineTile(null); } } - }else if(target.isValid() || (target instanceof TileEntity && ((TileEntity)target).damaged() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range)){ + }else if(target.isValid() || (target instanceof Tilec && ((Tilec)target).damaged() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range)){ //rotate toward and shoot the target if(mech.faceTarget){ rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f); diff --git a/core/src/mindustry/entities/type/TileEntity.java b/core/src/mindustry/entities/type/Tilec.java similarity index 97% rename from core/src/mindustry/entities/type/TileEntity.java rename to core/src/mindustry/entities/type/Tilec.java index 32975e52de..63246c3d8e 100644 --- a/core/src/mindustry/entities/type/TileEntity.java +++ b/core/src/mindustry/entities/type/Tilec.java @@ -6,10 +6,8 @@ import arc.Events; import arc.struct.Array; import arc.struct.ObjectSet; import arc.math.geom.Point2; -import arc.math.geom.Vec2; import arc.util.*; import arc.util.ArcAnnotate.*; -import mindustry.entities.EntityGroup; import mindustry.game.*; import mindustry.game.EventType.BlockDestroyEvent; import mindustry.gen.*; @@ -21,7 +19,7 @@ import java.io.*; import static mindustry.Vars.*; -public class TileEntity{ +public class Tilec__{ public static final float timeToSleep = 60f * 1; //1 second to fall asleep private static final ObjectSet tmpTiles = new ObjectSet<>(); /** This value is only used for debugging. */ @@ -63,7 +61,7 @@ public class TileEntity{ } /** Sets this tile entity data to this tile, and adds it if necessary. */ - public TileEntity init(Tile tile, boolean shouldAdd){ + public Tilec init(Tile tile, boolean shouldAdd){ this.tile = tile; x = tile.drawx(); y = tile.drawy(); @@ -148,11 +146,11 @@ public class TileEntity{ return 0; } - public boolean collide(Bullet other){ + public boolean collide(Bulletc other){ return true; } - public void collision(Bullet other){ + public void collision(Bulletc other){ block.handleBulletHit(this, other); } diff --git a/core/src/mindustry/entities/type/base/BuilderDrone.java b/core/src/mindustry/entities/type/base/BuilderDrone.java index 336be7be6e..0a53fb1174 100644 --- a/core/src/mindustry/entities/type/base/BuilderDrone.java +++ b/core/src/mindustry/entities/type/base/BuilderDrone.java @@ -39,7 +39,7 @@ public class BuilderDrone extends BaseDrone implements BuilderTrait{ public void update(){ BuildEntity entity = (BuildEntity)target; - TileEntity core = getClosestCore(); + Tilec core = getClosestCore(); if(isBuilding() && entity == null && canRebuild()){ target = world.tile(buildRequest().x, buildRequest().y); @@ -97,7 +97,7 @@ public class BuilderDrone extends BaseDrone implements BuilderTrait{ } }else{ incDrones(playerTarget); - TargetTrait prev = target; + Teamc prev = target; target = playerTarget; float dst = 90f + (id % 10)*3; float tdst = dst(target); diff --git a/core/src/mindustry/entities/type/base/GroundUnit.java b/core/src/mindustry/entities/type/base/GroundUnit.java index 5ffa40f359..d1529d73de 100644 --- a/core/src/mindustry/entities/type/base/GroundUnit.java +++ b/core/src/mindustry/entities/type/base/GroundUnit.java @@ -12,7 +12,6 @@ import mindustry.entities.bullet.*; import mindustry.entities.type.*; import mindustry.entities.units.*; import mindustry.game.*; -import mindustry.type.*; import mindustry.world.*; import mindustry.world.blocks.*; import mindustry.world.meta.*; @@ -34,7 +33,7 @@ public class GroundUnit extends BaseUnit{ } public void update(){ - TileEntity core = getClosestEnemyCore(); + Tilec core = getClosestEnemyCore(); if(core == null){ Tile closestSpawn = getClosestSpawner(); @@ -251,7 +250,7 @@ public class GroundUnit extends BaseUnit{ Tile tile = world.tileWorld(x, y); if(tile == null) return; Tile targetTile = pathfinder.getTargetTile(tile, enemy, PathTarget.enemyCores); - TileEntity core = getClosestCore(); + Tilec core = getClosestCore(); if(tile == targetTile || core == null || dst(core) < 120f) return; diff --git a/core/src/mindustry/entities/type/base/MinerDrone.java b/core/src/mindustry/entities/type/base/MinerDrone.java index cfa9ea16c8..6a79af4bef 100644 --- a/core/src/mindustry/entities/type/base/MinerDrone.java +++ b/core/src/mindustry/entities/type/base/MinerDrone.java @@ -3,7 +3,7 @@ package mindustry.entities.type.base; import arc.math.Mathf; import arc.util.Structs; import mindustry.content.Blocks; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.entities.units.UnitState; import mindustry.gen.Call; import mindustry.type.Item; @@ -28,7 +28,7 @@ public class MinerDrone extends BaseDrone implements MinerTrait{ } public void update(){ - TileEntity entity = getClosestCore(); + Tilec entity = getClosestCore(); if(entity == null) return; @@ -90,7 +90,7 @@ public class MinerDrone extends BaseDrone implements MinerTrait{ if(target == null) return; - TileEntity tile = (TileEntity)target; + Tilec tile = (Tilec)target; if(dst(target) < type.range){ if(tile.tile.block().acceptStack(item.item, item.amount, tile.tile, MinerDrone.this) > 0){ @@ -169,10 +169,10 @@ public class MinerDrone extends BaseDrone implements MinerTrait{ } protected void findItem(){ - TileEntity entity = getClosestCore(); + Tilec entity = getClosestCore(); if(entity == null){ return; } - targetItem = Structs.findMin(type.toMine, indexer::hasOre, (a, b) -> -Integer.compare(entity.items.get(a), entity.items.get(b))); + targetItem = Structs.findMin(type.toMine, indexer::hasOre, (a, b) -> -Integer.compare(entity.getItems().get(a), entity.getItems().get(b))); } } diff --git a/core/src/mindustry/entities/type/base/RepairDrone.java b/core/src/mindustry/entities/type/base/RepairDrone.java index a796d6eddc..29e3ffb398 100644 --- a/core/src/mindustry/entities/type/base/RepairDrone.java +++ b/core/src/mindustry/entities/type/base/RepairDrone.java @@ -1,7 +1,7 @@ package mindustry.entities.type.base; import mindustry.entities.Units; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.entities.units.UnitState; import mindustry.world.Pos; import mindustry.world.Tile; @@ -24,7 +24,7 @@ public class RepairDrone extends BaseDrone{ target = Units.findDamagedTile(team, x, y); } - if(target instanceof TileEntity && ((TileEntity)target).block instanceof BuildBlock){ + if(target instanceof Tilec && ((Tilec)target).block instanceof BuildBlock){ target = null; } @@ -58,7 +58,7 @@ public class RepairDrone extends BaseDrone{ @Override public void write(DataOutput data) throws IOException{ super.write(data); - data.writeInt(state.is(repair) && target instanceof TileEntity ? ((TileEntity)target).tile.pos() : Pos.invalid); + data.writeInt(state.is(repair) && target instanceof Tilec ? ((Tilec)target).tile.pos() : Pos.invalid); } @Override diff --git a/core/src/mindustry/entities/units/UnitDrops.java b/core/src/mindustry/entities/units/UnitDrops.java index f57ff0a75d..0097c359e9 100644 --- a/core/src/mindustry/entities/units/UnitDrops.java +++ b/core/src/mindustry/entities/units/UnitDrops.java @@ -3,8 +3,7 @@ package mindustry.entities.units; import arc.math.Mathf; import mindustry.Vars; import mindustry.content.Items; -import mindustry.entities.type.BaseUnit; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.gen.Call; import mindustry.type.Item; import static mindustry.Vars.*; @@ -18,7 +17,7 @@ public class UnitDrops{ return; } - TileEntity core = unit.getClosestEnemyCore(); + Tilec core = unit.getClosestEnemyCore(); if(core == null || core.dst(unit) > Vars.mineTransferRange){ return; diff --git a/core/src/mindustry/game/Saves.java b/core/src/mindustry/game/Saves.java index cd3389d1f0..09f09f122a 100644 --- a/core/src/mindustry/game/Saves.java +++ b/core/src/mindustry/game/Saves.java @@ -311,7 +311,7 @@ public class Saves{ public void delete(){ file.delete(); - saves.removeValue(this, true); + saves.remove(this, true); if(this == current){ current = null; } diff --git a/core/src/mindustry/game/SpawnGroup.java b/core/src/mindustry/game/SpawnGroup.java index c0a08d2661..0155c044e7 100644 --- a/core/src/mindustry/game/SpawnGroup.java +++ b/core/src/mindustry/game/SpawnGroup.java @@ -5,7 +5,6 @@ import arc.util.serialization.Json.Serializable; import arc.util.serialization.JsonValue; import mindustry.content.*; import mindustry.ctype.ContentType; -import mindustry.entities.type.BaseUnit; import mindustry.type.*; import static mindustry.Vars.content; diff --git a/core/src/mindustry/game/Teams.java b/core/src/mindustry/game/Teams.java index 62479c66ec..81bd679824 100644 --- a/core/src/mindustry/game/Teams.java +++ b/core/src/mindustry/game/Teams.java @@ -54,10 +54,10 @@ public class Teams{ return false; } - public void eachEnemyCore(Team team, Cons ret){ + public void eachEnemyCore(Team team, Cons ret){ for(TeamData data : active){ if(areEnemies(team, data.team)){ - for(TileEntity tile : data.cores){ + for(Tilec tile : data.cores){ ret.get(tile); } } diff --git a/core/src/mindustry/game/Tutorial.java b/core/src/mindustry/game/Tutorial.java index 4b344bc945..287492dedd 100644 --- a/core/src/mindustry/game/Tutorial.java +++ b/core/src/mindustry/game/Tutorial.java @@ -240,7 +240,7 @@ public class Tutorial{ //utility static void placeBlocks(){ - TileEntity core = state.teams.playerCores().first(); + Tilec core = state.teams.playerCores().first(); for(int i = 0; i < blocksToBreak; i++){ world.ltile(core.tile.x + blockOffset, core.tile.y + i).remove(); world.tile(core.tile.x + blockOffset, core.tile.y + i).setBlock(Blocks.scrapWall, state.rules.defaultTeam); @@ -248,7 +248,7 @@ public class Tutorial{ } static boolean blocksBroken(){ - TileEntity core = state.teams.playerCores().first(); + Tilec core = state.teams.playerCores().first(); for(int i = 0; i < blocksToBreak; i++){ if(world.tile(core.tile.x + blockOffset, core.tile.y + i).block() == Blocks.scrapWall){ diff --git a/core/src/mindustry/graphics/BlockRenderer.java b/core/src/mindustry/graphics/BlockRenderer.java index 41274e0349..a828e745cc 100644 --- a/core/src/mindustry/graphics/BlockRenderer.java +++ b/core/src/mindustry/graphics/BlockRenderer.java @@ -233,7 +233,7 @@ public class BlockRenderer implements Disposable{ addRequest(tile, block.layer2); } - if(tile.entity != null && tile.entity.power != null && tile.entity.power.links.size > 0){ + if(tile.entity != null && tile.entity.getPower() != null && tile.entity.getPower().links.size > 0){ for(Tile other : block.getPowerConnections(tile, outArray)){ if(other.block().layer == Layer.power){ addRequest(other, Layer.power); diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index a767c30b46..b55f1c6ec1 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -132,7 +132,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ ItemTransfer.create(item, player.x + Angles.trnsx(player.rotation + 180f, backTrns), player.y + Angles.trnsy(player.rotation + 180f, backTrns), new Vec2(tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y), () -> { - if(tile.block() != block || tile.entity == null || tile.entity.items == null) return; + if(tile.block() != block || tile.entity == null || tile.entity.getItems() == null) return; tile.block().handleStack(item, removed, tile, player); remaining[1] -= removed; @@ -595,7 +595,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ if(tile.interactable(player.getTeam()) && tile.block().consumesTap){ consumed = true; }else if(tile.interactable(player.getTeam()) && tile.block().synthetic() && !consumed){ - if(tile.block().hasItems && tile.entity.items.total() > 0){ + if(tile.block().hasItems && tile.entity.getItems().total() > 0){ frag.inv.showFor(tile); consumed = true; showedInventory = true; diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index a332454f3e..d3bfa4c3d5 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -16,11 +16,10 @@ import mindustry.*; import mindustry.content.*; import mindustry.core.GameState.*; import mindustry.entities.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.entities.units.*; import mindustry.game.EventType.*; import mindustry.game.*; -import mindustry.gen.*; import mindustry.graphics.*; import mindustry.ui.*; import mindustry.world.*; @@ -45,7 +44,7 @@ public class MobileInput extends InputHandler implements GestureListener{ private float lineScale; /** Animation data for crosshair. */ private float crosshairScale; - private TargetTrait lastTarget; + private Teamc lastTarget; /** Used for shifting build requests. */ private float shiftDeltaX, shiftDeltaY; @@ -77,7 +76,7 @@ public class MobileInput extends InputHandler implements GestureListener{ Tile tile = world.ltileWorld(x, y); if(tile != null && tile.synthetic() && player.getTeam().isEnemy(tile.getTeam())){ - TileEntity entity = tile.entity; + Tilec entity = tile.entity; player.setMineTile(null); player.target = entity; }else if(tile != null && player.mech.canHeal && tile.entity != null && tile.getTeam() == player.getTeam() && tile.entity.damaged()){ @@ -155,7 +154,7 @@ public class MobileInput extends InputHandler implements GestureListener{ } void removeRequest(BuildRequest request){ - selectRequests.removeValue(request, true); + selectRequests.remove(request, true); if(!request.breaking){ removals.add(request); } @@ -376,7 +375,7 @@ public class MobileInput extends InputHandler implements GestureListener{ } } - TargetTrait target = player.target; + Teamc target = player.target; //draw targeting crosshair if(target != null && !state.isEditor()){ diff --git a/core/src/mindustry/io/TypeIO.java b/core/src/mindustry/io/TypeIO.java index dd27139ffb..d79100e2d3 100644 --- a/core/src/mindustry/io/TypeIO.java +++ b/core/src/mindustry/io/TypeIO.java @@ -5,8 +5,7 @@ import mindustry.annotations.Annotations.WriteClass; import arc.graphics.Color; import mindustry.ctype.ContentType; import mindustry.entities.Effects; -import mindustry.entities.Effects.Effect; -import mindustry.entities.type.Bullet; +import mindustry.entities.*; import mindustry.entities.bullet.BulletType; import mindustry.entities.units.BuildRequest; import mindustry.entities.type.*; diff --git a/core/src/mindustry/io/versions/LegacyTypeTable.java b/core/src/mindustry/io/versions/LegacyTypeTable.java index 2aeb8c8d66..a8e5d3b97f 100644 --- a/core/src/mindustry/io/versions/LegacyTypeTable.java +++ b/core/src/mindustry/io/versions/LegacyTypeTable.java @@ -1,7 +1,6 @@ package mindustry.io.versions; import arc.func.Prov; -import mindustry.entities.type.Bullet; import mindustry.entities.effect.*; import mindustry.entities.type.Player; import mindustry.entities.type.base.*; diff --git a/core/src/mindustry/maps/generators/MapGenerator.java b/core/src/mindustry/maps/generators/MapGenerator.java index 69c11bdc7b..b64b03f2a7 100644 --- a/core/src/mindustry/maps/generators/MapGenerator.java +++ b/core/src/mindustry/maps/generators/MapGenerator.java @@ -111,7 +111,7 @@ public class MapGenerator extends Generator{ if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && world.getZone() != null){ for(Item item : world.getZone().resources){ if(Mathf.chance(0.3)){ - tile.entity.items.add(item, Math.min(Mathf.random(500), tile.block().itemCapacity)); + tile.entity.getItems().add(item, Math.min(Mathf.random(500), tile.block().itemCapacity)); } } } diff --git a/core/src/mindustry/net/Administration.java b/core/src/mindustry/net/Administration.java index 68c6db1edb..cfd3423608 100644 --- a/core/src/mindustry/net/Administration.java +++ b/core/src/mindustry/net/Administration.java @@ -190,7 +190,7 @@ public class Administration{ } } - bannedIPs.removeValue(ip, false); + bannedIPs.remove(ip, false); if(found){ save(); diff --git a/core/src/mindustry/type/Weapon.java b/core/src/mindustry/type/Weapon.java index a24142a725..940675784a 100644 --- a/core/src/mindustry/type/Weapon.java +++ b/core/src/mindustry/type/Weapon.java @@ -1,24 +1,15 @@ package mindustry.type; import arc.*; -import mindustry.annotations.Annotations.*; import arc.audio.*; import arc.graphics.g2d.*; -import arc.math.*; -import arc.util.*; import arc.util.ArcAnnotate.*; -import mindustry.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.Effects.*; import mindustry.entities.bullet.*; import mindustry.entities.traits.*; -import mindustry.entities.type.*; -import mindustry.entities.type.Bullet; import mindustry.gen.*; -import static mindustry.Vars.net; - public class Weapon{ /** displayed weapon region */ public String name; diff --git a/core/src/mindustry/ui/dialogs/JoinDialog.java b/core/src/mindustry/ui/dialogs/JoinDialog.java index afe3d30093..99f1e9c5e2 100644 --- a/core/src/mindustry/ui/dialogs/JoinDialog.java +++ b/core/src/mindustry/ui/dialogs/JoinDialog.java @@ -157,7 +157,7 @@ public class JoinDialog extends FloatingDialog{ inner.addImageButton(Icon.trash, Styles.emptyi, () -> { ui.showConfirm("$confirm", "$server.delete", () -> { - servers.removeValue(server, true); + servers.remove(server, true); saveServers(); setupRemote(); refreshRemote(); diff --git a/core/src/mindustry/ui/fragments/BlockInventoryFragment.java b/core/src/mindustry/ui/fragments/BlockInventoryFragment.java index 926c56460a..948834d923 100644 --- a/core/src/mindustry/ui/fragments/BlockInventoryFragment.java +++ b/core/src/mindustry/ui/fragments/BlockInventoryFragment.java @@ -71,7 +71,7 @@ public class BlockInventoryFragment extends Fragment{ return; } this.tile = t; - if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.total() == 0) + if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.getItems().total() == 0) return; rebuild(true); } @@ -98,14 +98,14 @@ public class BlockInventoryFragment extends Fragment{ table.touchable(Touchable.enabled); table.update(() -> { - if(state.is(State.menu) || tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.total() == 0){ + if(state.is(State.menu) || tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.getItems().total() == 0){ hide(); }else{ if(holding && lastItem != null){ holdTime += Time.delta(); if(holdTime >= holdWithdraw){ - int amount = Math.min(tile.entity.items.get(lastItem), player.maxAccepted(lastItem)); + int amount = Math.min(tile.entity.getItems().get(lastItem), player.maxAccepted(lastItem)); Call.requestItem(player, tile, lastItem, amount); holding = false; holdTime = 0f; @@ -117,7 +117,7 @@ public class BlockInventoryFragment extends Fragment{ updateTablePosition(); if(tile.block().hasItems){ for(int i = 0; i < content.items().size; i++){ - boolean has = tile.entity.items.has(content.item(i)); + boolean has = tile.entity.getItems().has(content.item(i)); if(has != container.contains(i)){ rebuild(false); } @@ -136,7 +136,7 @@ public class BlockInventoryFragment extends Fragment{ for(int i = 0; i < content.items().size; i++){ Item item = content.item(i); - if(!tile.entity.items.has(item)) continue; + if(!tile.entity.getItems().has(item)) continue; container.add(i); @@ -149,14 +149,14 @@ public class BlockInventoryFragment extends Fragment{ if(tile == null || tile.entity == null){ return ""; } - return round(tile.entity.items.get(item)); + return round(tile.entity.getItems().get(item)); }); image.addListener(l); image.addListener(new InputListener(){ @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){ - if(!canPick.get() || tile == null || tile.entity == null || tile.entity.items == null || !tile.entity.items.has(item)) return false; + if(!canPick.get() || tile == null || tile.entity == null || tile.entity.getItems() == null || !tile.entity.getItems().has(item)) return false; int amount = Math.min(1, player.maxAccepted(item)); if(amount > 0){ Call.requestItem(player, tile, item, amount); diff --git a/core/src/mindustry/ui/fragments/PlacementFragment.java b/core/src/mindustry/ui/fragments/PlacementFragment.java index 1cb2e653b3..fb5a60d40e 100644 --- a/core/src/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/mindustry/ui/fragments/PlacementFragment.java @@ -12,7 +12,7 @@ import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.*; import mindustry.content.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.entities.units.*; import mindustry.game.EventType.*; import mindustry.gen.*; @@ -220,7 +220,7 @@ public class PlacementFragment extends Fragment{ button.resizeImage(Cicon.medium.size); button.update(() -> { //color unplacable things gray - TileEntity core = player.getClosestCore(); + Tilec core = player.getClosestCore(); Color color = state.rules.infiniteResources || (core != null && (core.items.has(block.requirements, state.rules.buildCostMultiplier) || state.rules.infiniteResources)) ? Color.white : Color.gray; button.forEach(elem -> elem.setColor(color)); button.setChecked(control.input.block == block); @@ -308,7 +308,7 @@ public class PlacementFragment extends Fragment{ line.addImage(stack.item.icon(Cicon.small)).size(8 * 2); line.add(stack.item.localizedName).maxWidth(140f).fillX().color(Color.lightGray).padLeft(2).left().get().setEllipsis(true); line.labelWrap(() -> { - TileEntity core = player.getClosestCore(); + Tilec core = player.getClosestCore(); if(core == null || state.rules.infiniteResources) return "*/*"; int amount = core.items.get(stack.item); diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index efaf8675c8..386b6e7e76 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -1,12 +1,9 @@ package mindustry.world; import arc.*; -import mindustry.annotations.Annotations.*; import arc.Graphics.*; import arc.Graphics.Cursor.*; import arc.audio.*; -import arc.struct.EnumSet; -import arc.struct.*; import arc.func.*; import arc.graphics.*; import arc.graphics.g2d.*; @@ -14,11 +11,13 @@ import arc.graphics.g2d.TextureAtlas.*; import arc.math.*; import arc.math.geom.*; import arc.scene.ui.layout.*; +import arc.struct.EnumSet; +import arc.struct.*; import arc.util.*; import arc.util.ArcAnnotate.*; import arc.util.pooling.*; +import mindustry.annotations.Annotations.*; import mindustry.ctype.*; -import mindustry.ctype.ContentType; import mindustry.entities.*; import mindustry.entities.effect.*; import mindustry.entities.type.*; @@ -145,7 +144,7 @@ public class Block extends BlockStorage{ protected TextureRegion[] cacheRegions = {}; protected Array cacheRegionStrings = new Array<>(); - protected Prov entityType = TileEntity::new; + protected Prov entityType = TileData::new; protected Array tempTiles = new Array<>(); protected TextureRegion[] generatedIcons; @@ -177,7 +176,7 @@ public class Block extends BlockStorage{ } public void onProximityRemoved(Tile tile){ - if(tile.entity.power != null){ + if(tile.entity.getPower() != null){ tile.block().powerGraphRemoved(tile); } } @@ -187,49 +186,49 @@ public class Block extends BlockStorage{ } protected void updatePowerGraph(Tile tile){ - TileEntity entity = tile.ent(); + Tilec entity = tile.ent(); for(Tile other : getPowerConnections(tile, tempTiles)){ - if(other.entity.power != null){ - other.entity.power.graph.add(entity.power.graph); + if(other.entity.getPower() != null){ + other.entity.getPower().graph.add(entity.getPower().graph); } } } protected void powerGraphRemoved(Tile tile){ - if(tile.entity == null || tile.entity.power == null){ + if(tile.entity == null || tile.entity.getPower() == null){ return; } - tile.entity.power.graph.remove(tile); - for(int i = 0; i < tile.entity.power.links.size; i++){ - Tile other = world.tile(tile.entity.power.links.get(i)); - if(other != null && other.entity != null && other.entity.power != null){ - other.entity.power.links.removeValue(tile.pos()); + tile.entity.getPower().graph.remove(tile); + for(int i = 0; i < tile.entity.getPower().links.size; i++){ + Tile other = world.tile(tile.entity.getPower().links.get(i)); + if(other != null && other.entity != null && other.entity.getPower() != null){ + other.entity.getPower().links.removeValue(tile.pos()); } } } public Array getPowerConnections(Tile tile, Array out){ out.clear(); - if(tile == null || tile.entity == null || tile.entity.power == null) return out; + if(tile == null || tile.entity == null || tile.entity.getPower() == null) return out; for(Tile other : tile.entity.proximity()){ - if(other != null && other.entity != null && other.entity.power != null + if(other != null && other.entity != null && other.entity.getPower() != null && !(consumesPower && other.block().consumesPower && !outputsPower && !other.block().outputsPower) - && !tile.entity.power.links.contains(other.pos())){ + && !tile.entity.getPower().links.contains(other.pos())){ out.add(other); } } - for(int i = 0; i < tile.entity.power.links.size; i++){ - Tile link = world.tile(tile.entity.power.links.get(i)); - if(link != null && link.entity != null && link.entity.power != null) out.add(link); + for(int i = 0; i < tile.entity.getPower().links.size; i++){ + Tile link = world.tile(tile.entity.getPower().links.get(i)); + if(link != null && link.entity != null && link.entity.getPower() != null) out.add(link); } return out; } - protected float getProgressIncrease(TileEntity entity, float baseTime){ + protected float getProgressIncrease(Tilec entity, float baseTime){ return 1f / baseTime * entity.delta() * entity.efficiency(); } @@ -301,8 +300,8 @@ public class Block extends BlockStorage{ } public void drawLight(Tile tile){ - if(tile.entity != null && hasLiquids && drawLiquidLight && tile.entity.liquids.current().lightColor.a > 0.001f){ - drawLiquidLight(tile, tile.entity.liquids.current(), tile.entity.liquids.smoothAmount()); + if(tile.entity != null && hasLiquids && drawLiquidLight && tile.entity.getLiquids().current().lightColor.a > 0.001f){ + drawLiquidLight(tile, tile.entity.getLiquids().current(), tile.entity.getLiquids().smoothAmount()); } } @@ -340,14 +339,14 @@ public class Block extends BlockStorage{ Geometry.circle(tile.x, tile.y, range, (x, y) -> { Tile other = world.ltile(x, y); if(other != null && other.block instanceof PowerNode && ((PowerNode)other.block).linkValid(other, tile) && !PowerNode.insulated(other, tile) && !other.entity.proximity().contains(tile) && - !(outputsPower && tile.entity.proximity().contains(p -> p.entity != null && p.entity.power != null && p.entity.power.graph == other.entity.power.graph))){ + !(outputsPower && tile.entity.proximity().contains(p -> p.entity != null && p.entity.getPower() != null && p.entity.getPower().graph == other.entity.getPower().graph))){ tempTiles.add(other); } }); tempTiles.sort(Structs.comparingFloat(t -> t.dst2(tile))); if(!tempTiles.isEmpty()){ Tile toLink = tempTiles.first(); - if(!toLink.entity.power.links.contains(tile.pos())){ + if(!toLink.entity.getPower().links.contains(tile.pos())){ toLink.configureAny(tile.pos()); } } @@ -543,15 +542,15 @@ public class Block extends BlockStorage{ bars.add("health", entity -> new Bar("blocks.health", Pal.health, entity::healthf).blink(Color.white)); if(hasLiquids){ - Func current; + Func current; if(consumes.has(ConsumeType.liquid) && consumes.get(ConsumeType.liquid) instanceof ConsumeLiquid){ Liquid liquid = consumes.get(ConsumeType.liquid).liquid; current = entity -> liquid; }else{ - current = entity -> entity.liquids.current(); + current = entity -> entity.getLiquids().current(); } - bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName, - () -> current.get(entity).barColor(), () -> entity.liquids.get(current.get(entity)) / liquidCapacity)); + bars.add("liquid", entity -> new Bar(() -> entity.getLiquids().get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName, + () -> current.get(entity).barColor(), () -> entity.getLiquids().get(current.get(entity)) / liquidCapacity)); } if(hasPower && consumes.hasPower()){ @@ -559,12 +558,12 @@ public class Block extends BlockStorage{ boolean buffered = cons.buffered; float capacity = cons.capacity; - bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.status * capacity) ? "" : (int)(entity.power.status * capacity)) : - Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.status)); + bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.getPower().status * capacity) ? "" : (int)(entity.getPower().status * capacity)) : + Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.getPower().graph.getPowerProduced() + entity.getPower().graph.getBatteryStored() > 0f ? 1f : entity.getPower().status)); } if(hasItems && configurable){ - bars.add("items", entity -> new Bar(() -> Core.bundle.format("bar.items", entity.items.total()), () -> Pal.items, () -> (float)entity.items.total() / itemCapacity)); + bars.add("items", entity -> new Bar(() -> Core.bundle.format("bar.items", entity.getItems().total()), () -> Pal.items, () -> (float)entity.getItems().total() / itemCapacity)); } } @@ -589,7 +588,7 @@ public class Block extends BlockStorage{ return amount; } - public void handleBulletHit(TileEntity entity, Bullet bullet){ + public void handleBulletHit(Tilec entity, Bulletc bullet){ entity.damage(bullet.damage()); } @@ -609,24 +608,24 @@ public class Block extends BlockStorage{ if(hasItems){ for(Item item : content.items()){ - int amount = tile.entity.items.get(item); + int amount = tile.entity.getItems().get(item); explosiveness += item.explosiveness * amount; flammability += item.flammability * amount; } } if(hasLiquids){ - flammability += tile.entity.liquids.sum((liquid, amount) -> liquid.explosiveness * amount / 2f); - explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 2f); + flammability += tile.entity.getLiquids().sum((liquid, amount) -> liquid.explosiveness * amount / 2f); + explosiveness += tile.entity.getLiquids().sum((liquid, amount) -> liquid.flammability * amount / 2f); } if(consumes.hasPower() && consumes.getPower().buffered){ - power += tile.entity.power.status * consumes.getPower().capacity; + power += tile.entity.getPower().status * consumes.getPower().capacity; } if(hasLiquids){ - tile.entity.liquids.each((liquid, amount) -> { + tile.entity.getLiquids().each((liquid, amount) -> { float splash = Mathf.clamp(amount / 4f, 0f, 10f); for(int i = 0; i < Mathf.clamp(amount / 5, 0, 30); i++){ @@ -657,10 +656,10 @@ public class Block extends BlockStorage{ } return 0; }else{ - float result = tile.entity.items.sum((item, amount) -> item.flammability * amount); + float result = tile.entity.getItems().sum((item, amount) -> item.flammability * amount); if(hasLiquids){ - result += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 3f); + result += tile.entity.getLiquids().sum((liquid, amount) -> liquid.flammability * amount / 3f); } return result; @@ -676,7 +675,7 @@ public class Block extends BlockStorage{ } public void display(Tile tile, Table table){ - TileEntity entity = tile.entity; + Tilec entity = tile.entity; if(entity != null){ table.table(bars -> { @@ -702,7 +701,7 @@ public class Block extends BlockStorage{ } public void displayBars(Tile tile, Table table){ - for(Func bar : bars.list()){ + for(Func bar : bars.list()){ table.add(bar.get(tile.entity)).growX(); table.row(); } @@ -857,7 +856,7 @@ public class Block extends BlockStorage{ return destructible || update; } - public final TileEntity newEntity(){ + public final TileData newData(){ return entityType.get(); } diff --git a/core/src/mindustry/world/BlockStorage.java b/core/src/mindustry/world/BlockStorage.java index 9dbfba53f8..8e15231015 100644 --- a/core/src/mindustry/world/BlockStorage.java +++ b/core/src/mindustry/world/BlockStorage.java @@ -8,7 +8,7 @@ import mindustry.*; import mindustry.content.*; import mindustry.ctype.*; import mindustry.entities.effect.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.consumers.*; @@ -50,7 +50,7 @@ public abstract class BlockStorage extends UnlockableContent{ /** Returns the amount of items this block can accept. */ public int acceptStack(Item item, int amount, Tile tile, Teamc source){ if(acceptItem(item, tile, tile) && hasItems && (source == null || source.getTeam() == tile.getTeam())){ - return Math.min(getMaximumAccepted(tile, item) - tile.entity.items.get(item), amount); + return Math.min(getMaximumAccepted(tile, item) - tile.entity.getItems().get(item), amount); }else{ return 0; } @@ -62,17 +62,17 @@ public abstract class BlockStorage extends UnlockableContent{ /** Remove a stack from this inventory, and return the amount removed. */ public int removeStack(Tile tile, Item item, int amount){ - if(tile.entity == null || tile.entity.items == null) return 0; - amount = Math.min(amount, tile.entity.items.get(item)); + if(tile.entity == null || tile.entity.getItems() == null) return 0; + amount = Math.min(amount, tile.entity.getItems().get(item)); tile.entity.noSleep(); - tile.entity.items.remove(item, amount); + tile.entity.getItems().remove(item, amount); return amount; } /** Handle a stack input. */ public void handleStack(Item item, int amount, Tile tile, Teamc source){ tile.entity.noSleep(); - tile.entity.items.add(item, amount); + tile.entity.getItems().add(item, amount); } public boolean outputsItems(){ @@ -89,19 +89,19 @@ public abstract class BlockStorage extends UnlockableContent{ } public void handleItem(Item item, Tile tile, Tile source){ - tile.entity.items.add(item, 1); + tile.entity.getItems().add(item, 1); } public boolean acceptItem(Item item, Tile tile, Tile source){ - return consumes.itemFilters.get(item.id) && tile.entity.items.get(item) < getMaximumAccepted(tile, item); + return consumes.itemFilters.get(item.id) && tile.entity.getItems().get(item) < getMaximumAccepted(tile, item); } public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ - return hasLiquids && tile.entity.liquids.get(liquid) + amount < liquidCapacity && consumes.liquidfilters.get(liquid.id); + return hasLiquids && tile.entity.getLiquids().get(liquid) + amount < liquidCapacity && consumes.liquidfilters.get(liquid.id); } public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){ - tile.entity.liquids.add(liquid, amount); + tile.entity.getLiquids().add(liquid, amount); } public void tryDumpLiquid(Tile tile, Liquid liquid){ @@ -115,9 +115,9 @@ public abstract class BlockStorage extends UnlockableContent{ other = other.block().getLiquidDestination(other, in, liquid); - if(other != null && other.getTeam() == tile.getTeam() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid) && other.entity.liquids != null){ - float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity; - float fract = tile.entity.liquids.get(liquid) / liquidCapacity; + if(other != null && other.getTeam() == tile.getTeam() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid) && other.entity.getLiquids() != null){ + float ofract = other.entity.getLiquids().get(liquid) / other.block().liquidCapacity; + float fract = tile.entity.getLiquids().get(liquid) / liquidCapacity; if(ofract < fract) tryMoveLiquid(tile, in, other, (fract - ofract) * liquidCapacity / 2f, liquid); } @@ -130,11 +130,11 @@ public abstract class BlockStorage extends UnlockableContent{ } public void tryMoveLiquid(Tile tile, Tile tileSource, Tile next, float amount, Liquid liquid){ - float flow = Math.min(next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f, amount); + float flow = Math.min(next.block().liquidCapacity - next.entity.getLiquids().get(liquid) - 0.001f, amount); if(next.block().acceptLiquid(next, tileSource, liquid, flow)){ next.block().handleLiquid(next, tileSource, liquid, flow); - tile.entity.liquids.remove(liquid, flow); + tile.entity.getLiquids().remove(liquid, flow); } } @@ -148,20 +148,20 @@ public abstract class BlockStorage extends UnlockableContent{ next = next.link(); next = next.block().getLiquidDestination(next, tile, liquid); - if(next.getTeam() == tile.getTeam() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){ + if(next.getTeam() == tile.getTeam() && next.block().hasLiquids && tile.entity.getLiquids().get(liquid) > 0f){ if(next.block().acceptLiquid(next, tile, liquid, 0f)){ - float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity; - float fract = tile.entity.liquids.get(liquid) / liquidCapacity * liquidPressure; - float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.liquids.get(liquid)); - flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f); + float ofract = next.entity.getLiquids().get(liquid) / next.block().liquidCapacity; + float fract = tile.entity.getLiquids().get(liquid) / liquidCapacity * liquidPressure; + float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.getLiquids().get(liquid)); + flow = Math.min(flow, next.block().liquidCapacity - next.entity.getLiquids().get(liquid) - 0.001f); if(flow > 0f && ofract <= fract && next.block().acceptLiquid(next, tile, liquid, flow)){ next.block().handleLiquid(next, tile, liquid, flow); - tile.entity.liquids.remove(liquid, flow); + tile.entity.getLiquids().remove(liquid, flow); return flow; }else if(ofract > 0.1f && fract > 0.1f){ - Liquid other = next.entity.liquids.current(); + Liquid other = next.entity.getLiquids().current(); if((other.flammability > 0.3f && liquid.temperature > 0.7f) || (liquid.flammability > 0.3f && other.temperature > 0.7f)){ tile.entity.damage(1 * Time.delta()); next.entity.damage(1 * Time.delta()); @@ -169,7 +169,7 @@ public abstract class BlockStorage extends UnlockableContent{ Fx.fire.at((tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f); } }else if((liquid.temperature > 0.7f && other.temperature < 0.55f) || (other.temperature > 0.7f && liquid.temperature < 0.55f)){ - tile.entity.liquids.remove(liquid, Math.min(tile.entity.liquids.get(liquid), 0.7f * Time.delta())); + tile.entity.getLiquids().remove(liquid, Math.min(tile.entity.getLiquids().get(liquid), 0.7f * Time.delta())); if(Mathf.chance(0.2f * Time.delta())){ Fx.steam.at((tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f); } @@ -177,9 +177,9 @@ public abstract class BlockStorage extends UnlockableContent{ } } }else if(leakResistance != 100f && !next.block().solid && !next.block().hasLiquids){ - float leakAmount = tile.entity.liquids.get(liquid) / leakResistance; + float leakAmount = tile.entity.getLiquids().get(liquid) / leakResistance; Puddle.deposit(next, tile, liquid, leakAmount); - tile.entity.liquids.remove(liquid, leakAmount); + tile.entity.getLiquids().remove(liquid, leakAmount); } return 0; } @@ -219,8 +219,8 @@ public abstract class BlockStorage extends UnlockableContent{ * @param todump Item to dump. Can be null to dump anything. */ public boolean tryDump(Tile tile, Item todump){ - TileEntity entity = tile.entity; - if(entity == null || !hasItems || tile.entity.items.total() == 0 || (todump != null && !entity.items.has(todump))) + Tilec entity = tile.entity; + if(entity == null || !hasItems || tile.entity.getItems().total() == 0 || (todump != null && !entity.getItems().has(todump))) return false; Array proximity = entity.proximity(); @@ -237,9 +237,9 @@ public abstract class BlockStorage extends UnlockableContent{ for(int ii = 0; ii < Vars.content.items().size; ii++){ Item item = Vars.content.item(ii); - if(other.getTeam() == tile.getTeam() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){ + if(other.getTeam() == tile.getTeam() && entity.getItems().has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){ other.block().handleItem(item, other, in); - tile.entity.items.remove(item, 1); + tile.entity.getItems().remove(item, 1); incrementDump(tile, proximity.size); return true; } @@ -248,7 +248,7 @@ public abstract class BlockStorage extends UnlockableContent{ if(other.getTeam() == tile.getTeam() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){ other.block().handleItem(todump, other, in); - tile.entity.items.remove(todump, 1); + tile.entity.getItems().remove(todump, 1); incrementDump(tile, proximity.size); return true; } diff --git a/core/src/mindustry/world/CachedTile.java b/core/src/mindustry/world/CachedTile.java index 281828dcd7..e4b1fabecb 100644 --- a/core/src/mindustry/world/CachedTile.java +++ b/core/src/mindustry/world/CachedTile.java @@ -1,6 +1,6 @@ package mindustry.world; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.game.Team; import mindustry.world.modules.*; @@ -32,7 +32,7 @@ public class CachedTile extends Tile{ Block block = block(); if(block.hasEntity()){ - TileEntity n = block.newEntity(); + Tilec n = block.newEntity(); n.cons = new ConsumeModule(entity); n.tile = this; n.block = block; diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index 606a3f1ccd..a10baaa06a 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -7,8 +7,6 @@ import arc.struct.*; import arc.util.ArcAnnotate.*; import mindustry.annotations.Annotations.*; import mindustry.content.*; -import mindustry.entities.traits.*; -import mindustry.entities.type.*; import mindustry.game.*; import mindustry.gen.*; import mindustry.type.*; @@ -17,11 +15,11 @@ import mindustry.world.modules.*; import static mindustry.Vars.*; -public class Tile implements Position, TargetTrait{ +public class Tile implements Position{ /** Tile traversal cost. */ public byte cost = 1; /** Tile entity, usually null. */ - public TileEntity entity; + public Tilec entity; public short x, y; protected Block block; protected Floor floor; @@ -100,7 +98,7 @@ public class Tile implements Position, TargetTrait{ } @SuppressWarnings("unchecked") - public T ent(){ + public T ent(){ return (T)entity; } @@ -141,7 +139,6 @@ public class Tile implements Position, TargetTrait{ return (T)block; } - @Override public Team getTeam(){ return Team.get(link().team); } @@ -456,13 +453,14 @@ public class Tile implements Position, TargetTrait{ Block block = block(); if(block.hasEntity()){ + //TODO assign data and don't use new entity entity = block.newEntity().init(this, block.update); - entity.cons = new ConsumeModule(entity); - if(block.hasItems) entity.items = new ItemModule(); - if(block.hasLiquids) entity.liquids = new LiquidModule(); + entity.setCons(new ConsumeModule(entity)); + if(block.hasItems) entity.setItems(new ItemModule()); + if(block.hasLiquids) entity.setLiquids(new LiquidModule()); if(block.hasPower){ - entity.power = new PowerModule(); - entity.power.graph.add(this); + entity.setPower(new PowerModule()); + entity.getPower().graph.add(this); } if(!world.isGenerating()){ @@ -483,36 +481,16 @@ public class Tile implements Position, TargetTrait{ world.notifyChanged(this); } - @Override - public boolean isDead(){ - return entity == null; - } - - @Override - public Vec2 velocity(){ - return Vec2.ZERO; - } - @Override public float getX(){ return drawx(); } - @Override - public void setX(float x){ - throw new IllegalArgumentException("Tile position cannot change."); - } - @Override public float getY(){ return drawy(); } - @Override - public void setY(float y){ - throw new IllegalArgumentException("Tile position cannot change."); - } - @Override public String toString(){ return floor.name + ":" + block.name + ":" + overlay + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) + ":" + getTeam(); diff --git a/core/src/mindustry/world/TileData.java b/core/src/mindustry/world/TileData.java new file mode 100644 index 0000000000..cf34d5ef60 --- /dev/null +++ b/core/src/mindustry/world/TileData.java @@ -0,0 +1,4 @@ +package mindustry.world; + +public class TileData{ +} diff --git a/core/src/mindustry/world/blocks/BuildBlock.java b/core/src/mindustry/world/blocks/BuildBlock.java index b936b918a6..184911c83b 100644 --- a/core/src/mindustry/world/blocks/BuildBlock.java +++ b/core/src/mindustry/world/blocks/BuildBlock.java @@ -11,6 +11,7 @@ import arc.util.*; import mindustry.content.*; import mindustry.entities.effect.*; import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.entities.units.*; import mindustry.game.EventType.*; import mindustry.game.*; @@ -197,7 +198,7 @@ public class BuildBlock extends Block{ } } - public class BuildEntity extends TileEntity{ + public class BuildEntity extends Tilec{ /** * The recipe of the block that is being constructed. * If there is no recipe for this block, as is the case with rocks, 'previous' is used. @@ -217,7 +218,7 @@ public class BuildBlock extends Block{ private float[] accumulator; private float[] totalAccumulator; - public boolean construct(Unitc builder, @Nullable TileEntity core, float amount, boolean configured){ + public boolean construct(Unitc builder, @Nullable Tilec core, float amount, boolean configured){ if(cblock == null){ kill(); return false; @@ -247,7 +248,7 @@ public class BuildBlock extends Block{ return false; } - public void deconstruct(Unitc builder, @Nullable TileEntity core, float amount){ + public void deconstruct(Unitc builder, @Nullable Tilec core, float amount){ float deconstructMultiplier = 0.5f; if(cblock != null){ diff --git a/core/src/mindustry/world/blocks/LiquidBlock.java b/core/src/mindustry/world/blocks/LiquidBlock.java index 91cb843283..3aa52549d8 100644 --- a/core/src/mindustry/world/blocks/LiquidBlock.java +++ b/core/src/mindustry/world/blocks/LiquidBlock.java @@ -36,7 +36,7 @@ public class LiquidBlock extends Block{ @Override public void draw(Tile tile){ - LiquidModule mod = tile.entity.liquids; + LiquidModule mod = tile.entity.getLiquids(); int rotation = rotate ? tile.rotation() * 90 : 0; diff --git a/core/src/mindustry/world/blocks/defense/DeflectorWall.java b/core/src/mindustry/world/blocks/defense/DeflectorWall.java index ae535ca8a6..7c93fcdf54 100644 --- a/core/src/mindustry/world/blocks/defense/DeflectorWall.java +++ b/core/src/mindustry/world/blocks/defense/DeflectorWall.java @@ -5,8 +5,6 @@ import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; import arc.util.*; -import mindustry.entities.type.*; -import mindustry.entities.type.Bullet; import mindustry.world.*; import static mindustry.Vars.tilesize; @@ -42,18 +40,18 @@ public class DeflectorWall extends Wall{ } @Override - public void handleBulletHit(TileEntity entity, Bullet bullet){ + public void handleBulletHit(Tilec entity, Bullet bullet){ super.handleBulletHit(entity, bullet); //doesn't reflect powerful bullets if(bullet.damage() > maxDamageDeflect || bullet.isDeflected()) return; - float penX = Math.abs(entity.x - bullet.x), penY = Math.abs(entity.y - bullet.y); + float penX = Math.abs(entity.getX() - bullet.x), penY = Math.abs(entity.getY() - bullet.y); bullet.hitbox(rect2); Vec2 position = Geometry.raycastRect(bullet.x - bullet.velocity().x*Time.delta(), bullet.y - bullet.velocity().y*Time.delta(), bullet.x + bullet.velocity().x*Time.delta(), bullet.y + bullet.velocity().y*Time.delta(), - rect.setSize(size * tilesize + rect2.width*2 + rect2.height*2).setCenter(entity.x, entity.y)); + rect.setSize(size * tilesize + rect2.width*2 + rect2.height*2).setCenter(entity.getX(), entity.getY())); if(position != null){ bullet.set(position.x, position.y); @@ -73,7 +71,7 @@ public class DeflectorWall extends Wall{ ((DeflectorEntity)entity).hit = 1f; } - public static class DeflectorEntity extends TileEntity{ + public static class DeflectorEntity extends Tilec{ public float hit; } } diff --git a/core/src/mindustry/world/blocks/defense/Door.java b/core/src/mindustry/world/blocks/defense/Door.java index cb5c04d2d4..3783ea7a25 100644 --- a/core/src/mindustry/world/blocks/defense/Door.java +++ b/core/src/mindustry/world/blocks/defense/Door.java @@ -8,9 +8,9 @@ import arc.graphics.g2d.*; import arc.math.geom.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.Effects.*; import mindustry.entities.type.*; import mindustry.gen.*; +import mindustry.gen.*; import mindustry.world.*; import java.io.*; @@ -83,14 +83,14 @@ public class Door extends Wall{ public void tapped(Tile tile, Player player){ DoorEntity entity = tile.ent(); - if((Units.anyEntities(tile) && entity.open) || !tile.entity.timer.get(timerToggle, 30f)){ + if((Units.anyEntities(tile) && entity.open) || !tile.entity.timer(timerToggle, 30f)){ return; } Call.onDoorToggle(null, tile, !entity.open); } - public class DoorEntity extends TileEntity{ + public class DoorEntity extends Tilec{ public boolean open = false; @Override diff --git a/core/src/mindustry/world/blocks/defense/ForceProjector.java b/core/src/mindustry/world/blocks/defense/ForceProjector.java index ab7e7d3d36..06bd20dfbb 100644 --- a/core/src/mindustry/world/blocks/defense/ForceProjector.java +++ b/core/src/mindustry/world/blocks/defense/ForceProjector.java @@ -98,8 +98,8 @@ public class ForceProjector extends Block{ entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(phaseValid), 0.1f); - if(phaseValid && !entity.broken && entity.timer.get(timerUse, phaseUseTime) && entity.efficiency() > 0){ - entity.cons.trigger(); + if(phaseValid && !entity.broken && entity.timer(timerUse, phaseUseTime) && entity.efficiency() > 0){ + entity.consume(); } entity.radscl = Mathf.lerpDelta(entity.radscl, entity.broken ? 0f : entity.warmup, 0.05f); @@ -115,7 +115,7 @@ public class ForceProjector extends Block{ ConsumeLiquidFilter cons = consumes.get(ConsumeType.liquid); if(cons.valid(entity)){ cons.update(entity); - scale *= (cooldownLiquid * (1f + (entity.liquids.current().heatCapacity - 0.4f) * 0.9f)); + scale *= (cooldownLiquid * (1f + (entity.getLiquids().current().heatCapacity - 0.4f) * 0.9f)); } entity.buildup -= Time.delta() * scale; @@ -161,7 +161,7 @@ public class ForceProjector extends Block{ Draw.reset(); } - class ForceEntity extends TileEntity{ + class ForceEntity extends Tilec{ ShieldEntity shield; boolean broken = true; float buildup = 0f; diff --git a/core/src/mindustry/world/blocks/defense/MendProjector.java b/core/src/mindustry/world/blocks/defense/MendProjector.java index 552f823dd0..e71bf18764 100644 --- a/core/src/mindustry/world/blocks/defense/MendProjector.java +++ b/core/src/mindustry/world/blocks/defense/MendProjector.java @@ -7,7 +7,7 @@ import arc.graphics.g2d.*; import arc.math.Mathf; import arc.util.*; import mindustry.content.Fx; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.graphics.*; import mindustry.world.*; import mindustry.world.meta.*; @@ -64,13 +64,13 @@ public class MendProjector extends Block{ @Override public void update(Tile tile){ MendEntity entity = tile.ent(); - entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f); + entity.heat = Mathf.lerpDelta(entity.heat, entity.consValid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f); entity.charge += entity.heat * entity.delta(); entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f); - if(entity.cons.optionalValid() && entity.timer.get(timerUse, useTime) && entity.efficiency() > 0){ - entity.cons.trigger(); + if(entity.cons.optionalValid() && entity.timer(timerUse, useTime) && entity.efficiency() > 0){ + entity.consume(); } if(entity.charge >= reload){ @@ -120,7 +120,7 @@ public class MendProjector extends Block{ renderer.lights.add(tile.drawx(), tile.drawy(), 50f * tile.entity.efficiency(), baseColor, 0.7f * tile.entity.efficiency()); } - class MendEntity extends TileEntity{ + class MendEntity extends Tilec{ float heat; float charge = Mathf.random(reload); float phaseHeat; diff --git a/core/src/mindustry/world/blocks/defense/OverdriveProjector.java b/core/src/mindustry/world/blocks/defense/OverdriveProjector.java index fd18e2662e..31beb4d377 100644 --- a/core/src/mindustry/world/blocks/defense/OverdriveProjector.java +++ b/core/src/mindustry/world/blocks/defense/OverdriveProjector.java @@ -6,7 +6,7 @@ import arc.graphics.Color; import arc.graphics.g2d.*; import arc.math.Mathf; import arc.util.Time; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.graphics.*; import mindustry.world.*; import mindustry.world.meta.*; @@ -75,13 +75,13 @@ public class OverdriveProjector extends Block{ @Override public void update(Tile tile){ OverdriveEntity entity = tile.ent(); - entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() ? 1f : 0f, 0.08f); + entity.heat = Mathf.lerpDelta(entity.heat, entity.consValid() ? 1f : 0f, 0.08f); entity.charge += entity.heat * Time.delta(); entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f); - if(entity.timer.get(timerUse, useTime) && entity.efficiency() > 0){ - entity.cons.trigger(); + if(entity.timer(timerUse, useTime) && entity.efficiency() > 0){ + entity.consume(); } if(entity.charge >= reload){ @@ -118,7 +118,7 @@ public class OverdriveProjector extends Block{ Draw.reset(); } - class OverdriveEntity extends TileEntity{ + class OverdriveEntity extends Tilec{ float heat; float charge = Mathf.random(reload); float phaseHeat; diff --git a/core/src/mindustry/world/blocks/defense/ShockMine.java b/core/src/mindustry/world/blocks/defense/ShockMine.java index 4c6c526ea7..f40c5031e4 100644 --- a/core/src/mindustry/world/blocks/defense/ShockMine.java +++ b/core/src/mindustry/world/blocks/defense/ShockMine.java @@ -49,7 +49,7 @@ public class ShockMine extends Block{ @Override public void unitOn(Tile tile, Unitc unit){ - if(unit.getTeam() != tile.getTeam() && tile.entity.timer.get(timerDamage, cooldown)){ + if(unit.getTeam() != tile.getTeam() && tile.entity.timer(timerDamage, cooldown)){ for(int i = 0; i < tendrils; i++){ Lightning.create(tile.getTeam(), Pal.lancerLaser, damage, tile.drawx(), tile.drawy(), Mathf.random(360f), length); } diff --git a/core/src/mindustry/world/blocks/defense/SurgeWall.java b/core/src/mindustry/world/blocks/defense/SurgeWall.java index d679169c8b..eba0613183 100644 --- a/core/src/mindustry/world/blocks/defense/SurgeWall.java +++ b/core/src/mindustry/world/blocks/defense/SurgeWall.java @@ -1,9 +1,8 @@ package mindustry.world.blocks.defense; import arc.math.Mathf; -import mindustry.entities.type.Bullet; import mindustry.entities.effect.Lightning; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.graphics.Pal; public class SurgeWall extends Wall{ @@ -16,7 +15,7 @@ public class SurgeWall extends Wall{ } @Override - public void handleBulletHit(TileEntity entity, Bullet bullet){ + public void handleBulletHit(Tilec entity, Bullet bullet){ super.handleBulletHit(entity, bullet); if(Mathf.chance(lightningChance)){ Lightning.create(entity.getTeam(), Pal.surge, lightningDamage, bullet.x, bullet.y, bullet.rot() + 180f, lightningLength); diff --git a/core/src/mindustry/world/blocks/defense/turrets/ArtilleryTurret.java b/core/src/mindustry/world/blocks/defense/turrets/ArtilleryTurret.java index a74e4abf94..1a0d69f425 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/ArtilleryTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/ArtilleryTurret.java @@ -3,7 +3,6 @@ package mindustry.world.blocks.defense.turrets; import arc.math.Mathf; import arc.math.geom.Vec2; import mindustry.entities.Predict; -import mindustry.entities.type.Bullet; import mindustry.entities.bullet.BulletType; import mindustry.world.Tile; diff --git a/core/src/mindustry/world/blocks/defense/turrets/CooledTurret.java b/core/src/mindustry/world/blocks/defense/turrets/CooledTurret.java index ea337fc0d7..270bd6b45a 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/CooledTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/CooledTurret.java @@ -37,7 +37,7 @@ public class CooledTurret extends Turret{ @Override public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){ - if(tile.entity.liquids.currentAmount() <= 0.001f){ + if(tile.entity.getLiquids().currentAmount() <= 0.001f){ Events.fire(Trigger.turretCool); } @@ -51,11 +51,11 @@ public class CooledTurret extends Turret{ float maxUsed = consumes.get(ConsumeType.liquid).amount; TurretEntity entity = tile.ent(); - Liquid liquid = entity.liquids.current(); + Liquid liquid = entity.getLiquids().current(); - float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity)) * baseReloadSpeed(tile); + float used = Math.min(Math.min(entity.getLiquids().get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity)) * baseReloadSpeed(tile); entity.reload += used * liquid.heatCapacity * coolantMultiplier; - entity.liquids.remove(liquid, used); + entity.getLiquids().remove(liquid, used); if(Mathf.chance(0.06 * used)){ coolEffect.at(tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f)); diff --git a/core/src/mindustry/world/blocks/defense/turrets/ItemTurret.java b/core/src/mindustry/world/blocks/defense/turrets/ItemTurret.java index e8616599ad..03ed62b75f 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/ItemTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/ItemTurret.java @@ -53,7 +53,7 @@ public class ItemTurret extends CooledTurret{ } @Override - public boolean valid(TileEntity entity){ + public boolean valid(Tilec entity){ //valid when there's any ammo in the turret return !((ItemTurretEntity)entity).ammo.isEmpty(); } diff --git a/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java b/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java index 7dcb08191c..459c85294d 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java @@ -65,19 +65,19 @@ public class LaserTurret extends PowerTurret{ return; } - if(entity.reload >= reload && (entity.cons.valid() || tile.isEnemyCheat())){ + if(entity.reload >= reload && (entity.consValid() || tile.isEnemyCheat())){ BulletType type = peekAmmo(tile); shoot(tile, type); entity.reload = 0f; }else{ - Liquid liquid = entity.liquids.current(); + Liquid liquid = entity.getLiquids().current(); float maxUsed = consumes.get(ConsumeType.liquid).amount; - float used = baseReloadSpeed(tile) * (tile.isEnemyCheat() ? maxUsed : Math.min(entity.liquids.get(liquid), maxUsed * Time.delta())) * liquid.heatCapacity * coolantMultiplier; + float used = baseReloadSpeed(tile) * (tile.isEnemyCheat() ? maxUsed : Math.min(entity.getLiquids().get(liquid), maxUsed * Time.delta())) * liquid.heatCapacity * coolantMultiplier; entity.reload += used; - entity.liquids.remove(liquid, used); + entity.getLiquids().remove(liquid, used); if(Mathf.chance(0.06 * used)){ coolEffect.at(tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f)); diff --git a/core/src/mindustry/world/blocks/defense/turrets/LiquidTurret.java b/core/src/mindustry/world/blocks/defense/turrets/LiquidTurret.java index 33d39a65d4..8525a2206d 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/LiquidTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/LiquidTurret.java @@ -6,7 +6,7 @@ import arc.struct.*; import mindustry.entities.*; import mindustry.entities.bullet.*; import mindustry.entities.effect.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; @@ -38,8 +38,8 @@ public class LiquidTurret extends Turret{ TurretEntity entity = tile.ent(); if(Core.atlas.isFound(reg(liquidRegion))){ - Draw.color(entity.liquids.current().color); - Draw.alpha(entity.liquids.total() / liquidCapacity); + Draw.color(entity.getLiquids().current().color); + Draw.alpha(entity.getLiquids().total() / liquidCapacity); Draw.rect(reg(liquidRegion), tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); Draw.color(); } @@ -52,7 +52,7 @@ public class LiquidTurret extends Turret{ stats.add(BlockStat.ammo, new AmmoListValue<>(ammo)); consumes.add(new ConsumeLiquidFilter(i -> ammo.containsKey(i), 1f){ @Override - public boolean valid(TileEntity entity){ + public boolean valid(Tilec entity){ return !((TurretEntity)entity).ammo.isEmpty(); } @@ -72,7 +72,7 @@ public class LiquidTurret extends Turret{ @Override protected boolean validateTarget(Tile tile){ TurretEntity entity = tile.ent(); - if(entity.liquids.current().canExtinguish() && entity.target instanceof Tile){ + if(entity.getLiquids().current().canExtinguish() && entity.target instanceof Tile){ return Fire.has(((Tile)entity.target).x, ((Tile)entity.target).y); } return super.validateTarget(tile); @@ -81,7 +81,7 @@ public class LiquidTurret extends Turret{ @Override protected void findTarget(Tile tile){ TurretEntity entity = tile.ent(); - if(entity.liquids.current().canExtinguish()){ + if(entity.getLiquids().current().canExtinguish()){ int tr = (int)(range / tilesize); for(int x = -tr; x <= tr; x++){ for(int y = -tr; y <= tr; y++){ @@ -102,8 +102,8 @@ public class LiquidTurret extends Turret{ TurretEntity entity = tile.ent(); - type.shootEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.liquids.current().color); - type.smokeEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.liquids.current().color); + type.shootEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.getLiquids().current().color); + type.smokeEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.getLiquids().current().color); //shootSound.at(tile); if(shootShake > 0){ @@ -116,21 +116,21 @@ public class LiquidTurret extends Turret{ @Override public BulletType useAmmo(Tile tile){ TurretEntity entity = tile.ent(); - if(tile.isEnemyCheat()) return ammo.get(entity.liquids.current()); - BulletType type = ammo.get(entity.liquids.current()); - entity.liquids.remove(entity.liquids.current(), type.ammoMultiplier); + if(tile.isEnemyCheat()) return ammo.get(entity.getLiquids().current()); + BulletType type = ammo.get(entity.getLiquids().current()); + entity.getLiquids().remove(entity.getLiquids().current(), type.ammoMultiplier); return type; } @Override public BulletType peekAmmo(Tile tile){ - return ammo.get(tile.entity.liquids.current()); + return ammo.get(tile.entity.getLiquids().current()); } @Override public boolean hasAmmo(Tile tile){ TurretEntity entity = tile.ent(); - return ammo.get(entity.liquids.current()) != null && entity.liquids.total() >= ammo.get(entity.liquids.current()).ammoMultiplier; + return ammo.get(entity.getLiquids().current()) != null && entity.getLiquids().total() >= ammo.get(entity.getLiquids().current()).ammoMultiplier; } @Override @@ -141,7 +141,7 @@ public class LiquidTurret extends Turret{ @Override public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ return ammo.get(liquid) != null - && (tile.entity.liquids.current() == liquid || (ammo.containsKey(tile.entity.liquids.current()) && tile.entity.liquids.get(tile.entity.liquids.current()) <= ammo.get(tile.entity.liquids.current()).ammoMultiplier + 0.001f)); + && (tile.entity.getLiquids().current() == liquid || (ammo.containsKey(tile.entity.getLiquids().current()) && tile.entity.getLiquids().get(tile.entity.getLiquids().current()) <= ammo.get(tile.entity.getLiquids().current()).ammoMultiplier + 0.001f)); } } diff --git a/core/src/mindustry/world/blocks/defense/turrets/PowerTurret.java b/core/src/mindustry/world/blocks/defense/turrets/PowerTurret.java index 35b11319b8..d009fe7a18 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/PowerTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/PowerTurret.java @@ -47,6 +47,6 @@ public class PowerTurret extends CooledTurret{ @Override protected float baseReloadSpeed(Tile tile){ - return tile.isEnemyCheat() ? 1f : tile.entity.power.status; + return tile.isEnemyCheat() ? 1f : tile.entity.getPower().status; } } diff --git a/core/src/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/mindustry/world/blocks/defense/turrets/Turret.java index f411048f22..c39f1fabab 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/Turret.java @@ -14,10 +14,9 @@ import arc.math.geom.Vec2; import arc.util.Time; import mindustry.content.Fx; import mindustry.entities.*; -import mindustry.entities.Effects.Effect; -import mindustry.entities.type.Bullet; +import mindustry.entities.*; import mindustry.entities.bullet.BulletType; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.world.Block; @@ -153,7 +152,7 @@ public abstract class Turret extends Block{ if(hasAmmo(tile)){ - if(entity.timer.get(timerTarget, targetInterval)){ + if(entity.timer(timerTarget, targetInterval)){ findTarget(tile); } @@ -312,7 +311,7 @@ public abstract class Turret extends Block{ public abstract BulletType type(); } - public static class TurretEntity extends TileEntity{ + public static class TurretEntity extends Tilec{ public Array ammo = new Array<>(); public int totalAmmo; public float reload; @@ -320,7 +319,7 @@ public abstract class Turret extends Block{ public float recoil = 0f; public float heat; public int shots; - public TargetTrait target; + public Teamc target; @Override public void write(DataOutput stream) throws IOException{ diff --git a/core/src/mindustry/world/blocks/distribution/BufferedItemBridge.java b/core/src/mindustry/world/blocks/distribution/BufferedItemBridge.java index 3809fea966..8240d2db25 100644 --- a/core/src/mindustry/world/blocks/distribution/BufferedItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/BufferedItemBridge.java @@ -23,12 +23,12 @@ public class BufferedItemBridge extends ExtendingItemBridge{ public void updateTransport(Tile tile, Tile other){ BufferedItemBridgeEntity entity = tile.ent(); - if(entity.buffer.accepts() && entity.items.total() > 0){ - entity.buffer.accept(entity.items.take()); + if(entity.buffer.accepts() && entity.getItems().total() > 0){ + entity.buffer.accept(entity.getItems().take()); } Item item = entity.buffer.poll(); - if(entity.timer.get(timerAccept, 4) && item != null && other.block().acceptItem(item, other, tile)){ + if(entity.timer(timerAccept, 4) && item != null && other.block().acceptItem(item, other, tile)){ entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f); other.block().handleItem(item, other, tile); entity.buffer.remove(); diff --git a/core/src/mindustry/world/blocks/distribution/Conveyor.java b/core/src/mindustry/world/blocks/distribution/Conveyor.java index 575771c0af..6c3b32b3d5 100644 --- a/core/src/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/mindustry/world/blocks/distribution/Conveyor.java @@ -9,7 +9,7 @@ import arc.struct.*; import arc.util.ArcAnnotate.*; import arc.util.*; import mindustry.content.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -309,7 +309,7 @@ public class Conveyor extends Block implements Autotiler{ } } - public static class ConveyorEntity extends TileEntity{ + public static class ConveyorEntity extends Tilec{ //parallel array data Item[] ids = new Item[capacity]; float[] xs = new float[capacity]; @@ -317,7 +317,7 @@ public class Conveyor extends Block implements Autotiler{ //amount of items, always < capacity int len = 0; //next entity - @Nullable TileEntity next; + @Nullable Tilec next; @Nullable ConveyorEntity nextc; //whether the next conveyor's rotation == tile rotation boolean aligned; diff --git a/core/src/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/mindustry/world/blocks/distribution/ItemBridge.java index eeeb78bb66..bf31643446 100644 --- a/core/src/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ItemBridge.java @@ -187,7 +187,7 @@ public class ItemBridge extends Block{ }else{ ((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos()); - if(entity.cons.valid() && Mathf.zero(1f - entity.efficiency())){ + if(entity.consValid() && Mathf.zero(1f - entity.efficiency())){ entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f); }else{ entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f); @@ -200,14 +200,14 @@ public class ItemBridge extends Block{ public void updateTransport(Tile tile, Tile other){ ItemBridgeEntity entity = tile.ent(); - if(entity.uptime >= 0.5f && entity.timer.get(timerTransport, transportTime)){ - Item item = entity.items.take(); + if(entity.uptime >= 0.5f && entity.timer(timerTransport, transportTime)){ + Item item = entity.getItems().take(); if(item != null && other.block().acceptItem(item, other, tile)){ other.block().handleItem(item, other, tile); entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f); }else{ entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f); - if(item != null) entity.items.add(item, 1); + if(item != null) entity.getItems().add(item, 1); } } } @@ -266,10 +266,10 @@ public class ItemBridge extends Block{ if(rel == rel2) return false; }else{ - return source.block() instanceof ItemBridge && source.ent().link == tile.pos() && tile.entity.items.total() < itemCapacity; + return source.block() instanceof ItemBridge && source.ent().link == tile.pos() && tile.entity.getItems().total() < itemCapacity; } - return tile.entity.items.total() < itemCapacity; + return tile.entity.getItems().total() < itemCapacity; } @@ -315,7 +315,7 @@ public class ItemBridge extends Block{ return false; } - return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f); + return tile.entity.getLiquids().get(liquid) + amount < liquidCapacity && (tile.entity.getLiquids().current() == liquid || tile.entity.getLiquids().get(tile.entity.getLiquids().current()) < 0.2f); } @Override @@ -361,7 +361,7 @@ public class ItemBridge extends Block{ return other.block() == this && (!checkDouble || other.ent().link != tile.pos()); } - public static class ItemBridgeEntity extends TileEntity{ + public static class ItemBridgeEntity extends Tilec{ public int link = Pos.invalid; public IntSet incoming = new IntSet(); public float uptime; diff --git a/core/src/mindustry/world/blocks/distribution/Junction.java b/core/src/mindustry/world/blocks/distribution/Junction.java index d558d7ff3e..3221882f1b 100644 --- a/core/src/mindustry/world/blocks/distribution/Junction.java +++ b/core/src/mindustry/world/blocks/distribution/Junction.java @@ -1,7 +1,7 @@ package mindustry.world.blocks.distribution; import arc.util.Time; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.gen.BufferItem; import mindustry.type.Item; import mindustry.world.Block; @@ -86,7 +86,7 @@ public class Junction extends Block{ return to != null && to.link().entity != null && to.getTeam() == tile.getTeam(); } - class JunctionEntity extends TileEntity{ + class JunctionEntity extends Tilec{ DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity, speed); @Override diff --git a/core/src/mindustry/world/blocks/distribution/MassDriver.java b/core/src/mindustry/world/blocks/distribution/MassDriver.java index 5bfcb7eec7..55483d6def 100644 --- a/core/src/mindustry/world/blocks/distribution/MassDriver.java +++ b/core/src/mindustry/world/blocks/distribution/MassDriver.java @@ -9,7 +9,6 @@ import arc.util.pooling.Pool.*; import arc.util.pooling.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.Effects.*; import mindustry.entities.type.*; import mindustry.graphics.*; import mindustry.type.*; @@ -81,7 +80,7 @@ public class MassDriver extends Block{ //switch states if(entity.state == DriverState.idle){ //start accepting when idle and there's space - if(!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items.total() >= minDistribute)){ + if(!entity.waitingShooters.isEmpty() && (itemCapacity - entity.getItems().total() >= minDistribute)){ entity.state = DriverState.accepting; }else if(hasLink){ //switch to shooting if there's a valid link. entity.state = DriverState.shooting; @@ -94,13 +93,13 @@ public class MassDriver extends Block{ } //skip when there's no power - if(!entity.cons.valid()){ + if(!entity.consValid()){ return; } if(entity.state == DriverState.accepting){ //if there's nothing shooting at this, bail - OR, items full - if(entity.currentShooter() == null || (itemCapacity - entity.items.total() < minDistribute)){ + if(entity.currentShooter() == null || (itemCapacity - entity.getItems().total() < minDistribute)){ entity.state = DriverState.idle; return; } @@ -109,7 +108,7 @@ public class MassDriver extends Block{ entity.rotation = Mathf.slerpDelta(entity.rotation, tile.angleTo(entity.currentShooter()), rotateSpeed * entity.efficiency()); }else if(entity.state == DriverState.shooting){ //if there's nothing to shoot at OR someone wants to shoot at this thing, bail - if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items.total() >= minDistribute))){ + if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.getItems().total() >= minDistribute))){ entity.state = DriverState.idle; return; } @@ -117,8 +116,8 @@ public class MassDriver extends Block{ float targetRotation = tile.angleTo(link); if( - tile.entity.items.total() >= minDistribute && //must shoot minimum amount of items - link.block().itemCapacity - link.entity.items.total() >= minDistribute //must have minimum amount of space + tile.entity.getItems().total() >= minDistribute && //must shoot minimum amount of items + link.block().itemCapacity - link.entity.getItems().total() >= minDistribute //must have minimum amount of space ){ MassDriverEntity other = link.ent(); other.waitingShooters.add(tile); @@ -226,7 +225,7 @@ public class MassDriver extends Block{ @Override public boolean acceptItem(Item item, Tile tile, Tile source){ //mass drivers that ouput only cannot accept items - return tile.entity.items.total() < itemCapacity && linkValid(tile); + return tile.entity.getItems().total() < itemCapacity && linkValid(tile); } protected void fire(Tile tile, Tile target){ @@ -241,10 +240,10 @@ public class MassDriver extends Block{ data.to = other; int totalUsed = 0; for(int i = 0; i < content.items().size; i++){ - int maxTransfer = Math.min(entity.items.get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed); + int maxTransfer = Math.min(entity.getItems().get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed); data.items[i] = maxTransfer; totalUsed += maxTransfer; - entity.items.remove(content.item(i), maxTransfer); + entity.getItems().remove(content.item(i), maxTransfer); } float angle = tile.angleTo(target); @@ -263,12 +262,12 @@ public class MassDriver extends Block{ } protected void handlePayload(MassDriverEntity entity, Bullet bullet, DriverBulletData data){ - int totalItems = entity.items.total(); + int totalItems = entity.getItems().total(); //add all the items possible for(int i = 0; i < data.items.length; i++){ int maxAdd = Math.min(data.items[i], itemCapacity * 2 - totalItems); - entity.items.add(content.item(i), maxAdd); + entity.getItems().add(content.item(i), maxAdd); data.items[i] -= maxAdd; totalItems += maxAdd; @@ -312,7 +311,7 @@ public class MassDriver extends Block{ } } - public class MassDriverEntity extends TileEntity{ + public class MassDriverEntity extends Tilec{ int link = -1; float rotation = 90; float reload = 0f; diff --git a/core/src/mindustry/world/blocks/distribution/OverflowGate.java b/core/src/mindustry/world/blocks/distribution/OverflowGate.java index c3314577f3..dcf744d642 100644 --- a/core/src/mindustry/world/blocks/distribution/OverflowGate.java +++ b/core/src/mindustry/world/blocks/distribution/OverflowGate.java @@ -2,7 +2,7 @@ package mindustry.world.blocks.distribution; import arc.math.Mathf; import arc.util.Time; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.type.Item; import mindustry.world.*; import mindustry.world.meta.BlockGroup; @@ -42,8 +42,8 @@ public class OverflowGate extends Block{ public void update(Tile tile){ OverflowGateEntity entity = tile.ent(); - if(entity.lastItem == null && entity.items.total() > 0){ - entity.items.clear(); + if(entity.lastItem == null && entity.getItems().total() > 0){ + entity.getItems().clear(); } if(entity.lastItem != null){ @@ -53,7 +53,7 @@ public class OverflowGate extends Block{ if(target != null && (entity.time >= 1f)){ getTileTarget(tile, entity.lastItem, entity.lastInput, true); target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target)); - entity.items.remove(entity.lastItem, 1); + entity.getItems().remove(entity.lastItem, 1); entity.lastItem = null; } } @@ -63,13 +63,13 @@ public class OverflowGate extends Block{ public boolean acceptItem(Item item, Tile tile, Tile source){ OverflowGateEntity entity = tile.ent(); - return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.items.total() == 0; + return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.getItems().total() == 0; } @Override public void handleItem(Item item, Tile tile, Tile source){ OverflowGateEntity entity = tile.ent(); - entity.items.add(item, 1); + entity.getItems().add(item, 1); entity.lastItem = item; entity.time = 0f; entity.lastInput = source; @@ -113,7 +113,7 @@ public class OverflowGate extends Block{ return to; } - public class OverflowGateEntity extends TileEntity{ + public class OverflowGateEntity extends Tilec{ Item lastItem; Tile lastInput; float time; diff --git a/core/src/mindustry/world/blocks/distribution/Router.java b/core/src/mindustry/world/blocks/distribution/Router.java index 8cfa4525d0..2718ddb30b 100644 --- a/core/src/mindustry/world/blocks/distribution/Router.java +++ b/core/src/mindustry/world/blocks/distribution/Router.java @@ -3,7 +3,7 @@ package mindustry.world.blocks.distribution; import arc.struct.Array; import arc.util.Time; import mindustry.content.*; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.type.Item; import mindustry.world.*; import mindustry.world.meta.BlockGroup; @@ -26,8 +26,8 @@ public class Router extends Block{ public void update(Tile tile){ RouterEntity entity = tile.ent(); - if(entity.lastItem == null && entity.items.total() > 0){ - entity.items.clear(); + if(entity.lastItem == null && entity.getItems().total() > 0){ + entity.getItems().clear(); } if(entity.lastItem != null){ @@ -37,7 +37,7 @@ public class Router extends Block{ if(target != null && (entity.time >= 1f || !(target.block() instanceof Router))){ getTileTarget(tile, entity.lastItem, entity.lastInput, true); target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target)); - entity.items.remove(entity.lastItem, 1); + entity.getItems().remove(entity.lastItem, 1); entity.lastItem = null; } } @@ -47,13 +47,13 @@ public class Router extends Block{ public boolean acceptItem(Item item, Tile tile, Tile source){ RouterEntity entity = tile.ent(); - return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.items.total() == 0; + return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.getItems().total() == 0; } @Override public void handleItem(Item item, Tile tile, Tile source){ RouterEntity entity = tile.ent(); - entity.items.add(item, 1); + entity.getItems().add(item, 1); entity.lastItem = item; entity.time = 0f; entity.lastInput = source; @@ -83,7 +83,7 @@ public class Router extends Block{ return result; } - public class RouterEntity extends TileEntity{ + public class RouterEntity extends Tilec{ Item lastItem; Tile lastInput; float time; diff --git a/core/src/mindustry/world/blocks/distribution/Sorter.java b/core/src/mindustry/world/blocks/distribution/Sorter.java index 193aa47b3b..41b5359f07 100644 --- a/core/src/mindustry/world/blocks/distribution/Sorter.java +++ b/core/src/mindustry/world/blocks/distribution/Sorter.java @@ -139,7 +139,7 @@ public class Sorter extends Block{ }); } - public class SorterEntity extends TileEntity{ + public class SorterEntity extends Tilec{ @Nullable Item sortItem; @Override diff --git a/core/src/mindustry/world/blocks/liquid/Conduit.java b/core/src/mindustry/world/blocks/liquid/Conduit.java index cac41f7337..3d6a6bfc00 100644 --- a/core/src/mindustry/world/blocks/liquid/Conduit.java +++ b/core/src/mindustry/world/blocks/liquid/Conduit.java @@ -96,7 +96,7 @@ public class Conduit extends LiquidBlock implements Autotiler{ Draw.colorl(0.34f); Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation); - Draw.color(tile.entity.liquids.current().color); + Draw.color(tile.entity.getLiquids().current().color); Draw.alpha(entity.smoothLiquid); Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation); Draw.color(); @@ -107,10 +107,10 @@ public class Conduit extends LiquidBlock implements Autotiler{ @Override public void update(Tile tile){ ConduitEntity entity = tile.ent(); - entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.liquids.currentAmount() / liquidCapacity, 0.05f); + entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.getLiquids().currentAmount() / liquidCapacity, 0.05f); - if(tile.entity.liquids.total() > 0.001f && tile.entity.timer.get(timerFlow, 1)){ - tryMoveLiquid(tile, tile.getNearby(tile.rotation()), leakResistance, tile.entity.liquids.current()); + if(tile.entity.getLiquids().total() > 0.001f && tile.entity.timer(timerFlow, 1)){ + tryMoveLiquid(tile, tile.getNearby(tile.rotation()), leakResistance, tile.entity.getLiquids().current()); entity.noSleep(); }else{ entity.sleep(); @@ -125,11 +125,11 @@ public class Conduit extends LiquidBlock implements Autotiler{ @Override public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ tile.entity.noSleep(); - return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f) + return tile.entity.getLiquids().get(liquid) + amount < liquidCapacity && (tile.entity.getLiquids().current() == liquid || tile.entity.getLiquids().get(tile.entity.getLiquids().current()) < 0.2f) && ((source.absoluteRelativeTo(tile.x, tile.y) + 2) % 4 != tile.rotation()); } - public static class ConduitEntity extends TileEntity{ + public static class ConduitEntity extends Tilec{ public float smoothLiquid; int blendbits; diff --git a/core/src/mindustry/world/blocks/liquid/LiquidBridge.java b/core/src/mindustry/world/blocks/liquid/LiquidBridge.java index b1a790b491..e1a387c399 100644 --- a/core/src/mindustry/world/blocks/liquid/LiquidBridge.java +++ b/core/src/mindustry/world/blocks/liquid/LiquidBridge.java @@ -28,11 +28,11 @@ public class LiquidBridge extends ItemBridge{ Tile other = world.tile(entity.link); if(!linkValid(tile, other)){ - tryDumpLiquid(tile, entity.liquids.current()); + tryDumpLiquid(tile, entity.getLiquids().current()); }else{ ((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos()); - if(entity.cons.valid()){ + if(entity.consValid()){ float alpha = 0.04f; if(hasPower){ alpha *= entity.efficiency(); // Exceed boot time unless power is at max. @@ -44,7 +44,7 @@ public class LiquidBridge extends ItemBridge{ if(entity.uptime >= 0.5f){ - if(tryMoveLiquid(tile, other, false, entity.liquids.current()) > 0.1f){ + if(tryMoveLiquid(tile, other, false, entity.getLiquids().current()) > 0.1f){ entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f); }else{ entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f); diff --git a/core/src/mindustry/world/blocks/liquid/LiquidExtendingBridge.java b/core/src/mindustry/world/blocks/liquid/LiquidExtendingBridge.java index 8b7840e9ad..4ba16301b4 100644 --- a/core/src/mindustry/world/blocks/liquid/LiquidExtendingBridge.java +++ b/core/src/mindustry/world/blocks/liquid/LiquidExtendingBridge.java @@ -28,11 +28,11 @@ public class LiquidExtendingBridge extends ExtendingItemBridge{ Tile other = world.tile(entity.link); if(!linkValid(tile, other)){ - tryDumpLiquid(tile, entity.liquids.current()); + tryDumpLiquid(tile, entity.getLiquids().current()); }else{ ((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos()); - if(entity.cons.valid()){ + if(entity.consValid()){ entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f); }else{ entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f); @@ -40,7 +40,7 @@ public class LiquidExtendingBridge extends ExtendingItemBridge{ if(entity.uptime >= 0.5f){ - if(tryMoveLiquid(tile, other, false, entity.liquids.current()) > 0.1f){ + if(tryMoveLiquid(tile, other, false, entity.getLiquids().current()) > 0.1f){ entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f); }else{ entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f); diff --git a/core/src/mindustry/world/blocks/liquid/LiquidRouter.java b/core/src/mindustry/world/blocks/liquid/LiquidRouter.java index 35f7e09ea8..b912227d41 100644 --- a/core/src/mindustry/world/blocks/liquid/LiquidRouter.java +++ b/core/src/mindustry/world/blocks/liquid/LiquidRouter.java @@ -13,13 +13,13 @@ public class LiquidRouter extends LiquidBlock{ @Override public void update(Tile tile){ - if(tile.entity.liquids.total() > 0.01f){ - tryDumpLiquid(tile, tile.entity.liquids.current()); + if(tile.entity.getLiquids().total() > 0.01f){ + tryDumpLiquid(tile, tile.entity.getLiquids().current()); } } @Override public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ - return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f); + return tile.entity.getLiquids().get(liquid) + amount < liquidCapacity && (tile.entity.getLiquids().current() == liquid || tile.entity.getLiquids().get(tile.entity.getLiquids().current()) < 0.2f); } } diff --git a/core/src/mindustry/world/blocks/logic/MessageBlock.java b/core/src/mindustry/world/blocks/logic/MessageBlock.java index 697dda9401..49fcc287f0 100644 --- a/core/src/mindustry/world/blocks/logic/MessageBlock.java +++ b/core/src/mindustry/world/blocks/logic/MessageBlock.java @@ -13,6 +13,7 @@ import arc.util.pooling.*; import mindustry.entities.*; import mindustry.entities.type.*; import mindustry.gen.*; +import mindustry.gen.*; import mindustry.net.*; import mindustry.ui.*; import mindustry.ui.dialogs.*; @@ -146,7 +147,7 @@ public class MessageBlock extends Block{ table.setPosition(pos.x, pos.y, Align.bottom); } - public class MessageBlockEntity extends TileEntity{ + public class MessageBlockEntity extends Tilec{ public String message = ""; public String[] lines = {""}; diff --git a/core/src/mindustry/world/blocks/power/ConditionalConsumePower.java b/core/src/mindustry/world/blocks/power/ConditionalConsumePower.java index fa94ea64cc..35e3b08514 100644 --- a/core/src/mindustry/world/blocks/power/ConditionalConsumePower.java +++ b/core/src/mindustry/world/blocks/power/ConditionalConsumePower.java @@ -1,20 +1,20 @@ package mindustry.world.blocks.power; import arc.func.Boolf; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.world.consumers.ConsumePower; /** A power consumer that only activates sometimes. */ public class ConditionalConsumePower extends ConsumePower{ - private final Boolf consume; + private final Boolf consume; - public ConditionalConsumePower(float usage, Boolf consume){ + public ConditionalConsumePower(float usage, Boolf consume){ super(usage, 0, false); this.consume = consume; } @Override - public float requestedPower(TileEntity entity){ + public float requestedPower(Tilec entity){ return consume.get(entity) ? usage : 0f; } } diff --git a/core/src/mindustry/world/blocks/power/ImpactReactor.java b/core/src/mindustry/world/blocks/power/ImpactReactor.java index b791592a70..041c99727f 100644 --- a/core/src/mindustry/world/blocks/power/ImpactReactor.java +++ b/core/src/mindustry/world/blocks/power/ImpactReactor.java @@ -71,7 +71,7 @@ public class ImpactReactor extends PowerGenerator{ public void update(Tile tile){ FusionReactorEntity entity = tile.ent(); - if(entity.cons.valid() && entity.power.status >= 0.99f){ + if(entity.consValid() && entity.getPower().status >= 0.99f){ boolean prevOut = getPowerProduction(tile) <= consumes.getPower().requestedPower(entity); entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed); @@ -83,8 +83,8 @@ public class ImpactReactor extends PowerGenerator{ Events.fire(Trigger.impactPower); } - if(entity.timer.get(timerUse, itemDuration / entity.timeScale)){ - entity.cons.trigger(); + if(entity.timer(timerUse, itemDuration / entity.timeScale)){ + entity.consume(); } }else{ entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f); diff --git a/core/src/mindustry/world/blocks/power/ItemLiquidGenerator.java b/core/src/mindustry/world/blocks/power/ItemLiquidGenerator.java index ee8dacdb50..c324b203be 100644 --- a/core/src/mindustry/world/blocks/power/ItemLiquidGenerator.java +++ b/core/src/mindustry/world/blocks/power/ItemLiquidGenerator.java @@ -99,14 +99,14 @@ public class ItemLiquidGenerator extends PowerGenerator{ //Power amount is delta'd by PowerGraph class already. float calculationDelta = entity.delta(); - if(!entity.cons.valid()){ + if(!entity.consValid()){ entity.productionEfficiency = 0.0f; return; } Liquid liquid = null; for(Liquid other : content.liquids()){ - if(hasLiquids && entity.liquids.get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency){ + if(hasLiquids && entity.getLiquids().get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency){ liquid = other; break; } @@ -115,12 +115,12 @@ public class ItemLiquidGenerator extends PowerGenerator{ entity.heat = Mathf.lerpDelta(entity.heat, entity.generateTime >= 0.001f ? 1f : 0f, 0.05f); //liquid takes priority over solids - if(hasLiquids && liquid != null && entity.liquids.get(liquid) >= 0.001f){ + if(hasLiquids && liquid != null && entity.getLiquids().get(liquid) >= 0.001f){ float baseLiquidEfficiency = getLiquidEfficiency(liquid); float maximumPossible = maxLiquidGenerate * calculationDelta; - float used = Math.min(entity.liquids.get(liquid) * calculationDelta, maximumPossible); + float used = Math.min(entity.getLiquids().get(liquid) * calculationDelta, maximumPossible); - entity.liquids.remove(liquid, used * entity.power.graph.getUsageFraction()); + entity.getLiquids().remove(liquid, used * entity.getPower().graph.getUsageFraction()); entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible; if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){ @@ -128,16 +128,16 @@ public class ItemLiquidGenerator extends PowerGenerator{ } }else if(hasItems){ // No liquids accepted or none supplied, try using items if accepted - if(entity.generateTime <= 0f && entity.items.total() > 0){ + if(entity.generateTime <= 0f && entity.getItems().total() > 0){ generateEffect.at(tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f)); - Item item = entity.items.take(); + Item item = entity.getItems().take(); entity.productionEfficiency = getItemEfficiency(item); entity.explosiveness = item.explosiveness; entity.generateTime = 1f; } if(entity.generateTime > 0f){ - entity.generateTime -= Math.min(1f / itemDuration * entity.delta() * entity.power.graph.getUsageFraction(), entity.generateTime); + entity.generateTime -= Math.min(1f / itemDuration * entity.delta() * entity.getPower().graph.getUsageFraction(), entity.generateTime); if(randomlyExplode && state.rules.reactorExplosions && Mathf.chance(entity.delta() * 0.06 * Mathf.clamp(entity.explosiveness - 0.5f))){ //this block is run last so that in the event of a block destruction, no code relies on the block type @@ -166,8 +166,8 @@ public class ItemLiquidGenerator extends PowerGenerator{ } if(hasLiquids){ - Draw.color(entity.liquids.current().color); - Draw.alpha(entity.liquids.currentAmount() / liquidCapacity); + Draw.color(entity.getLiquids().current().color); + Draw.alpha(entity.getLiquids().currentAmount() / liquidCapacity); Draw.rect(liquidRegion, tile.drawx(), tile.drawy()); Draw.color(); } diff --git a/core/src/mindustry/world/blocks/power/LightBlock.java b/core/src/mindustry/world/blocks/power/LightBlock.java index 82637dd410..69d30d4de7 100644 --- a/core/src/mindustry/world/blocks/power/LightBlock.java +++ b/core/src/mindustry/world/blocks/power/LightBlock.java @@ -6,6 +6,7 @@ import arc.scene.ui.layout.*; import arc.util.*; import mindustry.entities.type.*; import mindustry.gen.*; +import mindustry.gen.*; import mindustry.graphics.*; import mindustry.world.*; @@ -72,7 +73,7 @@ public class LightBlock extends Block{ renderer.lights.add(tile.drawx(), tile.drawy(), radius, Tmp.c1.set(entity.color), brightness * tile.entity.efficiency()); } - public class LightEntity extends TileEntity{ + public class LightEntity extends Tilec{ public int color = Pal.accent.rgba(); @Override diff --git a/core/src/mindustry/world/blocks/power/NuclearReactor.java b/core/src/mindustry/world/blocks/power/NuclearReactor.java index 86eebd7ef4..e18e568c2a 100644 --- a/core/src/mindustry/world/blocks/power/NuclearReactor.java +++ b/core/src/mindustry/world/blocks/power/NuclearReactor.java @@ -79,24 +79,24 @@ public class NuclearReactor extends PowerGenerator{ ConsumeLiquid cliquid = consumes.get(ConsumeType.liquid); Item item = consumes.get(ConsumeType.item).items[0].item; - int fuel = entity.items.get(item); + int fuel = entity.getItems().get(item); float fullness = (float)fuel / itemCapacity; entity.productionEfficiency = fullness; if(fuel > 0){ entity.heat += fullness * heating * Math.min(entity.delta(), 4f); - if(entity.timer.get(timerFuel, itemDuration / entity.timeScale)){ - entity.cons.trigger(); + if(entity.timer(timerFuel, itemDuration / entity.timeScale)){ + entity.consume(); } } Liquid liquid = cliquid.liquid; if(entity.heat > 0){ - float maxUsed = Math.min(entity.liquids.get(liquid), entity.heat / coolantPower); + float maxUsed = Math.min(entity.getLiquids().get(liquid), entity.heat / coolantPower); entity.heat -= maxUsed * coolantPower; - entity.liquids.remove(liquid, maxUsed); + entity.getLiquids().remove(liquid, maxUsed); } if(entity.heat > smokeThreshold){ @@ -123,7 +123,7 @@ public class NuclearReactor extends PowerGenerator{ NuclearReactorEntity entity = tile.ent(); - int fuel = entity.items.get(consumes.get(ConsumeType.item).items[0].item); + int fuel = entity.getItems().get(consumes.get(ConsumeType.item).items[0].item); if((fuel < 5 && entity.heat < 0.5f) || !state.rules.reactorExplosions) return; @@ -166,8 +166,8 @@ public class NuclearReactor extends PowerGenerator{ Draw.color(coolColor, hotColor, entity.heat); Fill.rect(tile.drawx(), tile.drawy(), size * tilesize, size * tilesize); - Draw.color(entity.liquids.current().color); - Draw.alpha(entity.liquids.currentAmount() / liquidCapacity); + Draw.color(entity.getLiquids().current().color); + Draw.alpha(entity.getLiquids().currentAmount() / liquidCapacity); Draw.rect(topRegion, tile.drawx(), tile.drawy()); if(entity.heat > flashThreshold){ diff --git a/core/src/mindustry/world/blocks/power/PowerDiode.java b/core/src/mindustry/world/blocks/power/PowerDiode.java index 7584494d79..20204c48ac 100644 --- a/core/src/mindustry/world/blocks/power/PowerDiode.java +++ b/core/src/mindustry/world/blocks/power/PowerDiode.java @@ -29,8 +29,8 @@ public class PowerDiode extends Block{ if(tile.front() == null || tile.back() == null || !tile.back().block().hasPower || !tile.front().block().hasPower || tile.back().getTeam() != tile.front().getTeam()) return; - PowerGraph backGraph = tile.back().entity.power.graph; - PowerGraph frontGraph = tile.front().entity.power.graph; + PowerGraph backGraph = tile.back().entity.getPower().graph; + PowerGraph frontGraph = tile.front().entity.getPower().graph; if(backGraph == frontGraph) return; // 0f - 1f of battery capacity in use @@ -51,7 +51,7 @@ public class PowerDiode extends Block{ // battery % of the graph on either side, defaults to zero public float bar(Tile tile){ - return (tile != null && tile.block().hasPower) ? tile.entity.power.graph.getBatteryStored() / tile.entity.power.graph.getTotalBatteryCapacity() : 0f; + return (tile != null && tile.block().hasPower) ? tile.entity.getPower().graph.getBatteryStored() / tile.entity.getPower().graph.getTotalBatteryCapacity() : 0f; } @Override diff --git a/core/src/mindustry/world/blocks/power/PowerGenerator.java b/core/src/mindustry/world/blocks/power/PowerGenerator.java index b7cff15bd7..e900b68f5c 100644 --- a/core/src/mindustry/world/blocks/power/PowerGenerator.java +++ b/core/src/mindustry/world/blocks/power/PowerGenerator.java @@ -3,7 +3,7 @@ package mindustry.world.blocks.power; import arc.Core; import arc.struct.EnumSet; import arc.util.Strings; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.graphics.Pal; import mindustry.ui.Bar; import mindustry.world.Tile; @@ -53,7 +53,7 @@ public class PowerGenerator extends PowerDistributor{ return false; } - public static class GeneratorEntity extends TileEntity{ + public static class GeneratorEntity extends Tilec{ public float generateTime; /** The efficiency of the producer. An efficiency of 1.0 means 100% */ public float productionEfficiency = 0.0f; diff --git a/core/src/mindustry/world/blocks/power/PowerGraph.java b/core/src/mindustry/world/blocks/power/PowerGraph.java index be5d593797..06f43330af 100644 --- a/core/src/mindustry/world/blocks/power/PowerGraph.java +++ b/core/src/mindustry/world/blocks/power/PowerGraph.java @@ -88,7 +88,7 @@ public class PowerGraph{ for(Tile battery : batteries){ Consumers consumes = battery.block().consumes; if(consumes.hasPower()){ - totalAccumulator += battery.entity.power.status * consumes.getPower().capacity; + totalAccumulator += battery.entity.getPower().status * consumes.getPower().capacity; } } return totalAccumulator; @@ -99,7 +99,7 @@ public class PowerGraph{ for(Tile battery : batteries){ if(battery.block().consumes.hasPower()){ ConsumePower power = battery.block().consumes.getPower(); - totalCapacity += (1f - battery.entity.power.status) * power.capacity; + totalCapacity += (1f - battery.entity.getPower().status) * power.capacity; } } return totalCapacity; @@ -124,7 +124,7 @@ public class PowerGraph{ for(Tile battery : batteries){ Consumers consumes = battery.block().consumes; if(consumes.hasPower()){ - battery.entity.power.status *= (1f-consumedPowerPercentage); + battery.entity.getPower().status *= (1f-consumedPowerPercentage); } } return used; @@ -141,7 +141,7 @@ public class PowerGraph{ if(consumes.hasPower()){ ConsumePower consumePower = consumes.getPower(); if(consumePower.capacity > 0f){ - battery.entity.power.status += (1f-battery.entity.power.status) * chargedPercent; + battery.entity.getPower().status += (1f-battery.entity.getPower().status) * chargedPercent; } } } @@ -159,17 +159,17 @@ public class PowerGraph{ if(!Mathf.zero(consumePower.capacity)){ // Add an equal percentage of power to all buffers, based on the global power coverage in this graph float maximumRate = consumePower.requestedPower(consumer.entity) * coverage * consumer.entity.delta(); - consumer.entity.power.status = Mathf.clamp(consumer.entity.power.status + maximumRate / consumePower.capacity); + consumer.entity.getPower().status = Mathf.clamp(consumer.entity.getPower().status + maximumRate / consumePower.capacity); } }else{ //valid consumers get power as usual if(otherConsumersAreValid(consumer, consumePower)){ - consumer.entity.power.status = coverage; + consumer.entity.getPower().status = coverage; }else{ //invalid consumers get an estimate, if they were to activate - consumer.entity.power.status = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta())); + consumer.entity.getPower().status = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta())); //just in case - if(Float.isNaN(consumer.entity.power.status)){ - consumer.entity.power.status = 0f; + if(Float.isNaN(consumer.entity.getPower().status)){ + consumer.entity.getPower().status = 0f; } } } @@ -183,7 +183,7 @@ public class PowerGraph{ }else if(!consumers.isEmpty() && consumers.first().isEnemyCheat()){ //when cheating, just set status to 1 for(Tile tile : consumers){ - tile.entity.power.status = 1f; + tile.entity.getPower().status = 1f; } lastPowerNeeded = lastPowerProduced = lastUsageFraction = 1f; @@ -230,8 +230,8 @@ public class PowerGraph{ } public void add(Tile tile){ - if(tile.entity == null || tile.entity.power == null) return; - tile.entity.power.graph = this; + if(tile.entity == null || tile.entity.getPower() == null) return; + tile.entity.getPower().graph = this; all.add(tile); if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.getPower().buffered){ @@ -277,7 +277,7 @@ public class PowerGraph{ //go through all the connections of this tile for(Tile other : tile.block().getPowerConnections(tile, outArray1)){ //a graph has already been assigned to this tile from a previous call, skip it - if(other.entity.power.graph != this) continue; + if(other.entity.getPower().graph != this) continue; //create graph for this branch PowerGraph graph = new PowerGraph(); @@ -296,7 +296,7 @@ public class PowerGraph{ for(Tile next : child.block().getPowerConnections(child, outArray2)){ //make sure it hasn't looped back, and that the new graph being assigned hasn't already been assigned //also skip closed tiles - if(next != tile && next.entity.power.graph != graph && !closedSet.contains(next.pos())){ + if(next != tile && next.entity.getPower().graph != graph && !closedSet.contains(next.pos())){ queue.addLast(next); closedSet.add(next.pos()); } diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 65de453319..0650626f3a 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -39,40 +39,40 @@ public class PowerNode extends PowerBlock{ @Override public void configured(Tile tile, Player player, int value){ - TileEntity entity = tile.entity; + 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; + boolean contains = entity.getPower().links.contains(value), valid = other != null && other.entity != null && other.entity.getPower() != null; if(contains){ //unlink - entity.power.links.removeValue(value); - if(valid) other.entity.power.links.removeValue(tile.pos()); + entity.getPower().links.removeValue(value); + if(valid) other.entity.getPower().links.removeValue(tile.pos()); PowerGraph newgraph = new PowerGraph(); //reflow from this point, covering all tiles on this side newgraph.reflow(tile); - if(valid && other.entity.power.graph != newgraph){ + if(valid && other.entity.getPower().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){ + }else if(linkValid(tile, other) && valid && entity.getPower().links.size < maxNodes){ - if(!entity.power.links.contains(other.pos())){ - entity.power.links.add(other.pos()); + if(!entity.getPower().links.contains(other.pos())){ + entity.getPower().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(!other.entity.getPower().links.contains(tile.pos())){ + other.entity.getPower().links.add(tile.pos()); } } - entity.power.graph.add(other.entity.power.graph); + entity.getPower().graph.add(other.entity.getPower().graph); } } @@ -89,15 +89,15 @@ public class PowerNode extends PowerBlock{ super.setBars(); bars.add("power", entity -> new Bar(() -> Core.bundle.format("bar.powerbalance", - ((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.power.graph.getPowerBalance() * 60, 1))), + ((entity.getPower().graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.getPower().graph.getPowerBalance() * 60, 1))), () -> Pal.powerBar, - () -> Mathf.clamp(entity.power.graph.getLastPowerProduced() / entity.power.graph.getLastPowerNeeded()))); + () -> Mathf.clamp(entity.getPower().graph.getLastPowerProduced() / entity.getPower().graph.getLastPowerNeeded()))); bars.add("batteries", entity -> new Bar(() -> Core.bundle.format("bar.powerstored", - (ui.formatAmount((int)entity.power.graph.getBatteryStored())), ui.formatAmount((int)entity.power.graph.getTotalBatteryCapacity())), + (ui.formatAmount((int)entity.getPower().graph.getBatteryStored())), ui.formatAmount((int)entity.getPower().graph.getTotalBatteryCapacity())), () -> Pal.powerBar, - () -> Mathf.clamp(entity.power.graph.getBatteryStored() / entity.power.graph.getTotalBatteryCapacity()))); + () -> Mathf.clamp(entity.getPower().graph.getBatteryStored() / entity.getPower().graph.getTotalBatteryCapacity()))); } @Override @@ -105,7 +105,7 @@ public class PowerNode extends PowerBlock{ if(net.client()) return; Boolf valid = other -> other != null && other != tile && ((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) && linkValid(tile, other) - && !other.entity.proximity().contains(tile) && other.entity.power.graph != tile.entity.power.graph; + && !other.entity.proximity().contains(tile) && other.entity.getPower().graph != tile.entity.getPower().graph; tempTiles.clear(); Geometry.circle(tile.x, tile.y, (int)(laserRange + 2), (x, y) -> { @@ -123,7 +123,7 @@ public class PowerNode extends PowerBlock{ return Float.compare(a.dst2(tile), b.dst2(tile)); }); tempTiles.each(valid, other -> { - if(!tile.entity.power.links.contains(other.pos())){ + if(!tile.entity.getPower().links.contains(other.pos())){ tile.configureAny(other.pos()); } }); @@ -132,10 +132,10 @@ public class PowerNode extends PowerBlock{ } private void getPotentialLinks(Tile tile, Cons others){ - Boolf valid = other -> other != null && other != tile && other.entity != null && other.entity.power != null && + Boolf valid = other -> other != null && other != tile && other.entity != null && other.entity.getPower() != null && ((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) && overlaps(tile.x * tilesize + offset(), tile.y * tilesize + offset(), other, laserRange * tilesize) && other.getTeam() == player.getTeam() - && !other.entity.proximity().contains(tile) && !graphs.contains(other.entity.power.graph); + && !other.entity.proximity().contains(tile) && !graphs.contains(other.entity.getPower().graph); tempTiles.clear(); graphs.clear(); @@ -152,7 +152,7 @@ public class PowerNode extends PowerBlock{ return Float.compare(a.dst2(tile), b.dst2(tile)); }); tempTiles.each(valid, t -> { - graphs.add(t.entity.power.graph); + graphs.add(t.entity.getPower().graph); others.get(t); }); } @@ -167,12 +167,12 @@ public class PowerNode extends PowerBlock{ @Override public void update(Tile tile){ - tile.entity.power.graph.update(); + tile.entity.getPower().graph.update(); } @Override public boolean onConfigureTileTapped(Tile tile, Tile other){ - TileEntity entity = tile.ent(); + Tilec entity = tile.ent(); other = other.link(); if(linkValid(tile, other)){ @@ -181,7 +181,7 @@ public class PowerNode extends PowerBlock{ } if(tile == other){ - if(other.entity.power.links.size == 0){ + if(other.entity.getPower().links.size == 0){ int[] total = {0}; getPotentialLinks(tile, link -> { if(!insulated(tile, link) && total[0]++ < maxNodes){ @@ -189,8 +189,8 @@ public class PowerNode extends PowerBlock{ } }); }else{ - while(entity.power.links.size > 0){ - tile.configure(entity.power.links.get(0)); + while(entity.getPower().links.size > 0){ + tile.configure(entity.getPower().links.get(0)); } } return false; @@ -265,10 +265,10 @@ public class PowerNode extends PowerBlock{ public void drawLayer(Tile tile){ if(Core.settings.getInt("lasersopacity") == 0) return; - TileEntity entity = tile.ent(); + Tilec entity = tile.ent(); - for(int i = 0; i < entity.power.links.size; i++){ - Tile link = world.tile(entity.power.links.get(i)); + for(int i = 0; i < entity.getPower().links.size; i++){ + Tile link = world.tile(entity.getPower().links.get(i)); if(!linkValid(tile, link)) continue; @@ -281,7 +281,7 @@ public class PowerNode extends PowerBlock{ } protected boolean linked(Tile tile, Tile other){ - return tile.entity.power.links.contains(other.pos()); + return tile.entity.getPower().links.contains(other.pos()); } public boolean linkValid(Tile tile, Tile link){ @@ -293,7 +293,7 @@ public class PowerNode extends PowerBlock{ if(overlaps(tile, link, laserRange * tilesize) || (link.block() instanceof PowerNode && overlaps(link, tile, link.cblock().laserRange * tilesize))){ if(checkMaxNodes && link.block() instanceof PowerNode){ - return link.entity.power.links.size < link.cblock().maxNodes || link.entity.power.links.contains(tile.pos()); + return link.entity.getPower().links.size < link.cblock().maxNodes || link.entity.getPower().links.contains(tile.pos()); } return true; } @@ -331,7 +331,7 @@ public class PowerNode extends PowerBlock{ x2 += t2.x; y2 += t2.y; - float fract = 1f - tile.entity.power.graph.getSatisfaction(); + float fract = 1f - tile.entity.getPower().graph.getSatisfaction(); Draw.color(Color.white, Pal.powerLight, fract * 0.86f + Mathf.absin(3f, 0.1f)); Draw.alpha(opacity); diff --git a/core/src/mindustry/world/blocks/production/Cultivator.java b/core/src/mindustry/world/blocks/production/Cultivator.java index d4b5aa5014..2e7715d183 100644 --- a/core/src/mindustry/world/blocks/production/Cultivator.java +++ b/core/src/mindustry/world/blocks/production/Cultivator.java @@ -43,7 +43,7 @@ public class Cultivator extends GenericCrafter{ super.update(tile); CultivatorEntity entity = tile.ent(); - entity.warmup = Mathf.lerpDelta(entity.warmup, entity.cons.valid() ? 1f : 0f, 0.015f); + entity.warmup = Mathf.lerpDelta(entity.warmup, entity.consValid() ? 1f : 0f, 0.015f); } @Override @@ -110,7 +110,7 @@ public class Cultivator extends GenericCrafter{ } @Override - protected float getProgressIncrease(TileEntity entity, float baseTime){ + protected float getProgressIncrease(Tilec entity, float baseTime){ CultivatorEntity c = (CultivatorEntity)entity; return super.getProgressIncrease(entity, baseTime) * (1f + c.boost); } diff --git a/core/src/mindustry/world/blocks/production/Drill.java b/core/src/mindustry/world/blocks/production/Drill.java index 8831f93e48..4d5b73385c 100644 --- a/core/src/mindustry/world/blocks/production/Drill.java +++ b/core/src/mindustry/world/blocks/production/Drill.java @@ -8,8 +8,7 @@ import arc.math.*; import arc.util.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.Effects.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.type.*; @@ -77,7 +76,7 @@ public class Drill extends Block{ bars.add("drillspeed", e -> { DrillEntity entity = (DrillEntity)e; - return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.timeScale, 2)), () -> Pal.ammo, () -> entity.warmup); + return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.getTimeScale(), 2)), () -> Pal.ammo, () -> entity.warmup); }); } @@ -129,7 +128,7 @@ public class Drill extends Block{ @Override public boolean shouldConsume(Tile tile){ - return tile.entity.items.total() < itemCapacity; + return tile.entity.getItems().total() < itemCapacity; } @Override @@ -247,17 +246,17 @@ public class Drill extends Block{ entity.dominantItems = returnCount; } - if(entity.timer.get(timerDump, dumpTime)){ + if(entity.timer(timerDump, dumpTime)){ tryDump(tile, entity.dominantItem); } entity.drillTime += entity.warmup * entity.delta(); - if(entity.items.total() < itemCapacity && entity.dominantItems > 0 && entity.cons.valid()){ + if(entity.getItems().total() < itemCapacity && entity.dominantItems > 0 && entity.consValid()){ float speed = 1f; - if(entity.cons.optionalValid()){ + if(entity.getCons().optionalValid()){ speed = liquidBoostIntensity; } @@ -269,14 +268,14 @@ public class Drill extends Block{ * entity.dominantItems * speed * entity.warmup; if(Mathf.chance(Time.delta() * updateEffectChance * entity.warmup)) - updateEffect.at(entity.x + Mathf.range(size * 2f), entity.y + Mathf.range(size * 2f)); + updateEffect.at(entity.getX() + Mathf.range(size * 2f), entity.getY() + Mathf.range(size * 2f)); }else{ entity.lastDrillSpeed = 0f; entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, warmupSpeed); return; } - if(entity.dominantItems > 0 && entity.progress >= drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness && tile.entity.items.total() < itemCapacity){ + if(entity.dominantItems > 0 && entity.progress >= drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness && tile.entity.getItems().total() < itemCapacity){ offloadNear(tile, entity.dominantItem); @@ -285,8 +284,7 @@ public class Drill extends Block{ entity.index++; entity.progress = 0f; - drillEffect.at(entity.dominantItem.color, - entity.x + Mathf.range(size), entity.y + Mathf.range(size)); + drillEffect.at(entity.getX() + Mathf.range(size), entity.getY() + Mathf.range(size), entity.dominantItem.color); } } @@ -318,7 +316,7 @@ public class Drill extends Block{ return drops != null && drops.hardness <= tier; } - public static class DrillEntity extends TileEntity{ + public static class DrillEntity extends Tilec{ float progress; int index; float warmup; diff --git a/core/src/mindustry/world/blocks/production/Fracker.java b/core/src/mindustry/world/blocks/production/Fracker.java index 5642830c2e..b908aeaf96 100644 --- a/core/src/mindustry/world/blocks/production/Fracker.java +++ b/core/src/mindustry/world/blocks/production/Fracker.java @@ -44,7 +44,7 @@ public class Fracker extends SolidPump{ @Override public boolean shouldConsume(Tile tile){ - return tile.entity.liquids.get(result) < liquidCapacity - 0.01f; + return tile.entity.getLiquids().get(result) < liquidCapacity - 0.01f; } @Override @@ -55,7 +55,7 @@ public class Fracker extends SolidPump{ super.drawCracks(tile); Draw.color(result.color); - Draw.alpha(tile.entity.liquids.get(result) / liquidCapacity); + Draw.alpha(tile.entity.getLiquids().get(result) / liquidCapacity); Draw.rect(liquidRegion, tile.drawx(), tile.drawy()); Draw.color(); @@ -72,9 +72,9 @@ public class Fracker extends SolidPump{ public void update(Tile tile){ FrackerEntity entity = tile.ent(); - if(entity.cons.valid()){ + if(entity.consValid()){ if(entity.accumulator >= itemUseTime){ - entity.cons.trigger(); + entity.consume(); entity.accumulator -= itemUseTime; } @@ -87,7 +87,7 @@ public class Fracker extends SolidPump{ @Override public float typeLiquid(Tile tile){ - return tile.entity.liquids.get(result); + return tile.entity.getLiquids().get(result); } public static class FrackerEntity extends SolidPumpEntity{ diff --git a/core/src/mindustry/world/blocks/production/GenericCrafter.java b/core/src/mindustry/world/blocks/production/GenericCrafter.java index c7693b754a..f6e5b6fd91 100644 --- a/core/src/mindustry/world/blocks/production/GenericCrafter.java +++ b/core/src/mindustry/world/blocks/production/GenericCrafter.java @@ -6,8 +6,7 @@ import arc.math.*; import arc.util.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.Effects.*; -import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; @@ -61,7 +60,7 @@ public class GenericCrafter extends Block{ @Override public boolean shouldIdleSound(Tile tile){ - return tile.entity.cons.valid(); + return tile.entity.getCons().valid(); } @Override @@ -88,21 +87,21 @@ public class GenericCrafter extends Block{ public void update(Tile tile){ GenericCrafterEntity entity = tile.ent(); - if(entity.cons.valid()){ + if(entity.consValid()){ entity.progress += getProgressIncrease(entity, craftTime); entity.totalProgress += entity.delta(); entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f); if(Mathf.chance(Time.delta() * updateEffectChance)){ - updateEffect.at(entity.x + Mathf.range(size * 4f), entity.y + Mathf.range(size * 4)); + updateEffect.at(entity.getX() + Mathf.range(size * 4f), entity.getY() + Mathf.range(size * 4)); } }else{ entity.warmup = Mathf.lerp(entity.warmup, 0f, 0.02f); } if(entity.progress >= 1f){ - entity.cons.trigger(); + entity.consume(); if(outputItem != null){ useContent(tile, outputItem.item); @@ -120,7 +119,7 @@ public class GenericCrafter extends Block{ entity.progress = 0f; } - if(outputItem != null && tile.entity.timer.get(timerDump, dumpTime)){ + if(outputItem != null && tile.entity.timer(timerDump, dumpTime)){ tryDump(tile, outputItem.item); } @@ -136,10 +135,10 @@ public class GenericCrafter extends Block{ @Override public boolean shouldConsume(Tile tile){ - if(outputItem != null && tile.entity.items.get(outputItem.item) >= itemCapacity){ + if(outputItem != null && tile.entity.getItems().get(outputItem.item) >= itemCapacity){ return false; } - return outputLiquid == null || !(tile.entity.liquids.get(outputLiquid.liquid) >= liquidCapacity); + return outputLiquid == null || !(tile.entity.getLiquids().get(outputLiquid.liquid) >= liquidCapacity); } @Override @@ -147,7 +146,7 @@ public class GenericCrafter extends Block{ return itemCapacity; } - public static class GenericCrafterEntity extends TileEntity{ + public static class GenericCrafterEntity extends Tilec{ public float progress; public float totalProgress; public float warmup; diff --git a/core/src/mindustry/world/blocks/production/Incinerator.java b/core/src/mindustry/world/blocks/production/Incinerator.java index a1578c64d2..c99d6a1e7e 100644 --- a/core/src/mindustry/world/blocks/production/Incinerator.java +++ b/core/src/mindustry/world/blocks/production/Incinerator.java @@ -6,9 +6,8 @@ import arc.graphics.g2d.Fill; import arc.math.Mathf; import arc.util.Time; import mindustry.content.Fx; -import mindustry.entities.Effects; -import mindustry.entities.Effects.Effect; -import mindustry.entities.type.TileEntity; +import mindustry.entities.*; +import mindustry.gen.*; import mindustry.type.Item; import mindustry.type.Liquid; import mindustry.world.Block; @@ -31,7 +30,7 @@ public class Incinerator extends Block{ public void update(Tile tile){ IncineratorEntity entity = tile.ent(); - if(entity.cons.valid()){ + if(entity.consValid()){ entity.heat = Mathf.lerpDelta(entity.heat, 1f, 0.04f); }else{ entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.02f); @@ -85,7 +84,7 @@ public class Incinerator extends Block{ return entity.heat > 0.5f; } - public static class IncineratorEntity extends TileEntity{ + public static class IncineratorEntity extends Tilec{ public float heat; } } diff --git a/core/src/mindustry/world/blocks/production/LiquidConverter.java b/core/src/mindustry/world/blocks/production/LiquidConverter.java index b604867434..e2a36132e6 100644 --- a/core/src/mindustry/world/blocks/production/LiquidConverter.java +++ b/core/src/mindustry/world/blocks/production/LiquidConverter.java @@ -35,7 +35,7 @@ public class LiquidConverter extends GenericCrafter{ @Override public void drawLight(Tile tile){ if(hasLiquids && drawLiquidLight && outputLiquid.liquid.lightColor.a > 0.001f){ - drawLiquidLight(tile, outputLiquid.liquid, tile.entity.liquids.get(outputLiquid.liquid)); + drawLiquidLight(tile, outputLiquid.liquid, tile.entity.getLiquids().get(outputLiquid.liquid)); } } @@ -44,14 +44,14 @@ public class LiquidConverter extends GenericCrafter{ GenericCrafterEntity entity = tile.ent(); ConsumeLiquidBase cl = consumes.get(ConsumeType.liquid); - if(tile.entity.cons.valid()){ - float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.liquids.get(outputLiquid.liquid)) * entity.efficiency(); + if(tile.entity.getCons().valid()){ + float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.getLiquids().get(outputLiquid.liquid)) * entity.efficiency(); useContent(tile, outputLiquid.liquid); entity.progress += use / cl.amount / craftTime; - entity.liquids.add(outputLiquid.liquid, use); + entity.getLiquids().add(outputLiquid.liquid, use); if(entity.progress >= 1f){ - entity.cons.trigger(); + entity.consume(); entity.progress = 0f; } } diff --git a/core/src/mindustry/world/blocks/production/Pump.java b/core/src/mindustry/world/blocks/production/Pump.java index 010e7cb041..d78a8928a8 100644 --- a/core/src/mindustry/world/blocks/production/Pump.java +++ b/core/src/mindustry/world/blocks/production/Pump.java @@ -48,8 +48,8 @@ public class Pump extends LiquidBlock{ public void draw(Tile tile){ Draw.rect(name, tile.drawx(), tile.drawy()); - Draw.color(tile.entity.liquids.current().color); - Draw.alpha(tile.entity.liquids.total() / liquidCapacity); + Draw.color(tile.entity.getLiquids().current().color); + Draw.alpha(tile.entity.getLiquids().total() / liquidCapacity); Draw.rect(liquidRegion, tile.drawx(), tile.drawy()); Draw.color(); } @@ -118,16 +118,16 @@ public class Pump extends LiquidBlock{ liquidDrop = tile.floor().liquidDrop; } - if(tile.entity.cons.valid() && liquidDrop != null){ - float maxPump = Math.min(liquidCapacity - tile.entity.liquids.total(), tiles * pumpAmount * tile.entity.delta() / size / size) * tile.entity.efficiency(); - tile.entity.liquids.add(liquidDrop, maxPump); + if(tile.entity.getCons().valid() && liquidDrop != null){ + float maxPump = Math.min(liquidCapacity - tile.entity.getLiquids().total(), tiles * pumpAmount * tile.entity.delta() / size / size) * tile.entity.efficiency(); + tile.entity.getLiquids().add(liquidDrop, maxPump); } - if(tile.entity.liquids.currentAmount() > 0f && tile.entity.timer.get(timerContentCheck, 10)){ - useContent(tile, tile.entity.liquids.current()); + if(tile.entity.getLiquids().currentAmount() > 0f && tile.entity.timer(timerContentCheck, 10)){ + useContent(tile, tile.entity.getLiquids().current()); } - tryDumpLiquid(tile, tile.entity.liquids.current()); + tryDumpLiquid(tile, tile.entity.getLiquids().current()); } protected boolean isValid(Tile tile){ diff --git a/core/src/mindustry/world/blocks/production/Separator.java b/core/src/mindustry/world/blocks/production/Separator.java index 7361b8f4bb..25a46379a1 100644 --- a/core/src/mindustry/world/blocks/production/Separator.java +++ b/core/src/mindustry/world/blocks/production/Separator.java @@ -54,7 +54,7 @@ public class Separator extends Block{ @Override public boolean shouldConsume(Tile tile){ - return tile.entity.items.total() < itemCapacity; + return tile.entity.getItems().total() < itemCapacity; } @Override @@ -63,8 +63,8 @@ public class Separator extends Block{ GenericCrafterEntity entity = tile.ent(); - Draw.color(tile.entity.liquids.current().color); - Draw.alpha(tile.entity.liquids.total() / liquidCapacity); + Draw.color(tile.entity.getLiquids().current().color); + Draw.alpha(tile.entity.getLiquids().total() / liquidCapacity); Draw.rect(reg(liquidRegion), tile.drawx(), tile.drawy()); Draw.reset(); @@ -79,7 +79,7 @@ public class Separator extends Block{ entity.totalProgress += entity.warmup * entity.delta(); - if(entity.cons.valid()){ + if(entity.consValid()){ entity.progress += getProgressIncrease(entity, craftTime); entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f); }else{ @@ -104,14 +104,14 @@ public class Separator extends Block{ count += stack.amount; } - entity.cons.trigger(); + entity.consume(); - if(item != null && entity.items.get(item) < itemCapacity){ + if(item != null && entity.getItems().get(item) < itemCapacity){ offloadNear(tile, item); } } - if(entity.timer.get(timerDump, dumpTime)){ + if(entity.timer(timerDump, dumpTime)){ tryDump(tile); } } diff --git a/core/src/mindustry/world/blocks/production/SolidPump.java b/core/src/mindustry/world/blocks/production/SolidPump.java index 1cb9bf9696..2ad802dac5 100644 --- a/core/src/mindustry/world/blocks/production/SolidPump.java +++ b/core/src/mindustry/world/blocks/production/SolidPump.java @@ -8,9 +8,8 @@ import arc.util.*; import arc.util.ArcAnnotate.*; import mindustry.content.Fx; import mindustry.content.Liquids; -import mindustry.entities.Effects; -import mindustry.entities.Effects.Effect; -import mindustry.entities.type.TileEntity; +import mindustry.entities.*; +import mindustry.gen.*; import mindustry.graphics.Pal; import mindustry.type.Liquid; import mindustry.ui.Bar; @@ -75,8 +74,8 @@ public class SolidPump extends Pump{ SolidPumpEntity entity = tile.ent(); Draw.rect(region, tile.drawx(), tile.drawy()); - Draw.color(tile.entity.liquids.current().color); - Draw.alpha(tile.entity.liquids.total() / liquidCapacity); + Draw.color(tile.entity.getLiquids().current().color); + Draw.alpha(tile.entity.getLiquids().total() / liquidCapacity); Draw.rect(liquidRegion, tile.drawx(), tile.drawy()); Draw.color(); Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.pumpTime * rotateSpeed); @@ -106,13 +105,13 @@ public class SolidPump extends Pump{ fraction += entity.boost; - if(tile.entity.cons.valid() && typeLiquid(tile) < liquidCapacity - 0.001f){ + if(tile.entity.getCons().valid() && typeLiquid(tile) < liquidCapacity - 0.001f){ float maxPump = Math.min(liquidCapacity - typeLiquid(tile), pumpAmount * entity.delta() * fraction * entity.efficiency()); - tile.entity.liquids.add(result, maxPump); + tile.entity.getLiquids().add(result, maxPump); entity.lastPump = maxPump; entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f); if(Mathf.chance(entity.delta() * updateEffectChance)) - updateEffect.at(entity.x + Mathf.range(size * 2f), entity.y + Mathf.range(size * 2f)); + updateEffect.at(entity.getX() + Mathf.range(size * 2f), entity.getY() + Mathf.range(size * 2f)); }else{ entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f); entity.lastPump = 0f; @@ -153,10 +152,10 @@ public class SolidPump extends Pump{ } public float typeLiquid(Tile tile){ - return tile.entity.liquids.total(); + return tile.entity.getLiquids().total(); } - public static class SolidPumpEntity extends TileEntity{ + public static class SolidPumpEntity extends Tilec{ public float warmup; public float pumpTime; public float boost; diff --git a/core/src/mindustry/world/blocks/sandbox/ItemSource.java b/core/src/mindustry/world/blocks/sandbox/ItemSource.java index 2022df5fb4..47c491d1a5 100644 --- a/core/src/mindustry/world/blocks/sandbox/ItemSource.java +++ b/core/src/mindustry/world/blocks/sandbox/ItemSource.java @@ -73,9 +73,9 @@ public class ItemSource extends Block{ ItemSourceEntity entity = tile.ent(); if(entity.outputItem == null) return; - entity.items.set(entity.outputItem, 1); + entity.getItems().set(entity.outputItem, 1); tryDump(tile, entity.outputItem); - entity.items.set(entity.outputItem, 0); + entity.getItems().set(entity.outputItem, 0); } @Override @@ -92,7 +92,7 @@ public class ItemSource extends Block{ return false; } - public class ItemSourceEntity extends TileEntity{ + public class ItemSourceEntity extends Tilec{ Item outputItem; @Override diff --git a/core/src/mindustry/world/blocks/sandbox/LiquidSource.java b/core/src/mindustry/world/blocks/sandbox/LiquidSource.java index 00e58cdb8c..d2d05161d5 100644 --- a/core/src/mindustry/world/blocks/sandbox/LiquidSource.java +++ b/core/src/mindustry/world/blocks/sandbox/LiquidSource.java @@ -9,6 +9,7 @@ import arc.scene.ui.layout.*; import arc.util.*; import arc.util.ArcAnnotate.*; import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.type.*; @@ -53,9 +54,9 @@ public class LiquidSource extends Block{ LiquidSourceEntity entity = tile.ent(); if(entity.source == null){ - tile.entity.liquids.clear(); + tile.entity.getLiquids().clear(); }else{ - tile.entity.liquids.add(entity.source, liquidCapacity); + tile.entity.getLiquids().add(entity.source, liquidCapacity); tryDumpLiquid(tile, entity.source); } } @@ -112,7 +113,7 @@ public class LiquidSource extends Block{ tile.ent().source = value == -1 ? null : content.liquid(value); } - class LiquidSourceEntity extends TileEntity{ + class LiquidSourceEntity extends Tilec{ public @Nullable Liquid source = null; @Override diff --git a/core/src/mindustry/world/blocks/storage/CoreBlock.java b/core/src/mindustry/world/blocks/storage/CoreBlock.java index 1a681aa77f..55293099ae 100644 --- a/core/src/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/mindustry/world/blocks/storage/CoreBlock.java @@ -10,6 +10,7 @@ import arc.math.geom.*; import mindustry.content.*; import mindustry.entities.traits.*; import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.game.EventType.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -70,7 +71,7 @@ public class CoreBlock extends StorageBlock{ @Override public boolean acceptItem(Item item, Tile tile, Tile source){ - return tile.entity.items.get(item) < getMaximumAccepted(tile, item); + return tile.entity.getItems().get(item) < getMaximumAccepted(tile, item); } @Override @@ -83,27 +84,27 @@ public class CoreBlock extends StorageBlock{ public void onProximityUpdate(Tile tile){ CoreEntity entity = tile.ent(); - for(TileEntity other : state.teams.cores(tile.getTeam())){ + for(Tilec other : state.teams.cores(tile.getTeam())){ if(other.tile != tile){ - entity.items = other.items; + entity.getItems() = other.items; } } state.teams.registerCore(entity); entity.storageCapacity = itemCapacity + entity.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0); entity.proximity().each(this::isContainer, t -> { - t.entity.items = entity.items; + t.entity.getItems() = entity.getItems(); t.ent().linkedCore = tile; }); - for(TileEntity other : state.teams.cores(tile.getTeam())){ + for(Tilec other : state.teams.cores(tile.getTeam())){ if(other.tile == tile) continue; entity.storageCapacity += other.block.itemCapacity + other.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0); } if(!world.isGenerating()){ for(Item item : content.items()){ - entity.items.set(item, Math.min(entity.items.get(item), entity.storageCapacity)); + entity.getItems().set(item, Math.min(entity.getItems().get(item), entity.storageCapacity)); } } @@ -122,10 +123,10 @@ public class CoreBlock extends StorageBlock{ Draw.rect("block-select", t.drawx() + offset * p.x, t.drawy() + offset * p.y, i * 90); } }; - if(tile.entity.proximity().contains(e -> isContainer(e) && e.entity.items == tile.entity.items)){ + if(tile.entity.proximity().contains(e -> isContainer(e) && e.entity.getItems() == tile.entity.getItems())){ outline.get(tile); } - tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, outline); + tile.entity.proximity().each(e -> isContainer(e) && e.entity.getItems() == tile.entity.getItems(), outline); Draw.reset(); } @@ -150,15 +151,15 @@ public class CoreBlock extends StorageBlock{ @Override public void removed(Tile tile){ CoreEntity entity = tile.ent(); - int total = tile.entity.proximity().count(e -> e.entity != null && e.entity.items != null && e.entity.items == tile.entity.items); + int total = tile.entity.proximity().count(e -> e.entity != null && e.entity.getItems() != null && e.entity.getItems() == tile.entity.getItems()); float fract = 1f / total / state.teams.cores(tile.getTeam()).size; - tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, t -> { + tile.entity.proximity().each(e -> isContainer(e) && e.entity.getItems() == tile.entity.getItems(), t -> { StorageBlockEntity ent = (StorageBlockEntity)t.entity; ent.linkedCore = null; ent.items = new ItemModule(); for(Item item : content.items()){ - ent.items.set(item, (int)(fract * tile.entity.items.get(item))); + ent.items.set(item, (int)(fract * tile.entity.getItems().get(item))); } }); @@ -166,7 +167,7 @@ public class CoreBlock extends StorageBlock{ int max = itemCapacity * state.teams.cores(tile.getTeam()).size; for(Item item : content.items()){ - tile.entity.items.set(item, Math.min(tile.entity.items.get(item), max)); + tile.entity.getItems().set(item, Math.min(tile.entity.getItems().get(item), max)); } for(CoreEntity other : state.teams.cores(tile.getTeam())){ @@ -230,7 +231,7 @@ public class CoreBlock extends StorageBlock{ return entity.spawnPlayer != null; } - public class CoreEntity extends TileEntity implements SpawnerTrait{ + public class CoreEntity extends Tilec implements SpawnerTrait{ protected Player spawnPlayer; protected float progress; protected float time; diff --git a/core/src/mindustry/world/blocks/storage/LaunchPad.java b/core/src/mindustry/world/blocks/storage/LaunchPad.java index ed2a054032..1aa5a4c85c 100644 --- a/core/src/mindustry/world/blocks/storage/LaunchPad.java +++ b/core/src/mindustry/world/blocks/storage/LaunchPad.java @@ -7,8 +7,7 @@ import arc.math.Mathf; import arc.util.Time; import mindustry.Vars; import mindustry.content.Fx; -import mindustry.entities.Effects; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.game.EventType.*; import mindustry.graphics.Pal; import mindustry.type.Item; @@ -41,14 +40,14 @@ public class LaunchPad extends StorageBlock{ @Override public boolean acceptItem(Item item, Tile tile, Tile source){ - return item.type == ItemType.material && tile.entity.items.total() < itemCapacity; + return item.type == ItemType.material && tile.entity.getItems().total() < itemCapacity; } @Override public void draw(Tile tile){ super.draw(tile); - float progress = Mathf.clamp(Mathf.clamp((tile.entity.items.total() / (float)itemCapacity)) * ((tile.entity.timer.getTime(timerLaunch) / (launchTime / tile.entity.timeScale)))); + float progress = Mathf.clamp(Mathf.clamp((tile.entity.getItems().total() / (float)itemCapacity)) * ((tile.entity.timerTime(timerLaunch) / (launchTime / tile.entity.timeScale)))); float scale = size / 3f; Lines.stroke(2f); @@ -57,7 +56,7 @@ public class LaunchPad extends StorageBlock{ Draw.color(Pal.accent); - if(tile.entity.cons.valid()){ + if(tile.entity.getCons().valid()){ for(int i = 0; i < 3; i++){ float f = (Time.time() / 200f + i * 0.5f) % 1f; @@ -71,15 +70,15 @@ public class LaunchPad extends StorageBlock{ @Override public void update(Tile tile){ - TileEntity entity = tile.entity; + Tilec entity = tile.entity; - if(world.isZone() && entity.cons.valid() && entity.items.total() >= itemCapacity && entity.timer.get(timerLaunch, launchTime / entity.timeScale)){ + if(world.isZone() && entity.consValid() && entity.getItems().total() >= itemCapacity && entity.timer(timerLaunch, launchTime / entity.timeScale)){ for(Item item : Vars.content.items()){ Events.fire(Trigger.itemLaunch); Fx.padlaunch.at(tile); - int used = Math.min(entity.items.get(item), itemCapacity); + int used = Math.min(entity.getItems().get(item), itemCapacity); data.addItem(item, used); - entity.items.remove(item, used); + entity.getItems().remove(item, used); Events.fire(new LaunchItemEvent(item, used)); } } diff --git a/core/src/mindustry/world/blocks/storage/StorageBlock.java b/core/src/mindustry/world/blocks/storage/StorageBlock.java index 29aa7860b5..171c7ff022 100644 --- a/core/src/mindustry/world/blocks/storage/StorageBlock.java +++ b/core/src/mindustry/world/blocks/storage/StorageBlock.java @@ -1,7 +1,7 @@ package mindustry.world.blocks.storage; import arc.util.ArcAnnotate.*; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.type.Item; import mindustry.world.Block; import mindustry.world.Tile; @@ -17,7 +17,7 @@ public abstract class StorageBlock extends Block{ @Override public boolean acceptItem(Item item, Tile tile, Tile source){ StorageBlockEntity entity = tile.ent(); - return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(item, entity.linkedCore, source) : tile.entity.items.get(item) < getMaximumAccepted(tile, item); + return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(item, entity.linkedCore, source) : tile.entity.getItems().get(item) < getMaximumAccepted(tile, item); } @Override @@ -43,13 +43,13 @@ public abstract class StorageBlock extends Block{ * Returns null if no items are there. */ public Item removeItem(Tile tile, Item item){ - TileEntity entity = tile.entity; + Tilec entity = tile.entity; if(item == null){ - return entity.items.take(); + return entity.getItems().take(); }else{ - if(entity.items.has(item)){ - entity.items.remove(item, 1); + if(entity.getItems().has(item)){ + entity.getItems().remove(item, 1); return item; } @@ -62,15 +62,15 @@ public abstract class StorageBlock extends Block{ * If the item is null, it should return whether it has ANY items. */ public boolean hasItem(Tile tile, Item item){ - TileEntity entity = tile.entity; + Tilec entity = tile.entity; if(item == null){ - return entity.items.total() > 0; + return entity.getItems().total() > 0; }else{ - return entity.items.has(item); + return entity.getItems().has(item); } } - public class StorageBlockEntity extends TileEntity{ + public class StorageBlockEntity extends Tilec{ protected @Nullable Tile linkedCore; } diff --git a/core/src/mindustry/world/blocks/storage/Unloader.java b/core/src/mindustry/world/blocks/storage/Unloader.java index 20c65c9a3f..21373c2cbb 100644 --- a/core/src/mindustry/world/blocks/storage/Unloader.java +++ b/core/src/mindustry/world/blocks/storage/Unloader.java @@ -55,7 +55,7 @@ public class Unloader extends Block{ @Override public void configured(Tile tile, Player player, int value){ - tile.entity.items.clear(); + tile.entity.getItems().clear(); tile.ent().sortItem = content.item(value); } @@ -63,16 +63,16 @@ public class Unloader extends Block{ public void update(Tile tile){ UnloaderEntity entity = tile.ent(); - if(tile.entity.timer.get(timerUnload, speed / entity.timeScale) && tile.entity.items.total() == 0){ + if(tile.entity.timer(timerUnload, speed / entity.timeScale) && tile.entity.getItems().total() == 0){ for(Tile other : tile.entity.proximity()){ - if(other.interactable(tile.getTeam()) && other.block().unloadable && other.block().hasItems && entity.items.total() == 0 && - ((entity.sortItem == null && other.entity.items.total() > 0) || hasItem(other, entity.sortItem))){ + if(other.interactable(tile.getTeam()) && other.block().unloadable && other.block().hasItems && entity.getItems().total() == 0 && + ((entity.sortItem == null && other.entity.getItems().total() > 0) || hasItem(other, entity.sortItem))){ offloadNear(tile, removeItem(other, entity.sortItem)); } } } - if(entity.items.total() > 0){ + if(entity.getItems().total() > 0){ tryDump(tile); } } @@ -82,13 +82,13 @@ public class Unloader extends Block{ * Returns null if no items are there. */ private Item removeItem(Tile tile, Item item){ - TileEntity entity = tile.entity; + Tilec entity = tile.entity; if(item == null){ - return entity.items.take(); + return entity.getItems().take(); }else{ - if(entity.items.has(item)){ - entity.items.remove(item, 1); + if(entity.getItems().has(item)){ + entity.getItems().remove(item, 1); return item; } @@ -101,11 +101,11 @@ public class Unloader extends Block{ * If the item is null, it should return whether it has ANY items. */ private boolean hasItem(Tile tile, Item item){ - TileEntity entity = tile.entity; + Tilec entity = tile.entity; if(item == null){ - return entity.items.total() > 0; + return entity.getItems().total() > 0; }else{ - return entity.items.has(item); + return entity.getItems().has(item); } } @@ -129,7 +129,7 @@ public class Unloader extends Block{ }); } - public static class UnloaderEntity extends TileEntity{ + public static class UnloaderEntity extends Tilec{ public Item sortItem = null; @Override diff --git a/core/src/mindustry/world/blocks/units/CommandCenter.java b/core/src/mindustry/world/blocks/units/CommandCenter.java index 1544170878..38b9dfef1b 100644 --- a/core/src/mindustry/world/blocks/units/CommandCenter.java +++ b/core/src/mindustry/world/blocks/units/CommandCenter.java @@ -10,7 +10,6 @@ import arc.struct.*; import arc.util.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.entities.Effects.*; import mindustry.entities.type.*; import mindustry.entities.units.*; import mindustry.game.EventType.*; @@ -118,7 +117,7 @@ public class CommandCenter extends Block{ Events.fire(new CommandIssueEvent(tile, command)); } - public class CommandCenterEntity extends TileEntity{ + public class CommandCenterEntity extends Tilec{ public UnitCommand command = UnitCommand.attack; @Override diff --git a/core/src/mindustry/world/blocks/units/MechPad.java b/core/src/mindustry/world/blocks/units/MechPad.java index b20977f7ac..fb97c21319 100644 --- a/core/src/mindustry/world/blocks/units/MechPad.java +++ b/core/src/mindustry/world/blocks/units/MechPad.java @@ -11,6 +11,7 @@ import arc.util.ArcAnnotate.*; import mindustry.content.*; import mindustry.entities.traits.*; import mindustry.entities.type.*; +import mindustry.gen.*; import mindustry.game.EventType.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -49,7 +50,7 @@ public class MechPad extends Block{ MechFactoryEntity entity = tile.ent(); - if(!entity.cons.valid()) return; + if(!entity.consValid()) return; player.beginRespawning(entity); entity.sameMech = false; } @@ -80,7 +81,7 @@ public class MechPad extends Block{ protected static boolean checkValidTap(Tile tile, Player player){ MechFactoryEntity entity = tile.ent(); return !player.isDead() && tile.interactable(player.getTeam()) && Math.abs(player.x - tile.drawx()) <= tile.block().size * tilesize && - Math.abs(player.y - tile.drawy()) <= tile.block().size * tilesize && entity.cons.valid() && entity.player == null; + Math.abs(player.y - tile.drawy()) <= tile.block().size * tilesize && entity.consValid() && entity.player == null; } @Override @@ -99,7 +100,7 @@ public class MechPad extends Block{ if(checkValidTap(tile, player)){ Call.onMechFactoryTap(player, tile); - }else if(player.isLocal && mobile && !player.isDead() && entity.cons.valid() && entity.player == null){ + }else if(player.isLocal && mobile && !player.isDead() && entity.consValid() && entity.player == null){ //deselect on double taps player.moveTarget = player.moveTarget == tile.entity ? null : tile.entity; } @@ -133,7 +134,7 @@ public class MechPad extends Block{ } } - public class MechFactoryEntity extends TileEntity implements SpawnerTrait{ + public class MechFactoryEntity extends Tilec implements SpawnerTrait{ Player player; boolean sameMech; float progress; diff --git a/core/src/mindustry/world/blocks/units/RepairPoint.java b/core/src/mindustry/world/blocks/units/RepairPoint.java index e6cf13403b..fdb0aa4f43 100644 --- a/core/src/mindustry/world/blocks/units/RepairPoint.java +++ b/core/src/mindustry/world/blocks/units/RepairPoint.java @@ -9,7 +9,7 @@ import arc.math.Mathf; import arc.math.geom.Rect; import arc.util.Time; import mindustry.entities.Units; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.graphics.*; import mindustry.world.Block; import mindustry.world.Tile; @@ -112,7 +112,7 @@ public class RepairPoint extends Block{ boolean targetIsBeingRepaired = false; if(entity.target != null && (entity.target.isDead() || entity.target.dst(tile) > repairRadius || entity.target.health >= entity.target.maxHealth())){ entity.target = null; - }else if(entity.target != null && entity.cons.valid()){ + }else if(entity.target != null && entity.consValid()){ entity.target.health += repairSpeed * Time.delta() * entity.strength * entity.efficiency(); entity.target.clampHealth(); entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f); @@ -125,7 +125,7 @@ public class RepairPoint extends Block{ entity.strength = Mathf.lerpDelta(entity.strength, 0f, 0.07f * Time.delta()); } - if(entity.timer.get(timerTarget, 20)){ + if(entity.timer(timerTarget, 20)){ rect.setSize(repairRadius * 2).setCenter(tile.drawx(), tile.drawy()); entity.target = Units.closest(tile.getTeam(), tile.drawx(), tile.drawy(), repairRadius, unit -> unit.health < unit.maxHealth()); @@ -139,7 +139,7 @@ public class RepairPoint extends Block{ return entity.target != null; } - public class RepairPointEntity extends TileEntity{ + public class RepairPointEntity extends Tilec{ public Unitc target; public float strength, rotation = 90; } diff --git a/core/src/mindustry/world/blocks/units/UnitFactory.java b/core/src/mindustry/world/blocks/units/UnitFactory.java index 7e93202dfe..0348494422 100644 --- a/core/src/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/mindustry/world/blocks/units/UnitFactory.java @@ -159,7 +159,7 @@ public class UnitFactory extends Block{ return; } - if(entity.cons.valid() || tile.isEnemyCheat()){ + if(entity.consValid() || tile.isEnemyCheat()){ entity.time += entity.delta() * entity.speedScl * Vars.state.rules.unitBuildSpeedMultiplier * entity.efficiency(); entity.buildTime += entity.delta() * entity.efficiency() * Vars.state.rules.unitBuildSpeedMultiplier; entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f); @@ -173,7 +173,7 @@ public class UnitFactory extends Block{ Call.onUnitFactorySpawn(tile, entity.spawned + 1); useContent(tile, unitType); - entity.cons.trigger(); + entity.consume(); } } @@ -188,7 +188,7 @@ public class UnitFactory extends Block{ return entity.spawned < maxSpawn; } - public static class UnitFactoryEntity extends TileEntity{ + public static class UnitFactoryEntity extends Tilec{ float buildTime; float time; float speedScl; diff --git a/core/src/mindustry/world/consumers/Consume.java b/core/src/mindustry/world/consumers/Consume.java index b419f68d13..76827379d6 100644 --- a/core/src/mindustry/world/consumers/Consume.java +++ b/core/src/mindustry/world/consumers/Consume.java @@ -2,7 +2,7 @@ package mindustry.world.consumers; import arc.struct.*; import arc.scene.ui.layout.Table; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.world.Tile; import mindustry.world.meta.BlockStats; @@ -62,15 +62,15 @@ public abstract class Consume{ public abstract void build(Tile tile, Table table); /** Called when a consumption is triggered manually. */ - public void trigger(TileEntity entity){ + public void trigger(Tilec entity){ } public abstract String getIcon(); - public abstract void update(TileEntity entity); + public abstract void update(Tilec entity); - public abstract boolean valid(TileEntity entity); + public abstract boolean valid(Tilec entity); public abstract void display(BlockStats stats); } diff --git a/core/src/mindustry/world/consumers/ConsumeItemFilter.java b/core/src/mindustry/world/consumers/ConsumeItemFilter.java index 2dcab1a841..f9d4229dc7 100644 --- a/core/src/mindustry/world/consumers/ConsumeItemFilter.java +++ b/core/src/mindustry/world/consumers/ConsumeItemFilter.java @@ -35,7 +35,7 @@ public class ConsumeItemFilter extends Consume{ @Override public void build(Tile tile, Table table){ MultiReqImage image = new MultiReqImage(); - content.items().each(i -> filter.get(i) && (!world.isZone() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.items != null && tile.entity.items.has(item)))); + content.items().each(i -> filter.get(i) && (!world.isZone() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.getItems() != null && tile.entity.getItems().has(item)))); table.add(image).size(8 * 4); } @@ -46,26 +46,26 @@ public class ConsumeItemFilter extends Consume{ } @Override - public void update(TileEntity entity){ + public void update(Tilec entity){ } @Override - public void trigger(TileEntity entity){ + public void trigger(Tilec entity){ for(int i = 0; i < content.items().size; i++){ Item item = content.item(i); - if(entity.items != null && entity.items.has(item) && this.filter.get(item)){ - entity.items.remove(item, 1); + if(entity.getItems() != null && entity.getItems().has(item) && this.filter.get(item)){ + entity.getItems().remove(item, 1); break; } } } @Override - public boolean valid(TileEntity entity){ + public boolean valid(Tilec entity){ for(int i = 0; i < content.items().size; i++){ Item item = content.item(i); - if(entity.items != null && entity.items.has(item) && this.filter.get(item)){ + if(entity.getItems() != null && entity.getItems().has(item) && this.filter.get(item)){ return true; } } diff --git a/core/src/mindustry/world/consumers/ConsumeItems.java b/core/src/mindustry/world/consumers/ConsumeItems.java index c5f904bfeb..b71c95fc51 100644 --- a/core/src/mindustry/world/consumers/ConsumeItems.java +++ b/core/src/mindustry/world/consumers/ConsumeItems.java @@ -38,7 +38,7 @@ public class ConsumeItems extends Consume{ @Override public void build(Tile tile, Table table){ for(ItemStack stack : items){ - table.add(new ReqImage(new ItemImage(stack.item.icon(Cicon.medium), stack.amount), () -> tile.entity != null && tile.entity.items != null && tile.entity.items.has(stack.item, stack.amount))).size(8 * 4).padRight(5); + table.add(new ReqImage(new ItemImage(stack.item.icon(Cicon.medium), stack.amount), () -> tile.entity != null && tile.entity.getItems() != null && tile.entity.getItems().has(stack.item, stack.amount))).size(8 * 4).padRight(5); } } @@ -48,20 +48,20 @@ public class ConsumeItems extends Consume{ } @Override - public void update(TileEntity entity){ + public void update(Tilec entity){ } @Override - public void trigger(TileEntity entity){ + public void trigger(Tilec entity){ for(ItemStack stack : items){ - entity.items.remove(stack); + entity.getItems().remove(stack); } } @Override - public boolean valid(TileEntity entity){ - return entity.items != null && entity.items.has(items); + public boolean valid(Tilec entity){ + return entity.getItems() != null && entity.getItems().has(items); } @Override diff --git a/core/src/mindustry/world/consumers/ConsumeLiquid.java b/core/src/mindustry/world/consumers/ConsumeLiquid.java index dcb318150a..8be877ac0d 100644 --- a/core/src/mindustry/world/consumers/ConsumeLiquid.java +++ b/core/src/mindustry/world/consumers/ConsumeLiquid.java @@ -38,13 +38,13 @@ public class ConsumeLiquid extends ConsumeLiquidBase{ } @Override - public void update(TileEntity entity){ - entity.liquids.remove(liquid, Math.min(use(entity), entity.liquids.get(liquid))); + public void update(Tilec entity){ + entity.getLiquids().remove(liquid, Math.min(use(entity), entity.getLiquids().get(liquid))); } @Override - public boolean valid(TileEntity entity){ - return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(entity); + public boolean valid(Tilec entity){ + return entity != null && entity.getLiquids() != null && entity.getLiquids().get(liquid) >= use(entity); } @Override diff --git a/core/src/mindustry/world/consumers/ConsumeLiquidBase.java b/core/src/mindustry/world/consumers/ConsumeLiquidBase.java index 229121863d..312d74c3c6 100644 --- a/core/src/mindustry/world/consumers/ConsumeLiquidBase.java +++ b/core/src/mindustry/world/consumers/ConsumeLiquidBase.java @@ -1,6 +1,6 @@ package mindustry.world.consumers; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; public abstract class ConsumeLiquidBase extends Consume{ /** amount used per frame */ @@ -22,7 +22,7 @@ public abstract class ConsumeLiquidBase extends Consume{ return ConsumeType.liquid; } - protected float use(TileEntity entity){ + protected float use(Tilec entity){ return Math.min(amount * entity.delta(), entity.block.liquidCapacity); } } diff --git a/core/src/mindustry/world/consumers/ConsumeLiquidFilter.java b/core/src/mindustry/world/consumers/ConsumeLiquidFilter.java index 9d8450cfb8..577d0a5a38 100644 --- a/core/src/mindustry/world/consumers/ConsumeLiquidFilter.java +++ b/core/src/mindustry/world/consumers/ConsumeLiquidFilter.java @@ -3,7 +3,7 @@ package mindustry.world.consumers; import arc.struct.*; import arc.func.Boolf; import arc.scene.ui.layout.Table; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.type.Liquid; import mindustry.ui.Cicon; import mindustry.ui.MultiReqImage; @@ -32,7 +32,7 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{ public void build(Tile tile, Table table){ Array list = content.liquids().select(l -> !l.isHidden() && filter.get(l)); MultiReqImage image = new MultiReqImage(); - list.each(liquid -> image.add(new ReqImage(liquid.icon(Cicon.medium), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.entity)))); + list.each(liquid -> image.add(new ReqImage(liquid.icon(Cicon.medium), () -> tile.entity != null && tile.entity.getLiquids() != null && tile.entity.getLiquids().get(liquid) >= use(tile.entity)))); table.add(image).size(8 * 4); } @@ -43,13 +43,13 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{ } @Override - public void update(TileEntity entity){ - entity.liquids.remove(entity.liquids.current(), use(entity)); + public void update(Tilec entity){ + entity.getLiquids().remove(entity.getLiquids().current(), use(entity)); } @Override - public boolean valid(TileEntity entity){ - return entity != null && entity.liquids != null && filter.get(entity.liquids.current()) && entity.liquids.currentAmount() >= use(entity); + public boolean valid(Tilec entity){ + return entity != null && entity.getLiquids() != null && filter.get(entity.getLiquids().current()) && entity.getLiquids().currentAmount() >= use(entity); } @Override diff --git a/core/src/mindustry/world/consumers/ConsumePower.java b/core/src/mindustry/world/consumers/ConsumePower.java index 5df011349a..340e630400 100644 --- a/core/src/mindustry/world/consumers/ConsumePower.java +++ b/core/src/mindustry/world/consumers/ConsumePower.java @@ -2,7 +2,7 @@ package mindustry.world.consumers; import arc.math.Mathf; import arc.scene.ui.layout.Table; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.world.Tile; import mindustry.world.meta.*; @@ -41,16 +41,16 @@ public class ConsumePower extends Consume{ } @Override - public void update(TileEntity entity){ - // Nothing to do since PowerGraph directly updates entity.power.status + public void update(Tilec entity){ + // Nothing to do since PowerGraph directly updates entity.getPower().status } @Override - public boolean valid(TileEntity entity){ + public boolean valid(Tilec entity){ if(buffered){ return true; }else{ - return entity.power.status > 0f; + return entity.getPower().status > 0f; } } @@ -68,13 +68,13 @@ public class ConsumePower extends Consume{ * @param entity The entity which contains the power module. * @return The amount of power which is requested per tick. */ - public float requestedPower(TileEntity entity){ - if(entity.tile.entity == null) return 0f; + public float requestedPower(Tilec entity){ + if(entity.getTile().entity == null) return 0f; if(buffered){ - return (1f-entity.power.status)*capacity; + return (1f-entity.getPower().status)*capacity; }else{ try{ - return usage * Mathf.num(entity.block.shouldConsume(entity.tile)); + return usage * Mathf.num(entity.getBlock().shouldConsume(entity.getTile())); }catch(Exception e){ //HACK an error will only happen with a bar that is checking its requested power, and the entity is null/a different class return 0; diff --git a/core/src/mindustry/world/consumers/Consumers.java b/core/src/mindustry/world/consumers/Consumers.java index b6ebd7391a..4f0df357dc 100644 --- a/core/src/mindustry/world/consumers/Consumers.java +++ b/core/src/mindustry/world/consumers/Consumers.java @@ -4,7 +4,7 @@ import arc.struct.*; import arc.func.Boolf; import arc.util.Structs; import mindustry.Vars; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.type.*; import mindustry.world.blocks.power.ConditionalConsumePower; import mindustry.world.meta.BlockStats; @@ -48,7 +48,7 @@ public class Consumers{ } /** Creates a consumer which only consumes power when the condition is met. */ - public ConsumePower powerCond(float usage, Boolf cons){ + public ConsumePower powerCond(float usage, Boolf cons){ return add(new ConditionalConsumePower(usage, cons)); } diff --git a/core/src/mindustry/world/meta/BlockBars.java b/core/src/mindustry/world/meta/BlockBars.java index 5b319332ce..ec47b7ae47 100644 --- a/core/src/mindustry/world/meta/BlockBars.java +++ b/core/src/mindustry/world/meta/BlockBars.java @@ -2,13 +2,13 @@ package mindustry.world.meta; import arc.struct.OrderedMap; import arc.func.Func; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.ui.Bar; public class BlockBars{ - private OrderedMap> bars = new OrderedMap<>(); + private OrderedMap> bars = new OrderedMap<>(); - public void add(String name, Func sup){ + public void add(String name, Func sup){ bars.put(name, sup); } @@ -18,7 +18,7 @@ public class BlockBars{ bars.remove(name); } - public Iterable> list(){ + public Iterable> list(){ return bars.values(); } } diff --git a/core/src/mindustry/world/modules/ConsumeModule.java b/core/src/mindustry/world/modules/ConsumeModule.java index 44f8d471d4..d060fba5e4 100644 --- a/core/src/mindustry/world/modules/ConsumeModule.java +++ b/core/src/mindustry/world/modules/ConsumeModule.java @@ -1,15 +1,15 @@ package mindustry.world.modules; -import mindustry.entities.type.TileEntity; +import mindustry.gen.*; import mindustry.world.consumers.Consume; import java.io.*; public class ConsumeModule extends BlockModule{ private boolean valid, optionalValid; - private final TileEntity entity; + private final Tilec entity; - public ConsumeModule(TileEntity entity){ + public ConsumeModule(Tilec entity){ this.entity = entity; } diff --git a/desktop/src/mindustry/desktop/steam/SStats.java b/desktop/src/mindustry/desktop/steam/SStats.java index 3ada365289..cdc6288ebe 100644 --- a/desktop/src/mindustry/desktop/steam/SStats.java +++ b/desktop/src/mindustry/desktop/steam/SStats.java @@ -64,8 +64,8 @@ public class SStats implements SteamUserStatsCallback{ active50Crawlers.complete(); } - for(TileEntity entity : player.getTeam().cores()){ - if(!content.items().contains(i -> i.type == ItemType.material && entity.items.get(i) < entity.block.itemCapacity)){ + for(Tilec entity : player.getTeam().cores()){ + if(!content.items().contains(i -> i.type == ItemType.material && entity.getItems().get(i) < entity.block.itemCapacity)){ fillCoreAllCampaign.complete(); break; } diff --git a/tests/src/test/java/ApplicationTests.java b/tests/src/test/java/ApplicationTests.java index d124967728..1cbbb4636c 100644 --- a/tests/src/test/java/ApplicationTests.java +++ b/tests/src/test/java/ApplicationTests.java @@ -143,12 +143,12 @@ public class ApplicationTests{ void blockInventories(){ multiblock(); Tile tile = world.tile(4, 4); - tile.entity.items.add(Items.coal, 5); - tile.entity.items.add(Items.titanium, 50); - assertEquals(tile.entity.items.total(), 55); - tile.entity.items.remove(Items.phasefabric, 10); - tile.entity.items.remove(Items.titanium, 10); - assertEquals(tile.entity.items.total(), 45); + tile.entity.getItems().add(Items.coal, 5); + tile.entity.getItems().add(Items.titanium, 50); + assertEquals(tile.entity.getItems().total(), 55); + tile.entity.getItems().remove(Items.phasefabric, 10); + tile.entity.getItems().remove(Items.titanium, 10); + assertEquals(tile.entity.getItems().total(), 45); } @Test @@ -224,7 +224,7 @@ public class ApplicationTests{ world.tile(0, 0).setBlock(Blocks.itemSource); world.tile(0, 0).configureAny(Items.copper.id); - Array entities = Array.with(world.tile(0, 0).entity); + Array entities = Array.with(world.tile(0, 0).entity); for(int i = 0; i < length; i++){ world.tile(i + 1, 0).setBlock(Blocks.conveyor); @@ -246,12 +246,12 @@ public class ApplicationTests{ //warmup for(int i = 0; i < 100000; i++){ - entities.each(TileEntity::update); + entities.each(Tilec::update); } Time.mark(); for(int i = 0; i < 200000; i++){ - entities.each(TileEntity::update); + entities.each(Tilec::update); } Log.info(Time.elapsed() + "ms to process " + items[0] + " items"); assertTrue(items[0] > 0); @@ -422,7 +422,7 @@ public class ApplicationTests{ Tile core = world.tile(5, 5); core.set(Blocks.coreShard, Team.sharded); for(Item item : content.items()){ - core.entity.items.set(item, 3000); + core.entity.getItems().set(item, 3000); } assertEquals(core.entity, state.teams.get(Team.sharded).core()); @@ -439,12 +439,12 @@ public class ApplicationTests{ assertEquals(capacity - 1, deposited); tile.block().handleStack(item, capacity - 1, tile, unit); - assertEquals(tile.entity.items.get(item), capacity - 1); + assertEquals(tile.entity.getItems().get(item), capacity - 1); int overflow = tile.block().acceptStack(item, 10, tile, unit); assertEquals(1, overflow); tile.block().handleStack(item, 1, tile, unit); - assertEquals(capacity, tile.entity.items.get(item)); + assertEquals(capacity, tile.entity.getItems().get(item)); } } \ No newline at end of file diff --git a/tests/src/test/java/power/DirectConsumerTests.java b/tests/src/test/java/power/DirectConsumerTests.java index 19933045fe..9cd8df6dae 100644 --- a/tests/src/test/java/power/DirectConsumerTests.java +++ b/tests/src/test/java/power/DirectConsumerTests.java @@ -37,8 +37,8 @@ public class DirectConsumerTests extends PowerTestFixture{ consumes.power(requestedPower); consumes.items(new ItemStack(Items.silicon, 30), new ItemStack(Items.lead, 30)); }}); - consumerTile.entity.items.add(Items.silicon, siliconAmount); - consumerTile.entity.items.add(Items.lead, leadAmount); + consumertile.entity.getItems().add(Items.silicon, siliconAmount); + consumertile.entity.getItems().add(Items.lead, leadAmount); Tile producerTile = createFakeTile(2, 0, createFakeProducerBlock(producedPower)); producerTile.ent().productionEfficiency = 1f; @@ -50,6 +50,6 @@ public class DirectConsumerTests extends PowerTestFixture{ consumerTile.entity.update(); graph.update(); - assertEquals(expectedSatisfaction, consumerTile.entity.power.status); + assertEquals(expectedSatisfaction, consumertile.entity.getPower().status); } } diff --git a/tests/src/test/java/power/ItemLiquidGeneratorTests.java b/tests/src/test/java/power/ItemLiquidGeneratorTests.java index 7111c79658..894421b67e 100644 --- a/tests/src/test/java/power/ItemLiquidGeneratorTests.java +++ b/tests/src/test/java/power/ItemLiquidGeneratorTests.java @@ -87,13 +87,13 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{ createGenerator(inputType); assertTrue(generator.acceptLiquid(tile, null, liquid, availableLiquidAmount), inputType + " | " + parameterDescription + ": Liquids which will be declined by the generator don't need to be tested - The code won't be called for those cases."); - entity.liquids.add(liquid, availableLiquidAmount); + entity.getLiquids().add(liquid, availableLiquidAmount); entity.cons.update(); // Perform an update on the generator once - This should use up any resource up to the maximum liquid usage generator.update(tile); - assertEquals(expectedRemainingLiquidAmount, entity.liquids.get(liquid), inputType + " | " + parameterDescription + ": Remaining liquid amount mismatch."); + assertEquals(expectedRemainingLiquidAmount, entity.getLiquids().get(liquid), inputType + " | " + parameterDescription + ": Remaining liquid amount mismatch."); assertEquals(expectedEfficiency, entity.productionEfficiency, inputType + " | " + parameterDescription + ": Efficiency mismatch."); } @@ -130,7 +130,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{ assertTrue(generator.acceptItem(item, tile, null), inputType + " | " + parameterDescription + ": Items which will be declined by the generator don't need to be tested - The code won't be called for those cases."); if(amount > 0){ - entity.items.add(item, amount); + entity.getItems().add(item, amount); } entity.cons.update(); @@ -138,7 +138,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{ try{ generator.update(tile); - assertEquals(expectedRemainingItemAmount, entity.items.get(item), inputType + " | " + parameterDescription + ": Remaining item amount mismatch."); + assertEquals(expectedRemainingItemAmount, entity.getItems().get(item), inputType + " | " + parameterDescription + ": Remaining item amount mismatch."); assertEquals(expectedEfficiency, entity.productionEfficiency, inputType + " | " + parameterDescription + ": Efficiency mismatch."); }catch(NullPointerException e){ e.printStackTrace(); @@ -162,7 +162,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{ createGenerator(inputType); // Burn a single coal and test for the duration - entity.items.add(Items.coal, 1); + entity.getItems().add(Items.coal, 1); entity.cons.update(); generator.update(tile); diff --git a/tests/src/test/java/power/PowerTestFixture.java b/tests/src/test/java/power/PowerTestFixture.java index e5735052f5..d0ceb3ac77 100644 --- a/tests/src/test/java/power/PowerTestFixture.java +++ b/tests/src/test/java/power/PowerTestFixture.java @@ -87,19 +87,19 @@ public class PowerTestFixture{ // Simulate the "changed" method. Calling it through reflections would require half the game to be initialized. tile.entity = block.newEntity().init(tile, false); - tile.entity.cons = new ConsumeModule(tile.entity); - if(block.hasItems) tile.entity.items = new ItemModule(); - if(block.hasLiquids) tile.entity.liquids = new LiquidModule(); + tile.entity.getCons() = new ConsumeModule(tile.entity); + if(block.hasItems) tile.entity.getItems() = new ItemModule(); + if(block.hasLiquids) tile.entity.getLiquids() = new LiquidModule(); if(block.hasPower){ - tile.entity.power = new PowerModule(); - tile.entity.power.graph = new PowerGraph(){ + tile.entity.getPower() = new PowerModule(); + tile.entity.getPower().graph = new PowerGraph(){ //assume there's always something consuming power @Override public float getUsageFraction(){ return 1f; } }; - tile.entity.power.graph.add(tile); + tile.entity.getPower().graph.add(tile); } // Assign incredibly high health so the block does not get destroyed on e.g. burning Blast Compound diff --git a/tests/src/test/java/power/PowerTests.java b/tests/src/test/java/power/PowerTests.java index 6815f2e880..76acf79708 100644 --- a/tests/src/test/java/power/PowerTests.java +++ b/tests/src/test/java/power/PowerTests.java @@ -66,7 +66,7 @@ public class PowerTests extends PowerTestFixture{ // Update and check for the expected power status of the consumer powerGraph.update(); - assertEquals(expectedSatisfaction, directConsumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match"); + assertEquals(expectedSatisfaction, directConsumertile.entity.getPower().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match"); } /** @@ -104,14 +104,14 @@ public class PowerTests extends PowerTestFixture{ } float maxCapacity = 100f; Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity)); - batteryTile.entity.power.status = initialBatteryCapacity / maxCapacity; + batterytile.entity.getPower().status = initialBatteryCapacity / maxCapacity; powerGraph.add(batteryTile); powerGraph.update(); - assertEquals(expectedBatteryCapacity / maxCapacity, batteryTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match"); + assertEquals(expectedBatteryCapacity / maxCapacity, batterytile.entity.getPower().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match"); if(directConsumerTile != null){ - assertEquals(expectedSatisfaction, directConsumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match"); + assertEquals(expectedSatisfaction, directConsumertile.entity.getPower().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match"); } } @@ -127,13 +127,13 @@ public class PowerTests extends PowerTestFixture{ powerGraph.add(consumerTile); powerGraph.update(); - assertEquals(1.0f, consumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR); + assertEquals(1.0f, consumertile.entity.getPower().status, Mathf.FLOAT_ROUNDING_ERROR); powerGraph.remove(producerTile); powerGraph.add(consumerTile); powerGraph.update(); - assertEquals(0.0f, consumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR); + assertEquals(0.0f, consumertile.entity.getPower().status, Mathf.FLOAT_ROUNDING_ERROR); if(consumerTile.block().consumes.hasPower()){ ConsumePower consumePower = consumerTile.block().consumes.getPower(); assertFalse(consumePower.valid(consumerTile.ent()));