1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-09-03 19:07:56 +00:00

Switch a few more places to use Java 17 features

New ErrorProne hint, and one which is actually pretty useful!
This commit is contained in:
Jonathan Coates
2025-03-22 09:39:47 +00:00
parent c458360b18
commit 9c0ce27ce6
19 changed files with 58 additions and 59 deletions

View File

@@ -437,8 +437,8 @@ final class WiredNetworkImpl implements WiredNetwork {
}
private static WiredNodeImpl checkNode(WiredNode node) {
if (node instanceof WiredNodeImpl) {
return (WiredNodeImpl) node;
if (node instanceof WiredNodeImpl n) {
return n;
} else {
throw new IllegalArgumentException("Unknown implementation of IWiredNode: " + node);
}

View File

@@ -66,8 +66,8 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder<Command
public LiteralArgumentBuilder<CommandSourceStack> then(final ArgumentBuilder<CommandSourceStack, ?> argument) {
if (getRedirect() != null) throw new IllegalStateException("Cannot add children to a redirected node");
if (argument instanceof HelpingArgumentBuilder) {
children.add((HelpingArgumentBuilder) argument);
if (argument instanceof HelpingArgumentBuilder child) {
children.add(child);
} else if (argument instanceof LiteralArgumentBuilder) {
super.then(argument);
} else {

View File

@@ -38,7 +38,7 @@ public class WirelessModemBlockEntity extends BlockEntity {
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other || (other instanceof Peripheral && entity == ((Peripheral) other).entity);
return this == other || (other instanceof Peripheral o && entity == o.entity);
}
@Override

View File

@@ -40,7 +40,6 @@ import org.jspecify.annotations.Nullable;
* monitor.setCursorPos(1, 1)
* monitor.write("Hello, world!")
* }</pre>
*
* @cc.see monitor_resize Queued when a monitor is resized.
* @cc.see monitor_touch Queued when an advanced monitor is clicked.
*/
@@ -95,7 +94,7 @@ public class MonitorPeripheral extends TermMethods implements IPeripheral {
@Override
public boolean equals(@Nullable IPeripheral other) {
return other instanceof MonitorPeripheral && monitor == ((MonitorPeripheral) other).monitor;
return other instanceof MonitorPeripheral o && monitor == o.monitor;
}
private ServerMonitor getMonitor() throws LuaException {

View File

@@ -57,11 +57,10 @@ public final class MonitorWatcher {
if (monitor == null) continue;
var pos = tile.getBlockPos();
var world = tile.getLevel();
if (!(world instanceof ServerLevel)) continue;
if (!(tile.getLevel() instanceof ServerLevel level)) continue;
var chunk = world.getChunkAt(pos);
if (((ServerLevel) world).getChunkSource().chunkMap.getPlayers(chunk.getPos(), false).isEmpty()) {
var chunk = level.getChunkAt(pos);
if (level.getChunkSource().chunkMap.getPlayers(chunk.getPos(), false).isEmpty()) {
continue;
}

View File

@@ -53,7 +53,7 @@ public class SpeakerBlockEntity extends BlockEntity {
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other || (other instanceof Peripheral && speaker == ((Peripheral) other).speaker);
return this == other || (other instanceof Peripheral o && speaker == o.speaker);
}
}
}

View File

@@ -25,7 +25,6 @@ public class PocketSpeaker extends AbstractPocketUpgrade {
@Override
public void update(IPocketAccess access, @Nullable IPeripheral peripheral) {
if (!(peripheral instanceof PocketSpeakerPeripheral)) return;
((PocketSpeakerPeripheral) peripheral).update();
if (peripheral instanceof PocketSpeakerPeripheral speaker) speaker.update();
}
}

View File

@@ -62,14 +62,13 @@ public class TurtleDropCommand implements TurtleCommand {
}
}
switch (transferred) {
case ContainerTransfer.NO_SPACE:
return TurtleCommandResult.failure("No space for items");
case ContainerTransfer.NO_ITEMS:
return TurtleCommandResult.failure("No items to drop");
default:
return switch (transferred) {
case ContainerTransfer.NO_SPACE -> TurtleCommandResult.failure("No space for items");
case ContainerTransfer.NO_ITEMS -> TurtleCommandResult.failure("No items to drop");
default -> {
turtle.playAnimation(TurtleAnimation.WAIT);
return TurtleCommandResult.success();
}
yield TurtleCommandResult.success();
}
};
}
}

View File

@@ -50,15 +50,14 @@ public class TurtleSuckCommand implements TurtleCommand {
if (inventory != null) {
// Take from inventory of thing in front
var transferred = inventory.moveTo(TurtleUtil.getOffsetInventory(turtle), quantity);
switch (transferred) {
case ContainerTransfer.NO_SPACE:
return TurtleCommandResult.failure("No space for items");
case ContainerTransfer.NO_ITEMS:
return TurtleCommandResult.failure("No items to take");
default:
return switch (transferred) {
case ContainerTransfer.NO_SPACE -> TurtleCommandResult.failure("No space for items");
case ContainerTransfer.NO_ITEMS -> TurtleCommandResult.failure("No items to take");
default -> {
turtle.playAnimation(TurtleAnimation.WAIT);
return TurtleCommandResult.success();
}
yield TurtleCommandResult.success();
}
};
} else {
// Suck up loose items off the ground
var aabb = new AABB(

View File

@@ -70,9 +70,9 @@ public final class DropConsumer {
public static boolean onEntitySpawn(Entity entity) {
// Capture any nearby item spawns
if (dropWorld == entity.level() && entity instanceof ItemEntity
if (dropWorld == entity.level() && entity instanceof ItemEntity item
&& assertNonNull(dropBounds).contains(entity.position())) {
handleDrops(((ItemEntity) entity).getItem());
handleDrops(item.getItem());
return true;
}

View File

@@ -79,8 +79,8 @@ public class PrettyJsonWriter extends JsonWriter {
// Otherwise we either need to push to our list or finish a record pair.
var head = stack.getLast();
if (head instanceof DocList) {
((DocList) head).add(object);
if (head instanceof DocList headList) {
headList.add(object);
} else {
stack.removeLast();
((DocList) stack.getLast()).add(new Pair((String) head, object));

View File

@@ -83,7 +83,7 @@ object ClientTestHooks {
if (minecraft.levelSource.levelExists(LEVEL_NAME)) {
LOG.info("World already exists, opening.")
minecraft.createWorldOpenFlows().loadLevel(minecraft.screen, LEVEL_NAME)
minecraft.createWorldOpenFlows().loadLevel(minecraft.screen!!, LEVEL_NAME)
} else {
LOG.info("World does not exist, creating it.")
val rules = GameRules()