From e4ced551ebedadfeae79cb8a80eb425eba833046 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sun, 8 Aug 2021 12:02:25 +0100 Subject: [PATCH] Remove most of the turtle events I don't think anybody actually used these, and I'm not convinced they had much value anyway. It might be worth switching the refueling code to work as a registry instead, though events are kinda nice. --- .../dan200/computercraft/ComputerCraft.java | 3 - .../api/turtle/ITurtleUpgrade.java | 6 +- .../api/turtle/event/TurtleAction.java | 83 ------- .../api/turtle/event/TurtleActionEvent.java | 81 ------ .../api/turtle/event/TurtleAttackEvent.java | 79 ------ .../api/turtle/event/TurtleBlockEvent.java | 233 ------------------ .../api/turtle/event/TurtleEvent.java | 2 - .../turtle/event/TurtleInspectItemEvent.java | 91 ------- .../turtle/event/TurtleInventoryEvent.java | 84 ------- .../api/turtle/event/TurtlePlayerEvent.java | 43 ---- .../api/turtle/event/TurtleRefuelEvent.java | 7 +- .../dan200/computercraft/shared/Config.java | 21 -- .../shared/TurtlePermissions.java | 14 -- .../shared/turtle/apis/TurtleAPI.java | 6 - .../shared/turtle/core/TurtleDropCommand.java | 11 - .../turtle/core/TurtleEquipCommand.java | 9 - .../turtle/core/TurtleInspectCommand.java | 7 - .../shared/turtle/core/TurtleMoveCommand.java | 8 - .../turtle/core/TurtlePlaceCommand.java | 5 - .../turtle/core/TurtleRefuelCommand.java | 2 +- .../shared/turtle/core/TurtleSuckCommand.java | 10 - .../shared/turtle/core/TurtleTurnCommand.java | 9 - .../shared/turtle/upgrades/TurtleTool.java | 15 -- 23 files changed, 6 insertions(+), 823 deletions(-) delete mode 100644 src/main/java/dan200/computercraft/api/turtle/event/TurtleAction.java delete mode 100644 src/main/java/dan200/computercraft/api/turtle/event/TurtleActionEvent.java delete mode 100644 src/main/java/dan200/computercraft/api/turtle/event/TurtleAttackEvent.java delete mode 100644 src/main/java/dan200/computercraft/api/turtle/event/TurtleBlockEvent.java delete mode 100644 src/main/java/dan200/computercraft/api/turtle/event/TurtleInspectItemEvent.java delete mode 100644 src/main/java/dan200/computercraft/api/turtle/event/TurtleInventoryEvent.java delete mode 100644 src/main/java/dan200/computercraft/api/turtle/event/TurtlePlayerEvent.java diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index 679519219..8648d6ed2 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -5,7 +5,6 @@ */ package dan200.computercraft; -import dan200.computercraft.api.turtle.event.TurtleAction; import dan200.computercraft.core.apis.http.options.Action; import dan200.computercraft.core.apis.http.options.AddressRule; import dan200.computercraft.shared.Config; @@ -22,7 +21,6 @@ import java.util.Arrays; import java.util.Collections; -import java.util.EnumSet; import java.util.List; import java.util.concurrent.TimeUnit; @@ -70,7 +68,6 @@ public final class ComputerCraft public static int advancedTurtleFuelLimit = 100000; public static boolean turtlesObeyBlockProtection = true; public static boolean turtlesCanPush = true; - public static EnumSet turtleDisabledActions = EnumSet.noneOf( TurtleAction.class ); public static int computerTermWidth = 51; public static int computerTermHeight = 19; diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java index 18df15b7b..10dbb463d 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -9,8 +9,6 @@ import dan200.computercraft.api.IUpgradeBase; import dan200.computercraft.api.client.TransformedModel; import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.api.turtle.event.TurtleAttackEvent; -import dan200.computercraft.api.turtle.event.TurtleBlockEvent; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; @@ -61,8 +59,8 @@ default IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull Tu * Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called * by the turtle, and the tool is required to do some work. * - * Conforming implementations should fire {@link BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig} for - * digging, {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking. + * Conforming implementations should fire {@link BlockEvent.BreakEvent} for digging {@link AttackEntityEvent} + * for attacking. * * @param turtle Access to the turtle that the tool resides on. * @param side Which side of the turtle (left or right) the tool resides on. diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleAction.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleAction.java deleted file mode 100644 index f8515dff6..000000000 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleAction.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ -package dan200.computercraft.api.turtle.event; - -/** - * A basic action that a turtle may perform, as accessed by the {@code turtle} API. - * - * @see TurtleActionEvent - */ -public enum TurtleAction -{ - /** - * A turtle moves to a new position. - * - * @see TurtleBlockEvent.Move - */ - MOVE, - - /** - * A turtle turns in a specific direction. - */ - TURN, - - /** - * A turtle attempts to dig a block. - * - * @see TurtleBlockEvent.Dig - */ - DIG, - - /** - * A turtle attempts to place a block or item in the world. - * - * @see TurtleBlockEvent.Place - */ - PLACE, - - /** - * A turtle attempts to attack an entity. - * - * @see TurtleActionEvent - */ - ATTACK, - - /** - * Drop an item into an inventory/the world. - * - * @see TurtleInventoryEvent.Drop - */ - DROP, - - /** - * Suck an item from an inventory or the world. - * - * @see TurtleInventoryEvent.Suck - */ - SUCK, - - /** - * Refuel the turtle's fuel levels. - */ - REFUEL, - - /** - * Equip or unequip an item. - */ - EQUIP, - - /** - * Inspect a block in world. - * - * @see TurtleBlockEvent.Inspect - */ - INSPECT, - - /** - * Gather metdata about an item in the turtle's inventory. - */ - INSPECT_ITEM, -} diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleActionEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleActionEvent.java deleted file mode 100644 index fcaf39b41..000000000 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleActionEvent.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ -package dan200.computercraft.api.turtle.event; - -import dan200.computercraft.api.turtle.ITurtleAccess; -import dan200.computercraft.api.turtle.TurtleCommandResult; -import net.minecraftforge.eventbus.api.Cancelable; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.Objects; - -/** - * An event fired when a turtle is performing a known action. - */ -@Cancelable -public class TurtleActionEvent extends TurtleEvent -{ - private final TurtleAction action; - private String failureMessage; - - public TurtleActionEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action ) - { - super( turtle ); - - Objects.requireNonNull( action, "action cannot be null" ); - this.action = action; - } - - public TurtleAction getAction() - { - return action; - } - - /** - * Sets the cancellation state of this action. - * - * If {@code cancel} is {@code true}, this action will not be carried out. - * - * @param cancel The new canceled value. - * @see TurtleCommandResult#failure() - * @deprecated Use {@link #setCanceled(boolean, String)} instead. - */ - @Override - @Deprecated - public void setCanceled( boolean cancel ) - { - setCanceled( cancel, null ); - } - - /** - * Set the cancellation state of this action, setting a failure message if required. - * - * If {@code cancel} is {@code true}, this action will not be carried out. - * - * @param cancel The new canceled value. - * @param failureMessage The message to return to the user explaining the failure. - * @see TurtleCommandResult#failure(String) - */ - public void setCanceled( boolean cancel, @Nullable String failureMessage ) - { - super.setCanceled( cancel ); - this.failureMessage = cancel ? failureMessage : null; - } - - /** - * Get the message with which this will fail. - * - * @return The failure message. - * @see TurtleCommandResult#failure() - * @see #setCanceled(boolean, String) - */ - @Nullable - public String getFailureMessage() - { - return failureMessage; - } -} diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleAttackEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleAttackEvent.java deleted file mode 100644 index 1aced3475..000000000 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleAttackEvent.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ -package dan200.computercraft.api.turtle.event; - -import dan200.computercraft.api.turtle.ITurtleAccess; -import dan200.computercraft.api.turtle.ITurtleUpgrade; -import dan200.computercraft.api.turtle.TurtleSide; -import dan200.computercraft.api.turtle.TurtleVerb; -import net.minecraft.core.Direction; -import net.minecraft.world.entity.Entity; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.event.entity.player.AttackEntityEvent; - -import javax.annotation.Nonnull; -import java.util.Objects; - -/** - * Fired when a turtle attempts to attack an entity. - * - * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)}, - * as the base {@code turtle.attack()} command does not fire it. - * - * Note that such commands should also fire {@link AttackEntityEvent}, so you do not need to listen to both. - * - * @see TurtleAction#ATTACK - */ -public class TurtleAttackEvent extends TurtlePlayerEvent -{ - private final Entity target; - private final ITurtleUpgrade upgrade; - private final TurtleSide side; - - public TurtleAttackEvent( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Entity target, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side ) - { - super( turtle, TurtleAction.ATTACK, player ); - Objects.requireNonNull( target, "target cannot be null" ); - Objects.requireNonNull( upgrade, "upgrade cannot be null" ); - Objects.requireNonNull( side, "side cannot be null" ); - this.target = target; - this.upgrade = upgrade; - this.side = side; - } - - /** - * Get the entity being attacked by this turtle. - * - * @return The entity being attacked. - */ - @Nonnull - public Entity getTarget() - { - return target; - } - - /** - * Get the upgrade responsible for attacking. - * - * @return The upgrade responsible for attacking. - */ - @Nonnull - public ITurtleUpgrade getUpgrade() - { - return upgrade; - } - - /** - * Get the side the attacking upgrade is on. - * - * @return The upgrade's side. - */ - @Nonnull - public TurtleSide getSide() - { - return side; - } -} diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleBlockEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleBlockEvent.java deleted file mode 100644 index 85d5bb261..000000000 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleBlockEvent.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ -package dan200.computercraft.api.turtle.event; - -import dan200.computercraft.api.lua.MethodResult; -import dan200.computercraft.api.turtle.ITurtleAccess; -import dan200.computercraft.api.turtle.ITurtleUpgrade; -import dan200.computercraft.api.turtle.TurtleSide; -import dan200.computercraft.api.turtle.TurtleVerb; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.event.world.BlockEvent; - -import javax.annotation.Nonnull; -import java.util.Map; -import java.util.Objects; - -/** - * A general event for when a turtle interacts with a block or region. - * - * You should generally listen to one of the sub-events instead, cancelling them where - * appropriate. - * - * Note that you are not guaranteed to receive this event, if it has been cancelled by other - * mechanisms, such as block protection systems. - * - * Be aware that some events (such as {@link TurtleInventoryEvent}) do not necessarily interact - * with a block, simply objects within that block space. - */ -public abstract class TurtleBlockEvent extends TurtlePlayerEvent -{ - private final Level level; - private final BlockPos pos; - - protected TurtleBlockEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull Level level, @Nonnull BlockPos pos ) - { - super( turtle, action, player ); - - Objects.requireNonNull( level, "world cannot be null" ); - Objects.requireNonNull( pos, "pos cannot be null" ); - this.level = level; - this.pos = pos; - } - - /** - * Get the world the turtle is interacting in. - * - * @return The world the turtle is interacting in. - */ - public Level getLevel() - { - return level; - } - - /** - * Get the position the turtle is interacting with. Note that this is different - * to {@link ITurtleAccess#getPosition()}. - * - * @return The position the turtle is interacting with. - */ - public BlockPos getPos() - { - return pos; - } - - /** - * Fired when a turtle attempts to dig a block. - * - * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)}, - * as the base {@code turtle.dig()} command does not fire it. - * - * Note that such commands should also fire {@link BlockEvent.BreakEvent}, so you do not need to listen to both. - * - * @see TurtleAction#DIG - */ - public static class Dig extends TurtleBlockEvent - { - private final BlockState block; - private final ITurtleUpgrade upgrade; - private final TurtleSide side; - - public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side ) - { - super( turtle, TurtleAction.DIG, player, world, pos ); - - Objects.requireNonNull( block, "block cannot be null" ); - Objects.requireNonNull( upgrade, "upgrade cannot be null" ); - Objects.requireNonNull( side, "side cannot be null" ); - this.block = block; - this.upgrade = upgrade; - this.side = side; - } - - /** - * Get the block which is about to be broken. - * - * @return The block which is going to be broken. - */ - @Nonnull - public BlockState getBlock() - { - return block; - } - - /** - * Get the upgrade doing the digging. - * - * @return The upgrade doing the digging. - */ - @Nonnull - public ITurtleUpgrade getUpgrade() - { - return upgrade; - } - - /** - * Get the side the upgrade doing the digging is on. - * - * @return The upgrade's side. - */ - @Nonnull - public TurtleSide getSide() - { - return side; - } - } - - /** - * Fired when a turtle attempts to move into a block. - * - * @see TurtleAction#MOVE - */ - public static class Move extends TurtleBlockEvent - { - public Move( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos ) - { - super( turtle, TurtleAction.MOVE, player, world, pos ); - } - } - - /** - * Fired when a turtle attempts to place a block in the world. - * - * @see TurtleAction#PLACE - */ - public static class Place extends TurtleBlockEvent - { - private final ItemStack stack; - - public Place( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull ItemStack stack ) - { - super( turtle, TurtleAction.PLACE, player, world, pos ); - - Objects.requireNonNull( stack, "stack cannot be null" ); - this.stack = stack; - } - - /** - * Get the item stack that will be placed. This should not be modified. - * - * @return The item stack to be placed. - */ - @Nonnull - public ItemStack getStack() - { - return stack; - } - } - - /** - * Fired when a turtle gathers data on a block in world. - * - * You may prevent blocks being inspected, or add additional information to the result. - * - * @see TurtleAction#INSPECT - */ - public static class Inspect extends TurtleBlockEvent - { - private final BlockState state; - private final Map data; - - public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Map data ) - { - super( turtle, TurtleAction.INSPECT, player, world, pos ); - - Objects.requireNonNull( state, "state cannot be null" ); - Objects.requireNonNull( data, "data cannot be null" ); - this.data = data; - this.state = state; - } - - /** - * Get the block state which is being inspected. - * - * @return The inspected block state. - */ - @Nonnull - public BlockState getState() - { - return state; - } - - /** - * Get the "inspection data" from this block, which will be returned to the user. - * - * @return This block's inspection data. - */ - @Nonnull - public Map getData() - { - return data; - } - - /** - * Add new information to the inspection result. Note this will override fields with the same name. - * - * @param newData The data to add. Note all values should be convertible to Lua (see - * {@link MethodResult#of(Object)}). - */ - public void addData( @Nonnull Map newData ) - { - Objects.requireNonNull( newData, "newData cannot be null" ); - data.putAll( newData ); - } - } -} diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleEvent.java index b7e69ca54..d2be5ac8f 100644 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleEvent.java +++ b/src/main/java/dan200/computercraft/api/turtle/event/TurtleEvent.java @@ -16,8 +16,6 @@ * so sever specific methods on {@link ITurtleAccess} are safe to use. * * You should generally not need to subscribe to this event, preferring one of the more specific classes. - * - * @see TurtleActionEvent */ public abstract class TurtleEvent extends Event { diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleInspectItemEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleInspectItemEvent.java deleted file mode 100644 index 0126bce87..000000000 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleInspectItemEvent.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ -package dan200.computercraft.api.turtle.event; - -import dan200.computercraft.api.lua.MethodResult; -import dan200.computercraft.api.turtle.ITurtleAccess; -import net.minecraft.world.item.ItemStack; - -import javax.annotation.Nonnull; -import java.util.Map; -import java.util.Objects; - -/** - * Fired when a turtle gathers data on an item in its inventory. - * - * You may prevent items being inspected, or add additional information to the result. Be aware that this may be fired - * on the computer thread, and so any operations on it must be thread safe. - * - * @see TurtleAction#INSPECT_ITEM - */ -public class TurtleInspectItemEvent extends TurtleActionEvent -{ - private final ItemStack stack; - private final Map data; - private final boolean mainThread; - - @Deprecated - public TurtleInspectItemEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack, @Nonnull Map data ) - { - this( turtle, stack, data, false ); - } - - public TurtleInspectItemEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack, @Nonnull Map data, boolean mainThread ) - { - super( turtle, TurtleAction.INSPECT_ITEM ); - - Objects.requireNonNull( stack, "stack cannot be null" ); - Objects.requireNonNull( data, "data cannot be null" ); - this.stack = stack; - this.data = data; - this.mainThread = mainThread; - } - - /** - * The item which is currently being inspected. - * - * @return The item stack which is being inspected. This should not be modified. - */ - @Nonnull - public ItemStack getStack() - { - return stack; - } - - /** - * Get the "inspection data" from this item, which will be returned to the user. - * - * @return This items's inspection data. - */ - @Nonnull - public Map getData() - { - return data; - } - - /** - * If this event is being fired on the server thread. When true, information which relies on server state may be - * exposed. - * - * @return If this is run on the main thread. - */ - public boolean onMainThread() - { - return mainThread; - } - - /** - * Add new information to the inspection result. Note this will override fields with the same name. - * - * @param newData The data to add. Note all values should be convertible to Lua (see - * {@link MethodResult#of(Object)}). - */ - public void addData( @Nonnull Map newData ) - { - Objects.requireNonNull( newData, "newData cannot be null" ); - data.putAll( newData ); - } -} diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleInventoryEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleInventoryEvent.java deleted file mode 100644 index 0061c1885..000000000 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleInventoryEvent.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ -package dan200.computercraft.api.turtle.event; - -import dan200.computercraft.api.turtle.ITurtleAccess; -import net.minecraft.core.BlockPos; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.items.IItemHandler; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.Objects; - -/** - * Fired when a turtle attempts to interact with an inventory. - */ -public abstract class TurtleInventoryEvent extends TurtleBlockEvent -{ - private final IItemHandler handler; - - protected TurtleInventoryEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nullable IItemHandler handler ) - { - super( turtle, action, player, world, pos ); - this.handler = handler; - } - - /** - * Get the inventory being interacted with. - * - * @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world. - */ - @Nullable - public IItemHandler getItemHandler() - { - return handler; - } - - /** - * Fired when a turtle attempts to suck from an inventory. - * - * @see TurtleAction#SUCK - */ - public static class Suck extends TurtleInventoryEvent - { - public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nullable IItemHandler handler ) - { - super( turtle, TurtleAction.SUCK, player, world, pos, handler ); - } - } - - /** - * Fired when a turtle attempts to drop an item into an inventory. - * - * @see TurtleAction#DROP - */ - public static class Drop extends TurtleInventoryEvent - { - private final ItemStack stack; - - public Drop( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nullable IItemHandler handler, @Nonnull ItemStack stack ) - { - super( turtle, TurtleAction.DROP, player, world, pos, handler ); - - Objects.requireNonNull( stack, "stack cannot be null" ); - this.stack = stack; - } - - /** - * The item which will be inserted into the inventory/dropped on the ground. - * - * @return The item stack which will be dropped. This should not be modified. - */ - @Nonnull - public ItemStack getStack() - { - return stack; - } - } -} diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtlePlayerEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtlePlayerEvent.java deleted file mode 100644 index 2be611fa9..000000000 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtlePlayerEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ -package dan200.computercraft.api.turtle.event; - -import dan200.computercraft.api.turtle.ITurtleAccess; -import net.minecraftforge.common.util.FakePlayer; - -import javax.annotation.Nonnull; -import java.util.Objects; - -/** - * An action done by a turtle which is normally done by a player. - * - * {@link #getPlayer()} may be used to modify the player's attributes or perform permission checks. - */ -public abstract class TurtlePlayerEvent extends TurtleActionEvent -{ - private final FakePlayer player; - - protected TurtlePlayerEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player ) - { - super( turtle, action ); - - Objects.requireNonNull( player, "player cannot be null" ); - this.player = player; - } - - /** - * A fake player, representing this turtle. - * - * This may be used for triggering permission checks. - * - * @return A {@link FakePlayer} representing this turtle. - */ - @Nonnull - public FakePlayer getPlayer() - { - return player; - } -} diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleRefuelEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleRefuelEvent.java index c3347f7ae..ec7f41244 100644 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleRefuelEvent.java +++ b/src/main/java/dan200/computercraft/api/turtle/event/TurtleRefuelEvent.java @@ -15,17 +15,16 @@ /** * Fired when a turtle attempts to refuel from an item. * - * One may use {@link #setCanceled(boolean, String)} to prevent refueling from this specific item. Additionally, you - * may use {@link #setHandler(Handler)} to register a custom fuel provider. + * One may use {@link #setHandler(Handler)} to register a custom fuel provider for a given item. */ -public class TurtleRefuelEvent extends TurtleActionEvent +public class TurtleRefuelEvent extends TurtleEvent { private final ItemStack stack; private Handler handler; public TurtleRefuelEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack ) { - super( turtle, TurtleAction.REFUEL ); + super( turtle ); Objects.requireNonNull( turtle, "turtle cannot be null" ); this.stack = stack; diff --git a/src/main/java/dan200/computercraft/shared/Config.java b/src/main/java/dan200/computercraft/shared/Config.java index ec8480eed..45af41efe 100644 --- a/src/main/java/dan200/computercraft/shared/Config.java +++ b/src/main/java/dan200/computercraft/shared/Config.java @@ -11,7 +11,6 @@ import com.google.common.base.CaseFormat; import com.google.common.base.Converter; import dan200.computercraft.ComputerCraft; -import dan200.computercraft.api.turtle.event.TurtleAction; import dan200.computercraft.core.apis.http.NetworkUtils; import dan200.computercraft.core.apis.http.options.Action; import dan200.computercraft.core.apis.http.options.AddressRuleConfig; @@ -74,7 +73,6 @@ public final class Config private static final ConfigValue advancedTurtleFuelLimit; private static final ConfigValue turtlesObeyBlockProtection; private static final ConfigValue turtlesCanPush; - private static final ConfigValue> turtleDisabledActions; private static final ConfigValue computerTermWidth; private static final ConfigValue computerTermHeight; @@ -274,10 +272,6 @@ private Config() {} .comment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" ) .define( "can_push", ComputerCraft.turtlesCanPush ); - turtleDisabledActions = builder - .comment( "A list of turtle actions which are disabled." ) - .defineList( "disabled_actions", Collections.emptyList(), x -> x instanceof String && getAction( (String) x ) != null ); - builder.pop(); } @@ -367,9 +361,6 @@ public static void sync() ComputerCraft.turtlesObeyBlockProtection = turtlesObeyBlockProtection.get(); ComputerCraft.turtlesCanPush = turtlesCanPush.get(); - ComputerCraft.turtleDisabledActions.clear(); - for( String value : turtleDisabledActions.get() ) ComputerCraft.turtleDisabledActions.add( getAction( value ) ); - // Terminal size ComputerCraft.computerTermWidth = computerTermWidth.get(); ComputerCraft.computerTermHeight = computerTermHeight.get(); @@ -400,16 +391,4 @@ public static void sync( ModConfigEvent.Reloading event ) } private static final Converter converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE ); - - private static TurtleAction getAction( String value ) - { - try - { - return TurtleAction.valueOf( converter.convert( value ) ); - } - catch( IllegalArgumentException e ) - { - return null; - } - } } diff --git a/src/main/java/dan200/computercraft/shared/TurtlePermissions.java b/src/main/java/dan200/computercraft/shared/TurtlePermissions.java index 2523a1f12..98e4cd135 100644 --- a/src/main/java/dan200/computercraft/shared/TurtlePermissions.java +++ b/src/main/java/dan200/computercraft/shared/TurtlePermissions.java @@ -5,17 +5,12 @@ */ package dan200.computercraft.shared; -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.api.turtle.event.TurtleActionEvent; import net.minecraft.core.BlockPos; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID ) public final class TurtlePermissions { public static boolean isBlockEnterable( Level world, BlockPos pos, Player player ) @@ -28,13 +23,4 @@ public static boolean isBlockEditable( Level world, BlockPos pos, Player player { return isBlockEnterable( world, pos, player ); } - - @SubscribeEvent - public static void onTurtleAction( TurtleActionEvent event ) - { - if( ComputerCraft.turtleDisabledActions.contains( event.getAction() ) ) - { - event.setCanceled( true, "Action has been disabled" ); - } - } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java b/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java index 7fa7cc754..aa547839d 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java +++ b/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java @@ -10,8 +10,6 @@ import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.api.turtle.TurtleSide; -import dan200.computercraft.api.turtle.event.TurtleActionEvent; -import dan200.computercraft.api.turtle.event.TurtleInspectItemEvent; import dan200.computercraft.core.apis.IAPIEnvironment; import dan200.computercraft.core.asm.TaskCallback; import dan200.computercraft.core.tracking.TrackingField; @@ -19,7 +17,6 @@ import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods; import dan200.computercraft.shared.turtle.core.*; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.MinecraftForge; import java.util.HashMap; import java.util.Map; @@ -745,9 +742,6 @@ private Object[] getItemDetail( int slot, boolean detailed ) ? ItemData.fill( new HashMap<>(), stack ) : ItemData.fillBasicSafe( new HashMap<>(), stack ); - TurtleActionEvent event = new TurtleInspectItemEvent( turtle, stack, table, detailed ); - if( MinecraftForge.EVENT_BUS.post( event ) ) return new Object[] { false, event.getFailureMessage() }; - return new Object[] { table }; } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java index d670aae26..ca27db49c 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java @@ -9,14 +9,12 @@ import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleAnimation; import dan200.computercraft.api.turtle.TurtleCommandResult; -import dan200.computercraft.api.turtle.event.TurtleInventoryEvent; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; @@ -61,15 +59,6 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) IItemHandler inventory = InventoryUtil.getInventory( world, newPosition, side ); - // Fire the event, restoring the inventory and exiting if it is cancelled. - TurtlePlayer player = TurtlePlayer.getWithPosition( turtle, oldPosition, direction ); - TurtleInventoryEvent.Drop event = new TurtleInventoryEvent.Drop( turtle, player, world, newPosition, inventory, stack ); - if( MinecraftForge.EVENT_BUS.post( event ) ) - { - InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() ); - return TurtleCommandResult.failure( event.getFailureMessage() ); - } - if( inventory != null ) { // Drop the item into the inventory diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleEquipCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleEquipCommand.java index c95303c70..bab30c573 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleEquipCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleEquipCommand.java @@ -6,14 +6,11 @@ package dan200.computercraft.shared.turtle.core; import dan200.computercraft.api.turtle.*; -import dan200.computercraft.api.turtle.event.TurtleAction; -import dan200.computercraft.api.turtle.event.TurtleActionEvent; import dan200.computercraft.shared.TurtleUpgrades; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.core.BlockPos; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; @@ -64,12 +61,6 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) oldUpgradeStack = null; } - TurtleActionEvent event = new TurtleActionEvent( turtle, TurtleAction.EQUIP ); - if( MinecraftForge.EVENT_BUS.post( event ) ) - { - return TurtleCommandResult.failure( event.getFailureMessage() ); - } - // Do the swapping: if( newUpgradeStack != null ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java index c2130ac8c..42cab180d 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java @@ -8,13 +8,11 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleCommandResult; -import dan200.computercraft.api.turtle.event.TurtleBlockEvent; import dan200.computercraft.shared.peripheral.generic.data.BlockData; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.MinecraftForge; import javax.annotation.Nonnull; import java.util.HashMap; @@ -46,11 +44,6 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) Map table = BlockData.fill( new HashMap<>(), state ); - // Fire the event, exiting if it is cancelled - TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition( turtle, oldPosition, direction ); - TurtleBlockEvent.Inspect event = new TurtleBlockEvent.Inspect( turtle, turtlePlayer, world, newPosition, state, table ); - if( MinecraftForge.EVENT_BUS.post( event ) ) return TurtleCommandResult.failure( event.getFailureMessage() ); - return TurtleCommandResult.success( new Object[] { table } ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java index 4c607c622..5589aac16 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java @@ -10,7 +10,6 @@ import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleAnimation; import dan200.computercraft.api.turtle.TurtleCommandResult; -import dan200.computercraft.api.turtle.event.TurtleBlockEvent; import dan200.computercraft.shared.TurtlePermissions; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.core.BlockPos; @@ -21,7 +20,6 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.common.MinecraftForge; import javax.annotation.Nonnull; import java.util.List; @@ -93,12 +91,6 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) } } - TurtleBlockEvent.Move moveEvent = new TurtleBlockEvent.Move( turtle, turtlePlayer, oldWorld, newPosition ); - if( MinecraftForge.EVENT_BUS.post( moveEvent ) ) - { - return TurtleCommandResult.failure( moveEvent.getFailureMessage() ); - } - // Check fuel level if( turtle.isFuelNeeded() && turtle.getFuelLevel() < 1 ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java index af89fa3f4..189323040 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java @@ -10,7 +10,6 @@ import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleAnimation; import dan200.computercraft.api.turtle.TurtleCommandResult; -import dan200.computercraft.api.turtle.event.TurtleBlockEvent; import dan200.computercraft.shared.TurtlePermissions; import dan200.computercraft.shared.util.DropConsumer; import dan200.computercraft.shared.util.InventoryUtil; @@ -33,7 +32,6 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.Event.Result; import net.minecraftforge.items.IItemHandler; @@ -69,9 +67,6 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) BlockPos playerPosition = turtle.getPosition().relative( direction ); TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition( turtle, playerPosition, direction ); - TurtleBlockEvent.Place place = new TurtleBlockEvent.Place( turtle, turtlePlayer, turtle.getLevel(), coordinates, stack ); - if( MinecraftForge.EVENT_BUS.post( place ) ) return TurtleCommandResult.failure( place.getFailureMessage() ); - // Do the deploying turtlePlayer.loadInventory( turtle ); ErrorMessage message = new ErrorMessage(); diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java index 3b1f07979..4ae62ff77 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java @@ -33,7 +33,7 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) if( stack.isEmpty() ) return TurtleCommandResult.failure( "No items to combust" ); TurtleRefuelEvent event = new TurtleRefuelEvent( turtle, stack ); - if( MinecraftForge.EVENT_BUS.post( event ) ) return TurtleCommandResult.failure( event.getFailureMessage() ); + MinecraftForge.EVENT_BUS.post( event ); if( event.getHandler() == null ) return TurtleCommandResult.failure( "Items not combustible" ); if( limit != 0 ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java index 16113db17..febc68f2a 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java @@ -9,7 +9,6 @@ import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleAnimation; import dan200.computercraft.api.turtle.TurtleCommandResult; -import dan200.computercraft.api.turtle.event.TurtleInventoryEvent; import dan200.computercraft.shared.util.InventoryUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -18,7 +17,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; @@ -57,14 +55,6 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) IItemHandler inventory = InventoryUtil.getInventory( world, blockPosition, side ); - // Fire the event, exiting if it is cancelled. - TurtlePlayer player = TurtlePlayer.getWithPosition( turtle, turtlePosition, direction ); - TurtleInventoryEvent.Suck event = new TurtleInventoryEvent.Suck( turtle, player, world, blockPosition, inventory ); - if( MinecraftForge.EVENT_BUS.post( event ) ) - { - return TurtleCommandResult.failure( event.getFailureMessage() ); - } - if( inventory != null ) { // Take from inventory of thing in front diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleTurnCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleTurnCommand.java index 4011a0f7c..4db159fd2 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleTurnCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleTurnCommand.java @@ -9,9 +9,6 @@ import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleAnimation; import dan200.computercraft.api.turtle.TurtleCommandResult; -import dan200.computercraft.api.turtle.event.TurtleAction; -import dan200.computercraft.api.turtle.event.TurtleActionEvent; -import net.minecraftforge.common.MinecraftForge; import javax.annotation.Nonnull; @@ -28,12 +25,6 @@ public TurtleTurnCommand( TurnDirection direction ) @Override public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { - TurtleActionEvent event = new TurtleActionEvent( turtle, TurtleAction.TURN ); - if( MinecraftForge.EVENT_BUS.post( event ) ) - { - return TurtleCommandResult.failure( event.getFailureMessage() ); - } - switch( direction ) { case LEFT: diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java index 42c74114b..d53d6c581 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -10,8 +10,6 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.client.TransformedModel; import dan200.computercraft.api.turtle.*; -import dan200.computercraft.api.turtle.event.TurtleAttackEvent; -import dan200.computercraft.api.turtle.event.TurtleBlockEvent; import dan200.computercraft.shared.TurtlePermissions; import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.core.TurtlePlayer; @@ -151,12 +149,6 @@ private TurtleCommandResult attack( ITurtleAccess turtle, Direction direction, T return TurtleCommandResult.failure( "Nothing to attack here" ); } - TurtleAttackEvent attackEvent = new TurtleAttackEvent( turtle, turtlePlayer, hitEntity, this, side ); - if( MinecraftForge.EVENT_BUS.post( attackEvent ) ) - { - return TurtleCommandResult.failure( attackEvent.getFailureMessage() ); - } - // Start claiming entity drops DropConsumer.set( hitEntity, turtleDropConsumer( turtleTile, turtle ) ); @@ -243,13 +235,6 @@ private TurtleCommandResult dig( ITurtleAccess turtle, Direction direction, Turt return TurtleCommandResult.failure( "Unbreakable block detected" ); } - // Fire the dig event, checking whether it was cancelled. - TurtleBlockEvent.Dig digEvent = new TurtleBlockEvent.Dig( turtle, turtlePlayer, world, blockPosition, state, this, side ); - if( MinecraftForge.EVENT_BUS.post( digEvent ) ) - { - return TurtleCommandResult.failure( digEvent.getFailureMessage() ); - } - // Consume the items the block drops DropConsumer.set( world, blockPosition, turtleDropConsumer( turtleTile, turtle ) );