Skip to content

Commit 598fc4a

Browse files
committed
Merge branch 'mc-1.20.x' into mc-1.21.x
2 parents 3acb231 + dd7e8fc commit 598fc4a

File tree

26 files changed

+215
-22
lines changed

26 files changed

+215
-22
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See https://pre-commit.com/hooks.html for more hooks
77
repos:
88
- repo: https://github.com/pre-commit/pre-commit-hooks
9-
rev: v4.4.0
9+
rev: v5.0.0
1010
hooks:
1111
- id: trailing-whitespace
1212
- id: end-of-file-fixer

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ neogradle.subsystems.conventions.runs.enabled=false
1212

1313
# Mod properties
1414
isUnstable=true
15-
modVersion=1.115.0
15+
modVersion=1.115.1
1616

1717
# Minecraft properties: We want to configure this here so we can read it in settings.gradle
1818
mcVersion=1.21.1

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ rei = "16.0.729"
4747
sodium-fabric = "mc1.21-0.6.0-beta.1-fabric"
4848
sodium-forge = "mc1.21-0.6.0-beta.1-neoforge"
4949
mixinExtra = "0.3.5"
50-
create-forge = "0.5.1.f-33"
50+
create-forge = "6.0.0-6"
5151
create-fabric = "0.5.1-f-build.1467+mc1.20.1"
5252

5353
# Testing
@@ -105,7 +105,7 @@ slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
105105

106106
# Minecraft mods
107107
create-fabric = { module = "com.simibubi.create:create-fabric-1.20.1", version.ref = "create-fabric" }
108-
create-forge = { module = "com.simibubi.create:create-1.20.1", version.ref = "create-forge" }
108+
create-forge = { module = "com.simibubi.create:create-1.21.1", version.ref = "create-forge" }
109109
emi = { module = "dev.emi:emi-xplat-mojmap", version.ref = "emi" }
110110
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" }
111111
fabric-junit = { module = "net.fabricmc:fabric-loader-junit", version.ref = "fabric-loader" }

