mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-11-19 12:54:27 +00:00
Merge branch 'mc-1.20.x' into mc-1.21.x
This commit is contained in:
33 files changed
+433
-298
No files matched your search
@@ -74,6 +74,7 @@ tasks.withType(JavaCompile::class.java).configureEach {
|
||||
options.errorprone {
|
||||
check("MissingOverride", CheckSeverity.ERROR)
|
||||
check("AddNullMarkedToPackageInfo", CheckSeverity.ERROR)
|
||||
check("SystemOut", CheckSeverity.WARN)
|
||||
check("InvalidBlockTag", CheckSeverity.OFF) // Broken by @cc.xyz
|
||||
check("InlineMeSuggester", CheckSeverity.OFF) // Minecraft uses @Deprecated liberally
|
||||
// Too many false positives right now. Maybe we need an indirection for it later on.
|
||||
|
||||
@@ -72,7 +72,7 @@ modrinth {
|
||||
projectId = "gu7yAYhd"
|
||||
versionNumber = modVersion
|
||||
versionName = modVersion
|
||||
versionType = if (isUnstable) "alpha" else "release"
|
||||
versionType = if (isUnstable) "beta" else "release"
|
||||
uploadFile.setProvider(modPublishing.output)
|
||||
gameVersions.add(mcVersion)
|
||||
changelog =
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@ kotlin.stdlib.default.dependency=false
|
||||
kotlin.jvm.target.validation.mode=error
|
||||
|
||||
# Mod properties
|
||||
version=1.120.2
|
||||
version=1.121.0
|
||||
|
||||
isUnstable=true
|
||||
@@ -9,7 +9,7 @@
|
||||
minecraft = "1.21.1"
|
||||
fabric-api = "0.116.12+1.21.1"
|
||||
fabric-loader = "0.18.4"
|
||||
neoForge = "21.1.9"
|
||||
neoForge = "21.1.265"
|
||||
neoMergeTool = "2.0.0"
|
||||
mixin = "0.8.5"
|
||||
parchment = "2024.07.28"
|
||||
|
||||
@@ -30,7 +30,7 @@ dependencies {
|
||||
}
|
||||
|
||||
val javadocOverview = tasks.register<Copy>("javadocOverview") {
|
||||
from("src/overview.html")
|
||||
from("src/overview.md")
|
||||
into(layout.buildDirectory.dir(name))
|
||||
|
||||
expand(
|
||||
@@ -49,7 +49,7 @@ tasks.javadoc {
|
||||
(this as StandardJavadocDocletOptions)
|
||||
|
||||
inputs.files(javadocOverview)
|
||||
overview(javadocOverview.get().destinationDir.resolve("overview.html").absolutePath)
|
||||
overview(javadocOverview.get().destinationDir.resolve("overview.md").absolutePath)
|
||||
|
||||
groups = mapOf(
|
||||
"Common" to listOf(
|
||||
|
||||
+18
-1
@@ -4,6 +4,7 @@
|
||||
|
||||
package dan200.computercraft.api.pocket;
|
||||
|
||||
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
|
||||
import net.minecraft.core.component.DataComponentPatch;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -21,18 +22,34 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade {
|
||||
private final @Nullable ItemStack stack;
|
||||
private final Ingredient ingredient;
|
||||
|
||||
/**
|
||||
* Create a new {@link IPocketUpgrade}.
|
||||
*
|
||||
* @param adjective The adjective of the upgrade.
|
||||
* @param stack The stack the upgrade is crafted with.
|
||||
* @deprecated Use {@link AbstractTurtleUpgrade.StackAware}
|
||||
*/
|
||||
@Deprecated
|
||||
protected AbstractPocketUpgrade(Component adjective, ItemStack stack) {
|
||||
this.adjective = adjective;
|
||||
this.stack = stack;
|
||||
this.ingredient = Ingredient.of(stack);
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade(Component adjective, Ingredient ingredient) {
|
||||
private AbstractPocketUpgrade(Component adjective, Ingredient ingredient) {
|
||||
this.adjective = adjective;
|
||||
this.stack = null; // We need to lazily resolve the ingredient, so don't set the stack.
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link IPocketUpgrade}.
|
||||
*
|
||||
* @param adjective The adjective of the upgrade.
|
||||
* @param stack The stack the upgrade is crafted with.
|
||||
* @deprecated Use {@link AbstractTurtleUpgrade.StackAware}
|
||||
*/
|
||||
@Deprecated
|
||||
protected AbstractPocketUpgrade(String adjective, ItemStack stack) {
|
||||
this(Component.translatable(adjective), stack);
|
||||
}
|
||||
|
||||
+19
-1
@@ -22,6 +22,15 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade {
|
||||
private final @Nullable ItemStack stack;
|
||||
private final Ingredient ingredient;
|
||||
|
||||
/**
|
||||
* Create a new {@link ITurtleUpgrade}.
|
||||
*
|
||||
* @param type The type of upgrade.
|
||||
* @param adjective The adjective of the upgrade.
|
||||
* @param stack The stack the upgrade is crafted with.
|
||||
* @deprecated Use {@link AbstractTurtleUpgrade.StackAware}
|
||||
*/
|
||||
@Deprecated
|
||||
protected AbstractTurtleUpgrade(TurtleUpgradeType type, Component adjective, ItemStack stack) {
|
||||
this.type = type;
|
||||
this.adjective = adjective;
|
||||
@@ -29,13 +38,22 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade {
|
||||
this.ingredient = Ingredient.of(stack);
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade(TurtleUpgradeType type, Component adjective, Ingredient ingredient) {
|
||||
private AbstractTurtleUpgrade(TurtleUpgradeType type, Component adjective, Ingredient ingredient) {
|
||||
this.type = type;
|
||||
this.adjective = adjective;
|
||||
this.stack = null; // We need to lazily resolve the ingredient, so don't set the stack.
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ITurtleUpgrade}.
|
||||
*
|
||||
* @param type The type of upgrade.
|
||||
* @param adjective The adjective of the upgrade.
|
||||
* @param stack The stack the upgrade is crafted with.
|
||||
* @deprecated Use {@link AbstractTurtleUpgrade.StackAware}
|
||||
*/
|
||||
@Deprecated
|
||||
protected AbstractTurtleUpgrade(TurtleUpgradeType type, String adjective, ItemStack stack) {
|
||||
this(type, Component.translatable(adjective), stack);
|
||||
}
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2025 The CC: Tweaked Developers
|
||||
|
||||
SPDX-License-Identifier: MPL-2.0
|
||||
-->
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<p>
|
||||
This is the documentation for CC: Tweaked $modVersion for Minecraft $mcVersion. Documentation for other versions of
|
||||
Minecraft are available on the CC: Tweaked website:
|
||||
|
||||
<ul>
|
||||
<li><a href="/mc-1.20.x/javadoc/">Minecraft 1.20.1</a>
|
||||
<li><a href="/mc-1.21.x/javadoc/">Minecraft 1.21.1</a>
|
||||
<li><a href="/mc-26.3/javadoc/">Minecraft 26.3</a>
|
||||
</ul>
|
||||
|
||||
<h1>Quick links</h1>
|
||||
<p>
|
||||
You probably want to start in the following places:
|
||||
|
||||
<ul>
|
||||
<li>{@linkplain dan200.computercraft.api.peripheral Registering new peripherals}</li>
|
||||
<li>
|
||||
{@link dan200.computercraft.api.lua.LuaFunction} and {@link dan200.computercraft.api.lua.IArguments} for
|
||||
adding methods to your peripheral or Lua objects.
|
||||
</li>
|
||||
<li>{@linkplain dan200.computercraft.api.turtle.ITurtleUpgrade Turtle upgrades}</li>
|
||||
<li>{@linkplain dan200.computercraft.api.pocket.IPocketUpgrade Pocket upgrades}</li>
|
||||
</ul>
|
||||
|
||||
<h1>Using</h1>
|
||||
<p>
|
||||
CC: Tweaked is hosted on my maven repo, and so is relatively simple to depend on. You may wish to add a soft (or
|
||||
hard) dependency in your <code>mods.toml</code> file, with the appropriate version bounds, to ensure that API
|
||||
functionality you depend on is present.
|
||||
|
||||
<pre class="language language-groovy"><code>repositories {
|
||||
maven {
|
||||
url "https://maven.squiddev.cc"
|
||||
content { includeGroup("cc.tweaked") }
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Vanilla (i.e. for multi-loader systems)
|
||||
compileOnly("cc.tweaked:cc-tweaked-$mcVersion-common-api:$modVersion")
|
||||
|
||||
// Forge Gradle
|
||||
compileOnly("cc.tweaked:cc-tweaked-$mcVersion-core-api:$modVersion")
|
||||
compileOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge-api:$modVersion"))
|
||||
runtimeOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge:$modVersion"))
|
||||
|
||||
// Fabric Loom
|
||||
modCompileOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric-api:$modVersion")
|
||||
modRuntimeOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric:$modVersion")
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<p>
|
||||
You should also be careful to only use classes within the <code>dan200.computercraft.api</code> package. Non-API
|
||||
classes are subject to change at any point. If you depend on functionality outside the API (or need to mixin to
|
||||
CC:T), please <a href="https://github.com/cc-tweaked/CC-Tweaked/discussions/new/choose">start a discussion</a> to
|
||||
let me know!
|
||||
|
||||
|
||||
<h1>Updating from Minecraft 1.20.1 to 1.21.1</h1>
|
||||
|
||||
<h2>Peripherals</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<p>
|
||||
On NeoForge, the peripheral capability has migrated to NeoForge's new capability system.
|
||||
<code>dan200.computercraft.api.peripheral.PeripheralCapability</code> can be used to register a peripheral.
|
||||
<code>IPeripheralProvider</code> has also been removed, as capabilities can now be used for arbitrary
|
||||
blocks.
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
{@linkplain dan200.computercraft.api.peripheral Read more on registering peripherals}.
|
||||
|
||||
<h2>Turtle and pocket upgrades</h2>
|
||||
Turtle and pocket upgrades have been migrated to use Minecraft's dynamic registries. While upgrades themselves have not
|
||||
changed much, the interface for registering them is dramatically different.
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<p>
|
||||
<code>TurtleUpgradeSerialiser</code> and <code>PocketUpgradeSerialiser</code> have been unified into a
|
||||
single {@link dan200.computercraft.api.upgrades.UpgradeType} class
|
||||
<ul>
|
||||
<li>
|
||||
Replace <code>TurtleUpgradeSerialiser.registryId()</code> with
|
||||
{@link dan200.computercraft.api.turtle.ITurtleUpgrade#typeRegistry()} and <code>PocketUpgradeSerialiser.registryId()</code>
|
||||
with {@link dan200.computercraft.api.pocket.IPocketUpgrade#typeRegistry()}.
|
||||
<li>
|
||||
Replace all other usages of <code>TurtleUpgradeSerialiser</code> and <code>PocketUpgradeSerialiser</code>
|
||||
with {@link dan200.computercraft.api.upgrades.UpgradeType}.
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
Upgrades are now (de)serialised using codecs, rather than manually reading from JSON and encoding/decoding
|
||||
network packets. Instead of subclassing {@link dan200.computercraft.api.upgrades.UpgradeType}, it is recommended
|
||||
you use {@link dan200.computercraft.api.upgrades.UpgradeType#create} to create a new type from a
|
||||
<code>MapCodec</code>.
|
||||
|
||||
<li>
|
||||
Upgrades are no longer aware of their ID, and so cannot compute their adjective. The adjective must now either
|
||||
be hard-coded, or read as part of the codec.
|
||||
|
||||
<li>
|
||||
The upgrade data providers have been removed, in favour of mod-loaders built-in support for dynamic registries.
|
||||
I'm afraid it's probably easier if you delete your existing upgrade datagen code and start from scratch. See
|
||||
<a href="./dan200/computercraft/api/turtle/ITurtleUpgrade.html#datagen">the <code>ITurtleUpgrade</code>
|
||||
documentation for an example</a>.
|
||||
|
||||
<li>
|
||||
Upgrades now store their additional data ({@link dan200.computercraft.api.turtle.ITurtleAccess#getUpgradeData},
|
||||
{@link dan200.computercraft.api.pocket.IPocketAccess#getUpgradeData()}) as an immutable component map, rather
|
||||
than a compound tag.
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
{@linkplain dan200.computercraft.api.turtle.ITurtleUpgrade Read more on registering turtle upgrades}.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,93 @@
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2025 The CC: Tweaked Developers
|
||||
|
||||
SPDX-License-Identifier: MPL-2.0
|
||||
-->
|
||||
|
||||
This is the documentation for CC: Tweaked $modVersion for Minecraft $mcVersion. Documentation for other versions of
|
||||
Minecraft are available on the CC: Tweaked website:
|
||||
|
||||
- [Minecraft 1.20.1](/mc-1.20.x/javadoc/)
|
||||
- [Minecraft 1.21.1](/mc-1.21.x/javadoc/)
|
||||
- [Minecraft 26.3](/mc-26.3/javadoc/)
|
||||
|
||||
# Quick links
|
||||
|
||||
You probably want to start in the following places:
|
||||
|
||||
- [Registering new peripherals][dan200.computercraft.api.peripheral]
|
||||
- [dan200.computercraft.api.lua.LuaFunction] and [dan200.computercraft.api.lua.IArguments] for adding methods to your
|
||||
peripheral or Lua objects.
|
||||
- [Turtle upgrades][dan200.computercraft.api.turtle.ITurtleUpgrade]
|
||||
- [Pocket upgrades][dan200.computercraft.api.pocket.IPocketUpgrade]
|
||||
|
||||
# Using
|
||||
CC: Tweaked is hosted on my maven repo, and so is relatively simple to depend on. You may wish to add a soft (or hard)
|
||||
dependency in your `mods.toml` file, with the appropriate version bounds, to ensure that API functionality you depend on
|
||||
is present.
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
maven {
|
||||
url "https://maven.squiddev.cc"
|
||||
content { includeGroup("cc.tweaked") }
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Vanilla (i.e. for multi-loader systems)
|
||||
compileOnly("cc.tweaked:cc-tweaked-$mcVersion-common-api:$modVersion")
|
||||
|
||||
// Forge Gradle
|
||||
compileOnly("cc.tweaked:cc-tweaked-$mcVersion-core-api:$modVersion")
|
||||
compileOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge-api:$modVersion"))
|
||||
runtimeOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge:$modVersion"))
|
||||
|
||||
// Fabric Loom
|
||||
modCompileOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric-api:$modVersion")
|
||||
modRuntimeOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric:$modVersion")
|
||||
}
|
||||
```
|
||||
|
||||
You should also be careful to only use classes within the `dan200.computercraft.api` package. Non-API classes are
|
||||
subject to change at any point. If you depend on functionality outside the API (or need to mixin to CC:T), please
|
||||
[start a discussion](https://github.com/cc-tweaked/CC-Tweaked/discussions/new/choose) to let me know!
|
||||
# Updating from Minecraft 1.20.1 to 1.21.1
|
||||
|
||||
## Peripherals
|
||||
|
||||
- On NeoForge, the peripheral capability has migrated to NeoForge's new capability system.
|
||||
`dan200.computercraft.api.peripheral.PeripheralCapability` can be used to register a peripheral. `IPeripheralProvider`
|
||||
has also been removed, as capabilities can now be used for arbitrary blocks.
|
||||
|
||||
[Read more on registering peripherals][dan200.computercraft.api.peripheral].
|
||||
|
||||
## Turtle and pocket upgrades
|
||||
|
||||
Turtle and pocket upgrades have been migrated to use Minecraft's dynamic registries. While upgrades themselves have not
|
||||
changed much, the interface for registering them is dramatically different.
|
||||
|
||||
- `TurtleUpgradeSerialiser` and `PocketUpgradeSerialiser` have been unified into a single
|
||||
[dan200.computercraft.api.upgrades.UpgradeType] class.
|
||||
|
||||
- Replace `TurtleUpgradeSerialiser.registryId()` with [dan200.computercraft.api.turtle.ITurtleUpgrade#typeRegistry()]
|
||||
and `PocketUpgradeSerialiser.registryId()` with [dan200.computercraft.api.pocket.IPocketUpgrade#typeRegistry()].
|
||||
- Replace all other usages of `TurtleUpgradeSerialiser` and `PocketUpgradeSerialiser` with
|
||||
[dan200.computercraft.api.upgrades.UpgradeType].
|
||||
|
||||
- Upgrades are now (de)serialised using codecs, rather than manually reading from JSON and encoding/decoding network
|
||||
packets. Instead of subclassing [dan200.computercraft.api.upgrades.UpgradeType], it is recommended you use
|
||||
[dan200.computercraft.api.upgrades.UpgradeType#create] to create a new type from a `MapCodec`.
|
||||
|
||||
- Upgrades are no longer aware of their ID, and so cannot compute their adjective. The adjective must now either be
|
||||
hard-coded, or read as part of the codec.
|
||||
|
||||
- The upgrade data providers have been removed, in favour of mod loader's built-in support for dynamic registries. I'm
|
||||
afraid it's probably easier if you delete your existing upgrade datagen code and start from scratch. See
|
||||
[the `ITurtleUpgrade` documentation for an example](./dan200/computercraft/api/turtle/ITurtleUpgrade.html#datagen).
|
||||
|
||||
- Upgrades now store their additional data ([dan200.computercraft.api.turtle.ITurtleAccess#getUpgradeData],
|
||||
[dan200.computercraft.api.pocket.IPocketAccess#getUpgradeData()]) as an immutable component map, rather than a
|
||||
compound tag.
|
||||
|
||||
[Read more on registering turtle upgrades][dan200.computercraft.api.turtle.ITurtleUpgrade].
|
||||
+18
-27
@@ -10,9 +10,12 @@ import dan200.computercraft.shared.computer.upload.FileSlice;
|
||||
import dan200.computercraft.shared.computer.upload.FileUpload;
|
||||
import dan200.computercraft.shared.config.Config;
|
||||
import dan200.computercraft.shared.network.NetworkMessages;
|
||||
import dan200.computercraft.shared.network.codec.MoreStreamCodecs;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
@@ -35,6 +38,13 @@ public class UploadFileMessage extends ComputerServerMessage {
|
||||
public static final int MAX_FILES = 32;
|
||||
public static final int MAX_FILE_NAME = 128;
|
||||
|
||||
private static final StreamCodec<ByteBuf, List<FileSlice>> FILE_SLICE_STREAM_CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.VAR_INT, FileSlice::fileId,
|
||||
ByteBufCodecs.VAR_INT, FileSlice::offset,
|
||||
MoreStreamCodecs.byteBuffer(MAX_PACKET_SIZE), FileSlice::bytes,
|
||||
FileSlice::new
|
||||
).apply(ByteBufCodecs.list(MAX_FILES));
|
||||
|
||||
static final @VisibleForTesting int FLAG_FIRST = 1;
|
||||
static final @VisibleForTesting int FLAG_LAST = 2;
|
||||
|
||||
@@ -46,6 +56,11 @@ public class UploadFileMessage extends ComputerServerMessage {
|
||||
|
||||
UploadFileMessage(AbstractContainerMenu menu, UUID uuid, int flag, @Nullable List<FileUpload> files, List<FileSlice> slices) {
|
||||
super(menu.containerId);
|
||||
|
||||
if (files != null && files.size() > MAX_FILES) throw new IllegalArgumentException("Too many files");
|
||||
// We expect to have at most one slice per file in a packet.
|
||||
if (slices.size() > MAX_FILES) throw new IllegalArgumentException("Too many file slices");
|
||||
|
||||
this.uuid = uuid;
|
||||
this.flag = flag;
|
||||
this.files = files;
|
||||
@@ -79,21 +94,7 @@ public class UploadFileMessage extends ComputerServerMessage {
|
||||
files = null;
|
||||
}
|
||||
|
||||
var nSlices = buf.readVarInt();
|
||||
var slices = this.slices = new ArrayList<>(nSlices);
|
||||
for (var i = 0; i < nSlices; i++) {
|
||||
int fileId = buf.readUnsignedByte();
|
||||
var offset = buf.readVarInt();
|
||||
|
||||
var size = buf.readUnsignedShort();
|
||||
if (size > MAX_PACKET_SIZE) throw new DecoderException("File is too large");
|
||||
|
||||
var buffer = ByteBuffer.allocateDirect(size);
|
||||
buf.readBytes(buffer);
|
||||
buffer.flip();
|
||||
|
||||
slices.add(new FileSlice(fileId, offset, buffer));
|
||||
}
|
||||
slices = FILE_SLICE_STREAM_CODEC.decode(buf);
|
||||
}
|
||||
|
||||
private void write(FriendlyByteBuf buf) {
|
||||
@@ -111,15 +112,7 @@ public class UploadFileMessage extends ComputerServerMessage {
|
||||
}
|
||||
}
|
||||
|
||||
buf.writeVarInt(slices.size());
|
||||
for (var slice : slices) {
|
||||
buf.writeByte(slice.fileId());
|
||||
buf.writeVarInt(slice.offset());
|
||||
|
||||
var bytes = slice.bytes().duplicate();
|
||||
buf.writeShort(bytes.remaining());
|
||||
buf.writeBytes(bytes);
|
||||
}
|
||||
FILE_SLICE_STREAM_CODEC.encode(buf, slices);
|
||||
}
|
||||
|
||||
public static void send(AbstractContainerMenu container, List<FileUpload> files, Consumer<UploadFileMessage> send) {
|
||||
@@ -132,7 +125,7 @@ public class UploadFileMessage extends ComputerServerMessage {
|
||||
List<FileSlice> slices = new ArrayList<>(files.size());
|
||||
for (var fileId = 0; fileId < files.size(); fileId++) {
|
||||
var file = files.get(fileId);
|
||||
var contents = file.getBytes();
|
||||
var contents = file.getBytes().duplicate();
|
||||
var capacity = contents.limit();
|
||||
|
||||
var currentOffset = 0;
|
||||
@@ -153,8 +146,6 @@ public class UploadFileMessage extends ComputerServerMessage {
|
||||
currentOffset += canWrite;
|
||||
remaining -= canWrite;
|
||||
}
|
||||
|
||||
contents.position(0).limit(capacity);
|
||||
}
|
||||
|
||||
send.accept(first
|
||||
|
||||
+36
-7
@@ -101,9 +101,7 @@ public class TurtleBrain implements TurtleAccessInternal {
|
||||
}
|
||||
|
||||
public void setupComputer(ServerComputer computer) {
|
||||
for (var side : TurtleSide.values()) {
|
||||
computer.setPeripheral(toDirection(side), getPeripheral(side));
|
||||
}
|
||||
for (var side : TurtleSide.values()) applyUpgradePeripheral(computer, toDirection(side), upgrades.get(side));
|
||||
}
|
||||
|
||||
public void update() {
|
||||
@@ -495,18 +493,38 @@ public class TurtleBrain implements TurtleAccessInternal {
|
||||
holder = null;
|
||||
}
|
||||
|
||||
// Create peripheral and update the computer. We *always* create a peripheral, even if the computer is not
|
||||
// active, so that getPeripheral doesn't return null.
|
||||
// Create peripheral and update the computer.
|
||||
if (owner.getLevel() != null && !owner.getLevel().isClientSide) {
|
||||
var peripheral = holder == null ? null : (holder.peripheral = holder.getUpgrade().createPeripheral(this, side));
|
||||
// We *always* create a peripheral, even if the computer is not active, so that getPeripheral doesn't return
|
||||
// null.
|
||||
if (holder != null) holder.getOrCreatePeripheral();
|
||||
|
||||
var computer = owner.getServerComputer();
|
||||
if (computer != null) computer.setPeripheral(toDirection(side), peripheral);
|
||||
if (computer != null) applyUpgradePeripheral(computer, toDirection(side), holder);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an upgrade's peripheral to the computer.
|
||||
*
|
||||
* @param computer The computer to apply the upgrade to.
|
||||
* @param side The side to apply the upgrade to.
|
||||
* @param holder The upgrade holder, or {@code null}.
|
||||
*/
|
||||
private void applyUpgradePeripheral(ServerComputer computer, ComputerSide side, @Nullable UpgradeHolder holder) {
|
||||
if (holder == null) {
|
||||
computer.setPeripheral(side, null);
|
||||
} else {
|
||||
// setPeripheral may do nothing if the peripherals are equal (even if not the same object). We set the
|
||||
// peripheral, then override the holder's with whatever the computer has attached.
|
||||
var peripheral = holder.getOrCreatePeripheral();
|
||||
computer.setPeripheral(side, peripheral);
|
||||
holder.peripheral = computer.getPeripheral(side);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable IPeripheral getPeripheral(TurtleSide side) {
|
||||
var upgrade = upgrades.get(side);
|
||||
@@ -753,6 +771,8 @@ public class TurtleBrain implements TurtleAccessInternal {
|
||||
|
||||
private final class UpgradeHolder extends AbstractUpgradeHolder<ITurtleUpgrade> {
|
||||
private final TurtleSide side;
|
||||
|
||||
private boolean checkedPeripheral;
|
||||
private @Nullable IPeripheral peripheral;
|
||||
|
||||
private UpgradeHolder(TurtleSide side, UpgradeData<ITurtleUpgrade> upgrade) {
|
||||
@@ -775,5 +795,14 @@ public class TurtleBrain implements TurtleAccessInternal {
|
||||
protected void remove() {
|
||||
setUpgrade(side, null);
|
||||
}
|
||||
|
||||
private @Nullable IPeripheral getOrCreatePeripheral() {
|
||||
var peripheral = this.peripheral;
|
||||
if (!checkedPeripheral) {
|
||||
peripheral = this.peripheral = getUpgrade().createPeripheral(TurtleBrain.this, side);
|
||||
checkedPeripheral = true;
|
||||
}
|
||||
return peripheral;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -53,6 +53,10 @@ public final class TurtleStorage extends AbstractTurtleUpgrade.StackAware {
|
||||
* {@link #pullItems(Optional, Optional, Optional)} and {@link #pushItems(int, Optional, Optional)} transfer to/from
|
||||
* the turtle's inventory, rather than taking an inventory name.
|
||||
*
|
||||
* > [!INFO]
|
||||
* > This upgrade and peripheral is currently experimental. It is only enabled with the
|
||||
* > `computercraft/turtle_storage` datapack, and methods are subject to change.
|
||||
*
|
||||
* @cc.module turtle_storage
|
||||
* @cc.since 1.121.0
|
||||
*/
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
"commands.computercraft.view.desc": "Bir bilgisayarın terminalini aç ve uzaktan kontrole izin ver. Bununla Turtle envanterlerine erişilemez. Bilgisayarın oluşum kimliğini (örn. 123) ya da bilgisayar kimliğini (örn. #123) belirtebilirsiniz.",
|
||||
"commands.computercraft.view.not_player": "Oyuncu olmayanlar için terminal açılamaz",
|
||||
"commands.computercraft.view.synopsis": "Bir bilgisayarın terminalini görüntüle.",
|
||||
"dataPack.turtle_storage.description": "Turtle depolama yükseltmeleri",
|
||||
"gui.computercraft.config.command_require_creative": "Komut bilgisayarları yaratıcı modu gerektirir",
|
||||
"gui.computercraft.config.command_require_creative.tooltip": "Oyuncuların komut bilgisayarıyla etkileşime girebilmesi için yaratıcı modda\nve yetkili olmalarını gerektir. Bu, vanilla Komut blokları için varsayılan davranıştır.",
|
||||
"gui.computercraft.config.computer_space_limit": "Bilgisayar alan sınırı (bayt)",
|
||||
@@ -226,6 +227,7 @@
|
||||
"tracking_field.computercraft.websocket_incoming.name": "Websocket gelen",
|
||||
"tracking_field.computercraft.websocket_outgoing.name": "Websocket giden",
|
||||
"upgrade.computercraft.speaker.adjective": "Sesli",
|
||||
"upgrade.computercraft.storage.adjective": "Depolama",
|
||||
"upgrade.computercraft.wireless_modem_advanced.adjective": "Enderli",
|
||||
"upgrade.computercraft.wireless_modem_normal.adjective": "Kablosuz",
|
||||
"upgrade.minecraft.crafting_table.adjective": "Üretken",
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
"commands.computercraft.view.desc": "打开计算机的终端,允许远程控制计算机。这不提供对海龟背包的访问。你可以指定计算机的实例id(例如:123)或计算机id(例如:#123)。",
|
||||
"commands.computercraft.view.not_player": "无法为非玩家打开终端",
|
||||
"commands.computercraft.view.synopsis": "查看计算机的终端。",
|
||||
"dataPack.turtle_storage.description": "海龟存储升级",
|
||||
"gui.computercraft.config.command_require_creative": "命令计算机需要创造模式",
|
||||
"gui.computercraft.config.command_require_creative.tooltip": "玩家需要处于创造模式并为管理员才能与命令计算机交互。\n这是原版命令方块的默认行为。",
|
||||
"gui.computercraft.config.computer_space_limit": "计算机空间限制(字节)",
|
||||
@@ -226,6 +227,7 @@
|
||||
"tracking_field.computercraft.websocket_incoming.name": "Websocket传入",
|
||||
"tracking_field.computercraft.websocket_outgoing.name": "Websocket传出",
|
||||
"upgrade.computercraft.speaker.adjective": "嘈杂",
|
||||
"upgrade.computercraft.storage.adjective": "存储",
|
||||
"upgrade.computercraft.wireless_modem_advanced.adjective": "末影",
|
||||
"upgrade.computercraft.wireless_modem_normal.adjective": "无线",
|
||||
"upgrade.minecraft.crafting_table.adjective": "合成",
|
||||
|
||||
+21
-1
@@ -15,6 +15,7 @@ import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
/**
|
||||
* Bootstrap Minecraft before running these tests.
|
||||
@@ -24,14 +25,33 @@ import java.lang.annotation.Target;
|
||||
@ExtendWith(WithMinecraft.Setup.class)
|
||||
public @interface WithMinecraft {
|
||||
class Setup implements Extension, BeforeAllCallback {
|
||||
private static boolean setup = false;
|
||||
|
||||
@Override
|
||||
public void beforeAll(ExtensionContext context) {
|
||||
bootstrap();
|
||||
}
|
||||
|
||||
public static void bootstrap() {
|
||||
public static synchronized void bootstrap() {
|
||||
if (setup) return;
|
||||
setup = true;
|
||||
|
||||
var hooks = ServiceLoader.load(SetupHook.class, SetupHook.class.getClassLoader())
|
||||
.stream().map(ServiceLoader.Provider::get).toList();
|
||||
|
||||
for (var hook : hooks) hook.beforeBootstrap();
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
for (var hook : hooks) hook.afterBootstrap();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional hooks to run as part of bootstrap.
|
||||
*/
|
||||
interface SetupHook {
|
||||
void beforeBootstrap();
|
||||
|
||||
void afterBootstrap();
|
||||
}
|
||||
}
|
||||
@@ -67,9 +67,6 @@ class Recipe_Test {
|
||||
val pocketUpgrades = registries.lookupOrThrow(IPocketUpgrade.REGISTRY)
|
||||
val generator = UpgradeRecipeGenerator({ it }, registries)
|
||||
|
||||
println("Got packs => " + context.level.server.packRepository.selectedIds)
|
||||
println("Got items => " + turtleUpgrades.listElementIds().toList())
|
||||
|
||||
fun checkUsage(message: String, size: Int, item: ItemStack) {
|
||||
val recipes = generator.findRecipesWithInput(item)
|
||||
assertEquals(size, recipes.size, message)
|
||||
|
||||
@@ -952,6 +952,20 @@ class Turtle_Test {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert we can push and pull items from a shulker box.
|
||||
*/
|
||||
@GameTest(required = false) // FIXME: This is broken on Fabric due to getCapacity() returning 1.
|
||||
fun Shulker_push_pull(helper: GameTestHelper) = helper.sequence {
|
||||
thenOnComputer {
|
||||
callPeripheral("left", "pullItems").assertArrayEquals(32)
|
||||
callPeripheral("left", "list")
|
||||
.assertArrayEquals(mapOf(1 to mapOf("name" to "minecraft:dirt", "count" to 32)))
|
||||
callPeripheral("left", "pushItems", 1).assertArrayEquals(32)
|
||||
callPeripheral("left", "list").assertArrayEquals(emptyMap<Any, Any>())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a turtle can break a block that explodes, causing the turtle itself to explode.
|
||||
*
|
||||
|
||||
Generated
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
DataVersion: 3465,
|
||||
size: [5, 5, 5],
|
||||
data: [
|
||||
{pos: [0, 0, 0], state: "minecraft:polished_andesite"},
|
||||
{pos: [0, 0, 1], state: "minecraft:polished_andesite"},
|
||||
{pos: [0, 0, 2], state: "minecraft:polished_andesite"},
|
||||
{pos: [0, 0, 3], state: "minecraft:polished_andesite"},
|
||||
{pos: [0, 0, 4], state: "minecraft:polished_andesite"},
|
||||
{pos: [1, 0, 0], state: "minecraft:polished_andesite"},
|
||||
{pos: [1, 0, 1], state: "minecraft:polished_andesite"},
|
||||
{pos: [1, 0, 2], state: "minecraft:polished_andesite"},
|
||||
{pos: [1, 0, 3], state: "minecraft:polished_andesite"},
|
||||
{pos: [1, 0, 4], state: "minecraft:polished_andesite"},
|
||||
{pos: [2, 0, 0], state: "minecraft:polished_andesite"},
|
||||
{pos: [2, 0, 1], state: "minecraft:polished_andesite"},
|
||||
{pos: [2, 0, 2], state: "minecraft:polished_andesite"},
|
||||
{pos: [2, 0, 3], state: "minecraft:polished_andesite"},
|
||||
{pos: [2, 0, 4], state: "minecraft:polished_andesite"},
|
||||
{pos: [3, 0, 0], state: "minecraft:polished_andesite"},
|
||||
{pos: [3, 0, 1], state: "minecraft:polished_andesite"},
|
||||
{pos: [3, 0, 2], state: "minecraft:polished_andesite"},
|
||||
{pos: [3, 0, 3], state: "minecraft:polished_andesite"},
|
||||
{pos: [3, 0, 4], state: "minecraft:polished_andesite"},
|
||||
{pos: [4, 0, 0], state: "minecraft:polished_andesite"},
|
||||
{pos: [4, 0, 1], state: "minecraft:polished_andesite"},
|
||||
{pos: [4, 0, 2], state: "minecraft:polished_andesite"},
|
||||
{pos: [4, 0, 3], state: "minecraft:polished_andesite"},
|
||||
{pos: [4, 0, 4], state: "minecraft:polished_andesite"},
|
||||
{pos: [2, 1, 2], state: "computercraft:turtle_normal{facing:south,waterlogged:false}", nbt: {ComputerId: 1, Fuel: 0, Items: [{Count: 32b, Slot: 0b, id: "minecraft:dirt"}], Label: "turtle_test.shulker_push_pull", LeftUpgrade: "computercraft:shulker", LeftUpgradeItem: {Count: 1b, id: "minecraft:shulker_box"}, On: 1b, Owner: {LowerId: -8206256985233105631L, Name: "Player889", UpperId: -6771803214216546387L}, Slot: 0, id: "computercraft:turtle_normal"}}
|
||||
],
|
||||
entities: [],
|
||||
palette: [
|
||||
"minecraft:polished_andesite",
|
||||
"computercraft:turtle_normal{facing:south,waterlogged:false}"
|
||||
]
|
||||
}
|
||||
@@ -318,7 +318,8 @@ public class FSAPI implements ILuaAPI {
|
||||
* <p>
|
||||
* The mode may also have a "b" at the end, which opens the file in "binary
|
||||
* mode". This changes {@link ReadHandle#read(Optional)} and {@link WriteHandle#write(IArguments)}
|
||||
* to read/write single bytes as numbers rather than strings.
|
||||
* to read/write single bytes as numbers rather than strings. This option exists for backwards compatibility with
|
||||
* older programs, and is not recommended with new code.
|
||||
*
|
||||
* @param path The path to the file to open.
|
||||
* @param mode The mode to open the file with.
|
||||
|
||||
+49
-6
@@ -10,10 +10,8 @@ import dan200.computercraft.core.apis.http.options.AddressPredicate.HostRange;
|
||||
import dan200.computercraft.core.apis.http.options.AddressPredicate.PrivatePattern;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -73,8 +71,7 @@ public final class AddressRule {
|
||||
var address = socketAddress.getAddress();
|
||||
if (address == null) throw new IllegalStateException("Socket address must be resolved");
|
||||
|
||||
var ipv4Address = address instanceof Inet6Address inet6 && InetAddresses.is6to4Address(inet6)
|
||||
? InetAddresses.get6to4IPv4Address(inet6) : null;
|
||||
var ipv4Address = address instanceof Inet6Address inet6 ? getEmbeddedV4Address(inet6) : null;
|
||||
|
||||
for (var rule : rules) {
|
||||
if (!rule.matches(domain, port, address, ipv4Address)) continue;
|
||||
@@ -83,4 +80,50 @@ public final class AddressRule {
|
||||
|
||||
return options.toOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract any IPv4 address embedded inside an IPv6 address. This includes:
|
||||
* <ul>
|
||||
* <li>{@linkplain #isIPv4MappedAddress(Inet6Address) IPv4-mapped addresses} ({@code ::ffff:1.2.3.4})</li>
|
||||
* <li>{@linkplain InetAddresses#isCompatIPv4Address(Inet6Address) IPv4-compatibility addresses} ({@code ::1.2.3.4})</li>
|
||||
* <li>{@linkplain InetAddresses#is6to4Address(Inet6Address) 6-to-4 addresses} ({@code 2002:1.2.3.4}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* This also extracts {@linkplain InetAddresses#isTeredoAddress(Inet6Address) Teredo addresses}, and does
|
||||
* <em>not</em> extract NAT64. However, these are both blocked by {@link AddressPredicate.PrivatePattern} by
|
||||
* default.
|
||||
*
|
||||
* @param address The IPv6 address to extract from.
|
||||
* @return The IPv4 address or {@code null}
|
||||
*/
|
||||
private static @Nullable Inet4Address getEmbeddedV4Address(Inet6Address address) {
|
||||
if (InetAddresses.hasEmbeddedIPv4ClientAddress(address)) {
|
||||
return InetAddresses.getEmbeddedIPv4ClientAddress(address);
|
||||
}
|
||||
|
||||
if (isIPv4MappedAddress(address)) {
|
||||
try {
|
||||
return (Inet4Address) InetAddress.getByAddress(Arrays.copyOfRange(address.getAddress(), 12, 16));
|
||||
} catch (UnknownHostException e) {
|
||||
throw new IllegalStateException("getByAddress should not fail", e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an IP address is an IPv4-mapped address (of the form {@code ::ffff:aabb:ccdd}).
|
||||
*
|
||||
* @param address The IPv6 address.
|
||||
* @return Whether this is an IPv4-mapped address.
|
||||
* @see InetAddresses#isMappedIPv4Address(String)
|
||||
*/
|
||||
private static boolean isIPv4MappedAddress(Inet6Address address) {
|
||||
var bytes = address.getAddress();
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (bytes[i] != 0) return false;
|
||||
}
|
||||
return bytes[10] == (byte) 0xff && bytes[11] == (byte) 0xff;
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,9 @@ end
|
||||
@tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||
of this request.
|
||||
@tparam[opt=false] boolean binary Whether the [response handle][`fs.ReadHandle`]
|
||||
should be opened in binary mode.
|
||||
should be opened in binary mode, meaning [`read()`][`fs.ReadHandle.read`] will
|
||||
return a number rather than a string. This option exists for backwards
|
||||
compatibility with older programs, and is not recommended with new code.
|
||||
|
||||
@tparam[2] {
|
||||
url = string, headers? = { [string] = string },
|
||||
@@ -120,7 +122,9 @@ end
|
||||
@tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||
of this request.
|
||||
@tparam[opt=false] boolean binary Whether the [response handle][`fs.ReadHandle`]
|
||||
should be opened in binary mode.
|
||||
should be opened in binary mode, meaning [`read()`][`fs.ReadHandle.read`] will
|
||||
return a number rather than a string. This option exists for backwards
|
||||
compatibility with older programs, and is not recommended with new code.
|
||||
|
||||
@tparam[2] {
|
||||
url = string, body? = string, headers? = { [string] = string },
|
||||
@@ -170,7 +174,9 @@ request. If specified, a `POST` request will be made instead.
|
||||
@tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||
of this request.
|
||||
@tparam[opt=false] boolean binary Whether the [response handle][`fs.ReadHandle`]
|
||||
should be opened in binary mode.
|
||||
should be opened in binary mode, meaning [`read()`][`fs.ReadHandle.read`] will
|
||||
return a number rather than a string. This option exists for backwards
|
||||
compatibility with older programs, and is not recommended with new code.
|
||||
|
||||
@tparam[2] {
|
||||
url = string, body? = string, headers? = { [string] = string },
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# New features in CC: Tweaked 1.121.0
|
||||
|
||||
* Support arbitrary HTTP verbs in `http.request`.
|
||||
* Allow wrapping non-slotted Fabric inventories as peripherals.
|
||||
* Rewrite turtle/pocket computer upgrade API. Upgrades now preserve the item they were equipped with.
|
||||
|
||||
Several bug fixes:
|
||||
* Fix multishell not culling after changing focus.
|
||||
* Fix `turtle.place()` using items if Forge event was cancelled.
|
||||
* Fix computers not refreshing redstone output on world load.
|
||||
* Send websocket close messages on `Websocket.close()` rather than terminating the connection.
|
||||
* Fix various compatibility issues with SNBT parsing in `textutils.unserialiseJSON`.
|
||||
* Apply HTTP rules to IPv4-mapped addresses.
|
||||
|
||||
# New features in CC: Tweaked 1.120.2
|
||||
|
||||
Several bug fixes:
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
New features in CC: Tweaked 1.120.2
|
||||
New features in CC: Tweaked 1.121.0
|
||||
|
||||
* Support arbitrary HTTP verbs in `http.request`.
|
||||
* Allow wrapping non-slotted Fabric inventories as peripherals.
|
||||
* Rewrite turtle/pocket computer upgrade API. Upgrades now preserve the item they were equipped with.
|
||||
|
||||
Several bug fixes:
|
||||
* Fix shell crashing if `read()` doesn't yield.
|
||||
* Fix pocket/printout lecterns not rendering when at the very bottom of the screen.
|
||||
* Several documentation fixes. (tomodachi94)
|
||||
* Fix multishell not culling after changing focus.
|
||||
* Fix `turtle.place()` using items if Forge event was cancelled.
|
||||
* Fix computers not refreshing redstone output on world load.
|
||||
* Send websocket close messages on `Websocket.close()` rather than terminating the connection.
|
||||
* Fix various compatibility issues with SNBT parsing in `textutils.unserialiseJSON`.
|
||||
* Apply HTTP rules to IPv4-mapped addresses.
|
||||
|
||||
Type "help changelog" to see the full version history.
|
||||
@@ -42,6 +42,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -187,27 +188,47 @@ public class ComputerTestDelegate {
|
||||
|
||||
private static class DynamicNodeBuilder {
|
||||
private final String name;
|
||||
private final URI uri;
|
||||
private final @Nullable URI uri;
|
||||
private final Map<String, DynamicNodeBuilder> children;
|
||||
private final Executable executor;
|
||||
|
||||
DynamicNodeBuilder(String name, String path) {
|
||||
DynamicNodeBuilder(String name, @Nullable String path) {
|
||||
this.name = name;
|
||||
this.uri = getUri(path);
|
||||
this.children = new HashMap<>();
|
||||
this.executor = null;
|
||||
}
|
||||
|
||||
DynamicNodeBuilder(String name, String path, Executable executor) {
|
||||
DynamicNodeBuilder(String name, @Nullable String path, Executable executor) {
|
||||
this.name = name;
|
||||
this.uri = getUri(path);
|
||||
this.children = Map.of();
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
private static URI getUri(String path) {
|
||||
// Unfortunately ?line=xxx doesn't appear to work with IntelliJ, so don't worry about getting it working.
|
||||
return path == null ? null : new File("src/test/resources" + path.substring(0, path.indexOf(':'))).toURI();
|
||||
/**
|
||||
* Decode our Lua location ({@code @path:line:col} into a {@code UriSource}-compatible URI.
|
||||
*
|
||||
* @param path The path to parse.
|
||||
* @return The URI, or {@code null} if not present.
|
||||
*/
|
||||
private static @Nullable URI getUri(@Nullable String path) {
|
||||
if (path == null || !path.startsWith("@")) return null;
|
||||
|
||||
var parts = Splitter.on(':').splitToList(path);
|
||||
if (parts.size() != 3) {
|
||||
LOG.warn("Invalid path '{}'", path);
|
||||
return null;
|
||||
}
|
||||
|
||||
var uri = new File("src/test/resources" + parts.get(0).substring(1)).toURI();
|
||||
try {
|
||||
return new URI(
|
||||
uri.getScheme(), uri.getAuthority(), uri.getPath(), "line=" + parts.get(1) + "&column=" + parts.get(2), null
|
||||
);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalStateException("Invalid URI", e);
|
||||
}
|
||||
}
|
||||
|
||||
DynamicNodeBuilder get(String name) {
|
||||
|
||||
+7
-1
@@ -5,6 +5,7 @@
|
||||
package dan200.computercraft.core.apis.http.options;
|
||||
|
||||
import dan200.computercraft.core.apis.http.NettyHttp;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
@@ -36,6 +37,9 @@ public class AddressRuleTest {
|
||||
"10.0.0.1",
|
||||
// IPv4-mapped address. This is converted to IPv4 by getByName.
|
||||
"0:0:0:0:0:ffff:c0a8:172",
|
||||
// However, results which are resolved via DNS name bypass this, as they're constructed via JNI:
|
||||
// https://github.com/openjdk/jdk/blob/6c8f70f22e1621f7cd32a03150bee0f602e1a699/src/java.base/windows/native/libnet/Inet6AddressImpl.c#L204-L224
|
||||
"0.0.0.0.0.ffff.7f00.0001.backname.io",
|
||||
// 6to4 address
|
||||
"2002:7f00:0001::", // 127.0.0.1
|
||||
// Multicast
|
||||
@@ -69,6 +73,8 @@ public class AddressRuleTest {
|
||||
}
|
||||
|
||||
private Options apply(Iterable<AddressRule> rules, String host, int port) {
|
||||
return AddressRule.apply(rules, host, new InetSocketAddress(host, port));
|
||||
var address = new InetSocketAddress(host, port);
|
||||
Assumptions.assumeTrue(address.getAddress() != null, "Address is not resolved");
|
||||
return AddressRule.apply(rules, host, address);
|
||||
}
|
||||
}
|
||||
@@ -438,7 +438,9 @@ local tests_locked = false
|
||||
local test_list = {}
|
||||
local test_map, test_count = {}, 0
|
||||
|
||||
local function format_loc(info) return ("%s:%d"):format(info.short_src, info.currentline) end
|
||||
local function format_loc(info)
|
||||
return ("%s:%d:%d"):format(info.source, info.currentline, info.currentcolumn)
|
||||
end
|
||||
|
||||
--- Add a new test to our queue.
|
||||
--
|
||||
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026 The CC: Tweaked Developers
|
||||
//
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package dan200.computercraft.shared.platform;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.mojang.datafixers.util.Unit;
|
||||
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
|
||||
import net.fabricmc.fabric.api.transfer.v1.item.base.SingleStackStorage;
|
||||
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
|
||||
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage;
|
||||
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
|
||||
import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ItemContainerContents;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* {@link Storage} implementation for shulker boxes in item form.
|
||||
*/
|
||||
final class ShulkerItemStorage extends BasicSlottedStorage {
|
||||
private final ItemStack stack;
|
||||
private final NonNullList<ItemStack> items;
|
||||
private final @Nullable SlotImpl[] slots;
|
||||
private final SnapshotParticipantImpl snapshotParticipant = new SnapshotParticipantImpl();
|
||||
|
||||
ShulkerItemStorage(ItemStack stack, int size) {
|
||||
this.stack = stack;
|
||||
|
||||
var contents = stack.getOrDefault(DataComponents.CONTAINER, ItemContainerContents.EMPTY);
|
||||
var trueSize = Ints.saturatedCast(Math.max(contents.stream().count(), size));
|
||||
items = NonNullList.withSize(trueSize, ItemStack.EMPTY);
|
||||
contents.copyInto(items);
|
||||
|
||||
slots = new SlotImpl[trueSize];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleSlotStorage<ItemVariant> getSlot(int slot) {
|
||||
var slotInfo = slots[slot];
|
||||
return slotInfo == null ? slots[slot] = new SlotImpl(slot) : slotInfo;
|
||||
}
|
||||
|
||||
private final class SlotImpl extends SingleStackStorage {
|
||||
private final int slot;
|
||||
|
||||
private SlotImpl(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getStack() {
|
||||
return items.get(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setStack(ItemStack stack) {
|
||||
items.set(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canInsert(ItemVariant itemVariant) {
|
||||
return itemVariant.getItem().canFitInsideContainerItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSnapshots(TransactionContext transaction) {
|
||||
super.updateSnapshots(transaction);
|
||||
snapshotParticipant.updateSnapshots(transaction);
|
||||
}
|
||||
}
|
||||
|
||||
private final class SnapshotParticipantImpl extends SnapshotParticipant<Unit> {
|
||||
@Override
|
||||
protected Unit createSnapshot() {
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readSnapshot(Unit snapshot) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinalCommit() {
|
||||
super.onFinalCommit();
|
||||
stack.set(DataComponents.CONTAINER, ItemContainerContents.fromItems(items));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* Registers textures and models for items.
|
||||
*/
|
||||
@EventBusSubscriber(modid = ComputerCraftAPI.MOD_ID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
|
||||
@EventBusSubscriber(modid = ComputerCraftAPI.MOD_ID, value = Dist.CLIENT)
|
||||
public final class ForgeClientRegistry {
|
||||
private static final Object lock = new Object();
|
||||
private static boolean gatheredModellers = false;
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||
@EventBusSubscriber
|
||||
public class ForgeDataProviders {
|
||||
@SubscribeEvent
|
||||
public static void gather(GatherDataEvent event) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.neoforged.fml.common.EventBusSubscriber;
|
||||
/**
|
||||
* The client-side entry point for the Forge version of our example mod.
|
||||
*/
|
||||
@EventBusSubscriber(modid = ExampleMod.MOD_ID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
|
||||
@EventBusSubscriber(modid = ExampleMod.MOD_ID, value = Dist.CLIENT)
|
||||
public class ForgeExampleModClient {
|
||||
// @start region=turtle_modellers
|
||||
@SubscribeEvent
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
/**
|
||||
* Data generators for the Forge version of our example mod.
|
||||
*/
|
||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||
@EventBusSubscriber
|
||||
public class ForgeExampleModDataGenerator {
|
||||
@SubscribeEvent
|
||||
public static void gather(GatherDataEvent event) {
|
||||
|
||||
@@ -75,7 +75,7 @@ import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@Mod(ComputerCraftAPI.MOD_ID)
|
||||
@EventBusSubscriber(modid = ComputerCraftAPI.MOD_ID, bus = EventBusSubscriber.Bus.MOD)
|
||||
@EventBusSubscriber(modid = ComputerCraftAPI.MOD_ID)
|
||||
public final class ComputerCraft {
|
||||
private static @Nullable IEventBus eventBus;
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// SPDX-FileCopyrightText: 2025 The CC: Tweaked Developers
|
||||
//
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package dan200.computercraft.test.shared;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.neoforged.fml.loading.LoadingModList;
|
||||
import net.neoforged.neoforge.common.CommonHooks;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Ensures NeoForge is configured as part of the Minecraft's bootstrap.
|
||||
*/
|
||||
@AutoService(WithMinecraft.SetupHook.class)
|
||||
public final class NeoSetupHook implements WithMinecraft.SetupHook {
|
||||
@Override
|
||||
public void beforeBootstrap() {
|
||||
// Bits of Minecraft depend on the loader being present. Do some nasty things to inject it.
|
||||
// TODO: Switch to using NF's JUnit support instead.
|
||||
LoadingModList.of(List.of(), List.of(), List.of(), List.of(), Map.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterBootstrap() {
|
||||
try {
|
||||
// Allow HolderSet.emptyNamed as a component, as tags have not been loaded. Yes, this is horrible.
|
||||
CommonHooks.markComponentClassAsValid(HolderSet.class.getClassLoader().loadClass(HolderSet.class.getName() + "$1"));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user