mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-12-15 01:48:05 +00:00
More instanceof pattern matching
This commit is contained in:
@@ -209,7 +209,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
|||||||
|
|
||||||
private void continueUpload()
|
private void continueUpload()
|
||||||
{
|
{
|
||||||
if( minecraft.screen instanceof OptionScreen ) ((OptionScreen) minecraft.screen).disable();
|
if( minecraft.screen instanceof OptionScreen screen ) screen.disable();
|
||||||
NetworkHandler.sendToServer( new ContinueUploadMessage( computer.getInstanceID(), true ) );
|
NetworkHandler.sendToServer( new ContinueUploadMessage( computer.getInstanceID(), true ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class BinaryWritableHandle extends HandleGeneric
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Technically this is not needed
|
// Technically this is not needed
|
||||||
if( writer instanceof FileChannel ) ((FileChannel) writer).force( false );
|
if( writer instanceof FileChannel channel ) channel.force( false );
|
||||||
}
|
}
|
||||||
catch( IOException ignored )
|
catch( IOException ignored )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class WebsocketHandle implements Closeable
|
|||||||
return MethodResult.of();
|
return MethodResult.of();
|
||||||
}
|
}
|
||||||
else if( event.length >= 2 && timeoutId != -1 && Objects.equal( event[0], TIMER_EVENT )
|
else if( event.length >= 2 && timeoutId != -1 && Objects.equal( event[0], TIMER_EVENT )
|
||||||
&& event[1] instanceof Number && ((Number) event[1]).intValue() == timeoutId )
|
&& event[1] instanceof Number id && id.intValue() == timeoutId )
|
||||||
{
|
{
|
||||||
// If we received a matching timer event then abort.
|
// If we received a matching timer event then abort.
|
||||||
return MethodResult.of();
|
return MethodResult.of();
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public final class CommonHooks
|
|||||||
public static void onServerStarting( FMLServerStartingEvent event )
|
public static void onServerStarting( FMLServerStartingEvent event )
|
||||||
{
|
{
|
||||||
MinecraftServer server = event.getServer();
|
MinecraftServer server = event.getServer();
|
||||||
if( server instanceof DedicatedServer && ((DedicatedServer) server).getProperties().enableJmxMonitoring )
|
if( server instanceof DedicatedServer dediServer && dediServer.getProperties().enableJmxMonitoring )
|
||||||
{
|
{
|
||||||
ComputerMBean.register();
|
ComputerMBean.register();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -384,7 +384,7 @@ public final class Config
|
|||||||
{
|
{
|
||||||
// Ensure file configs are reloaded. Forge should probably do this, so worth checking in the future.
|
// Ensure file configs are reloaded. Forge should probably do this, so worth checking in the future.
|
||||||
CommentedConfig config = event.getConfig().getConfigData();
|
CommentedConfig config = event.getConfig().getConfigData();
|
||||||
if( config instanceof CommentedFileConfig ) ((CommentedFileConfig) config).load();
|
if( config instanceof CommentedFileConfig loadable ) loadable.load();
|
||||||
|
|
||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,6 @@ public enum UserLevel implements Predicate<CommandSourceStack>
|
|||||||
Entity sender = source.getEntity();
|
Entity sender = source.getEntity();
|
||||||
return server.isDedicatedServer()
|
return server.isDedicatedServer()
|
||||||
? source.getEntity() == null && source.hasPermission( 4 ) && source.getTextName().equals( "Server" )
|
? source.getEntity() == null && source.hasPermission( 4 ) && source.getTextName().equals( "Server" )
|
||||||
: sender instanceof Player && ((Player) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() );
|
: sender instanceof Player player && player.getGameProfile().getName().equalsIgnoreCase( server.getServerModName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public abstract class BlockGeneric extends BaseEntityBlock
|
|||||||
BlockEntity tile = world.getBlockEntity( pos );
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
super.onRemove( block, world, pos, replace, bool );
|
super.onRemove( block, world, pos, replace, bool );
|
||||||
world.removeBlockEntity( pos );
|
world.removeBlockEntity( pos );
|
||||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).destroy();
|
if( tile instanceof TileGeneric generic ) generic.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -53,7 +53,7 @@ public abstract class BlockGeneric extends BaseEntityBlock
|
|||||||
public final InteractionResult use( @Nonnull BlockState state, Level world, @Nonnull BlockPos pos, @Nonnull Player player, @Nonnull InteractionHand hand, @Nonnull BlockHitResult hit )
|
public final InteractionResult use( @Nonnull BlockState state, Level world, @Nonnull BlockPos pos, @Nonnull Player player, @Nonnull InteractionHand hand, @Nonnull BlockHitResult hit )
|
||||||
{
|
{
|
||||||
BlockEntity tile = world.getBlockEntity( pos );
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
return tile instanceof TileGeneric ? ((TileGeneric) tile).onActivate( player, hand, hit ) : InteractionResult.PASS;
|
return tile instanceof TileGeneric generic ? generic.onActivate( player, hand, hit ) : InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,14 +61,14 @@ public abstract class BlockGeneric extends BaseEntityBlock
|
|||||||
public final void neighborChanged( @Nonnull BlockState state, Level world, @Nonnull BlockPos pos, @Nonnull Block neighbourBlock, @Nonnull BlockPos neighbourPos, boolean isMoving )
|
public final void neighborChanged( @Nonnull BlockState state, Level world, @Nonnull BlockPos pos, @Nonnull Block neighbourBlock, @Nonnull BlockPos neighbourPos, boolean isMoving )
|
||||||
{
|
{
|
||||||
BlockEntity tile = world.getBlockEntity( pos );
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos );
|
if( tile instanceof TileGeneric generic ) generic.onNeighbourChange( neighbourPos );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onNeighborChange( BlockState state, LevelReader world, BlockPos pos, BlockPos neighbour )
|
public final void onNeighborChange( BlockState state, LevelReader world, BlockPos pos, BlockPos neighbour )
|
||||||
{
|
{
|
||||||
BlockEntity tile = world.getBlockEntity( pos );
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourTileEntityChange( neighbour );
|
if( tile instanceof TileGeneric generic ) generic.onNeighbourTileEntityChange( neighbour );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -76,7 +76,7 @@ public abstract class BlockGeneric extends BaseEntityBlock
|
|||||||
public void tick( @Nonnull BlockState state, ServerLevel world, @Nonnull BlockPos pos, @Nonnull Random rand )
|
public void tick( @Nonnull BlockState state, ServerLevel world, @Nonnull BlockPos pos, @Nonnull Random rand )
|
||||||
{
|
{
|
||||||
BlockEntity te = world.getBlockEntity( pos );
|
BlockEntity te = world.getBlockEntity( pos );
|
||||||
if( te instanceof TileGeneric ) ((TileGeneric) te).blockTick();
|
if( te instanceof TileGeneric generic ) generic.blockTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
super.onPlace( state, world, pos, oldState, isMoving );
|
super.onPlace( state, world, pos, oldState, isMoving );
|
||||||
|
|
||||||
BlockEntity tile = world.getBlockEntity( pos );
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
if( tile instanceof TileComputerBase ) ((TileComputerBase) tile).updateInput();
|
if( tile instanceof TileComputerBase computer ) computer.updateInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public final class BlockNamedEntityLootCondition implements LootItemCondition
|
|||||||
public boolean test( LootContext lootContext )
|
public boolean test( LootContext lootContext )
|
||||||
{
|
{
|
||||||
BlockEntity tile = lootContext.getParamOrNull( LootContextParams.BLOCK_ENTITY );
|
BlockEntity tile = lootContext.getParamOrNull( LootContextParams.BLOCK_ENTITY );
|
||||||
return tile instanceof Nameable && ((Nameable) tile).hasCustomName();
|
return tile instanceof Nameable nameable && nameable.hasCustomName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public final class HasComputerIdLootCondition implements LootItemCondition
|
|||||||
public boolean test( LootContext lootContext )
|
public boolean test( LootContext lootContext )
|
||||||
{
|
{
|
||||||
BlockEntity tile = lootContext.getParamOrNull( LootContextParams.BLOCK_ENTITY );
|
BlockEntity tile = lootContext.getParamOrNull( LootContextParams.BLOCK_ENTITY );
|
||||||
return tile instanceof IComputerTile && ((IComputerTile) tile).getComputerID() >= 0;
|
return tile instanceof IComputerTile computer && computer.getComputerID() >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public final class PlayerCreativeLootCondition implements LootItemCondition
|
|||||||
public boolean test( LootContext lootContext )
|
public boolean test( LootContext lootContext )
|
||||||
{
|
{
|
||||||
Entity entity = lootContext.getParamOrNull( LootContextParams.THIS_ENTITY );
|
Entity entity = lootContext.getParamOrNull( LootContextParams.THIS_ENTITY );
|
||||||
return entity instanceof Player && ((Player) entity).getAbilities().instabuild;
|
return entity instanceof Player player && player.getAbilities().instabuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -62,12 +62,9 @@ public final class PrintoutRecipe extends CustomRecipe
|
|||||||
ItemStack stack = inventory.getItem( x + y * inventory.getWidth() );
|
ItemStack stack = inventory.getItem( x + y * inventory.getWidth() );
|
||||||
if( !stack.isEmpty() )
|
if( !stack.isEmpty() )
|
||||||
{
|
{
|
||||||
if( stack.getItem() instanceof ItemPrintout && ((ItemPrintout) stack.getItem()).getType() != ItemPrintout.Type.BOOK )
|
if( stack.getItem() instanceof ItemPrintout printout && printout.getType() != ItemPrintout.Type.BOOK )
|
||||||
{
|
{
|
||||||
if( printouts == null )
|
if( printouts == null ) printouts = new ItemStack[9];
|
||||||
{
|
|
||||||
printouts = new ItemStack[9];
|
|
||||||
}
|
|
||||||
printouts[numPrintouts] = stack;
|
printouts[numPrintouts] = stack;
|
||||||
numPages += ItemPrintout.getPageCount( stack );
|
numPages += ItemPrintout.getPageCount( stack );
|
||||||
numPrintouts++;
|
numPrintouts++;
|
||||||
|
|||||||
@@ -62,13 +62,13 @@ public class BlockDiskDrive extends BlockGeneric
|
|||||||
@Override
|
@Override
|
||||||
public void playerDestroy( @Nonnull Level world, @Nonnull Player player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity te, @Nonnull ItemStack stack )
|
public void playerDestroy( @Nonnull Level world, @Nonnull Player player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity te, @Nonnull ItemStack stack )
|
||||||
{
|
{
|
||||||
if( te instanceof Nameable && ((Nameable) te).hasCustomName() )
|
if( te instanceof Nameable nameable && nameable.hasCustomName() )
|
||||||
{
|
{
|
||||||
player.awardStat( Stats.BLOCK_MINED.get( this ) );
|
player.awardStat( Stats.BLOCK_MINED.get( this ) );
|
||||||
player.causeFoodExhaustion( 0.005F );
|
player.causeFoodExhaustion( 0.005F );
|
||||||
|
|
||||||
ItemStack result = new ItemStack( this );
|
ItemStack result = new ItemStack( this );
|
||||||
result.setHoverName( ((Nameable) te).getCustomName() );
|
result.setHoverName( nameable.getCustomName() );
|
||||||
popResource( world, pos, result );
|
popResource( world, pos, result );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -80,10 +80,9 @@ public class BlockDiskDrive extends BlockGeneric
|
|||||||
@Override
|
@Override
|
||||||
public void setPlacedBy( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack )
|
public void setPlacedBy( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack )
|
||||||
{
|
{
|
||||||
if( stack.hasCustomHoverName() )
|
if( stack.hasCustomHoverName() && world.getBlockEntity( pos ) instanceof TileDiskDrive drive )
|
||||||
{
|
{
|
||||||
BlockEntity tileentity = world.getBlockEntity( pos );
|
drive.customName = stack.getHoverName();
|
||||||
if( tileentity instanceof TileDiskDrive ) ((TileDiskDrive) tileentity).customName = stack.getHoverName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public class DiskDrivePeripheral implements IPeripheral
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals( IPeripheral other )
|
public boolean equals( IPeripheral other )
|
||||||
{
|
{
|
||||||
return this == other || other instanceof DiskDrivePeripheral && ((DiskDrivePeripheral) other).diskDrive == diskDrive;
|
return this == other || other instanceof DiskDrivePeripheral drive && drive.diskDrive == diskDrive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -58,13 +58,13 @@ public class BlockPrinter extends BlockGeneric
|
|||||||
@Override
|
@Override
|
||||||
public void playerDestroy( @Nonnull Level world, @Nonnull Player player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity te, @Nonnull ItemStack stack )
|
public void playerDestroy( @Nonnull Level world, @Nonnull Player player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity te, @Nonnull ItemStack stack )
|
||||||
{
|
{
|
||||||
if( te instanceof Nameable && ((Nameable) te).hasCustomName() )
|
if( te instanceof Nameable nameable && nameable.hasCustomName() )
|
||||||
{
|
{
|
||||||
player.awardStat( Stats.BLOCK_MINED.get( this ) );
|
player.awardStat( Stats.BLOCK_MINED.get( this ) );
|
||||||
player.causeFoodExhaustion( 0.005F );
|
player.causeFoodExhaustion( 0.005F );
|
||||||
|
|
||||||
ItemStack result = new ItemStack( this );
|
ItemStack result = new ItemStack( this );
|
||||||
result.setHoverName( ((Nameable) te).getCustomName() );
|
result.setHoverName( nameable.getCustomName() );
|
||||||
popResource( world, pos, result );
|
popResource( world, pos, result );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -76,10 +76,9 @@ public class BlockPrinter extends BlockGeneric
|
|||||||
@Override
|
@Override
|
||||||
public void setPlacedBy( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack )
|
public void setPlacedBy( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack )
|
||||||
{
|
{
|
||||||
if( stack.hasCustomHoverName() )
|
if( stack.hasCustomHoverName() && world.getBlockEntity( pos ) instanceof TilePrinter printer )
|
||||||
{
|
{
|
||||||
BlockEntity tileentity = world.getBlockEntity( pos );
|
printer.customName = stack.getHoverName();
|
||||||
if( tileentity instanceof TilePrinter ) ((TilePrinter) tileentity).customName = stack.getHoverName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public class PrinterPeripheral implements IPeripheral
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals( IPeripheral other )
|
public boolean equals( IPeripheral other )
|
||||||
{
|
{
|
||||||
return other instanceof PrinterPeripheral && ((PrinterPeripheral) other).printer == printer;
|
return this == other || (other instanceof PrinterPeripheral otherPrinter && otherPrinter.printer == printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
|||||||
{
|
{
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
return item == Items.PAPER
|
return item == Items.PAPER
|
||||||
|| (item instanceof ItemPrintout && ((ItemPrintout) item).getType() == ItemPrintout.Type.PAGE);
|
|| (item instanceof ItemPrintout printout && printout.getType() == ItemPrintout.Type.PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canInputPage()
|
private boolean canInputPage()
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
|||||||
@Override
|
@Override
|
||||||
public void updateUpgradeNBTData()
|
public void updateUpgradeNBTData()
|
||||||
{
|
{
|
||||||
if( entity instanceof Player ) ((Player) entity).getInventory().setChanged();
|
if( entity instanceof Player player ) player.getInventory().setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user