1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-09-09 22:05:59 +00:00

Merge branch 'mc-1.20.x' into mc-1.21.x

This commit is contained in:
Jonathan Coates
2025-03-25 08:44:19 +00:00
37 changed files with 613 additions and 616 deletions

View File

@@ -108,6 +108,8 @@ public final class LanguageProvider implements DataProvider {
add(ComputerCraftTags.Items.TURTLE, "Turtles");
add(ComputerCraftTags.Items.WIRED_MODEM, "Wired modems");
add(ComputerCraftTags.Items.MONITOR, "Monitors");
add(ComputerCraftTags.Items.DISKS, "Disks");
add(ComputerCraftTags.Items.POCKET_COMPUTERS, "Pocket Computers");
add(ComputerCraftTags.Items.DYEABLE, "Dyable items");
add(ComputerCraftTags.Items.TURTLE_CAN_PLACE, "Turtle-placeable items");

View File

@@ -96,6 +96,8 @@ class TagProvider {
tags.copy(ComputerCraftTags.Blocks.TURTLE, ComputerCraftTags.Items.TURTLE);
tags.tag(ComputerCraftTags.Items.WIRED_MODEM).add(ModRegistry.Items.WIRED_MODEM.get(), ModRegistry.Items.WIRED_MODEM_FULL.get());
tags.copy(ComputerCraftTags.Blocks.MONITOR, ComputerCraftTags.Items.MONITOR);
tags.tag(ComputerCraftTags.Items.DISKS).add(ModRegistry.Items.DISK.get(), ModRegistry.Items.TREASURE_DISK.get());
tags.tag(ComputerCraftTags.Items.POCKET_COMPUTERS).add(ModRegistry.Items.POCKET_COMPUTER_NORMAL.get(), ModRegistry.Items.POCKET_COMPUTER_ADVANCED.get());
tags.tag(ComputerCraftTags.Items.DYEABLE)
.addTag(ComputerCraftTags.Items.TURTLE)

View File

@@ -205,8 +205,10 @@
"item.computercraft.treasure_disk": "Floppy Disk",
"itemGroup.computercraft": "ComputerCraft",
"tag.item.computercraft.computer": "Computers",
"tag.item.computercraft.disks": "Disks",
"tag.item.computercraft.dyeable": "Dyable items",
"tag.item.computercraft.monitor": "Monitors",
"tag.item.computercraft.pocket_computers": "Pocket Computers",
"tag.item.computercraft.turtle": "Turtles",
"tag.item.computercraft.turtle_can_place": "Turtle-placeable items",
"tag.item.computercraft.wired_modem": "Wired modems",

View File

@@ -0,0 +1 @@
{"values": ["computercraft:disk", "computercraft:treasure_disk"]}

View File

@@ -0,0 +1 @@
{"values": ["computercraft:pocket_computer_normal", "computercraft:pocket_computer_advanced"]}

View File

@@ -432,8 +432,8 @@ final class WiredNetworkImpl {
}
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

@@ -39,7 +39,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

@@ -58,11 +58,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

@@ -41,11 +41,12 @@ public final class PocketBrain implements IPocketAccess {
private int colour = -1;
private int lightColour = -1;
public PocketBrain(PocketHolder holder, @Nullable UpgradeData<IPocketUpgrade> upgrade, ServerComputer.Properties properties) {
public PocketBrain(PocketHolder holder, @Nullable UpgradeData<IPocketUpgrade> upgrade, int colour, ServerComputer.Properties properties) {
this.computer = new PocketServerComputer(this, holder, properties);
this.holder = holder;
this.position = holder.pos();
this.upgrade = upgrade;
this.colour = colour;
invalidatePeripheral();
}

View File

@@ -35,6 +35,7 @@ import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.DyedItemColor;
import net.minecraft.world.level.Level;
import org.jspecify.annotations.Nullable;
@@ -202,7 +203,7 @@ public class PocketComputerItem extends Item {
var computerID = NonNegativeId.getOrCreate(level.getServer(), stack, ModRegistry.DataComponents.COMPUTER_ID.get(), IDAssigner.COMPUTER);
var brain = new PocketBrain(
holder, getUpgradeWithData(stack),
holder, getUpgradeWithData(stack), DyedItemColor.getOrDefault(stack, -1),
ServerComputer.properties(computerID, getFamily())
.label(getLabel(stack))
.storageCapacity(StorageCapacity.getOrDefault(stack.get(ModRegistry.DataComponents.STORAGE_CAPACITY.get()), -1))
@@ -241,10 +242,14 @@ public class PocketComputerItem extends Item {
// item. However, if we've just crafted the computer with an upgrade, we should sync the other way, and update
// the computer.
var server = level.getServer();
if (server != null) {
var computer = getServerComputer(server, stack);
if (computer != null) computer.getBrain().setUpgrade(getUpgradeWithData(stack));
}
if (server == null) return;
var computer = getServerComputer(server, stack);
if (computer == null) return;
var brain = computer.getBrain();
brain.setUpgrade(getUpgradeWithData(stack));
brain.setColour(DyedItemColor.getOrDefault(stack, -1));
}
public ComputerFamily getFamily() {

View File

@@ -26,8 +26,7 @@ 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();
}
@Override

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

@@ -256,8 +256,8 @@ public class TurtleTool extends AbstractTurtleUpgrade {
EnchantmentHelper.doPostAttackEffects(player.serverLevel(), entity, source);
// Damage the original item stack.
if (!tool.isEmpty() && entity instanceof LivingEntity && didHurt) {
tool.postHurtEnemy((LivingEntity) entity, player);
if (!tool.isEmpty() && entity instanceof LivingEntity living && didHurt) {
tool.postHurtEnemy(living, player);
}
return true;

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));