From 59ec09e82cb1f1c91ec35f718b2270139c3a08c1 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 14 Aug 2018 12:16:21 -0400 Subject: [PATCH] Crash fixes / Resource-steal fixed / No-build while shooting fixed --- core/src/io/anuke/mindustry/entities/Player.java | 8 ++------ core/src/io/anuke/mindustry/net/NetworkIO.java | 1 + core/src/io/anuke/mindustry/world/BaseBlock.java | 12 ++++++------ .../io/anuke/mindustry/world/blocks/BuildBlock.java | 2 +- .../world/blocks/power/PowerDistributor.java | 2 +- .../mindustry/world/blocks/power/PowerNode.java | 6 +++--- .../mindustry/world/blocks/storage/CoreBlock.java | 2 +- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 8f850da16f..d8684f8095 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -365,9 +365,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra public void drawOver(){ if(dead) return; - if(!isShooting()){ - drawBuilding(this); - } + drawBuilding(this); if(mech.flying || boostHeat > 0.001f){ float wobblyness = 0.6f; @@ -478,9 +476,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra avoidOthers(8f); } - if(!isShooting()){ - updateBuilding(this); - } + updateBuilding(this); x = Mathf.clamp(x, 0, world.width() * tilesize); y = Mathf.clamp(y, 0, world.height() * tilesize); diff --git a/core/src/io/anuke/mindustry/net/NetworkIO.java b/core/src/io/anuke/mindustry/net/NetworkIO.java index dcf8ccbf21..208d6c836f 100644 --- a/core/src/io/anuke/mindustry/net/NetworkIO.java +++ b/core/src/io/anuke/mindustry/net/NetworkIO.java @@ -189,6 +189,7 @@ public class NetworkIO{ Map currentMap = new Map(map, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null); currentMap.meta.tags.clear(); currentMap.meta.tags.putAll(tags); + world.setSector(null); world.setMap(currentMap); Tile[][] tiles = world.createTiles(width, height); diff --git a/core/src/io/anuke/mindustry/world/BaseBlock.java b/core/src/io/anuke/mindustry/world/BaseBlock.java index e6408b4fb4..cbb50bab1a 100644 --- a/core/src/io/anuke/mindustry/world/BaseBlock.java +++ b/core/src/io/anuke/mindustry/world/BaseBlock.java @@ -121,7 +121,7 @@ public abstract class BaseBlock{ Tile other = proximity.get((i + dump) % proximity.size); Tile in = Edges.getFacingEdge(tile, other); - if(other.block().hasLiquids && canDumpLiquid(tile, other, liquid)){ + if(other.getTeamID() == tile.getTeamID() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid)){ float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity; float fract = tile.entity.liquids.get(liquid) / liquidCapacity; @@ -149,7 +149,7 @@ public abstract class BaseBlock{ next = next.target(); - if(next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){ + if(next.getTeamID() == tile.getTeamID() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){ if(next.block().acceptLiquid(next, tile, liquid, 0f)){ float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity; @@ -199,7 +199,7 @@ public abstract class BaseBlock{ incrementDump(tile, proximity.size); Tile other = proximity.get((i + dump) % proximity.size); Tile in = Edges.getFacingEdge(tile, other); - if(other.block().acceptItem(item, other, in) && canDump(tile, other, item)){ + if(other.getTeamID() == tile.getTeamID() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){ other.block().handleItem(item, other, in); return; } @@ -239,7 +239,7 @@ public abstract class BaseBlock{ for(int ii = 0; ii < Item.all().size; ii++){ Item item = Item.getByID(ii); - if(entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){ + if(other.getTeamID() == tile.getTeamID() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){ other.block().handleItem(item, other, in); tile.entity.items.remove(item, 1); incrementDump(tile, proximity.size); @@ -248,7 +248,7 @@ public abstract class BaseBlock{ } }else{ - if(other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){ + if(other.getTeamID() == tile.getTeamID() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){ other.block().handleItem(todump, other, in); tile.entity.items.remove(todump, 1); incrementDump(tile, proximity.size); @@ -274,7 +274,7 @@ public abstract class BaseBlock{ /** Try offloading an item to a nearby container in its facing direction. Returns true if success.*/ public boolean offloadDir(Tile tile, Item item){ Tile other = tile.getNearby(tile.getRotation()); - if(other != null && other.block().acceptItem(item, other, tile)){ + if(other != null && other.getTeamID() == tile.getTeamID() && other.block().acceptItem(item, other, tile)){ other.block().handleItem(item, other, tile); return true; } diff --git a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java index a6c4f9f599..98502f45e3 100644 --- a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java @@ -225,7 +225,7 @@ public class BuildBlock extends Block{ int accumulated = (int) (accumulator[i]); //get amount - if(amount > 0){ //if it's positive, add it to the core + if(amount > 0 && accumulated > 0){ //if it's positive, add it to the core int accepting = core.tile.block().acceptStack(requirements[i].item, accumulated, core.tile, builder); core.tile.block().handleStack(requirements[i].item, accepting, core.tile, builder); diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java index 991bd165d2..4b4410b485 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java @@ -53,7 +53,7 @@ public class PowerDistributor extends PowerBlock{ protected boolean shouldDistribute(Tile tile, Tile other){ other = other.target(); //only generators can distribute to other generators - return (!(other.block() instanceof PowerGenerator) || tile.block() instanceof PowerGenerator) + return other.getTeamID() == tile.getTeamID() && (!(other.block() instanceof PowerGenerator) || tile.block() instanceof PowerGenerator) && other.entity != null && other.block().hasPower && other.entity.power.amount / other.block().powerCapacity < tile.entity.power.amount / powerCapacity; diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java index f031a9636b..dfbdaefd96 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -60,7 +60,7 @@ public class PowerNode extends PowerBlock{ entity.links.add(other.packedPosition()); } - if(other.block() instanceof PowerNode){ + if(other.getTeamID() == tile.getTeamID() && other.block() instanceof PowerNode){ DistributorEntity oe = other.entity(); if(!oe.links.contains(tile.packedPosition())){ @@ -224,12 +224,12 @@ public class PowerNode extends PowerBlock{ } protected boolean shouldDistribute(Tile tile, Tile other){ - return other.entity.power.amount / other.block().powerCapacity <= tile.entity.power.amount / powerCapacity && + return other.getTeamID() == tile.getTeamID() && other.entity.power.amount / other.block().powerCapacity <= tile.entity.power.amount / powerCapacity && !(other.block() instanceof PowerGenerator); //do not distribute to power generators } protected boolean shouldLeechPower(Tile tile, Tile other){ - return !(other.block() instanceof PowerNode) + return other.getTeamID() == tile.getTeamID() && !(other.block() instanceof PowerNode) && other.block() instanceof PowerDistributor //only suck power from batteries and power generators && other.entity.power.amount / other.block().powerCapacity > tile.entity.power.amount / powerCapacity; } diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index aa50783fd5..d6d90797e6 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -103,7 +103,7 @@ public class CoreBlock extends StorageBlock{ @Override public float handleDamage(Tile tile, float amount){ - return amount; + return debug ? 0 : amount; } @Override