From ced11c88bc966f9caa7b58a20fc222551ee665d9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 25 Jun 2018 15:44:09 -0400 Subject: [PATCH] Fixed smelter not using items, unit factory recipe --- .../io/anuke/mindustry/content/Recipes.java | 12 +++--- .../mindustry/content/blocks/UnitBlocks.java | 2 +- .../mindustry/entities/units/BaseUnit.java | 14 +++++++ .../world/blocks/production/Smelter.java | 2 +- .../world/blocks/units/UnitFactory.java | 39 +++++++++++++------ 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index 9dbdfef11b..8599a9e415 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -60,13 +60,13 @@ public class Recipes implements ContentList{ //processing new Recipe(crafting, CraftingBlocks.biomatterCompressor, new ItemStack(Items.lead, 70), new ItemStack(Items.silicon, 60)); new Recipe(crafting, CraftingBlocks.separator, new ItemStack(Items.tungsten, 60), new ItemStack(Items.carbide, 50)); - new Recipe(crafting, CraftingBlocks.centrifuge, new ItemStack(Items.tungsten, 130), new ItemStack(Items.carbide, 130), new ItemStack(Items.silicon, 30), new ItemStack(Items.titanium, 40)); + new Recipe(crafting, CraftingBlocks.centrifuge, new ItemStack(Items.tungsten, 130), new ItemStack(Items.carbide, 130), new ItemStack(Items.silicon, 60), new ItemStack(Items.titanium, 50)); //POWER new Recipe(power, PowerBlocks.powernode, new ItemStack(Items.tungsten, 2), new ItemStack(Items.lead, 6)); new Recipe(power, PowerBlocks.powernodelarge, new ItemStack(Items.carbide, 10), new ItemStack(Items.lead, 20), new ItemStack(Items.silicon, 6)); new Recipe(power, PowerBlocks.battery, new ItemStack(Items.tungsten, 8), new ItemStack(Items.lead, 30), new ItemStack(Items.silicon, 4)); - new Recipe(power, PowerBlocks.batteryLarge, new ItemStack(Items.carbide, 16), new ItemStack(Items.tungsten, 16), new ItemStack(Items.lead, 80), new ItemStack(Items.silicon, 20)); + new Recipe(power, PowerBlocks.batteryLarge, new ItemStack(Items.carbide, 40), new ItemStack(Items.lead, 80), new ItemStack(Items.silicon, 30)); //generators new Recipe(power, PowerBlocks.combustiongenerator, new ItemStack(Items.tungsten, 30), new ItemStack(Items.lead, 30)); @@ -80,8 +80,8 @@ public class Recipes implements ContentList{ //DRILLS, PRODUCERS new Recipe(production, ProductionBlocks.tungstenDrill, new ItemStack(Items.tungsten, 30)); - new Recipe(production, ProductionBlocks.carbideDrill, new ItemStack(Items.tungsten, 40), new ItemStack(Items.carbide, 40)); - new Recipe(production, ProductionBlocks.laserdrill, new ItemStack(Items.tungsten, 60), new ItemStack(Items.carbide, 70), new ItemStack(Items.silicon, 60), new ItemStack(Items.carbide, 60)); + new Recipe(production, ProductionBlocks.carbideDrill, new ItemStack(Items.tungsten, 60), new ItemStack(Items.carbide, 60)); + new Recipe(production, ProductionBlocks.laserdrill, new ItemStack(Items.tungsten, 80), new ItemStack(Items.carbide, 90), new ItemStack(Items.silicon, 60), new ItemStack(Items.titanium, 80)); new Recipe(production, ProductionBlocks.waterextractor, new ItemStack(Items.tungsten, 50), new ItemStack(Items.carbide, 50), new ItemStack(Items.lead, 40)); new Recipe(production, ProductionBlocks.cultivator, new ItemStack(Items.tungsten, 20), new ItemStack(Items.lead, 50), new ItemStack(Items.silicon, 20)); @@ -93,8 +93,8 @@ public class Recipes implements ContentList{ //new Recipe(units, UpgradeBlocks.deltaFactory, new ItemStack(Items.tungsten, 30), new ItemStack(Items.lead, 50), new ItemStack(Items.silicon, 30)); //actual unit related stuff - new Recipe(units, UnitBlocks.droneFactory, new ItemStack(Items.tungsten, 30), new ItemStack(Items.lead, 50), new ItemStack(Items.silicon, 30)); - new Recipe(units, UnitBlocks.repairPoint, new ItemStack(Items.lead, 30), new ItemStack(Items.tungsten, 30), new ItemStack(Items.silicon, 20)); + new Recipe(units, UnitBlocks.droneFactory, new ItemStack(Items.tungsten, 30), new ItemStack(Items.lead, 50), new ItemStack(Items.silicon, 80)); + new Recipe(units, UnitBlocks.repairPoint, new ItemStack(Items.lead, 30), new ItemStack(Items.tungsten, 30), new ItemStack(Items.silicon, 30)); //LIQUIDS new Recipe(liquid, LiquidBlocks.conduit, new ItemStack(Items.lead, 1)); diff --git a/core/src/io/anuke/mindustry/content/blocks/UnitBlocks.java b/core/src/io/anuke/mindustry/content/blocks/UnitBlocks.java index 3cdc75ae29..e34b4b309c 100644 --- a/core/src/io/anuke/mindustry/content/blocks/UnitBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/UnitBlocks.java @@ -17,7 +17,7 @@ public class UnitBlocks extends BlockList implements ContentList { produceTime = 300; size = 2; requirements = new ItemStack[]{ - new ItemStack(Items.tungsten, 20) + new ItemStack(Items.silicon, 20), new ItemStack(Items.lead, 20) }; }}; diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index 77bad39ce0..27ec6709dc 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -21,6 +21,7 @@ import io.anuke.mindustry.net.Net; import io.anuke.mindustry.type.AmmoType; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.world.Tile; +import io.anuke.mindustry.world.blocks.units.UnitFactory.UnitFactoryEntity; import io.anuke.mindustry.world.meta.BlockFlag; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; @@ -52,12 +53,17 @@ public abstract class BaseUnit extends Unit{ protected boolean isWave; protected Squad squad; + protected UnitFactoryEntity spawner; public BaseUnit(UnitType type, Team team){ this.type = type; this.team = team; } + public void setSpawner(UnitFactoryEntity spawner) { + this.spawner = spawner; + } + public UnitType getType() { return type; } @@ -259,6 +265,14 @@ public abstract class BaseUnit extends Unit{ } + @Override + public void removed() { + if(spawner != null){ + spawner.hasSpawned = false; + spawner = null; + } + } + @Override public float drawSize(){ return 14; diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java b/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java index 415016ffbc..3574058f8d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java @@ -111,7 +111,7 @@ public class Smelter extends Block{ return; } - boolean consumeInputs = false; + boolean consumeInputs = true; if(useFlux){ //remove flux materials if present diff --git a/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java b/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java index 6cfd42443c..e81173ac45 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java @@ -1,14 +1,19 @@ package io.anuke.mindustry.world.blocks.units; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import io.anuke.annotations.Annotations.Loc; +import io.anuke.annotations.Annotations.Remote; import io.anuke.mindustry.Vars; import io.anuke.mindustry.content.fx.BlockFx; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.Units; import io.anuke.mindustry.entities.units.BaseUnit; import io.anuke.mindustry.entities.units.UnitType; +import io.anuke.mindustry.gen.CallBlocks; import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.graphics.Shaders; +import io.anuke.mindustry.net.In; +import io.anuke.mindustry.net.Net; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.world.BarType; @@ -119,7 +124,7 @@ public class UnitFactory extends Block { } } - if(hasRequirements(entity.items, entity.buildTime/produceTime) && + if(!entity.hasSpawned && hasRequirements(entity.items, entity.buildTime/produceTime) && entity.power.amount >= used && !entity.open){ entity.buildTime += Timers.delta(); @@ -132,16 +137,7 @@ public class UnitFactory extends Block { if(entity.buildTime >= produceTime && !entity.open){ entity.open = true; - Timers.run(openDuration/1.5f, () -> { - entity.buildTime = 0f; - Effects.shake(2f, 3f, entity); - Effects.effect(BlockFx.producesmoke, tile.drawx(), tile.drawy()); - - BaseUnit unit = type.create(tile.getTeam()); - unit.set(tile.drawx(), tile.drawy()); - unit.add(); - unit.getVelocity().y = launchVelocity; - }); + Timers.run(openDuration / 1.5f, () -> CallBlocks.onUnitFactorySpawn(tile)); entity.openCountdown = openDuration; @@ -175,12 +171,33 @@ public class UnitFactory extends Block { return true; } + @Remote(called = Loc.server, in = In.blocks) + public static void onUnitFactorySpawn(Tile tile){ + UnitFactoryEntity entity = tile.entity(); + UnitFactory factory = (UnitFactory)tile.block(); + + entity.buildTime = 0f; + entity.hasSpawned = true; + + Effects.shake(2f, 3f, entity); + Effects.effect(BlockFx.producesmoke, tile.drawx(), tile.drawy()); + + if(!Net.client()) { + BaseUnit unit = factory.type.create(tile.getTeam()); + unit.setSpawner(entity); + unit.set(tile.drawx(), tile.drawy()); + unit.add(); + unit.getVelocity().y = factory.launchVelocity; + } + } + public static class UnitFactoryEntity extends TileEntity{ public float buildTime; public boolean open; public float openCountdown; public float time; public float speedScl; + public boolean hasSpawned; @Override public void write(DataOutputStream stream) throws IOException {