mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-10-05 18:30:47 +00:00
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.
This commit is contained in:
parent
6eec9ba1a3
commit
e4ced551eb
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft;
|
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.Action;
|
||||||
import dan200.computercraft.core.apis.http.options.AddressRule;
|
import dan200.computercraft.core.apis.http.options.AddressRule;
|
||||||
import dan200.computercraft.shared.Config;
|
import dan200.computercraft.shared.Config;
|
||||||
@ -22,7 +21,6 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -70,7 +68,6 @@ public final class ComputerCraft
|
|||||||
public static int advancedTurtleFuelLimit = 100000;
|
public static int advancedTurtleFuelLimit = 100000;
|
||||||
public static boolean turtlesObeyBlockProtection = true;
|
public static boolean turtlesObeyBlockProtection = true;
|
||||||
public static boolean turtlesCanPush = true;
|
public static boolean turtlesCanPush = true;
|
||||||
public static EnumSet<TurtleAction> turtleDisabledActions = EnumSet.noneOf( TurtleAction.class );
|
|
||||||
|
|
||||||
public static int computerTermWidth = 51;
|
public static int computerTermWidth = 51;
|
||||||
public static int computerTermHeight = 19;
|
public static int computerTermHeight = 19;
|
||||||
|
@ -9,8 +9,6 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
|||||||
import dan200.computercraft.api.IUpgradeBase;
|
import dan200.computercraft.api.IUpgradeBase;
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
import dan200.computercraft.api.client.TransformedModel;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
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.client.resources.model.ModelResourceLocation;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
@ -61,8 +59,8 @@ public interface ITurtleUpgrade extends IUpgradeBase
|
|||||||
* Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
|
* 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.
|
* by the turtle, and the tool is required to do some work.
|
||||||
*
|
*
|
||||||
* Conforming implementations should fire {@link BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig} for
|
* Conforming implementations should fire {@link BlockEvent.BreakEvent} for digging {@link AttackEntityEvent}
|
||||||
* digging, {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking.
|
* for attacking.
|
||||||
*
|
*
|
||||||
* @param turtle Access to the turtle that the tool resides on.
|
* @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.
|
* @param side Which side of the turtle (left or right) the tool resides on.
|
||||||
|
@ -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,
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<String, Object> data;
|
|
||||||
|
|
||||||
public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Map<String, Object> 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<String, Object> 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<String, ?> newData )
|
|
||||||
{
|
|
||||||
Objects.requireNonNull( newData, "newData cannot be null" );
|
|
||||||
data.putAll( newData );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,8 +16,6 @@ import java.util.Objects;
|
|||||||
* so sever specific methods on {@link ITurtleAccess} are safe to use.
|
* 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.
|
* 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
|
public abstract class TurtleEvent extends Event
|
||||||
{
|
{
|
||||||
|
@ -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<String, Object> data;
|
|
||||||
private final boolean mainThread;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public TurtleInspectItemEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack, @Nonnull Map<String, Object> data )
|
|
||||||
{
|
|
||||||
this( turtle, stack, data, false );
|
|
||||||
}
|
|
||||||
|
|
||||||
public TurtleInspectItemEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack, @Nonnull Map<String, Object> 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 <b>not</b> 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<String, Object> 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<String, ?> newData )
|
|
||||||
{
|
|
||||||
Objects.requireNonNull( newData, "newData cannot be null" );
|
|
||||||
data.putAll( newData );
|
|
||||||
}
|
|
||||||
}
|
|
@ -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 <b>not</b> be modified.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
public ItemStack getStack()
|
|
||||||
{
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,17 +15,16 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* Fired when a turtle attempts to refuel from an item.
|
* 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
|
* One may use {@link #setHandler(Handler)} to register a custom fuel provider for a given item.
|
||||||
* may use {@link #setHandler(Handler)} to register a custom fuel provider.
|
|
||||||
*/
|
*/
|
||||||
public class TurtleRefuelEvent extends TurtleActionEvent
|
public class TurtleRefuelEvent extends TurtleEvent
|
||||||
{
|
{
|
||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
|
|
||||||
public TurtleRefuelEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack )
|
public TurtleRefuelEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack )
|
||||||
{
|
{
|
||||||
super( turtle, TurtleAction.REFUEL );
|
super( turtle );
|
||||||
|
|
||||||
Objects.requireNonNull( turtle, "turtle cannot be null" );
|
Objects.requireNonNull( turtle, "turtle cannot be null" );
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
|
@ -11,7 +11,6 @@ import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
|||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.base.Converter;
|
import com.google.common.base.Converter;
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
|
||||||
import dan200.computercraft.core.apis.http.NetworkUtils;
|
import dan200.computercraft.core.apis.http.NetworkUtils;
|
||||||
import dan200.computercraft.core.apis.http.options.Action;
|
import dan200.computercraft.core.apis.http.options.Action;
|
||||||
import dan200.computercraft.core.apis.http.options.AddressRuleConfig;
|
import dan200.computercraft.core.apis.http.options.AddressRuleConfig;
|
||||||
@ -74,7 +73,6 @@ public final class Config
|
|||||||
private static final ConfigValue<Integer> advancedTurtleFuelLimit;
|
private static final ConfigValue<Integer> advancedTurtleFuelLimit;
|
||||||
private static final ConfigValue<Boolean> turtlesObeyBlockProtection;
|
private static final ConfigValue<Boolean> turtlesObeyBlockProtection;
|
||||||
private static final ConfigValue<Boolean> turtlesCanPush;
|
private static final ConfigValue<Boolean> turtlesCanPush;
|
||||||
private static final ConfigValue<List<? extends String>> turtleDisabledActions;
|
|
||||||
|
|
||||||
private static final ConfigValue<Integer> computerTermWidth;
|
private static final ConfigValue<Integer> computerTermWidth;
|
||||||
private static final ConfigValue<Integer> computerTermHeight;
|
private static final ConfigValue<Integer> computerTermHeight;
|
||||||
@ -274,10 +272,6 @@ public final class Config
|
|||||||
.comment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" )
|
.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 );
|
.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();
|
builder.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,9 +361,6 @@ public final class Config
|
|||||||
ComputerCraft.turtlesObeyBlockProtection = turtlesObeyBlockProtection.get();
|
ComputerCraft.turtlesObeyBlockProtection = turtlesObeyBlockProtection.get();
|
||||||
ComputerCraft.turtlesCanPush = turtlesCanPush.get();
|
ComputerCraft.turtlesCanPush = turtlesCanPush.get();
|
||||||
|
|
||||||
ComputerCraft.turtleDisabledActions.clear();
|
|
||||||
for( String value : turtleDisabledActions.get() ) ComputerCraft.turtleDisabledActions.add( getAction( value ) );
|
|
||||||
|
|
||||||
// Terminal size
|
// Terminal size
|
||||||
ComputerCraft.computerTermWidth = computerTermWidth.get();
|
ComputerCraft.computerTermWidth = computerTermWidth.get();
|
||||||
ComputerCraft.computerTermHeight = computerTermHeight.get();
|
ComputerCraft.computerTermHeight = computerTermHeight.get();
|
||||||
@ -400,16 +391,4 @@ public final class Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE );
|
private static final Converter<String, String> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,12 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared;
|
package dan200.computercraft.shared;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.api.turtle.event.TurtleActionEvent;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
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 final class TurtlePermissions
|
||||||
{
|
{
|
||||||
public static boolean isBlockEnterable( Level world, BlockPos pos, Player player )
|
public static boolean isBlockEnterable( Level world, BlockPos pos, Player player )
|
||||||
@ -28,13 +23,4 @@ public final class TurtlePermissions
|
|||||||
{
|
{
|
||||||
return isBlockEnterable( world, pos, 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" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
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.apis.IAPIEnvironment;
|
||||||
import dan200.computercraft.core.asm.TaskCallback;
|
import dan200.computercraft.core.asm.TaskCallback;
|
||||||
import dan200.computercraft.core.tracking.TrackingField;
|
import dan200.computercraft.core.tracking.TrackingField;
|
||||||
@ -19,7 +17,6 @@ import dan200.computercraft.shared.peripheral.generic.data.ItemData;
|
|||||||
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods;
|
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods;
|
||||||
import dan200.computercraft.shared.turtle.core.*;
|
import dan200.computercraft.shared.turtle.core.*;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -745,9 +742,6 @@ public class TurtleAPI implements ILuaAPI
|
|||||||
? ItemData.fill( new HashMap<>(), stack )
|
? ItemData.fill( new HashMap<>(), stack )
|
||||||
: ItemData.fillBasicSafe( 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 };
|
return new Object[] { table };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,14 +9,12 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleInventoryEvent;
|
|
||||||
import dan200.computercraft.shared.util.InventoryUtil;
|
import dan200.computercraft.shared.util.InventoryUtil;
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -61,15 +59,6 @@ public class TurtleDropCommand implements ITurtleCommand
|
|||||||
|
|
||||||
IItemHandler inventory = InventoryUtil.getInventory( world, newPosition, side );
|
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 )
|
if( inventory != null )
|
||||||
{
|
{
|
||||||
// Drop the item into the inventory
|
// Drop the item into the inventory
|
||||||
|
@ -6,14 +6,11 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.*;
|
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.TurtleUpgrades;
|
||||||
import dan200.computercraft.shared.util.InventoryUtil;
|
import dan200.computercraft.shared.util.InventoryUtil;
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -64,12 +61,6 @@ public class TurtleEquipCommand implements ITurtleCommand
|
|||||||
oldUpgradeStack = null;
|
oldUpgradeStack = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
TurtleActionEvent event = new TurtleActionEvent( turtle, TurtleAction.EQUIP );
|
|
||||||
if( MinecraftForge.EVENT_BUS.post( event ) )
|
|
||||||
{
|
|
||||||
return TurtleCommandResult.failure( event.getFailureMessage() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do the swapping:
|
// Do the swapping:
|
||||||
if( newUpgradeStack != null )
|
if( newUpgradeStack != null )
|
||||||
{
|
{
|
||||||
|
@ -8,13 +8,11 @@ package dan200.computercraft.shared.turtle.core;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
|
|
||||||
import dan200.computercraft.shared.peripheral.generic.data.BlockData;
|
import dan200.computercraft.shared.peripheral.generic.data.BlockData;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -46,11 +44,6 @@ public class TurtleInspectCommand implements ITurtleCommand
|
|||||||
|
|
||||||
Map<String, Object> table = BlockData.fill( new HashMap<>(), state );
|
Map<String, Object> 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 } );
|
return TurtleCommandResult.success( new Object[] { table } );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
|
|
||||||
import dan200.computercraft.shared.TurtlePermissions;
|
import dan200.computercraft.shared.TurtlePermissions;
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@ -21,7 +20,6 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import net.minecraft.world.phys.shapes.Shapes;
|
import net.minecraft.world.phys.shapes.Shapes;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -93,12 +91,6 @@ public class TurtleMoveCommand implements ITurtleCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TurtleBlockEvent.Move moveEvent = new TurtleBlockEvent.Move( turtle, turtlePlayer, oldWorld, newPosition );
|
|
||||||
if( MinecraftForge.EVENT_BUS.post( moveEvent ) )
|
|
||||||
{
|
|
||||||
return TurtleCommandResult.failure( moveEvent.getFailureMessage() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check fuel level
|
// Check fuel level
|
||||||
if( turtle.isFuelNeeded() && turtle.getFuelLevel() < 1 )
|
if( turtle.isFuelNeeded() && turtle.getFuelLevel() < 1 )
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,6 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
|
|
||||||
import dan200.computercraft.shared.TurtlePermissions;
|
import dan200.computercraft.shared.TurtlePermissions;
|
||||||
import dan200.computercraft.shared.util.DropConsumer;
|
import dan200.computercraft.shared.util.DropConsumer;
|
||||||
import dan200.computercraft.shared.util.InventoryUtil;
|
import dan200.computercraft.shared.util.InventoryUtil;
|
||||||
@ -33,7 +32,6 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.common.ForgeHooks;
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.minecraftforge.eventbus.api.Event.Result;
|
import net.minecraftforge.eventbus.api.Event.Result;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
@ -69,9 +67,6 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
|||||||
BlockPos playerPosition = turtle.getPosition().relative( direction );
|
BlockPos playerPosition = turtle.getPosition().relative( direction );
|
||||||
TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition( turtle, playerPosition, 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
|
// Do the deploying
|
||||||
turtlePlayer.loadInventory( turtle );
|
turtlePlayer.loadInventory( turtle );
|
||||||
ErrorMessage message = new ErrorMessage();
|
ErrorMessage message = new ErrorMessage();
|
||||||
|
@ -33,7 +33,7 @@ public class TurtleRefuelCommand implements ITurtleCommand
|
|||||||
if( stack.isEmpty() ) return TurtleCommandResult.failure( "No items to combust" );
|
if( stack.isEmpty() ) return TurtleCommandResult.failure( "No items to combust" );
|
||||||
|
|
||||||
TurtleRefuelEvent event = new TurtleRefuelEvent( turtle, stack );
|
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( event.getHandler() == null ) return TurtleCommandResult.failure( "Items not combustible" );
|
||||||
|
|
||||||
if( limit != 0 )
|
if( limit != 0 )
|
||||||
|
@ -9,7 +9,6 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleInventoryEvent;
|
|
||||||
import dan200.computercraft.shared.util.InventoryUtil;
|
import dan200.computercraft.shared.util.InventoryUtil;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
@ -18,7 +17,6 @@ import net.minecraft.world.entity.item.ItemEntity;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -57,14 +55,6 @@ public class TurtleSuckCommand implements ITurtleCommand
|
|||||||
|
|
||||||
IItemHandler inventory = InventoryUtil.getInventory( world, blockPosition, side );
|
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 )
|
if( inventory != null )
|
||||||
{
|
{
|
||||||
// Take from inventory of thing in front
|
// Take from inventory of thing in front
|
||||||
|
@ -9,9 +9,6 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
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;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@ -28,12 +25,6 @@ public class TurtleTurnCommand implements ITurtleCommand
|
|||||||
@Override
|
@Override
|
||||||
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
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 )
|
switch( direction )
|
||||||
{
|
{
|
||||||
case LEFT:
|
case LEFT:
|
||||||
|
@ -10,8 +10,6 @@ import com.mojang.math.Transformation;
|
|||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
import dan200.computercraft.api.client.TransformedModel;
|
||||||
import dan200.computercraft.api.turtle.*;
|
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.TurtlePermissions;
|
||||||
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
||||||
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
|
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
|
||||||
@ -151,12 +149,6 @@ public class TurtleTool extends AbstractTurtleUpgrade
|
|||||||
return TurtleCommandResult.failure( "Nothing to attack here" );
|
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
|
// Start claiming entity drops
|
||||||
DropConsumer.set( hitEntity, turtleDropConsumer( turtleTile, turtle ) );
|
DropConsumer.set( hitEntity, turtleDropConsumer( turtleTile, turtle ) );
|
||||||
|
|
||||||
@ -243,13 +235,6 @@ public class TurtleTool extends AbstractTurtleUpgrade
|
|||||||
return TurtleCommandResult.failure( "Unbreakable block detected" );
|
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
|
// Consume the items the block drops
|
||||||
DropConsumer.set( world, blockPosition, turtleDropConsumer( turtleTile, turtle ) );
|
DropConsumer.set( world, blockPosition, turtleDropConsumer( turtleTile, turtle ) );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user