Implement IPeripheral.getTarget on a few additional TEs

Also make it nullable. Hopefully this will allow us to distinguish
between non-default implementations more easily.
This commit is contained in:
SquidDev 2020-05-15 17:34:00 +01:00
parent 5409d441b5
commit 4f8217d1ab
7 changed files with 45 additions and 2 deletions

View File

@ -81,10 +81,10 @@ default void detach( @Nonnull IComputerAccess computer )
*
* @return The object this peripheral targets
*/
@Nonnull
@Nullable
default Object getTarget()
{
return this;
return null;
}
/**

View File

@ -72,6 +72,13 @@ public boolean equals( IPeripheral other )
return other != null && other.getClass() == getClass();
}
@Nonnull
@Override
public Object getTarget()
{
return commandBlock;
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> cap, @Nullable Direction side )

View File

@ -114,6 +114,13 @@ public Vec3d getPosition()
BlockPos pos = getPos().offset( modemDirection );
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
}
@Nonnull
@Override
public Object getTarget()
{
return TileCable.this;
}
};
private LazyOptional<IPeripheral> modemCap;

View File

@ -407,6 +407,13 @@ public Vec3d getPosition()
BlockPos pos = getPos().offset( side );
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
}
@Nonnull
@Override
public Object getTarget()
{
return TileWiredModemFull.this;
}
};
}
}

View File

@ -70,6 +70,13 @@ public boolean equals( IPeripheral other )
{
return this == other || (other instanceof Peripheral && entity == ((Peripheral) other).entity);
}
@Nonnull
@Override
public Object getTarget()
{
return entity;
}
}
private final boolean advanced;

View File

@ -14,6 +14,7 @@
import dan200.computercraft.core.terminal.Terminal;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class MonitorPeripheral extends TermMethods implements IPeripheral
{
@ -85,4 +86,11 @@ public boolean isColour() throws LuaException
{
return getMonitor().isColour();
}
@Nullable
@Override
public Object getTarget()
{
return monitor;
}
}

View File

@ -44,4 +44,11 @@ public boolean equals( IPeripheral other )
{
return other instanceof CraftingTablePeripheral;
}
@Nonnull
@Override
public Object getTarget()
{
return turtle;
}
}