projects/common-api/src/main/java/dan200/computercraft/api/detail/DetailProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
* @param <T> The type of object that this provider can provide details for.
1616
* @see DetailRegistry
17+
* @see dan200.computercraft.api.detail An overview of the detail system.
1718
*/
1819
@FunctionalInterface
1920
public interface DetailProvider<T> {

projects/common-api/src/main/java/dan200/computercraft/api/detail/DetailRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* also in this package.
1818
*
1919
* @param <T> The type of object that this registry provides details for.
20+
* @see dan200.computercraft.api.detail An overview of the detail system.
2021
*/
2122
@ApiStatus.NonExtendable
2223
public interface DetailRegistry<T> {

projects/common-api/src/main/java/dan200/computercraft/api/detail/VanillaDetailRegistries.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class VanillaDetailRegistries {
1717
* <p>
1818
* This instance's {@link DetailRegistry#getBasicDetails(Object)} is thread safe (assuming the stack is immutable)
1919
* and may be called from the computer thread.
20+
* <p>
21+
* This does not have special handling for {@linkplain ItemStack#isEmpty() empty item stacks}, and so the returned
22+
* details will be an empty stack of air. Callers should generally check for empty stacks before calling this.
2023
*/
2124
public static final DetailRegistry<ItemStack> ITEM_STACK = ComputerCraftAPIService.get().getItemStackDetailRegistry();
2225

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-FileCopyrightText: 2025 The CC: Tweaked Developers
2+
//
3+
// SPDX-License-Identifier: MPL-2.0
4+
5+
/**
6+
* The detail system provides a standard way for mods to return descriptions of common game objects, such as blocks or
7+
* items, as well as registering additional detail to be included in those descriptions.
8+
* <p>
9+
* For instance, the built-in {@code turtle.getItemDetail()} method uses
10+
* {@linkplain dan200.computercraft.api.detail.VanillaDetailRegistries#ITEM_STACK in order to provide information about}
11+
* the selected item:
12+
*
13+
* <pre class="language language-lua">{@code
14+
* local item = turtle.getItemDetail(nil, true)
15+
* --[[
16+
* item = {
17+
* name = "minecraft:wheat",
18+
* displayName = "Wheat",
19+
* count = 1,
20+
* maxCount = 64,
21+
* tags = {},
22+
* }
23+
* ]]
24+
* }</pre>
25+
*
26+
* <h2>Built-in detail providers</h2>
27+
* While you can define your own detail providers (perhaps for types from your own mod), CC comes with several built-in
28+
* detail registries for vanilla and mod-loader objects:
29+
*
30+
* <ul>
31+
* <li>{@link dan200.computercraft.api.detail.VanillaDetailRegistries}, for vanilla objects</li>
32+
* <li>{@code dan200.computercraft.api.detail.ForgeDetailRegistries} for Forge-specific objects</li>
33+
* <li>{@code dan200.computercraft.api.detail.FabricDetailRegistries} for Fabric-specific objects</li>
34+
* </ul>
35+
*
36+
* <h2>Example: Returning details from methods</h2>
37+
* Here we define a {@code getHeldItem()} method for pocket computers which finds the currently held item of the player
38+
* and returns it to the user using {@link dan200.computercraft.api.detail.VanillaDetailRegistries#ITEM_STACK} and
39+
* {@link dan200.computercraft.api.detail.DetailRegistry#getDetails(java.lang.Object)}.
40+
*
41+
* {@snippet class=com.example.examplemod.ExamplePocketPeripheral region=details}
42+
*
43+
* <h2>Example: Registering custom detail registries</h2>
44+
* Here we define a new detail provider for items that includes the nutrition and saturation values in the returned object.
45+
*
46+
* {@snippet class=com.example.examplemod.ExampleMod region=details}
47+
*/
48+
package dan200.computercraft.api.detail;

projects/common/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ dependencies {
3939
compileOnly(libs.mixin)
4040
compileOnly(libs.mixinExtra)
4141
compileOnly(libs.bundles.externalMods.common)
42-
compileOnly(variantOf(libs.create.forge) { classifier("slim") }) { isTransitive = false }
4342
clientCompileOnly(variantOf(libs.emi) { classifier("api") })
4443

4544
annotationProcessorEverywhere(libs.autoService)

projects/common/src/client/java/dan200/computercraft/client/model/LecternPocketModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class LecternPocketModel {
4545
public static final float TERM_HEIGHT = 14.0f / 32.0f;
4646

4747
// The size of the texture. The texture is 36x36, but is at 2x resolution.
48-
private static final int TEXTURE_WIDTH = 36 / 2;
49-
private static final int TEXTURE_HEIGHT = 36 / 2;
48+
private static final int TEXTURE_WIDTH = 48 / 2;
49+
private static final int TEXTURE_HEIGHT = 48 / 2;
5050

5151
private final ModelPart root;
5252

projects/common/src/client/java/dan200/computercraft/client/sound/SpeakerInstance.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,38 @@ public class SpeakerInstance {
2424
SpeakerInstance() {
2525
}
2626

27-
private void pushAudio(EncodedAudio buffer) {
27+
private void pushAudio(EncodedAudio buffer, float volume) {
2828
var sound = this.sound;
2929

3030
var stream = currentStream;
3131
if (stream == null) stream = currentStream = new DfpwmStream();
3232
var exhausted = stream.isEmpty();
3333
stream.push(buffer);
3434

35-
// If we've got nothing left in the buffer, enqueue an additional one just in case.
36-
if (exhausted && sound != null && sound.stream == stream && stream.channel != null && stream.executor != null) {
35+
if (sound == null) return;
36+
37+
var volumeChanged = sound.setVolume(volume);
38+
39+
if ((exhausted || volumeChanged) && sound.stream == stream && stream.channel != null && stream.executor != null) {
3740
var actualStream = sound.stream;
3841
stream.executor.execute(() -> {
3942
var channel = Nullability.assertNonNull(actualStream.channel);
40-
if (!channel.stopped()) channel.pumpBuffers(1);
43+
if (channel.stopped()) return;
44+
45+
// If we've got nothing left in the buffer, enqueue an additional one just in case.
46+
if (exhausted) channel.pumpBuffers(1);
47+
48+
// Update the attenuation if the volume has changed: SoundEngine.tickNonPaused updates the volume
49+
// itself, but leaves the attenuation unchanged. We mirror the logic of SoundEngine.play here.
50+
if (volumeChanged) {
51+
channel.linearAttenuation(Math.max(volume, 1) * sound.getSound().getAttenuationDistance());
52+
}
4153
});
4254
}
4355
}
4456

4557
public void playAudio(SpeakerPosition position, float volume, EncodedAudio buffer) {
46-
pushAudio(buffer);
58+
pushAudio(buffer, volume);
4759

4860
var soundManager = Minecraft.getInstance().getSoundManager();
4961

0 commit comments

Comments
 (0)