diff --git a/core/src/mindustry/editor/EditorTool.java b/core/src/mindustry/editor/EditorTool.java index 50442ff0f2..8e197bf42e 100644 --- a/core/src/mindustry/editor/EditorTool.java +++ b/core/src/mindustry/editor/EditorTool.java @@ -118,7 +118,7 @@ public enum EditorTool{ if(editor.drawBlock.isOverlay()){ Block dest = tile.overlay(); if(dest == editor.drawBlock) return; - tester = t -> t.overlay() == dest; + tester = t -> t.overlay() == dest && !t.floor().isLiquid; setter = t -> t.setOverlay(editor.drawBlock); }else if(editor.drawBlock.isFloor()){ Block dest = tile.floor(); diff --git a/core/src/mindustry/entities/type/Unit.java b/core/src/mindustry/entities/type/Unit.java index 6a037d6f36..42463dc508 100644 --- a/core/src/mindustry/entities/type/Unit.java +++ b/core/src/mindustry/entities/type/Unit.java @@ -252,6 +252,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ Tile tile = world.tileWorld(x, y); status.update(this); + item.amount = Mathf.clamp(this.item.amount, 0, getItemCapacity()); velocity.limit(maxVelocity()).scl(1f + (status.getSpeedMultiplier() - 1f) * Time.delta()); @@ -341,6 +342,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ public void addItem(Item item, int amount){ this.item.amount = this.item.item == item ? this.item.amount + amount : amount; this.item.item = item; + this.item.amount = Mathf.clamp(this.item.amount, 0, getItemCapacity()); } public void clearItem(){ diff --git a/core/src/mindustry/net/Administration.java b/core/src/mindustry/net/Administration.java index 7806b1a9db..aa36705c39 100644 --- a/core/src/mindustry/net/Administration.java +++ b/core/src/mindustry/net/Administration.java @@ -1,12 +1,17 @@ package mindustry.net; import arc.*; +import arc.func.*; import arc.struct.*; -import arc.util.*; import arc.util.ArcAnnotate.*; +import arc.util.*; +import arc.util.pooling.*; +import arc.util.pooling.Pool.*; import mindustry.*; import mindustry.annotations.Annotations.*; import mindustry.entities.type.*; +import mindustry.type.*; +import mindustry.world.*; import static mindustry.Vars.headless; import static mindustry.game.EventType.*; @@ -97,12 +102,16 @@ public class Administration{ } /** @return whether this action is allowed by the action filters. */ - public boolean allowAction(Player player, PlayerAction action){ + public boolean allowAction(Player player, ActionType type, Tile tile, Cons setter){ + PlayerAction act = Pools.obtain(PlayerAction.class, PlayerAction::new); + setter.get(act.set(player, type, tile)); for(ActionFilter filter : actionFilters){ - if(!filter.allow(player, action)){ + if(!filter.allow(act)){ + Pools.free(act); return false; } } + Pools.free(act); return true; } @@ -498,7 +507,7 @@ public class Administration{ /** Allows or disallows player actions. */ public interface ActionFilter{ /** @return whether this action should be permitted. if applicable, make sure to send this player a message specify why the action was prohibited. */ - boolean allow(Player player, PlayerAction action); + boolean allow(PlayerAction action); } public static class TraceInfo{ @@ -513,9 +522,39 @@ public class Administration{ } } - //TODO implement - public static class PlayerAction{ + /** Defines a (potentially dangerous) action that a player has done in the world. + * These objects are pooled; do not cache them! */ + public static class PlayerAction implements Poolable{ + public @NonNull Player player; + public @NonNull ActionType type; + public @NonNull Tile tile; + /** valid for configure and rotation-type events only. */ + public int config; + + /** valid for item-type events only. */ + public @Nullable Item item; + public int itemAmount; + + public PlayerAction set(Player player, ActionType type, Tile tile){ + this.player = player; + this.type = type; + this.tile = tile; + return this; + } + + @Override + public void reset(){ + item = null; + itemAmount = config = 0; + player = null; + type = null; + tile = null; + } + } + + public enum ActionType{ + breakBlock, placeBlock, rotate, configure, withdrawItem, depositItem } }