From cc92edfa58006984a0b824705e939a95d0203cb9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 4 Jul 2018 15:22:59 -0400 Subject: [PATCH] Fixed item drop duplicates, invincible players --- .../anuke/mindustry/content/bullets/TurretBullets.java | 4 ++-- core/src/io/anuke/mindustry/core/NetClient.java | 6 ++++-- core/src/io/anuke/mindustry/entities/Player.java | 2 +- .../io/anuke/mindustry/entities/effect/ItemDrop.java | 3 +-- .../io/anuke/mindustry/entities/units/UnitDrops.java | 4 ++-- core/src/io/anuke/mindustry/input/InputHandler.java | 4 ++-- .../io/anuke/mindustry/ui/fragments/DebugFragment.java | 10 +++++----- .../world/blocks/distribution/MassDriver.java | 4 ++-- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/bullets/TurretBullets.java b/core/src/io/anuke/mindustry/content/bullets/TurretBullets.java index 673378e629..5ae4f300e8 100644 --- a/core/src/io/anuke/mindustry/content/bullets/TurretBullets.java +++ b/core/src/io/anuke/mindustry/content/bullets/TurretBullets.java @@ -12,8 +12,8 @@ import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.entities.bullet.BulletType; import io.anuke.mindustry.entities.bullet.LiquidBulletType; import io.anuke.mindustry.entities.effect.Fire; +import io.anuke.mindustry.entities.effect.ItemDrop; import io.anuke.mindustry.entities.effect.Lightning; -import io.anuke.mindustry.gen.CallEntity; import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.type.ContentList; import io.anuke.mindustry.type.Item; @@ -258,7 +258,7 @@ public class TurretBullets extends BulletList implements ContentList { if(amountDropped > 0){ float angle = b.angle() + Mathf.range(100f); float vs = Mathf.random(0f, 4f); - CallEntity.createItemDrop(Item.getByID(i), amountDropped, b.x, b.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs)); + ItemDrop.create(Item.getByID(i), amountDropped, b.x, b.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs)); } } } diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index acbe9149c1..cee76a9eae 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -353,7 +353,9 @@ public class NetClient extends Module { if(entity == null){ entity = (SyncTrait) TypeTrait.getTypeByID(typeID).get(); //create entity from supplier entity.resetID(id); - add = true; + if(!netClient.isEntityUsed(entity.getID())){ + add = true; + } } //read the entity @@ -364,7 +366,7 @@ public class NetClient extends Module { throw new RuntimeException("Error reading entity of type '"+ group.getType() + "': Read length mismatch [write=" + readLength + ", read=" + (netClient.byteStream.position() - position - 1)+ "]"); } - if(add && !netClient.isEntityUsed(entity.getID())){ + if(add){ entity.add(); netClient.addRemovedEntity(entity.getID()); } diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 5ff4375ee7..46bdc124f4 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -199,7 +199,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra public void damage(float amount){ CallEntity.onPlayerDamage(this, calculateDamage(amount)); - if(health <= 0 && !dead && isLocal){ + if(health <= 0 && !dead){ CallEntity.onPlayerDeath(this); } } diff --git a/core/src/io/anuke/mindustry/entities/effect/ItemDrop.java b/core/src/io/anuke/mindustry/entities/effect/ItemDrop.java index 8e974897ed..2e4063ef8b 100644 --- a/core/src/io/anuke/mindustry/entities/effect/ItemDrop.java +++ b/core/src/io/anuke/mindustry/entities/effect/ItemDrop.java @@ -57,8 +57,7 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT return drop; } - @Remote(called = Loc.server, in = In.entities) - public static void createItemDrop(Item item, int amount, float x, float y, float velocityX, float velocityY){ + public static void create(Item item, int amount, float x, float y, float velocityX, float velocityY){ create(item, amount, x, y, 0).getVelocity().set(velocityX, velocityY); } diff --git a/core/src/io/anuke/mindustry/entities/units/UnitDrops.java b/core/src/io/anuke/mindustry/entities/units/UnitDrops.java index 5bae5543a7..39f931103c 100644 --- a/core/src/io/anuke/mindustry/entities/units/UnitDrops.java +++ b/core/src/io/anuke/mindustry/entities/units/UnitDrops.java @@ -2,7 +2,7 @@ package io.anuke.mindustry.entities.units; import io.anuke.mindustry.Vars; import io.anuke.mindustry.content.Items; -import io.anuke.mindustry.gen.CallEntity; +import io.anuke.mindustry.entities.effect.ItemDrop; import io.anuke.mindustry.type.Item; import io.anuke.ucore.util.Mathf; @@ -23,7 +23,7 @@ public class UnitDrops { for(Item item : dropTable){ if(Mathf.chance(0.2)){ int amount = Mathf.random(1, 5); - CallEntity.createItemDrop(item, amount, unit.x + Mathf.range(2f), unit.y + Mathf.range(2f), + ItemDrop.create(item, amount, unit.x + Mathf.range(2f), unit.y + Mathf.range(2f), unit.getVelocity().x + Mathf.range(3f), unit.getVelocity().y + Mathf.range(3f)); } } diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index c935930e22..aff1520cbd 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -220,7 +220,7 @@ public abstract class InputHandler extends InputAdapter{ if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.block().hasItems){ CallBlocks.transferInventory(player, tile); }else{ - CallEntity.dropItem(player, player.angleTo(x, y)); + CallEntity.dropItem(player.angleTo(x, y)); } } @@ -267,7 +267,7 @@ public abstract class InputHandler extends InputAdapter{ player.addBuildRequest(new BuildRequest(tile.x, tile.y)); } - @Remote(targets = Loc.both, called = Loc.server, in = In.entities) + @Remote(targets = Loc.client, called = Loc.server, in = In.entities) public static void dropItem(Player player, float angle){ if(Net.server() && !player.inventory.hasItem()){ throw new ValidateException(player, "Player cannot drop an item."); diff --git a/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java b/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java index 1d187e9057..fde6ff3527 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java @@ -2,14 +2,14 @@ package io.anuke.mindustry.ui.fragments; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; -import io.anuke.mindustry.content.bullets.TurretBullets; import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; -import io.anuke.mindustry.entities.bullet.Bullet; +import io.anuke.mindustry.entities.effect.ItemDrop; import io.anuke.mindustry.entities.units.BaseUnit; import io.anuke.mindustry.entities.units.UnitType; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.net.Net; +import io.anuke.mindustry.type.Item; import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.EntityGroup; @@ -59,13 +59,13 @@ public class DebugFragment extends Fragment { row(); new button("noclip", "toggle", () -> noclip = !noclip); row(); - new button("fire", () -> { + new button("items", () -> { for (int i = 0; i < 10; i++) { - Bullet.create(TurretBullets.fireball, player, player.x, player.y, Mathf.random(360f)); + ItemDrop.create(Item.all().random(), 5, player.x, player.y, Mathf.random(360f)); } }); row(); - new button("team", "toggle", () -> player.toggleTeam()); + new button("team", "toggle", player::toggleTeam); row(); new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug); row(); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java b/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java index 386dea7396..e0a81c997e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java @@ -10,8 +10,8 @@ import io.anuke.mindustry.content.fx.ShootFx; import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.bullet.Bullet; +import io.anuke.mindustry.entities.effect.ItemDrop; import io.anuke.mindustry.gen.CallBlocks; -import io.anuke.mindustry.gen.CallEntity; import io.anuke.mindustry.graphics.Layer; import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.net.In; @@ -241,7 +241,7 @@ public class MassDriver extends Block { if(amountDropped > 0){ float angle = Mathf.range(180f); float vs = Mathf.random(0f, 4f); - CallEntity.createItemDrop(Item.getByID(i), amountDropped, bullet.x, bullet.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs)); + ItemDrop.create(Item.getByID(i), amountDropped, bullet.x, bullet.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs)); } }