mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-06-04 23:54:10 +00:00
Start using Java's instanceof pattern matching
Well, not really pattern matching, but it's still an improvement!
This commit is contained in:
parent
e4ced551eb
commit
aa857c1be3
@ -153,7 +153,7 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
checkstyle "com.puppycrawl.tools:checkstyle:8.25"
|
||||
checkstyle "com.puppycrawl.tools:checkstyle:8.45"
|
||||
|
||||
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
||||
|
||||
|
@ -58,13 +58,20 @@
|
||||
<module name="SimplifyBooleanExpression" />
|
||||
<module name="SimplifyBooleanReturn" />
|
||||
<module name="StringLiteralEquality" />
|
||||
<module name="UnnecessaryParentheses" />
|
||||
<module name="UnnecessaryParentheses">
|
||||
<!-- Default minus LAND. -->
|
||||
<property name="tokens" value="EXPR,IDENT,NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG,STRING_LITERAL,LITERAL_NULL,LITERAL_FALSE,LITERAL_TRUE,ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN,LAMBDA,TEXT_BLOCK_LITERAL_BEGIN,LITERAL_INSTANCEOF,GT,LT,GE,LE,EQUAL,NOT_EQUAL,UNARY_MINUS,UNARY_PLUS,INC,DEC,LNOT,BNOT,POST_INC,POST_DEC" />
|
||||
</module>
|
||||
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration" />
|
||||
<module name="UnnecessarySemicolonInTryWithResources" />
|
||||
<module name="UnnecessarySemicolonInEnumeration" />
|
||||
|
||||
<!-- Imports -->
|
||||
<module name="CustomImportOrder" />
|
||||
<module name="CustomImportOrder">
|
||||
<property name="customImportOrderRules"
|
||||
value="THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE###STATIC"
|
||||
/>
|
||||
</module>
|
||||
<module name="IllegalImport" />
|
||||
<module name="RedundantImport" />
|
||||
<module name="UnusedImports" />
|
||||
|
@ -47,9 +47,8 @@ public final class MonitorHighlightRenderer
|
||||
BlockPos pos = event.getTarget().getBlockPos();
|
||||
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( !(tile instanceof TileMonitor) ) return;
|
||||
if( !(tile instanceof TileMonitor monitor) ) return;
|
||||
|
||||
TileMonitor monitor = (TileMonitor) tile;
|
||||
event.setCanceled( true );
|
||||
|
||||
// Determine which sides are part of the external faces of the monitor, and so which need to be rendered.
|
||||
|
@ -73,9 +73,8 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
public boolean equals( Object other )
|
||||
{
|
||||
if( other == this ) return true;
|
||||
if( !(other instanceof TurtleModelCombination) ) return false;
|
||||
if( !(other instanceof TurtleModelCombination otherCombo) ) return false;
|
||||
|
||||
TurtleModelCombination otherCombo = (TurtleModelCombination) other;
|
||||
return otherCombo.colour == colour &&
|
||||
otherCombo.leftUpgrade == leftUpgrade &&
|
||||
otherCombo.rightUpgrade == rightUpgrade &&
|
||||
|
@ -96,9 +96,8 @@ public abstract class HandleGeneric
|
||||
|
||||
protected static SeekableByteChannel asSeekable( Channel channel )
|
||||
{
|
||||
if( !(channel instanceof SeekableByteChannel) ) return null;
|
||||
if( !(channel instanceof SeekableByteChannel seekable) ) return null;
|
||||
|
||||
SeekableByteChannel seekable = (SeekableByteChannel) channel;
|
||||
try
|
||||
{
|
||||
seekable.position( seekable.position() );
|
||||
|
@ -100,9 +100,8 @@ public final class HttpRequestHandler extends SimpleChannelInboundHandler<HttpOb
|
||||
{
|
||||
if( closed || request.checkClosed() ) return;
|
||||
|
||||
if( message instanceof HttpResponse )
|
||||
if( message instanceof HttpResponse response )
|
||||
{
|
||||
HttpResponse response = (HttpResponse) message;
|
||||
|
||||
if( request.redirects.get() > 0 )
|
||||
{
|
||||
@ -137,9 +136,8 @@ public final class HttpRequestHandler extends SimpleChannelInboundHandler<HttpOb
|
||||
responseHeaders.add( response.headers() );
|
||||
}
|
||||
|
||||
if( message instanceof HttpContent )
|
||||
if( message instanceof HttpContent content )
|
||||
{
|
||||
HttpContent content = (HttpContent) message;
|
||||
|
||||
if( responseBody == null )
|
||||
{
|
||||
@ -162,9 +160,8 @@ public final class HttpRequestHandler extends SimpleChannelInboundHandler<HttpOb
|
||||
responseBody.addComponent( true, partial.retain() );
|
||||
}
|
||||
|
||||
if( message instanceof LastHttpContent )
|
||||
if( message instanceof LastHttpContent last )
|
||||
{
|
||||
LastHttpContent last = (LastHttpContent) message;
|
||||
responseHeaders.add( last.trailingHeaders() );
|
||||
|
||||
// Set the content length, if not already given.
|
||||
|
@ -55,9 +55,8 @@ public class WebsocketHandler extends SimpleChannelInboundHandler<Object>
|
||||
return;
|
||||
}
|
||||
|
||||
if( msg instanceof FullHttpResponse )
|
||||
if( msg instanceof FullHttpResponse response )
|
||||
{
|
||||
FullHttpResponse response = (FullHttpResponse) msg;
|
||||
throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString( CharsetUtil.UTF_8 ) + ')' );
|
||||
}
|
||||
|
||||
@ -76,9 +75,8 @@ public class WebsocketHandler extends SimpleChannelInboundHandler<Object>
|
||||
websocket.environment().addTrackingChange( TrackingField.WEBSOCKET_INCOMING, converted.length );
|
||||
websocket.environment().queueEvent( MESSAGE_EVENT, websocket.address(), converted, true );
|
||||
}
|
||||
else if( frame instanceof CloseWebSocketFrame )
|
||||
else if( frame instanceof CloseWebSocketFrame closeFrame )
|
||||
{
|
||||
CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame;
|
||||
websocket.close( closeFrame.statusCode(), closeFrame.reasonText() );
|
||||
}
|
||||
else if( frame instanceof PingWebSocketFrame )
|
||||
|
@ -52,9 +52,8 @@ final class Reflect
|
||||
{
|
||||
if( underlying instanceof Class<?> ) return (Class<?>) underlying;
|
||||
|
||||
if( underlying instanceof ParameterizedType )
|
||||
if( underlying instanceof ParameterizedType type )
|
||||
{
|
||||
ParameterizedType type = (ParameterizedType) underlying;
|
||||
if( !allowParameter )
|
||||
{
|
||||
for( java.lang.reflect.Type arg : type.getActualTypeArguments() )
|
||||
|
@ -293,9 +293,8 @@ class MountWrapper
|
||||
|
||||
private FileSystemException localExceptionOf( @Nullable String localPath, @Nonnull IOException e )
|
||||
{
|
||||
if( !location.isEmpty() && e instanceof FileOperationException )
|
||||
if( !location.isEmpty() && e instanceof FileOperationException ex )
|
||||
{
|
||||
FileOperationException ex = (FileOperationException) e;
|
||||
if( ex.getFilename() != null ) return localExceptionOf( ex.getFilename(), ex.getMessage() );
|
||||
}
|
||||
|
||||
|
@ -260,14 +260,12 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
if( object instanceof Number ) return valueOf( ((Number) object).doubleValue() );
|
||||
if( object instanceof Boolean ) return valueOf( (Boolean) object );
|
||||
if( object instanceof String ) return valueOf( object.toString() );
|
||||
if( object instanceof byte[] )
|
||||
if( object instanceof byte[] b )
|
||||
{
|
||||
byte[] b = (byte[]) object;
|
||||
return valueOf( Arrays.copyOf( b, b.length ) );
|
||||
}
|
||||
if( object instanceof ByteBuffer )
|
||||
if( object instanceof ByteBuffer b )
|
||||
{
|
||||
ByteBuffer b = (ByteBuffer) object;
|
||||
byte[] bytes = new byte[b.remaining()];
|
||||
b.get( bytes );
|
||||
return valueOf( bytes );
|
||||
@ -304,9 +302,8 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
return table;
|
||||
}
|
||||
|
||||
if( object instanceof Collection )
|
||||
if( object instanceof Collection<?> objects )
|
||||
{
|
||||
Collection<?> objects = (Collection<?>) object;
|
||||
LuaTable table = new LuaTable( objects.size(), 0 );
|
||||
values.put( object, table );
|
||||
int i = 0;
|
||||
@ -314,9 +311,8 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
return table;
|
||||
}
|
||||
|
||||
if( object instanceof Object[] )
|
||||
if( object instanceof Object[] objects )
|
||||
{
|
||||
Object[] objects = (Object[]) object;
|
||||
LuaTable table = new LuaTable( objects.length, 0 );
|
||||
values.put( object, table );
|
||||
for( int i = 0; i < objects.length; i++ ) table.rawset( i + 1, toValue( objects[i], values ) );
|
||||
|
@ -177,9 +177,8 @@ public final class CommandComputerCraft
|
||||
if( world == null || pos == null ) throw TP_NOT_THERE.create();
|
||||
|
||||
Entity entity = context.getSource().getEntityOrException();
|
||||
if( !(entity instanceof ServerPlayer) ) throw TP_NOT_PLAYER.create();
|
||||
if( !(entity instanceof ServerPlayer player) ) throw TP_NOT_PLAYER.create();
|
||||
|
||||
ServerPlayer player = (ServerPlayer) entity;
|
||||
if( player.getCommandSenderWorld() == world )
|
||||
{
|
||||
player.connection.teleport(
|
||||
|
@ -24,9 +24,8 @@ public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider
|
||||
public static int getDefaultBundledRedstoneOutput( Level world, BlockPos pos, Direction side )
|
||||
{
|
||||
Block block = world.getBlockState( pos ).getBlock();
|
||||
if( block instanceof IBundledRedstoneBlock )
|
||||
if( block instanceof IBundledRedstoneBlock generic )
|
||||
{
|
||||
IBundledRedstoneBlock generic = (IBundledRedstoneBlock) block;
|
||||
if( generic.getBundledRedstoneConnectivity( world, pos, side ) )
|
||||
{
|
||||
return generic.getBundledRedstoneOutput( world, pos, side );
|
||||
|
@ -74,9 +74,8 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
public int getDirectSignal( @Nonnull BlockState state, BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction incomingSide )
|
||||
{
|
||||
BlockEntity entity = world.getBlockEntity( pos );
|
||||
if( !(entity instanceof TileComputerBase) ) return 0;
|
||||
if( !(entity instanceof TileComputerBase computerEntity) ) return 0;
|
||||
|
||||
TileComputerBase computerEntity = (TileComputerBase) entity;
|
||||
ServerComputer computer = computerEntity.getServerComputer();
|
||||
if( computer == null ) return 0;
|
||||
|
||||
@ -109,9 +108,8 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
public int getBundledRedstoneOutput( Level world, BlockPos pos, Direction side )
|
||||
{
|
||||
BlockEntity entity = world.getBlockEntity( pos );
|
||||
if( !(entity instanceof TileComputerBase) ) return 0;
|
||||
if( !(entity instanceof TileComputerBase computerEntity) ) return 0;
|
||||
|
||||
TileComputerBase computerEntity = (TileComputerBase) entity;
|
||||
ServerComputer computer = computerEntity.getServerComputer();
|
||||
if( computer == null ) return 0;
|
||||
|
||||
@ -144,16 +142,14 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
@Override
|
||||
public void playerWillDestroy( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Player player )
|
||||
{
|
||||
if( !(world instanceof ServerLevel) ) return;
|
||||
ServerLevel serverWorld = (ServerLevel) world;
|
||||
if( !(world instanceof ServerLevel serverWorld) ) return;
|
||||
|
||||
// We drop the item here instead of doing it in the harvest method, as we should
|
||||
// drop computers for creative players too.
|
||||
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( tile instanceof TileComputerBase )
|
||||
if( tile instanceof TileComputerBase computer )
|
||||
{
|
||||
TileComputerBase computer = (TileComputerBase) tile;
|
||||
LootContext.Builder context = new LootContext.Builder( serverWorld )
|
||||
.withRandom( world.random )
|
||||
.withParameter( LootContextParams.ORIGIN, Vec3.atCenterOf( pos ) )
|
||||
@ -176,10 +172,8 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
super.setPlacedBy( world, pos, state, placer, stack );
|
||||
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( !world.isClientSide && tile instanceof IComputerTile && stack.getItem() instanceof IComputerItem )
|
||||
if( !world.isClientSide && tile instanceof IComputerTile computer && stack.getItem() instanceof IComputerItem item )
|
||||
{
|
||||
IComputerTile computer = (IComputerTile) tile;
|
||||
IComputerItem item = (IComputerItem) stack.getItem();
|
||||
|
||||
int id = item.getComputerID( stack );
|
||||
if( id != -1 ) computer.setComputerID( id );
|
||||
|
@ -362,9 +362,8 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
||||
if( player == null ) return null;
|
||||
|
||||
AbstractContainerMenu container = player.containerMenu;
|
||||
if( !(container instanceof IContainerComputer) ) return null;
|
||||
if( !(container instanceof IContainerComputer computerContainer) ) return null;
|
||||
|
||||
IContainerComputer computerContainer = (IContainerComputer) container;
|
||||
return computerContainer.getComputer() != this ? null : computerContainer;
|
||||
}
|
||||
|
||||
|
@ -114,9 +114,8 @@ public class JEIComputerCraft implements IModPlugin
|
||||
*/
|
||||
private static final IIngredientSubtypeInterpreter<ItemStack> turtleSubtype = ( stack, ctx ) -> {
|
||||
Item item = stack.getItem();
|
||||
if( !(item instanceof ITurtleItem) ) return IIngredientSubtypeInterpreter.NONE;
|
||||
if( !(item instanceof ITurtleItem turtle) ) return IIngredientSubtypeInterpreter.NONE;
|
||||
|
||||
ITurtleItem turtle = (ITurtleItem) item;
|
||||
StringBuilder name = new StringBuilder( "turtle:" );
|
||||
|
||||
// Add left and right upgrades to the identifier
|
||||
@ -150,9 +149,7 @@ public class JEIComputerCraft implements IModPlugin
|
||||
*/
|
||||
private static final IIngredientSubtypeInterpreter<ItemStack> diskSubtype = ( stack, ctx ) -> {
|
||||
Item item = stack.getItem();
|
||||
if( !(item instanceof ItemDisk) ) return IIngredientSubtypeInterpreter.NONE;
|
||||
|
||||
ItemDisk disk = (ItemDisk) item;
|
||||
if( !(item instanceof ItemDisk disk) ) return IIngredientSubtypeInterpreter.NONE;
|
||||
|
||||
int colour = disk.getColour( stack );
|
||||
return colour == -1 ? IIngredientSubtypeInterpreter.NONE : String.format( "%06x", colour );
|
||||
|
@ -96,9 +96,8 @@ class RecipeResolver implements IRecipeManagerPlugin
|
||||
public <V> List<ResourceLocation> getRecipeCategoryUids( @Nonnull IFocus<V> focus )
|
||||
{
|
||||
V value = focus.getValue();
|
||||
if( !(value instanceof ItemStack) ) return Collections.emptyList();
|
||||
if( !(value instanceof ItemStack stack) ) return Collections.emptyList();
|
||||
|
||||
ItemStack stack = (ItemStack) value;
|
||||
switch( focus.getMode() )
|
||||
{
|
||||
case INPUT:
|
||||
@ -119,12 +118,11 @@ class RecipeResolver implements IRecipeManagerPlugin
|
||||
@Override
|
||||
public <T, V> List<T> getRecipes( @Nonnull IRecipeCategory<T> recipeCategory, @Nonnull IFocus<V> focus )
|
||||
{
|
||||
if( !(focus.getValue() instanceof ItemStack) || !recipeCategory.getUid().equals( VanillaRecipeCategoryUid.CRAFTING ) )
|
||||
if( !(focus.getValue() instanceof ItemStack stack) || !recipeCategory.getUid().equals( VanillaRecipeCategoryUid.CRAFTING ) )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
ItemStack stack = (ItemStack) focus.getValue();
|
||||
switch( focus.getMode() )
|
||||
{
|
||||
case INPUT:
|
||||
@ -148,10 +146,9 @@ class RecipeResolver implements IRecipeManagerPlugin
|
||||
{
|
||||
setupCache();
|
||||
|
||||
if( stack.getItem() instanceof ITurtleItem )
|
||||
if( stack.getItem() instanceof ITurtleItem item )
|
||||
{
|
||||
// Suggest possible upgrades which can be applied to this turtle
|
||||
ITurtleItem item = (ITurtleItem) stack.getItem();
|
||||
ITurtleUpgrade left = item.getUpgrade( stack, TurtleSide.LEFT );
|
||||
ITurtleUpgrade right = item.getUpgrade( stack, TurtleSide.RIGHT );
|
||||
if( left != null && right != null ) return Collections.emptyList();
|
||||
@ -227,9 +224,8 @@ class RecipeResolver implements IRecipeManagerPlugin
|
||||
private static List<Shaped> findRecipesWithOutput( @Nonnull ItemStack stack )
|
||||
{
|
||||
// Find which upgrade this item currently has, an so how we could build it.
|
||||
if( stack.getItem() instanceof ITurtleItem )
|
||||
if( stack.getItem() instanceof ITurtleItem item )
|
||||
{
|
||||
ITurtleItem item = (ITurtleItem) stack.getItem();
|
||||
List<Shaped> recipes = new ArrayList<>( 0 );
|
||||
|
||||
ITurtleUpgrade left = item.getUpgrade( stack, TurtleSide.LEFT );
|
||||
|
@ -68,9 +68,8 @@ public class MoreRedIntegration
|
||||
|
||||
BlockPos pos = wirePos.relative( wireFace );
|
||||
BlockState state = world.getBlockState( pos );
|
||||
if( !(state.getBlock() instanceof IBundledRedstoneBlock) ) return 0;
|
||||
if( !(state.getBlock() instanceof IBundledRedstoneBlock block) ) return 0;
|
||||
|
||||
IBundledRedstoneBlock block = (IBundledRedstoneBlock) state.getBlock();
|
||||
return (block.getBundledRedstoneOutput( world, pos, wireFace.getOpposite() ) & (1 << channel)) != 0 ? 31 : 0;
|
||||
}
|
||||
|
||||
|
@ -67,9 +67,8 @@ class GenericPeripheral implements IDynamicPeripheral
|
||||
public boolean equals( @Nullable IPeripheral other )
|
||||
{
|
||||
if( other == this ) return true;
|
||||
if( !(other instanceof GenericPeripheral) ) return false;
|
||||
if( !(other instanceof GenericPeripheral generic) ) return false;
|
||||
|
||||
GenericPeripheral generic = (GenericPeripheral) other;
|
||||
return tile == generic.tile && methods.equals( generic.methods );
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,8 @@ final class SaturatedMethod
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if( obj == this ) return true;
|
||||
if( !(obj instanceof SaturatedMethod) ) return false;
|
||||
if( !(obj instanceof SaturatedMethod other) ) return false;
|
||||
|
||||
SaturatedMethod other = (SaturatedMethod) obj;
|
||||
return method == other.method && target.equals( other.target );
|
||||
}
|
||||
|
||||
|
@ -107,9 +107,8 @@ public class BlockCable extends BlockGeneric implements SimpleWaterloggedBlock
|
||||
if( hit.getType() == HitResult.Type.BLOCK )
|
||||
{
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( tile instanceof TileCable && tile.hasLevel() )
|
||||
if( tile instanceof TileCable cable && tile.hasLevel() )
|
||||
{
|
||||
TileCable cable = (TileCable) tile;
|
||||
|
||||
ItemStack item;
|
||||
BlockState newState;
|
||||
@ -164,9 +163,8 @@ public class BlockCable extends BlockGeneric implements SimpleWaterloggedBlock
|
||||
public void setPlacedBy( Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack )
|
||||
{
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( tile instanceof TileCable )
|
||||
if( tile instanceof TileCable cable )
|
||||
{
|
||||
TileCable cable = (TileCable) tile;
|
||||
if( cable.hasCable() ) cable.connectionsChanged();
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,8 @@ public abstract class ItemBlockCable extends BlockItem
|
||||
world.playSound( null, pos, soundType.getPlaceSound(), SoundSource.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
|
||||
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( tile instanceof TileCable )
|
||||
if( tile instanceof TileCable cable )
|
||||
{
|
||||
TileCable cable = (TileCable) tile;
|
||||
cable.modemChanged();
|
||||
cable.connectionsChanged();
|
||||
}
|
||||
|
@ -236,9 +236,8 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
||||
@Override
|
||||
public boolean equals( IPeripheral other )
|
||||
{
|
||||
if( other instanceof WiredModemPeripheral )
|
||||
if( other instanceof WiredModemPeripheral otherModem )
|
||||
{
|
||||
WiredModemPeripheral otherModem = (WiredModemPeripheral) other;
|
||||
return otherModem.modem == modem;
|
||||
}
|
||||
return false;
|
||||
|
@ -83,9 +83,8 @@ public class BlockMonitor extends BlockGeneric
|
||||
super.setPlacedBy( world, pos, blockState, livingEntity, itemStack );
|
||||
|
||||
BlockEntity entity = world.getBlockEntity( pos );
|
||||
if( entity instanceof TileMonitor && !world.isClientSide )
|
||||
if( entity instanceof TileMonitor monitor && !world.isClientSide )
|
||||
{
|
||||
TileMonitor monitor = (TileMonitor) entity;
|
||||
// Defer the block update if we're being placed by another TE. See #691
|
||||
if( livingEntity == null || livingEntity instanceof FakePlayer )
|
||||
{
|
||||
|
@ -54,9 +54,8 @@ public final class MonitorWatcher
|
||||
for( BlockEntity te : chunk.getBlockEntities().values() )
|
||||
{
|
||||
// Find all origin monitors who are not already on the queue.
|
||||
if( !(te instanceof TileMonitor) ) continue;
|
||||
if( !(te instanceof TileMonitor monitor) ) continue;
|
||||
|
||||
TileMonitor monitor = (TileMonitor) te;
|
||||
ServerMonitor serverMonitor = getMonitor( monitor );
|
||||
if( serverMonitor == null || monitor.enqueued ) continue;
|
||||
|
||||
|
@ -392,9 +392,8 @@ public class TileMonitor extends TileGeneric
|
||||
if( world == null || !world.isAreaLoaded( pos, 0 ) ) return MonitorState.UNLOADED;
|
||||
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( !(tile instanceof TileMonitor) ) return MonitorState.MISSING;
|
||||
if( !(tile instanceof TileMonitor monitor) ) return MonitorState.MISSING;
|
||||
|
||||
TileMonitor monitor = (TileMonitor) tile;
|
||||
return !monitor.visiting && !monitor.destroyed && advanced == monitor.advanced
|
||||
&& getDirection() == monitor.getDirection() && getOrientation() == monitor.getOrientation()
|
||||
? MonitorState.present( monitor ) : MonitorState.MISSING;
|
||||
|
@ -63,8 +63,7 @@ public class PocketAPI implements ILuaAPI
|
||||
public final Object[] equipBack()
|
||||
{
|
||||
Entity entity = computer.getEntity();
|
||||
if( !(entity instanceof Player) ) return new Object[] { false, "Cannot find player" };
|
||||
Player player = (Player) entity;
|
||||
if( !(entity instanceof Player player) ) return new Object[] { false, "Cannot find player" };
|
||||
Inventory inventory = player.getInventory();
|
||||
IPocketUpgrade previousUpgrade = computer.getUpgrade();
|
||||
|
||||
@ -108,8 +107,7 @@ public class PocketAPI implements ILuaAPI
|
||||
public final Object[] unequipBack()
|
||||
{
|
||||
Entity entity = computer.getEntity();
|
||||
if( !(entity instanceof Player) ) return new Object[] { false, "Cannot find player" };
|
||||
Player player = (Player) entity;
|
||||
if( !(entity instanceof Player player) ) return new Object[] { false, "Cannot find player" };
|
||||
Inventory inventory = player.getInventory();
|
||||
IPocketUpgrade previousUpgrade = computer.getUpgrade();
|
||||
|
||||
|
@ -56,9 +56,8 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
Inventory inventory = ((Player) entity).getInventory();
|
||||
return inventory.items.contains( stack ) || inventory.offhand.contains( stack ) ? entity : null;
|
||||
}
|
||||
else if( entity instanceof LivingEntity )
|
||||
else if( entity instanceof LivingEntity living )
|
||||
{
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
return living.getMainHandItem() == stack || living.getOffhandItem() == stack ? entity : null;
|
||||
}
|
||||
else
|
||||
@ -184,10 +183,9 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
{
|
||||
super.broadcastState( force );
|
||||
|
||||
if( (hasTerminalChanged() || force) && entity instanceof ServerPlayer )
|
||||
if( (hasTerminalChanged() || force) && entity instanceof ServerPlayer player )
|
||||
{
|
||||
// Broadcast the state to the current entity if they're not already interacting with it.
|
||||
ServerPlayer player = (ServerPlayer) entity;
|
||||
if( player.connection != null && !isInteracting( player ) )
|
||||
{
|
||||
NetworkHandler.sendToPlayer( player, createTerminalPacket() );
|
||||
|
@ -41,12 +41,10 @@ public class PocketModem extends AbstractPocketUpgrade
|
||||
@Override
|
||||
public void update( @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
|
||||
{
|
||||
if( !(peripheral instanceof PocketModemPeripheral) ) return;
|
||||
if( !(peripheral instanceof PocketModemPeripheral modem) ) return;
|
||||
|
||||
Entity entity = access.getEntity();
|
||||
|
||||
PocketModemPeripheral modem = (PocketModemPeripheral) peripheral;
|
||||
|
||||
if( entity != null ) modem.setLocation( entity.getCommandSenderWorld(), entity.getEyePosition( 1 ) );
|
||||
|
||||
ModemState state = modem.getModemState();
|
||||
|
@ -32,9 +32,7 @@ public class PocketSpeaker extends AbstractPocketUpgrade
|
||||
@Override
|
||||
public void update( @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
|
||||
{
|
||||
if( !(peripheral instanceof PocketSpeakerPeripheral) ) return;
|
||||
|
||||
PocketSpeakerPeripheral speaker = (PocketSpeakerPeripheral) peripheral;
|
||||
if( !(peripheral instanceof PocketSpeakerPeripheral speaker) ) return;
|
||||
|
||||
Entity entity = access.getEntity();
|
||||
if( entity != null )
|
||||
|
@ -88,7 +88,7 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements Simple
|
||||
public VoxelShape getShape( @Nonnull BlockState state, BlockGetter world, @Nonnull BlockPos pos, @Nonnull CollisionContext context )
|
||||
{
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
Vec3 offset = tile instanceof TileTurtle ? ((TileTurtle) tile).getRenderOffset( 1.0f ) : Vec3.ZERO;
|
||||
Vec3 offset = tile instanceof TileTurtle turtle ? turtle.getRenderOffset( 1.0f ) : Vec3.ZERO;
|
||||
return offset.equals( Vec3.ZERO ) ? DEFAULT_SHAPE : DEFAULT_SHAPE.move( offset.x, offset.y, offset.z );
|
||||
}
|
||||
|
||||
@ -119,24 +119,17 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements Simple
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlacedBy( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity player, @Nonnull ItemStack stack )
|
||||
public void setPlacedBy( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity entity, @Nonnull ItemStack stack )
|
||||
{
|
||||
super.setPlacedBy( world, pos, state, player, stack );
|
||||
super.setPlacedBy( world, pos, state, entity, stack );
|
||||
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( !world.isClientSide && tile instanceof TileTurtle )
|
||||
if( !world.isClientSide && tile instanceof TileTurtle turtle )
|
||||
{
|
||||
TileTurtle turtle = (TileTurtle) tile;
|
||||
if( entity instanceof Player player ) turtle.setOwningPlayer( player.getGameProfile() );
|
||||
|
||||
if( player instanceof Player )
|
||||
if( stack.getItem() instanceof ITurtleItem item )
|
||||
{
|
||||
((TileTurtle) tile).setOwningPlayer( ((Player) player).getGameProfile() );
|
||||
}
|
||||
|
||||
if( stack.getItem() instanceof ITurtleItem )
|
||||
{
|
||||
ITurtleItem item = (ITurtleItem) stack.getItem();
|
||||
|
||||
// Set Upgrades
|
||||
for( TurtleSide side : TurtleSide.values() )
|
||||
{
|
||||
@ -172,7 +165,7 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements Simple
|
||||
@Override
|
||||
protected ItemStack getItem( TileComputerBase tile )
|
||||
{
|
||||
return tile instanceof TileTurtle ? TurtleItemFactory.create( (TileTurtle) tile ) : ItemStack.EMPTY;
|
||||
return tile instanceof TileTurtle turtle ? TurtleItemFactory.create( turtle ) : ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -162,12 +162,12 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
ItemStack currentItem = player.getItemInHand( hand );
|
||||
if( !currentItem.isEmpty() )
|
||||
{
|
||||
if( currentItem.getItem() instanceof DyeItem )
|
||||
if( currentItem.getItem() instanceof DyeItem dyeItem )
|
||||
{
|
||||
// Dye to change turtle colour
|
||||
if( !getLevel().isClientSide )
|
||||
{
|
||||
DyeColor dye = ((DyeItem) currentItem.getItem()).getDyeColor();
|
||||
DyeColor dye = dyeItem.getDyeColor();
|
||||
if( brain.getDyeColour() != dye )
|
||||
{
|
||||
brain.setDyeColour( dye );
|
||||
|
@ -327,10 +327,9 @@ public class TurtleBrain implements ITurtleAccess
|
||||
if( block == oldBlock.getBlock() )
|
||||
{
|
||||
BlockEntity newTile = world.getBlockEntity( pos );
|
||||
if( newTile instanceof TileTurtle )
|
||||
if( newTile instanceof TileTurtle newTurtle )
|
||||
{
|
||||
// Copy the old turtle state into the new turtle
|
||||
TileTurtle newTurtle = (TileTurtle) newTile;
|
||||
newTurtle.setLevel( world );
|
||||
newTurtle.transferStateFrom( oldOwner );
|
||||
newTurtle.createServerComputer().setLevel( world );
|
||||
@ -956,12 +955,12 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public MethodResult resume( Object[] response )
|
||||
{
|
||||
if( response.length < 3 || !(response[1] instanceof Number) || !(response[2] instanceof Boolean) )
|
||||
if( response.length < 3 || !(response[1] instanceof Number id) || !(response[2] instanceof Boolean) )
|
||||
{
|
||||
return pull;
|
||||
}
|
||||
|
||||
if( ((Number) response[1]).intValue() != command ) return pull;
|
||||
if( id.intValue() != command ) return pull;
|
||||
|
||||
return MethodResult.of( Arrays.copyOfRange( response, 2, response.length ) );
|
||||
}
|
||||
|
@ -165,9 +165,9 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
if( interact != null ) return interact.consumesAction();
|
||||
|
||||
if( hitEntity.interact( turtlePlayer, InteractionHand.MAIN_HAND ).consumesAction() ) return true;
|
||||
if( hitEntity instanceof LivingEntity )
|
||||
if( hitEntity instanceof LivingEntity hitLiving )
|
||||
{
|
||||
return stack.interactLivingEntity( turtlePlayer, (LivingEntity) hitEntity, InteractionHand.MAIN_HAND ).consumesAction();
|
||||
return stack.interactLivingEntity( turtlePlayer, hitLiving, InteractionHand.MAIN_HAND ).consumesAction();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -236,7 +236,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
boolean placed = doDeployOnBlock( stack, turtlePlayer, position, context, hit ).consumesAction();
|
||||
|
||||
// Set text on signs
|
||||
if( placed && item instanceof SignItem && extraArguments != null && extraArguments.length >= 1 && extraArguments[0] instanceof String )
|
||||
if( placed && item instanceof SignItem && extraArguments != null && extraArguments.length >= 1 && extraArguments[0] instanceof String message )
|
||||
{
|
||||
Level world = turtle.getLevel();
|
||||
BlockEntity tile = world.getBlockEntity( position );
|
||||
@ -245,7 +245,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
tile = world.getBlockEntity( position.relative( side ) );
|
||||
}
|
||||
|
||||
if( tile instanceof SignBlockEntity ) setSignText( world, tile, (String) extraArguments[0] );
|
||||
if( tile instanceof SignBlockEntity ) setSignText( world, tile, message );
|
||||
}
|
||||
|
||||
return placed;
|
||||
|
@ -74,9 +74,8 @@ public final class TurtlePlayer extends FakePlayer
|
||||
|
||||
public static TurtlePlayer get( ITurtleAccess access )
|
||||
{
|
||||
if( !(access instanceof TurtleBrain) ) return create( access );
|
||||
if( !(access instanceof TurtleBrain brain) ) return create( access );
|
||||
|
||||
TurtleBrain brain = (TurtleBrain) access;
|
||||
TurtlePlayer player = brain.cachedPlayer;
|
||||
if( player == null || player.getGameProfile() != getProfile( access.getOwningPlayer() )
|
||||
|| player.getCommandSenderWorld() != access.getLevel() )
|
||||
|
@ -57,7 +57,7 @@ public class TurtleModem extends AbstractTurtleUpgrade
|
||||
@Override
|
||||
public boolean equals( IPeripheral other )
|
||||
{
|
||||
return this == other || (other instanceof Peripheral && ((Peripheral) other).turtle == turtle);
|
||||
return this == other || (other instanceof Peripheral modem && modem.turtle == turtle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,9 +131,9 @@ public class TurtleModem extends AbstractTurtleUpgrade
|
||||
if( !turtle.getLevel().isClientSide )
|
||||
{
|
||||
IPeripheral peripheral = turtle.getPeripheral( side );
|
||||
if( peripheral instanceof Peripheral )
|
||||
if( peripheral instanceof Peripheral modem )
|
||||
{
|
||||
ModemState state = ((Peripheral) peripheral).getModemState();
|
||||
ModemState state = modem.getModemState();
|
||||
if( state.pollChanged() )
|
||||
{
|
||||
turtle.getUpgradeNBTData( side ).putBoolean( "active", state.isOpen() );
|
||||
|
@ -53,7 +53,7 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
|
||||
@Override
|
||||
public boolean equals( IPeripheral other )
|
||||
{
|
||||
return this == other || (other instanceof Peripheral && turtle == ((Peripheral) other).turtle);
|
||||
return this == other || (other instanceof Peripheral speaker && turtle == speaker.turtle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
|
||||
@Override
|
||||
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide turtleSide )
|
||||
{
|
||||
IPeripheral turtlePeripheral = turtle.getPeripheral( turtleSide );
|
||||
if( turtlePeripheral instanceof Peripheral ) ((Peripheral) turtlePeripheral).update();
|
||||
IPeripheral peripheral = turtle.getPeripheral( turtleSide );
|
||||
if( peripheral instanceof Peripheral speaker ) speaker.update();
|
||||
}
|
||||
}
|
||||
|
@ -165,18 +165,12 @@ public class TurtleTool extends AbstractTurtleUpgrade
|
||||
{
|
||||
// Special case for armor stands: attack twice to guarantee destroy
|
||||
hitEntity.hurt( source, damage );
|
||||
if( hitEntity.isAlive() )
|
||||
{
|
||||
hitEntity.hurt( source, damage );
|
||||
}
|
||||
if( hitEntity.isAlive() ) hitEntity.hurt( source, damage );
|
||||
attacked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( hitEntity.hurt( source, damage ) )
|
||||
{
|
||||
attacked = true;
|
||||
}
|
||||
if( hitEntity.hurt( source, damage ) ) attacked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,8 @@ public final class NBTUtil
|
||||
if( object instanceof Boolean ) return ByteTag.valueOf( (byte) ((boolean) (Boolean) object ? 1 : 0) );
|
||||
if( object instanceof Number ) return DoubleTag.valueOf( ((Number) object).doubleValue() );
|
||||
if( object instanceof String ) return StringTag.valueOf( object.toString() );
|
||||
if( object instanceof Map )
|
||||
if( object instanceof Map<?, ?> m )
|
||||
{
|
||||
Map<?, ?> m = (Map<?, ?>) object;
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
int i = 0;
|
||||
for( Map.Entry<?, ?> entry : m.entrySet() )
|
||||
|
@ -340,9 +340,8 @@ public class ComputerTestDelegate
|
||||
DynamicNodeBuilder root = new DynamicNodeBuilder( "" );
|
||||
for( Object key : tests.keySet() )
|
||||
{
|
||||
if( !(key instanceof String) ) throw new LuaException( "Non-key string " + getType( key ) );
|
||||
if( !(key instanceof String name) ) throw new LuaException( "Non-key string " + getType( key ) );
|
||||
|
||||
String name = (String) key;
|
||||
String[] parts = name.split( "\0" );
|
||||
DynamicNodeBuilder builder = root;
|
||||
for( int i = 0; i < parts.length - 1; i++ ) builder = builder.get( parts[i] );
|
||||
|
@ -24,8 +24,8 @@ public class ObjectWrapper implements ILuaContext
|
||||
public ObjectWrapper( Object object )
|
||||
{
|
||||
this.object = object;
|
||||
String[] dynamicMethods = object instanceof IDynamicLuaObject
|
||||
? Objects.requireNonNull( ((IDynamicLuaObject) object).getMethodNames(), "Methods cannot be null" )
|
||||
String[] dynamicMethods = object instanceof IDynamicLuaObject dynamic
|
||||
? Objects.requireNonNull( dynamic.getMethodNames(), "Methods cannot be null" )
|
||||
: LuaMethod.EMPTY_METHODS;
|
||||
|
||||
List<NamedMethod<LuaMethod>> methods = LuaMethod.GENERATOR.getMethods( object.getClass() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user