diff --git a/.circleci/config.yml b/.circleci/config.yml index c930e6163..e4ad193db 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ jobs: build: docker: # specify the version you desire here - - image: openjdk:17-jdk-slim + - image: openjdk:21-jdk-slim resource_class: large working_directory: ~/repo diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index b597c3c8a..b420a674f 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -6,9 +6,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.gradle/caches @@ -18,16 +18,16 @@ jobs: restore-keys: | caches- - name: JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '17' + java-version: '21' - name: Gradle - uses: gradle/wrapper-validation-action@v1 + uses: gradle/actions/wrapper-validation@v3 - name: Build run: ./gradlew --no-daemon build - name: Upload-Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: jar path: build/libs/Galaxy.jar @@ -45,22 +45,22 @@ jobs: shell: bash run: echo IMAGE_TAG=$([ "$GITHUB_REF" = "refs/heads/master" ] && echo "latest" || ([ "$GITHUB_EVENT_NAME" = 'pull_request' ] && echo pr-${{github.event.pull_request.number}} || echo ${GITHUB_REF##*/})) >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Checkout submodules shell: bash run: | auth_header="$(git config --local --get http.https://github.com/.extraheader)" git submodule sync --recursive git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: jar path: docker/mods/Galaxy.jar - name: login if: env.USERNAME != '' && env.PASSWORD != '' - uses: azure/docker-login@v1 + uses: docker/login-action@v3 with: - login-server: harbor.k8s.oktw.one + registry: harbor.k8s.oktw.one username: ${{ secrets.OKTW_HARBOR_USERNAME }} password: ${{ secrets.OKTW_HARBOR_PASSWORD }} - name: build cache diff --git a/build.gradle.kts b/build.gradle.kts index 60c447dcb..869545a73 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,18 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { // "maven-publish" - kotlin("jvm") version "1.9.22" - id("fabric-loom") version "1.4-SNAPSHOT" + kotlin("jvm") version "2.0.10" + id("fabric-loom") version "1.7-SNAPSHOT" } val version = "0.0.1" val group = "one.oktw" -val fabricVersion = "0.92.0+1.20.4" -val galaxyLibVersion = "9a964eaf" +val fabricVersion = "0.102.1+1.21.1" +val galaxyLibVersion = "7376fcdf" repositories { mavenCentral() @@ -22,15 +24,15 @@ base { } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } -tasks.withType { - kotlinOptions { - apiVersion = "1.7" - languageVersion = "1.7" - jvmTarget = "17" +tasks.withType().configureEach { + compilerOptions { + apiVersion = KotlinVersion.KOTLIN_2_0 + languageVersion = KotlinVersion.KOTLIN_2_0 + jvmTarget = JvmTarget.JVM_21 } } @@ -40,9 +42,9 @@ loom { dependencies { // Core - minecraft(group = "com.mojang", name = "minecraft", version = "1.20.4") - mappings(group = "net.fabricmc", name = "yarn", version = "1.20.4+build.3", classifier = "v2") - modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.15.3") + minecraft(group = "com.mojang", name = "minecraft", version = "1.21.1") + mappings(group = "net.fabricmc", name = "yarn", version = "1.21.1+build.3", classifier = "v2") + modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.15.11") // fabric api modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = fabricVersion) { diff --git a/docker b/docker index 2f1840bc5..61954b2cd 160000 --- a/docker +++ b/docker @@ -1 +1 @@ -Subproject commit 2f1840bc58917af73e5858f04650194a9df87406 +Subproject commit 61954b2cd9a65a0c8c9d3dbcf15132cdb498075e diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c1962a79e..2c3521197 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c30b486a8..09523c0e5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index aeb74cbb4..f5feea6d6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,7 +85,9 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -130,10 +134,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -141,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -149,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -198,11 +205,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 6689b85be..9b42019c7 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/src/main/java/one/oktw/galaxy/mixin/accessor/SerializingRegionBasedStorageAccessor.java b/src/main/java/one/oktw/galaxy/mixin/accessor/SerializingRegionBasedStorageAccessor.java index 894608e9a..2e7193223 100644 --- a/src/main/java/one/oktw/galaxy/mixin/accessor/SerializingRegionBasedStorageAccessor.java +++ b/src/main/java/one/oktw/galaxy/mixin/accessor/SerializingRegionBasedStorageAccessor.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,8 +18,9 @@ package one.oktw.galaxy.mixin.accessor; -import com.mojang.serialization.DynamicOps; import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.registry.RegistryOps; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.poi.PointOfInterestSet; import net.minecraft.world.storage.SerializingRegionBasedStorage; @@ -40,5 +41,5 @@ public interface SerializingRegionBasedStorageAccessor { CompletableFuture> callLoadNbt(ChunkPos pos); @Invoker - void callUpdate(ChunkPos pos, DynamicOps dynamicOps, @Nullable T data); + void callUpdate(ChunkPos pos, RegistryOps ops, @Nullable NbtCompound nbt); } diff --git a/src/main/java/one/oktw/galaxy/mixin/accessor/ThreadedAnvilChunkStorageAccessor.java b/src/main/java/one/oktw/galaxy/mixin/accessor/ServerChunkLoadingManagerAccessor.java similarity index 84% rename from src/main/java/one/oktw/galaxy/mixin/accessor/ThreadedAnvilChunkStorageAccessor.java rename to src/main/java/one/oktw/galaxy/mixin/accessor/ServerChunkLoadingManagerAccessor.java index eca3e823e..fe35ce359 100644 --- a/src/main/java/one/oktw/galaxy/mixin/accessor/ThreadedAnvilChunkStorageAccessor.java +++ b/src/main/java/one/oktw/galaxy/mixin/accessor/ServerChunkLoadingManagerAccessor.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -19,13 +19,13 @@ package one.oktw.galaxy.mixin.accessor; import net.minecraft.server.world.ChunkHolder; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; +import net.minecraft.server.world.ServerChunkLoadingManager; import net.minecraft.util.math.ChunkPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -@Mixin(ThreadedAnvilChunkStorage.class) -public interface ThreadedAnvilChunkStorageAccessor { +@Mixin(ServerChunkLoadingManager.class) +public interface ServerChunkLoadingManagerAccessor { @Invoker Iterable callEntryIterator(); diff --git a/src/main/java/one/oktw/galaxy/mixin/accessor/ServerPlayerEntityFunctionAccessor.java b/src/main/java/one/oktw/galaxy/mixin/accessor/ServerPlayerEntityFunctionAccessor.java deleted file mode 100644 index 6a2fbd714..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/accessor/ServerPlayerEntityFunctionAccessor.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2020 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.mixin.accessor; - -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(ServerPlayerEntity.class) -public interface ServerPlayerEntityFunctionAccessor { - @Invoker(value = "moveToSpawn") - void moveToWorldSpawn(ServerWorld world); -} diff --git a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_RecipeManager.java b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_RecipeManager.java index c482e3898..90647e878 100644 --- a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_RecipeManager.java +++ b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_RecipeManager.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -19,10 +19,12 @@ package one.oktw.galaxy.mixin.recipe; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; import com.google.gson.JsonElement; import net.minecraft.recipe.RecipeEntry; import net.minecraft.recipe.RecipeManager; import net.minecraft.recipe.RecipeType; +import net.minecraft.registry.RegistryOps; import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; import net.minecraft.util.profiler.Profiler; @@ -38,8 +40,8 @@ @Mixin(RecipeManager.class) public class MixinCustomRecipe_RecipeManager implements CustomRecipeManager { @Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;", ordinal = 0), locals = LocalCapture.CAPTURE_FAILSOFT) - private void recipeLoad(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci, Map, ImmutableMap.Builder>> map2, ImmutableMap.Builder> builder) { - customRecipes.forEach((i, v) -> map2.computeIfAbsent(i, k -> ImmutableMap.builder()).putAll(v)); - customRecipes.forEach((i, v) -> builder.putAll(v)); + private void recipeLoad(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci, ImmutableMultimap.Builder, RecipeEntry> builder, ImmutableMap.Builder> builder2, RegistryOps registryOps) { + customRecipes.forEach((type, recipeEntryHashMap) -> builder.putAll(type, recipeEntryHashMap.values())); + customRecipes.forEach((type, recipeEntryHashMap) -> builder2.putAll(recipeEntryHashMap)); } } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ServerChunkLoadingManager.java similarity index 80% rename from src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java rename to src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ServerChunkLoadingManager.java index a514077fc..c721c719f 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ServerChunkLoadingManager.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,22 +18,23 @@ package one.oktw.galaxy.mixin.tweak; -import com.mojang.datafixers.util.Either; +import com.mojang.datafixers.DataFixer; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtOps; import net.minecraft.registry.RegistryOps; -import net.minecraft.server.world.ChunkHolder; +import net.minecraft.server.world.ServerChunkLoadingManager; import net.minecraft.server.world.ServerWorld; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.thread.ThreadExecutor; import net.minecraft.world.ChunkSerializer; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.ChunkStatus; +import net.minecraft.world.chunk.ChunkType; import net.minecraft.world.chunk.ProtoChunk; import net.minecraft.world.poi.PointOfInterestSet; import net.minecraft.world.poi.PointOfInterestStorage; +import net.minecraft.world.storage.StorageKey; +import net.minecraft.world.storage.VersionedChunkStorage; import one.oktw.galaxy.mixin.accessor.SerializingRegionBasedStorageAccessor; import org.slf4j.Logger; import org.spongepowered.asm.mixin.Final; @@ -41,12 +42,13 @@ import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import java.nio.file.Path; import java.util.HashMap; import java.util.Optional; import java.util.concurrent.CompletableFuture; -@Mixin(ThreadedAnvilChunkStorage.class) -public abstract class MixinAsyncChunk_ThreadedAnvilChunkStorage { +@Mixin(ServerChunkLoadingManager.class) +public abstract class MixinAsyncChunk_ServerChunkLoadingManager extends VersionedChunkStorage { private final HashMap> poiFutures = new HashMap<>(); @Shadow @@ -62,6 +64,10 @@ public abstract class MixinAsyncChunk_ThreadedAnvilChunkStorage { @Final private ThreadExecutor mainThreadExecutor; + public MixinAsyncChunk_ServerChunkLoadingManager(StorageKey storageKey, Path directory, DataFixer dataFixer, boolean dsync) { + super(storageKey, directory, dataFixer, dsync); + } + @Shadow private static boolean containsStatus(NbtCompound nbt) { return false; @@ -74,17 +80,17 @@ private static boolean containsStatus(NbtCompound nbt) { protected abstract Chunk getProtoChunk(ChunkPos chunkPos); @Shadow - protected abstract byte mark(ChunkPos pos, ChunkStatus.ChunkType type); + protected abstract byte mark(ChunkPos pos, ChunkType type); @Shadow - protected abstract Either recoverFromException(Throwable throwable, ChunkPos chunkPos); + protected abstract Chunk recoverFromException(Throwable throwable, ChunkPos chunkPos); /** * @author James58899 * @reason Async POI loading */ @Overwrite - private CompletableFuture> loadChunk(ChunkPos pos) { + private CompletableFuture loadChunk(ChunkPos pos) { CompletableFuture> chunkNbtFuture = this.getUpdatedChunkNbt(pos).thenApply(nbt -> nbt.filter(nbt2 -> { boolean bl = containsStatus(nbt2); if (!bl) { @@ -112,11 +118,11 @@ private CompletableFuture> loadChunk(ChunkPo var nbt = chunkNbtFuture.join(); this.world.getProfiler().visit("chunkLoad"); if (nbt.isPresent()) { - ProtoChunk chunk = ChunkSerializer.deserialize(this.world, this.pointOfInterestStorage, pos, nbt.get()); + ProtoChunk chunk = ChunkSerializer.deserialize(this.world, this.pointOfInterestStorage, this.getStorageKey(), pos, nbt.get()); this.mark(pos, ((Chunk) chunk).getStatus().getChunkType()); - return Either.left(chunk); + return chunk; } - return Either.left(this.getProtoChunk(pos)); + return this.getProtoChunk(pos); }, this.mainThreadExecutor).exceptionallyAsync(throwable -> this.recoverFromException(throwable, pos), this.mainThreadExecutor); } } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ServerChunkManager.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ServerChunkManager.java index c130a7be7..c24677d4c 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ServerChunkManager.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ServerChunkManager.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,14 +18,11 @@ package one.oktw.galaxy.mixin.tweak; -import net.minecraft.server.world.ChunkHolder; -import net.minecraft.server.world.ServerChunkManager; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; +import net.minecraft.server.world.*; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.chunk.ChunkStatus; import net.minecraft.world.chunk.WorldChunk; -import one.oktw.galaxy.mixin.accessor.ThreadedAnvilChunkStorageAccessor; +import one.oktw.galaxy.mixin.accessor.ServerChunkLoadingManagerAccessor; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -56,12 +53,12 @@ public abstract class MixinAsyncChunk_ServerChunkManager { */ @Overwrite public boolean isChunkLoaded(int x, int z) { - return !this.isMissingForLevel(this.getChunkHolder(ChunkPos.toLong(x, z)), 33 + ChunkStatus.getDistanceFromFull(ChunkStatus.FULL)); + return !this.isMissingForLevel(this.getChunkHolder(ChunkPos.toLong(x, z)), ChunkLevels.getLevelFromStatus(ChunkStatus.FULL)); } - @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ThreadedAnvilChunkStorage;entryIterator()Ljava/lang/Iterable;")) - private Iterable earlyCheckChunkShouldTick(ThreadedAnvilChunkStorage instance) { - ThreadedAnvilChunkStorageAccessor accessor = (ThreadedAnvilChunkStorageAccessor) instance; + @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkLoadingManager;entryIterator()Ljava/lang/Iterable;")) + private Iterable earlyCheckChunkShouldTick(ServerChunkLoadingManager instance) { + ServerChunkLoadingManagerAccessor accessor = (ServerChunkLoadingManagerAccessor) instance; var stream = StreamSupport.stream(accessor.callEntryIterator().spliterator(), false); return stream.filter(chunkHolder -> { WorldChunk chunk = chunkHolder.getWorldChunk(); @@ -76,8 +73,8 @@ private boolean skipDupTickCheck(ServerWorld instance, ChunkPos pos) { return true; } - @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ThreadedAnvilChunkStorage;shouldTick(Lnet/minecraft/util/math/ChunkPos;)Z")) - private boolean skipDupTickCheck(ThreadedAnvilChunkStorage instance, ChunkPos pos) { + @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkLoadingManager;shouldTick(Lnet/minecraft/util/math/ChunkPos;)Z")) + private boolean skipDupTickCheck(ServerChunkLoadingManager instance, ChunkPos pos) { return true; } } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_StorageIoWorker.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_StorageIoWorker.java index 615339491..bc02ce311 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_StorageIoWorker.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_StorageIoWorker.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -25,6 +25,7 @@ import net.minecraft.util.thread.TaskQueue; import net.minecraft.world.storage.StorageIoWorker; import net.minecraft.world.storage.StorageIoWorker.Priority; +import net.minecraft.world.storage.StorageKey; import one.oktw.galaxy.util.KotlinCoroutineTaskExecutor; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.*; @@ -60,9 +61,9 @@ public abstract class MixinAsyncChunk_StorageIoWorker { protected abstract void write(ChunkPos pos, StorageIoWorker.Result result); @Inject(method = "", at = @At("RETURN")) - private void parallelExecutor(Path directory, boolean dsync, String name, CallbackInfo ci) { + private void parallelExecutor(StorageKey storageKey, Path directory, boolean dsync, CallbackInfo ci) { results = new ConcurrentHashMap<>(); - executor = new KotlinCoroutineTaskExecutor<>(new TaskQueue.Prioritized(4 /* FOREGROUND,BACKGROUND,WRITE_DONE,SHUTDOWN */), "IOWorker-" + name); + executor = new KotlinCoroutineTaskExecutor<>(new TaskQueue.Prioritized(4 /* FOREGROUND,BACKGROUND,WRITE_DONE,SHUTDOWN */), "IOWorker-" + storageKey.type()); } /** diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_BarrierBlock.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_BarrierBlock.java index 70c827129..76632028c 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_BarrierBlock.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_BarrierBlock.java @@ -47,13 +47,11 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { return CustomBlock.Companion.getDUMMY().createBlockEntity(pos); } - @SuppressWarnings("deprecation") @Override public boolean hasComparatorOutput(BlockState state) { return true; } - @SuppressWarnings("deprecation") @Override public int getComparatorOutput(BlockState state, World world, BlockPos pos) { return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos)); @@ -65,7 +63,6 @@ public BlockEntityTicker getTicker(World world, Block return new CustomBlockEntityTicker<>(); } - @SuppressWarnings("deprecation") @Override public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { if (!state.isOf(newState.getBlock())) { diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_ChunkData.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_ChunkData.java new file mode 100644 index 000000000..fa72703a3 --- /dev/null +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_ChunkData.java @@ -0,0 +1,39 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2024 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.mixin.tweak; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.network.packet.s2c.play.ChunkData; +import net.minecraft.util.math.BlockPos; +import one.oktw.galaxy.block.entity.CustomBlockEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +@Mixin(ChunkData.class) +public class MixinCustomBlockEntity_ChunkData { + @Redirect(method = "(Lnet/minecraft/world/chunk/WorldChunk;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;")) + private Set> removeCustomBlock(Map instance) { + return instance.entrySet().stream().filter(e -> !(e.getValue() instanceof CustomBlockEntity)).collect(Collectors.toSet()); + } +} diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOneSpawnChunk_MinecraftServer.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOneSpawnChunk_MinecraftServer.java deleted file mode 100644 index d08645cc7..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOneSpawnChunk_MinecraftServer.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2020 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.mixin.tweak; - -import net.minecraft.server.MinecraftServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - -@Mixin(MinecraftServer.class) -public class MixinOneSpawnChunk_MinecraftServer { - @ModifyConstant(method = "prepareStartRegion", constant = @Constant(intValue = 11)) - private int onlyForceLoadOneChunk(int radius) { - return 1; - } - - @ModifyConstant(method = "prepareStartRegion", constant = @Constant(intValue = 441)) - private int skipChunkPreGen(int loadedChunks) { - return 1; - } -} diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOneSpawnChunk_ServerWorld.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOneSpawnChunk_ServerWorld.java deleted file mode 100644 index 356a78eff..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOneSpawnChunk_ServerWorld.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2020 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.mixin.tweak; - -import net.minecraft.server.world.ServerWorld; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - -@Mixin(ServerWorld.class) -public class MixinOneSpawnChunk_ServerWorld { - @ModifyConstant(method = "setSpawnPos", constant = @Constant(intValue = 11)) - private int onlyForceLoadOneChunk(int radius) { - return 1; - } -} diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_AvailableSlots.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_AvailableSlots.java deleted file mode 100644 index 09ed3ccd4..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_AvailableSlots.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2021 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.mixin.tweak; - -import net.minecraft.block.entity.LootableContainerBlockEntity; -import net.minecraft.inventory.Inventory; -import one.oktw.galaxy.mixin.interfaces.InventoryAvailableSlots; -import org.spongepowered.asm.mixin.Mixin; - -import java.util.Arrays; - -@Mixin(LootableContainerBlockEntity.class) -public abstract class MixinOptimizeContainer_AvailableSlots implements InventoryAvailableSlots, Inventory { - private int[] availableSlots; - - @Override - public int[] getAvailableSlots() { - if (availableSlots == null) { - int[] array = new int[size()]; - Arrays.setAll(array, i -> i); - availableSlots = array; - } - - return availableSlots; - } -} diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_HopperBlockEntity.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_HopperBlockEntity.java deleted file mode 100644 index 03ac999aa..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_HopperBlockEntity.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2021 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.mixin.tweak; - -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.entity.Hopper; -import net.minecraft.block.entity.HopperBlockEntity; -import net.minecraft.block.entity.LootableContainerBlockEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import one.oktw.galaxy.mixin.interfaces.InventoryAvailableSlots; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.Arrays; - -@Mixin(HopperBlockEntity.class) -public abstract class MixinOptimizeContainer_HopperBlockEntity extends LootableContainerBlockEntity { - protected MixinOptimizeContainer_HopperBlockEntity(BlockEntityType blockEntityType, BlockPos blockPos, BlockState blockState) { - super(blockEntityType, blockPos, blockState); - } - - @Shadow - private static boolean extract(Hopper hopper, Inventory inventory, int slot, Direction side) { - return false; - } - - @Shadow - private static boolean canMergeItems(ItemStack first, ItemStack second) { - return false; - } - - /** - * @author James58899 - * @reason No stream forEach - */ - @Overwrite - private static boolean isInventoryEmpty(Inventory inv, Direction facing) { - for (int i : getAvailableSlots_NoStream(inv, facing)) { - if (!inv.getStack(i).isEmpty()) return false; - } - - return true; - } - - /** - * @author James58899 - * @reason No stream forEach - */ - @Overwrite - private static boolean isInventoryFull(Inventory inv, Direction direction) { - for (int i : getAvailableSlots_NoStream(inv, direction)) { - ItemStack itemStack = inv.getStack(i); - if (itemStack.getCount() < itemStack.getMaxCount()) return false; - } - return true; - } - - @Inject(method = "extract(Lnet/minecraft/block/entity/Hopper;Lnet/minecraft/inventory/Inventory;ILnet/minecraft/util/math/Direction;)Z", - at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;copy()Lnet/minecraft/item/ItemStack;", shift = At.Shift.BEFORE), - locals = LocalCapture.CAPTURE_FAILHARD, - cancellable = true) - private static void extract_EarlyCheck(Hopper hopper, Inventory inventory, int slot, Direction side, CallbackInfoReturnable cir, ItemStack itemStack) { - for (int i : getAvailableSlots_NoStream(hopper, null)) { - ItemStack slotItem = hopper.getStack(i); - if (slotItem.isEmpty() || canMergeItems(slotItem, itemStack)) return; - } - - cir.setReturnValue(false); - } - - @Inject(method = "insert", - at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", shift = At.Shift.BEFORE, ordinal = 0), - locals = LocalCapture.CAPTURE_FAILHARD, - cancellable = true) - private static void insert_EarlyCheck(World world, BlockPos pos, BlockState state, Inventory inventory, CallbackInfoReturnable cir, Inventory inventory2, Direction direction, int slot) { - ItemStack itemStack = inventory.getStack(slot); - for (int i : getAvailableSlots_NoStream(inventory2, direction)) { - ItemStack slotItem = inventory2.getStack(i); - if (slotItem.isEmpty() || canMergeItems(slotItem, itemStack)) return; - } - - cir.setReturnValue(false); - } - - @Inject(method = "extract(Lnet/minecraft/world/World;Lnet/minecraft/block/entity/Hopper;)Z", - at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/HopperBlockEntity;isInventoryEmpty(Lnet/minecraft/inventory/Inventory;Lnet/minecraft/util/math/Direction;)Z"), - cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) - private static void extract_NoStream(World world, Hopper hopper, CallbackInfoReturnable cir, Inventory inventory, Direction direction) { - if (!isInventoryEmpty(inventory, direction)) { - for (int i : getAvailableSlots_NoStream(inventory, direction)) { - if (extract(hopper, inventory, i, direction)) { - cir.setReturnValue(true); - return; - } - } - } - cir.setReturnValue(false); - } - - private static int[] getAvailableSlots_NoStream(Inventory inventory, Direction side) { - if (inventory instanceof SidedInventory) return ((SidedInventory) inventory).getAvailableSlots(side); - if (inventory instanceof InventoryAvailableSlots) return (((InventoryAvailableSlots) inventory).getAvailableSlots()); - - int[] array = new int[inventory.size()]; - Arrays.setAll(array, i -> i); - return array; - } -} diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_LootableContainerBlockEntity.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_LootableContainerBlockEntity.java deleted file mode 100644 index 50505f784..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_LootableContainerBlockEntity.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.mixin.tweak; - -import net.minecraft.block.entity.LootableContainerBlockEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.collection.DefaultedList; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(LootableContainerBlockEntity.class) -public abstract class MixinOptimizeContainer_LootableContainerBlockEntity { - @Shadow - protected abstract DefaultedList method_11282(); - - @Inject(method = "isEmpty", - at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/LootableContainerBlockEntity;generateLoot(Lnet/minecraft/entity/player/PlayerEntity;)V", shift = At.Shift.AFTER), - cancellable = true) - private void replaceStream(CallbackInfoReturnable cir) { - for (ItemStack itemStack : method_11282()) { - if (!itemStack.isEmpty()) { - cir.setReturnValue(false); - return; - } - } - - cir.setReturnValue(true); - } -} diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityMixin_RealTime.java index ee2900def..de770eca3 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityMixin_RealTime.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -58,8 +58,6 @@ public abstract class EntityMixin_RealTime { public int timeUntilRegen; @Shadow protected int ridingCooldown; - @Shadow - protected int netherPortalTime; @Shadow public abstract World getWorld(); @@ -86,20 +84,4 @@ public abstract class EntityMixin_RealTime { final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks(); this.ridingCooldown = Math.max(0, this.ridingCooldown - ticks); } - - @Redirect(method = "tickPortal", - at = @At( - value = "FIELD", - target = "Lnet/minecraft/entity/Entity;netherPortalTime:I", - opcode = Opcodes.PUTFIELD, ordinal = 0 - ), - slice = @Slice( - from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getMaxNetherPortalTime()I"), - to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;resetPortalCooldown()V") - ) - ) - private void realTimeImpl$adjustForRealTimePortalCounter(final Entity self, final int modifier) { - final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks(); - this.netherPortalTime += ticks; - } } diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/world/dimension/PortalManagerMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/world/dimension/PortalManagerMixin_RealTime.java new file mode 100644 index 000000000..f67790ae9 --- /dev/null +++ b/src/main/java/org/spongepowered/common/mixin/realtime/world/dimension/PortalManagerMixin_RealTime.java @@ -0,0 +1,50 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2024 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.spongepowered.common.mixin.realtime.world.dimension; + +import net.minecraft.entity.Entity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.dimension.PortalManager; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.common.bridge.RealTimeTrackingBridge; + +@Mixin(PortalManager.class) +public abstract class PortalManagerMixin_RealTime { + @Shadow + private int ticksInPortal; + + @Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/world/dimension/PortalManager;ticksInPortal:I", opcode = Opcodes.GETFIELD)) + private void realTimeImpl$adjustForRealTimePortalCounter(ServerWorld world, Entity entity, boolean canUsePortals, CallbackInfoReturnable cir) { + final int ticks = (int) ((RealTimeTrackingBridge) world).realTimeBridge$getRealTimeTicks() - 1; + this.ticksInPortal += Math.max(0, ticks); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/PortalManager;decayTicksInPortal()V")) + private void realTimeImpl$PortalDecayCounter(ServerWorld world, Entity entity, boolean canUsePortals, CallbackInfoReturnable cir) { + final int ticks = (int) ((RealTimeTrackingBridge) world).realTimeBridge$getRealTimeTicks() - 1; + if (ticks > 0) { + this.ticksInPortal = Math.max(0, this.ticksInPortal - ticks * 4); + } + } +} diff --git a/src/main/kotlin/one/oktw/galaxy/Main.kt b/src/main/kotlin/one/oktw/galaxy/Main.kt index ab61ee396..634759674 100644 --- a/src/main/kotlin/one/oktw/galaxy/Main.kt +++ b/src/main/kotlin/one/oktw/galaxy/Main.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -24,9 +24,9 @@ import kotlinx.coroutines.asCoroutineDispatcher import net.fabricmc.api.DedicatedServerModInitializer import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking import net.minecraft.server.dedicated.MinecraftDedicatedServer -import net.minecraft.util.Identifier import one.oktw.galaxy.block.CustomBlock import one.oktw.galaxy.block.event.AngelBlock import one.oktw.galaxy.block.event.BlockEvents @@ -40,13 +40,14 @@ import one.oktw.galaxy.event.EventManager import one.oktw.galaxy.event.type.ProxyResponseEvent import one.oktw.galaxy.item.event.CustomItemEventHandler import one.oktw.galaxy.item.event.Wrench +import one.oktw.galaxy.network.ProxyAPIPayload +import one.oktw.galaxy.network.ProxyChatPayload import one.oktw.galaxy.player.Harvest import one.oktw.galaxy.proxy.api.ProxyAPI import one.oktw.galaxy.recipe.RecipeRegistry import java.util.* import kotlin.coroutines.CoroutineContext -@Suppress("unused") class Main : DedicatedServerModInitializer, CoroutineScope { private val job = SupervisorJob() lateinit var server: MinecraftDedicatedServer @@ -57,7 +58,6 @@ class Main : DedicatedServerModInitializer, CoroutineScope { get() = job + server.asCoroutineDispatcher() companion object { - val PROXY_IDENTIFIER = Identifier("galaxy", "proxy") var main: Main? = null private set val selfUUID by lazy { @@ -86,10 +86,16 @@ class Main : DedicatedServerModInitializer, CoroutineScope { server = it as MinecraftDedicatedServer eventManager = EventManager(server) - // Register Proxy packet receiver - ServerPlayNetworking.registerGlobalReceiver(PROXY_IDENTIFIER) { _, player, _, buf, _ -> - eventManager.emit(ProxyResponseEvent(player, ProxyAPI.decode(buf.nioBuffer()))) + // Register Custom Payload + // Register Proxy Packet (C2S: Send, S2C: Receive) + PayloadTypeRegistry.playC2S().register(ProxyAPIPayload.ID, ProxyAPIPayload.CODEC) + PayloadTypeRegistry.playS2C().register(ProxyAPIPayload.ID, ProxyAPIPayload.CODEC) + // Register Event + ServerPlayNetworking.registerGlobalReceiver(ProxyAPIPayload.ID) { payload, context -> + eventManager.emit(ProxyResponseEvent(context.player(), payload.packet)) } + // Register Proxy Chat Packet + PayloadTypeRegistry.playS2C().register(ProxyChatPayload.ID, ProxyChatPayload.CODEC) //Events eventManager.register(Exchange()) diff --git a/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt b/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt index df9d8c2d3..92a548a52 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -32,7 +32,7 @@ import one.oktw.galaxy.util.CustomRegistry import one.oktw.galaxy.util.Registrable open class CustomBlock(final override val identifier: Identifier, val baseBlock: Block = BARRIER) : Registrable { - constructor(id: String, baseBlock: Block = BARRIER) : this(Identifier("galaxy", "block/$id"), baseBlock) + constructor(id: String, baseBlock: Block = BARRIER) : this(Identifier.of("galaxy", "block/$id"), baseBlock) protected val blockEntityType: BlockEntityType = Registry.register( Registries.BLOCK_ENTITY_TYPE, diff --git a/src/main/kotlin/one/oktw/galaxy/block/DummyBlock.kt b/src/main/kotlin/one/oktw/galaxy/block/DummyBlock.kt index de964d7d9..a4a2fa37a 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/DummyBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/DummyBlock.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2021 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -22,6 +22,6 @@ import net.minecraft.util.Identifier import net.minecraft.util.math.BlockPos import one.oktw.galaxy.block.entity.DummyBlockEntity -class DummyBlock : CustomBlock(Identifier("galaxy", "block/dummy")) { +class DummyBlock : CustomBlock(Identifier.of("galaxy", "block/dummy")) { override fun createBlockEntity(pos: BlockPos) = DummyBlockEntity(blockEntityType, pos) } diff --git a/src/main/kotlin/one/oktw/galaxy/block/ModelCustomBlock.kt b/src/main/kotlin/one/oktw/galaxy/block/ModelCustomBlock.kt index 3d05b4754..68b80a915 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/ModelCustomBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/ModelCustomBlock.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -28,7 +28,7 @@ import one.oktw.galaxy.item.CustomBlockItem import one.oktw.galaxy.item.CustomItemHelper open class ModelCustomBlock(identifier: Identifier, protected open val modelItem: ItemStack) : CustomBlock(identifier, BARRIER) { - constructor(id: String, modelItem: ItemStack) : this(Identifier("galaxy", "block/$id"), modelItem) + constructor(id: String, modelItem: ItemStack) : this(Identifier.of("galaxy", "block/$id"), modelItem) override fun toItem() = modelItem.let { CustomItemHelper.getItem(it) as? CustomBlockItem } diff --git a/src/main/kotlin/one/oktw/galaxy/block/TrashcanBlock.kt b/src/main/kotlin/one/oktw/galaxy/block/TrashcanBlock.kt index 9455540e5..20d4fb07a 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/TrashcanBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/TrashcanBlock.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -24,7 +24,7 @@ import net.minecraft.util.math.BlockPos import one.oktw.galaxy.block.entity.CustomBlockEntity import one.oktw.galaxy.block.entity.TrashcanBlockEntity -class TrashcanBlock(id: String, modelItem: ItemStack) : ModelCustomBlock(Identifier("galaxy", "block/$id"), modelItem) { +class TrashcanBlock(id: String, modelItem: ItemStack) : ModelCustomBlock(Identifier.of("galaxy", "block/$id"), modelItem) { override fun createBlockEntity(pos: BlockPos): CustomBlockEntity { return TrashcanBlockEntity(blockEntityType, pos, modelItem) } diff --git a/src/main/kotlin/one/oktw/galaxy/block/entity/CustomBlockEntity.kt b/src/main/kotlin/one/oktw/galaxy/block/entity/CustomBlockEntity.kt index 3a9fb92a2..c07b31fff 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/CustomBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/CustomBlockEntity.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -22,19 +22,20 @@ import net.minecraft.block.Blocks import net.minecraft.block.entity.BlockEntity import net.minecraft.block.entity.BlockEntityType import net.minecraft.nbt.NbtCompound +import net.minecraft.registry.RegistryWrapper import net.minecraft.util.math.BlockPos // BlockEntity need extend open class CustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos) : BlockEntity(type, pos, Blocks.BARRIER.defaultState) { fun getId() = BlockEntityType.getId(type)!! - override fun readNbt(nbt: NbtCompound) { - super.readNbt(nbt) - readCopyableData(nbt) + override fun readNbt(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + super.readNbt(nbt, registryLookup) + readCopyableData(nbt, registryLookup) } - override fun writeNbt(nbt: NbtCompound) { - super.writeNbt(nbt) + override fun writeNbt(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + super.writeNbt(nbt, registryLookup) nbt.putString("id", getId().toString()) // We need ID to mapping block entity, always write it. } @@ -43,5 +44,5 @@ open class CustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos) : BlockEnt * * Also call by [readNbt]. */ - open fun readCopyableData(nbt: NbtCompound) = Unit + open fun readCopyableData(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) = Unit } diff --git a/src/main/kotlin/one/oktw/galaxy/block/entity/DummyBlockEntity.kt b/src/main/kotlin/one/oktw/galaxy/block/entity/DummyBlockEntity.kt index dae181605..82f8d1ed2 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/DummyBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/DummyBlockEntity.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -20,22 +20,23 @@ package one.oktw.galaxy.block.entity import net.minecraft.block.entity.BlockEntityType import net.minecraft.nbt.NbtCompound +import net.minecraft.registry.RegistryWrapper import net.minecraft.util.Identifier import net.minecraft.util.math.BlockPos import one.oktw.galaxy.block.CustomBlock class DummyBlockEntity(type: BlockEntityType<*>, pos: BlockPos) : CustomBlockEntity(type, pos) { - override fun readNbt(nbt: NbtCompound) { - super.readNbt(nbt) + override fun readNbt(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + super.readNbt(nbt, registryLookup) nbt.getString("id")?.let(Identifier::tryParse)?.let(CustomBlock.registry::get)?.let { if (it != CustomBlock.DUMMY) { world?.removeBlockEntity(pos) - world?.addBlockEntity(it.createBlockEntity(pos).apply { readCopyableData(nbt) }) + world?.addBlockEntity(it.createBlockEntity(pos).apply { readCopyableData(nbt, registryLookup) }) } } } - override fun writeNbt(nbt: NbtCompound) { + override fun writeNbt(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { // I'm dummy. } } diff --git a/src/main/kotlin/one/oktw/galaxy/block/entity/HarvestBlockEntity.kt b/src/main/kotlin/one/oktw/galaxy/block/entity/HarvestBlockEntity.kt index 1fb143687..41b1cd0e5 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/HarvestBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/HarvestBlockEntity.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -26,6 +26,7 @@ import net.minecraft.inventory.SidedInventory import net.minecraft.item.HoeItem import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound +import net.minecraft.registry.RegistryWrapper import net.minecraft.screen.ScreenHandlerType import net.minecraft.screen.slot.Slot import net.minecraft.server.network.ServerPlayerEntity @@ -103,7 +104,7 @@ class HarvestBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite if (originItem.isEmpty) { setStack(slot, item) break - } else if (originItem.count < originItem.maxCount && ItemStack.canCombine(originItem, item)) { + } else if (originItem.count < originItem.maxCount && ItemStack.areItemsAndComponentsEqual(originItem, item)) { val count = item.count.coerceAtMost(originItem.maxCount - originItem.count) item.decrement(count) originItem.increment(count) @@ -111,7 +112,7 @@ class HarvestBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite } } } - if (tool.damage(1, world.random, null)) { + tool.damage(1, world, null) { tool.decrement(1) tool.damage = 0 } @@ -123,13 +124,13 @@ class HarvestBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite } } - override fun readCopyableData(nbt: NbtCompound) { - Inventories.readNbt(nbt, inventory) + override fun readCopyableData(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + Inventories.readNbt(nbt, inventory, registryLookup) } - override fun writeNbt(nbt: NbtCompound) { - super.writeNbt(nbt) - Inventories.writeNbt(nbt, inventory) + override fun writeNbt(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + super.writeNbt(nbt, registryLookup) + Inventories.writeNbt(nbt, inventory, registryLookup) } override fun onClick(player: PlayerEntity, hand: Hand, hit: BlockHitResult): ActionResult { diff --git a/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt b/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt index 4c1836bc9..994bf7954 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -25,6 +25,7 @@ import net.minecraft.entity.EquipmentSlot import net.minecraft.entity.decoration.ArmorStandEntity import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound +import net.minecraft.registry.RegistryWrapper import net.minecraft.server.world.ServerWorld import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Direction @@ -66,15 +67,15 @@ open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, priva } } - override fun readNbt(nbt: NbtCompound) { - super.readNbt(nbt) + override fun readNbt(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + super.readNbt(nbt, registryLookup) val data = nbt.get("GalaxyData") as? NbtCompound ?: return data.getUuid("ModelEntity")?.let { entityUUID = it } data.getString("Facing")?.let { facing = Direction.byName(it) } } - override fun writeNbt(nbt: NbtCompound) { - super.writeNbt(nbt) + override fun writeNbt(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + super.writeNbt(nbt, registryLookup) val data = NbtCompound() entityUUID?.let { data.putUuid("ModelEntity", it) } facing?.let { data.putString("Facing", it.getName()) } diff --git a/src/main/kotlin/one/oktw/galaxy/block/entity/TestGuiBlockEntity.kt b/src/main/kotlin/one/oktw/galaxy/block/entity/TestGuiBlockEntity.kt index efa702488..3f057ea7a 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/TestGuiBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/TestGuiBlockEntity.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -19,11 +19,13 @@ package one.oktw.galaxy.block.entity import net.minecraft.block.entity.BlockEntityType +import net.minecraft.component.DataComponentTypes import net.minecraft.entity.player.PlayerEntity import net.minecraft.inventory.Inventories import net.minecraft.inventory.Inventory import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound +import net.minecraft.registry.RegistryWrapper import net.minecraft.screen.ScreenHandlerType import net.minecraft.screen.slot.Slot import net.minecraft.server.network.ServerPlayerEntity @@ -61,20 +63,20 @@ class TestGuiBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite }.build().apply { editInventory { fill(0 until 9, 3..3, Gui.MAIN_FIELD.createItemStack()) - set(4, 3, Button.CROSS_MARK.createItemStack().setCustomName(Text.of("CLOSE ALL"))) + set(4, 3, Button.CROSS_MARK.createItemStack().apply { this.set(DataComponentTypes.ITEM_NAME, Text.of("CLOSE ALL")) }) } addBinding(4, 3) { GUISBackStackManager.closeAll(player) } } - override fun readCopyableData(nbt: NbtCompound) { - Inventories.readNbt(nbt, inventory) + override fun readCopyableData(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + Inventories.readNbt(nbt, inventory, registryLookup) } - override fun writeNbt(nbt: NbtCompound) { - super.writeNbt(nbt) - Inventories.writeNbt(nbt, inventory) + override fun writeNbt(nbt: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { + super.writeNbt(nbt, registryLookup) + Inventories.writeNbt(nbt, inventory, registryLookup) } override fun onClick(player: PlayerEntity, hand: Hand, hit: BlockHitResult): ActionResult { diff --git a/src/main/kotlin/one/oktw/galaxy/chat/Exchange.kt b/src/main/kotlin/one/oktw/galaxy/chat/Exchange.kt index 6545df625..606b43119 100644 --- a/src/main/kotlin/one/oktw/galaxy/chat/Exchange.kt +++ b/src/main/kotlin/one/oktw/galaxy/chat/Exchange.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,23 +18,18 @@ package one.oktw.galaxy.chat -import io.netty.buffer.Unpooled +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking.createS2CPacket -import net.minecraft.network.PacketByteBuf +import net.minecraft.registry.DynamicRegistryManager import net.minecraft.text.Text -import net.minecraft.util.Identifier import one.oktw.galaxy.Main import one.oktw.galaxy.event.annotation.EventListener import one.oktw.galaxy.event.type.PlayerChatEvent +import one.oktw.galaxy.network.ProxyChatPayload import one.oktw.galaxy.proxy.api.ProxyAPI -import one.oktw.galaxy.proxy.api.ProxyAPI.encode import one.oktw.galaxy.proxy.api.packet.MessageSend class Exchange { - companion object { - val PROXY_CHAT_IDENTIFIER = Identifier("galaxy", "proxy-chat") - } - @EventListener(true) fun handleChat(event: PlayerChatEvent) { if (Main.selfUUID == ProxyAPI.dummyUUID) return @@ -43,15 +38,11 @@ class Exchange { event.player.networkHandler.sendPacket( createS2CPacket( - PROXY_CHAT_IDENTIFIER, PacketByteBuf( - Unpooled.wrappedBuffer( - encode( - MessageSend( - sender = event.player.uuid, - message = Text.Serialization.toJsonString(event.message), - targets = listOf(ProxyAPI.globalChatChannel) - ) - ) + ProxyChatPayload( + MessageSend( + sender = event.player.uuid, + message = Text.Serialization.toJsonString(event.message, DynamicRegistryManager.EMPTY), + targets = listOf(ProxyAPI.globalChatChannel) ) ) ) diff --git a/src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt b/src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt index 1b0f01ab2..9b2289e15 100644 --- a/src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt +++ b/src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -22,7 +22,6 @@ import com.mojang.brigadier.CommandDispatcher import kotlinx.coroutines.delay import kotlinx.coroutines.launch import net.minecraft.block.RespawnAnchorBlock -import net.minecraft.entity.player.PlayerEntity import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket import net.minecraft.server.command.CommandManager import net.minecraft.server.command.ServerCommandSource @@ -30,6 +29,7 @@ import net.minecraft.sound.SoundCategory import net.minecraft.sound.SoundEvents import net.minecraft.text.Text import net.minecraft.util.Formatting +import net.minecraft.world.TeleportTarget import one.oktw.galaxy.Main.Companion.main import one.oktw.galaxy.command.Command import java.util.* @@ -63,14 +63,8 @@ class Home : Command { val world = source.server.getWorld(player.spawnPointDimension) - val spawnPoint = PlayerEntity.findRespawnPosition( - world, - spawnPointPosition, - player.spawnAngle, - player.isSpawnForced, - player.notInAnyWorld - ) - if (!spawnPoint.isPresent) { + val teleportTarget = player.getRespawnTarget(player.notInAnyWorld, TeleportTarget.NO_OP) + if (teleportTarget.missingRespawnBlock()) { player.sendMessage(Text.translatable("block.minecraft.spawn.not_valid").styled { it.withColor(Formatting.RED) }, false) lock -= player.uuid } else { @@ -93,21 +87,16 @@ class Home : Command { player.sendMessage(Text.translatable("Respond.TeleportStart").styled { it.withColor(Formatting.GREEN) }, true) // Check Again - val checkAgain = PlayerEntity.findRespawnPosition( - world, - spawnPointPosition, - player.spawnAngle, - player.isSpawnForced, - player.notInAnyWorld - ) - if (!checkAgain.isPresent) { + val teleportTargetDoubleCheck = player.getRespawnTarget(player.notInAnyWorld, TeleportTarget.NO_OP) + + if (teleportTargetDoubleCheck.missingRespawnBlock()) { player.sendMessage(Text.translatable("block.minecraft.spawn.not_valid").styled { it.withColor(Formatting.RED) }, false) lock -= player.uuid return@launch } - val world2 = if (world != null && checkAgain.isPresent) world else source.server.overworld - val position = checkAgain.get() + val world2 = if (world != null && !teleportTargetDoubleCheck.missingRespawnBlock()) world else source.server.overworld + val position = teleportTarget.pos() player.teleport( world2, position.x, diff --git a/src/main/kotlin/one/oktw/galaxy/command/commands/Join.kt b/src/main/kotlin/one/oktw/galaxy/command/commands/Join.kt index ab1506481..3348b5fe8 100644 --- a/src/main/kotlin/one/oktw/galaxy/command/commands/Join.kt +++ b/src/main/kotlin/one/oktw/galaxy/command/commands/Join.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -21,21 +21,18 @@ package one.oktw.galaxy.command.commands import com.mojang.authlib.GameProfile import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.suggestion.Suggestions -import io.netty.buffer.Unpooled.wrappedBuffer import kotlinx.coroutines.* import kotlinx.coroutines.sync.Mutex import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking import net.minecraft.command.argument.GameProfileArgumentType -import net.minecraft.network.PacketByteBuf import net.minecraft.server.command.CommandManager import net.minecraft.server.command.ServerCommandSource import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.text.Text -import one.oktw.galaxy.Main.Companion.PROXY_IDENTIFIER import one.oktw.galaxy.Main.Companion.main import one.oktw.galaxy.command.Command import one.oktw.galaxy.event.type.ProxyResponseEvent -import one.oktw.galaxy.proxy.api.ProxyAPI.encode +import one.oktw.galaxy.network.ProxyAPIPayload import one.oktw.galaxy.proxy.api.packet.CreateGalaxy import one.oktw.galaxy.proxy.api.packet.ProgressStage.* import one.oktw.galaxy.proxy.api.packet.SearchPlayer @@ -56,11 +53,7 @@ class Join : Command, CoroutineScope by CoroutineScope(Dispatchers.Default + Sup val future = CompletableFuture() val player = commandContext.source.playerOrThrow - ServerPlayNetworking.send( - player, - PROXY_IDENTIFIER, - PacketByteBuf(wrappedBuffer(encode(SearchPlayer(suggestionsBuilder.remaining, 10)))) - ) + ServerPlayNetworking.send(player, ProxyAPIPayload(SearchPlayer(suggestionsBuilder.remaining, 10))) val listeners = fun(event: ProxyResponseEvent) { val result = event.packet as? SearchPlayer.Result ?: return @@ -93,7 +86,7 @@ class Join : Command, CoroutineScope by CoroutineScope(Dispatchers.Default + Sup val targetPlayer = collection.first() - ServerPlayNetworking.send(sourcePlayer, PROXY_IDENTIFIER, PacketByteBuf(wrappedBuffer(encode(CreateGalaxy(targetPlayer.id))))) + ServerPlayNetworking.send(sourcePlayer, ProxyAPIPayload(CreateGalaxy(targetPlayer.id))) source.sendFeedback({ Text.of(if (sourcePlayer.gameProfile == targetPlayer) "正在加入您的星系" else "正在加入 ${targetPlayer.name} 的星系") }, false) launch { diff --git a/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt b/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt index fb0500608..1bf4d61af 100644 --- a/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt +++ b/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -30,7 +30,6 @@ import net.minecraft.util.Formatting import net.minecraft.world.World import one.oktw.galaxy.Main.Companion.main import one.oktw.galaxy.command.Command -import one.oktw.galaxy.mixin.accessor.ServerPlayerEntityFunctionAccessor import java.util.* import java.util.concurrent.TimeUnit @@ -88,7 +87,7 @@ class Spawn : Command { return@launch } - (player as ServerPlayerEntityFunctionAccessor).moveToWorldSpawn(world) + player.refreshPositionAndAngles(player.getWorldSpawnPos(world, world.spawnPos).toBottomCenterPos(), 0.0f, 0.0f) // force teleport when player pos does not change at all if (oldPos.distanceTo(player.pos) == 0.0) { val spawnPosition = world.spawnPos diff --git a/src/main/kotlin/one/oktw/galaxy/gui/GUI.kt b/src/main/kotlin/one/oktw/galaxy/gui/GUI.kt index c7b6ba0b5..7406b1aaa 100644 --- a/src/main/kotlin/one/oktw/galaxy/gui/GUI.kt +++ b/src/main/kotlin/one/oktw/galaxy/gui/GUI.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -265,7 +265,7 @@ class GUI private constructor(private val type: ScreenHandlerType acc or i }) // ALL - putInt("CustomModelData", modelData) - putBoolean("Unbreakable", true) - put("AttributeModifiers", NbtList()) + set(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelDataComponent(modelData)) + set(DataComponentTypes.UNBREAKABLE, UnbreakableComponent(false)) + set(DataComponentTypes.ATTRIBUTE_MODIFIERS, AttributeModifiersComponent(emptyList(), false)) + set(DataComponentTypes.ITEM_NAME, this@CustomItem.getName()) + + // Galaxy Data + val galaxyNbt = CustomItemHelper.getNbt(this) + writeCustomNbt(galaxyNbt) + apply(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT) { component -> + component.apply { nbt -> + nbt.put("GalaxyData", galaxyNbt) + } } - setCustomName(this@CustomItem.getName()) - writeCustomNbt(getOrCreateSubNbt("GalaxyData")) }.also { if (cacheable) cacheItemStack = it.copy() } } } diff --git a/src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt b/src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt index 5c80d75dd..0dad44e18 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2021 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,14 +18,22 @@ package one.oktw.galaxy.item +import net.minecraft.component.DataComponentTypes +import net.minecraft.component.type.NbtComponent import net.minecraft.item.ItemStack +import net.minecraft.nbt.NbtCompound import net.minecraft.util.Identifier object CustomItemHelper { + fun getNbt(itemStack: ItemStack): NbtCompound { + val galaxyData = (itemStack.get(DataComponentTypes.CUSTOM_DATA) ?: NbtComponent.DEFAULT).copyNbt() + return galaxyData.getCompound("GalaxyData") + } + fun getItem(itemStack: ItemStack): CustomItem? { - val customNbt = itemStack.getSubNbt("GalaxyData") + val customNbt = getNbt(itemStack) - return customNbt?.getString("CustomItemIdentifier")?.let(Identifier::tryParse) + return customNbt.getString("CustomItemIdentifier")?.let(Identifier::tryParse) ?.let(CustomItem.registry::get) ?.run { readCustomNbt(customNbt) } } diff --git a/src/main/kotlin/one/oktw/galaxy/item/Gui.kt b/src/main/kotlin/one/oktw/galaxy/item/Gui.kt index 0593799a5..0e976cdd7 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Gui.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Gui.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -22,7 +22,7 @@ import net.minecraft.item.Items.DIAMOND_HOE import net.minecraft.text.Text import net.minecraft.util.Identifier -class Gui private constructor(id: String, modelData: Int) : CustomItem(Identifier("galaxy", "item/gui/base/$id"), DIAMOND_HOE, modelData) { +class Gui private constructor(id: String, modelData: Int) : CustomItem(Identifier.of("galaxy", "item/gui/base/$id"), DIAMOND_HOE, modelData) { companion object { val BLANK = registry.register(Gui("blank", 1000000)) val MAIN_FIELD = registry.register(Gui("main_field", 1010000)) diff --git a/src/main/kotlin/one/oktw/galaxy/item/Material.kt b/src/main/kotlin/one/oktw/galaxy/item/Material.kt index d270c877e..c3df52c1d 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Material.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Material.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -25,7 +25,7 @@ import net.minecraft.util.Formatting import net.minecraft.util.Identifier class Material private constructor(id: String, modelData: Int, private val name: String) : - CustomItem(Identifier("galaxy", "item/material/$id"), COMMAND_BLOCK, modelData) { + CustomItem(Identifier.of("galaxy", "item/material/$id"), COMMAND_BLOCK, modelData) { companion object { val RAW_BASE_PLATE = registry.register(Material("raw_base_plate", 4010100, "item.Material.PART_RAW_BASE")) val BASE_PLATE = registry.register(Material("base_plate", 4010101, "item.Material.PART_BASE")) diff --git a/src/main/kotlin/one/oktw/galaxy/item/Tool.kt b/src/main/kotlin/one/oktw/galaxy/item/Tool.kt index 6dba40fe0..78b7de083 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Tool.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Tool.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -27,7 +27,7 @@ import net.minecraft.util.Identifier import net.minecraft.util.math.MathHelper class Tool private constructor(id: String, modelData: Int, private val name: String) : - CustomItem(Identifier("galaxy", "item/tool/$id"), COMMAND_BLOCK, modelData) { + CustomItem(Identifier.of("galaxy", "item/tool/$id"), COMMAND_BLOCK, modelData) { override val cacheable = false companion object { diff --git a/src/main/kotlin/one/oktw/galaxy/item/Upgrade.kt b/src/main/kotlin/one/oktw/galaxy/item/Upgrade.kt index 3e9594bce..99c6bd2a4 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Upgrade.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Upgrade.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -25,7 +25,7 @@ import net.minecraft.util.Formatting import net.minecraft.util.Identifier class Upgrade private constructor(id: String, modelData: Int, private val name: String, private val level: Int) : - CustomItem(Identifier("galaxy", "item/upgrade/$id"), COMMAND_BLOCK, modelData) { + CustomItem(Identifier.of("galaxy", "item/upgrade/$id"), COMMAND_BLOCK, modelData) { companion object { val BASE = registry.register(Upgrade("base", 5000100, "item.Upgrade.BASE", 0)) val COOLING_LV1 = registry.register(Upgrade("cooling_lv1", 5010100, "item.Upgrade.COOLING", 1)) diff --git a/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt b/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt index 7351ec435..bba401013 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -27,7 +27,7 @@ import net.minecraft.util.Identifier import net.minecraft.util.math.MathHelper class Weapon private constructor(id: String, modelData: Int, private val name: String) : - CustomItem(Identifier("galaxy", "item/weapon/$id"), COMMAND_BLOCK, modelData) { + CustomItem(Identifier.of("galaxy", "item/weapon/$id"), COMMAND_BLOCK, modelData) { override val cacheable = false companion object { diff --git a/src/main/kotlin/one/oktw/galaxy/network/ProxyAPIPayload.kt b/src/main/kotlin/one/oktw/galaxy/network/ProxyAPIPayload.kt new file mode 100644 index 000000000..b85717a7e --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/network/ProxyAPIPayload.kt @@ -0,0 +1,48 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2024 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.network + +import io.netty.buffer.Unpooled.wrappedBuffer +import net.minecraft.network.PacketByteBuf +import net.minecraft.network.codec.PacketCodec +import net.minecraft.network.packet.CustomPayload +import net.minecraft.util.Identifier +import one.oktw.galaxy.proxy.api.ProxyAPI +import one.oktw.galaxy.proxy.api.ProxyAPI.encode +import one.oktw.galaxy.proxy.api.packet.Packet + +@JvmRecord +data class ProxyAPIPayload(val packet: Packet) : CustomPayload { + companion object { + private val PROXY_IDENTIFIER = Identifier.of("galaxy", "proxy") + val ID = CustomPayload.Id(PROXY_IDENTIFIER) + val CODEC: PacketCodec = PacketCodec.of( + { value, buf -> buf.writeBytes(wrappedBuffer(encode(value.packet))) }, + { buf -> + val packet = ProxyAPIPayload(ProxyAPI.decode(buf.nioBuffer())) + // FIXME: Workaround force clear buffer to suppress "Packet was larger than I expected" error + buf.clear() + return@of packet + }) + } + + override fun getId(): CustomPayload.Id { + return ID + } +} diff --git a/src/main/kotlin/one/oktw/galaxy/network/ProxyChatPayload.kt b/src/main/kotlin/one/oktw/galaxy/network/ProxyChatPayload.kt new file mode 100644 index 000000000..b18511807 --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/network/ProxyChatPayload.kt @@ -0,0 +1,48 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2024 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.network + +import io.netty.buffer.Unpooled.wrappedBuffer +import net.minecraft.network.PacketByteBuf +import net.minecraft.network.codec.PacketCodec +import net.minecraft.network.packet.CustomPayload +import net.minecraft.util.Identifier +import one.oktw.galaxy.proxy.api.ProxyAPI +import one.oktw.galaxy.proxy.api.ProxyAPI.encode +import one.oktw.galaxy.proxy.api.packet.Packet + +@JvmRecord +data class ProxyChatPayload(val packet: Packet) : CustomPayload { + companion object { + private val PROXY_CHAT_IDENTIFIER = Identifier.of("galaxy", "proxy-chat") + val ID = CustomPayload.Id(PROXY_CHAT_IDENTIFIER) + val CODEC: PacketCodec = PacketCodec.of( + { value, buf -> buf.writeBytes(wrappedBuffer(encode(value.packet))) }, + { buf -> + val packet = ProxyChatPayload(ProxyAPI.decode(buf.nioBuffer())) + // FIXME: Workaround force clear buffer to suppress "Packet was larger than I expected" error + buf.clear() + return@of packet + }) + } + + override fun getId(): CustomPayload.Id { + return ID + } +} diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/RecipeRegistry.kt b/src/main/kotlin/one/oktw/galaxy/recipe/RecipeRegistry.kt index f3d99aeb9..43cab5c1b 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/RecipeRegistry.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/RecipeRegistry.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -32,12 +32,12 @@ import one.oktw.galaxy.recipe.tools.Wrench object RecipeRegistry { fun register() { // Recipe - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "item/wrench"), Wrench()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "item/crowbar"), Crowbar()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "block/elevator"), Elevator()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "block/htct"), HTCraftingTable()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "block/harvest"), Harvest()) - CustomRecipeManager.addRecipe(RecipeType.SMELTING, Identifier("galaxy", "material/ceramic_plate"), CeramicPlate()) - CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier("galaxy", "block/trashcan"), Trashcan()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier.of("galaxy", "item/wrench"), Wrench()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier.of("galaxy", "item/crowbar"), Crowbar()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier.of("galaxy", "block/elevator"), Elevator()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier.of("galaxy", "block/htct"), HTCraftingTable()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier.of("galaxy", "block/harvest"), Harvest()) + CustomRecipeManager.addRecipe(RecipeType.SMELTING, Identifier.of("galaxy", "material/ceramic_plate"), CeramicPlate()) + CustomRecipeManager.addRecipe(RecipeType.CRAFTING, Identifier.of("galaxy", "block/trashcan"), Trashcan()) } } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/materials/CeramicPlate.kt b/src/main/kotlin/one/oktw/galaxy/recipe/materials/CeramicPlate.kt index 8cacc8cd1..9587a4104 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/materials/CeramicPlate.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/materials/CeramicPlate.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,10 +18,10 @@ package one.oktw.galaxy.recipe.materials -import net.minecraft.inventory.Inventory import net.minecraft.recipe.Ingredient import net.minecraft.recipe.SmeltingRecipe import net.minecraft.recipe.book.CookingRecipeCategory +import net.minecraft.recipe.input.SingleStackRecipeInput import net.minecraft.world.World import one.oktw.galaxy.item.CustomItemHelper import one.oktw.galaxy.item.Material @@ -34,8 +34,8 @@ class CeramicPlate : SmeltingRecipe( 0.1F, 200 ) { - override fun matches(inventory: Inventory, world: World): Boolean { - val input = inventory.getStack(0) ?: return false + override fun matches(singleStackRecipeInput: SingleStackRecipeInput, world: World): Boolean { + val input = singleStackRecipeInput.getStackInSlot(0) ?: return false return CustomItemHelper.getItem(input) == Material.RAW_BASE_PLATE } } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/tools/Crowbar.kt b/src/main/kotlin/one/oktw/galaxy/recipe/tools/Crowbar.kt index cf1099d37..e668a2cdf 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/tools/Crowbar.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/tools/Crowbar.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,12 +18,12 @@ package one.oktw.galaxy.recipe.tools -import net.minecraft.inventory.RecipeInputInventory import net.minecraft.item.Items import net.minecraft.recipe.RawShapedRecipe import net.minecraft.recipe.ShapedRecipe import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager +import net.minecraft.recipe.input.CraftingRecipeInput +import net.minecraft.registry.RegistryWrapper import one.oktw.galaxy.item.Tool class Crowbar : ShapedRecipe( @@ -37,5 +37,5 @@ class Crowbar : ShapedRecipe( ), Tool.CROWBAR.createItemStack() ) { - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = Tool.CROWBAR.createItemStack() + override fun craft(craftingRecipeInput: CraftingRecipeInput, wrapperLookup: RegistryWrapper.WrapperLookup) = Tool.CROWBAR.createItemStack() } diff --git a/src/main/kotlin/one/oktw/galaxy/recipe/tools/Wrench.kt b/src/main/kotlin/one/oktw/galaxy/recipe/tools/Wrench.kt index f6f152955..748f0a6c9 100644 --- a/src/main/kotlin/one/oktw/galaxy/recipe/tools/Wrench.kt +++ b/src/main/kotlin/one/oktw/galaxy/recipe/tools/Wrench.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,13 +18,13 @@ package one.oktw.galaxy.recipe.tools -import net.minecraft.inventory.RecipeInputInventory import net.minecraft.item.Items import net.minecraft.recipe.Ingredient import net.minecraft.recipe.RawShapedRecipe import net.minecraft.recipe.ShapedRecipe import net.minecraft.recipe.book.CraftingRecipeCategory -import net.minecraft.registry.DynamicRegistryManager +import net.minecraft.recipe.input.CraftingRecipeInput +import net.minecraft.registry.RegistryWrapper import one.oktw.galaxy.item.Tool class Wrench : ShapedRecipe( @@ -38,5 +38,5 @@ class Wrench : ShapedRecipe( ), Tool.WRENCH.createItemStack() ) { - override fun craft(inv: RecipeInputInventory, registryManager: DynamicRegistryManager) = Tool.WRENCH.createItemStack() + override fun craft(craftingRecipeInput: CraftingRecipeInput, wrapperLookup: RegistryWrapper.WrapperLookup) = Tool.WRENCH.createItemStack() } diff --git a/src/main/kotlin/one/oktw/galaxy/util/LoreEditor.kt b/src/main/kotlin/one/oktw/galaxy/util/LoreEditor.kt deleted file mode 100644 index fd1dc8305..000000000 --- a/src/main/kotlin/one/oktw/galaxy/util/LoreEditor.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2023 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.util - -import com.google.gson.JsonParseException -import net.minecraft.item.ItemStack -import net.minecraft.item.ItemStack.DISPLAY_KEY -import net.minecraft.item.ItemStack.LORE_KEY -import net.minecraft.nbt.NbtElement -import net.minecraft.nbt.NbtList -import net.minecraft.nbt.NbtString -import net.minecraft.text.MutableText -import net.minecraft.text.Style -import net.minecraft.text.Text -import net.minecraft.text.Texts -import net.minecraft.util.Formatting.DARK_PURPLE - -class LoreEditor private constructor(val item: ItemStack) { - companion object { - // Edit ItemStack Lore - fun ItemStack.loreEditor(block: LoreEditor.() -> Unit) { - val builder = LoreEditor(this) // Receiver - builder.block() // Run lambda block - this.apply { builder.apply() } // Return Item - } - - // Get ItemStack Lore - fun ItemStack.getLoreTexts() = LoreEditor(this).getLoreList() - } - - private val list = item.nbt?.getCompound(DISPLAY_KEY)?.getList(LORE_KEY, NbtElement.STRING_TYPE.toInt()) ?: NbtList() - - fun addText(text: Text): LoreEditor { - this.list.add(NbtString.of(Text.Serialization.toJsonString(text))) - return this - } - - fun addText(texts: ArrayList): LoreEditor { - for (text in texts) { - addText(text) - } - return this - } - - fun clear(): LoreEditor { - this.list.clear() - return this - } - - private fun getLoreList(): List { - val textList = ArrayList() - for (i in 0 until list.size) { - val string = list.getString(i) ?: continue - try { - val text: MutableText = Text.Serialization.fromJson(string) ?: continue - textList.add(Texts.setStyleIfAbsent(text, Style.EMPTY.withColor(DARK_PURPLE).withItalic(true))) // default lore style - } catch (e: JsonParseException) { - continue // skip lore - } - } - return textList - } - - private fun apply(): ItemStack = item.apply { orCreateNbt.apply { getCompound(DISPLAY_KEY).apply { put(LORE_KEY, list) } } } -} diff --git a/src/main/resources/accessor.mixin.json b/src/main/resources/accessor.mixin.json index f753904e9..be509346a 100644 --- a/src/main/resources/accessor.mixin.json +++ b/src/main/resources/accessor.mixin.json @@ -1,13 +1,12 @@ { "required": true, "package": "one.oktw.galaxy.mixin.accessor", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_21", "mixins": [ "BeaconLevelAccessor", "PlayerAbilitiesAccessor", "SerializingRegionBasedStorageAccessor", - "ServerPlayerEntityFunctionAccessor", - "ThreadedAnvilChunkStorageAccessor" + "ServerChunkLoadingManagerAccessor" ], "client": [], "injectors": { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4de5be9cc..9784dda85 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,8 +27,8 @@ "recipe.mixin.json" ], "depends": { - "minecraft": "1.20.x", - "fabricloader": ">=0.14.21", + "minecraft": "1.21.x", + "fabricloader": ">=0.15.11", "fabric": ">=0.83.0" }, "suggests": {} diff --git a/src/main/resources/galaxy.mixin.json b/src/main/resources/galaxy.mixin.json index 07f25f563..d24c4da9e 100644 --- a/src/main/resources/galaxy.mixin.json +++ b/src/main/resources/galaxy.mixin.json @@ -1,7 +1,7 @@ { "required": true, "package": "one.oktw.galaxy.mixin.event", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_21", "mixins": [ "MixinPlayerAction_NetworkHandler", "MixinPlayerChat_MeCommand", diff --git a/src/main/resources/recipe.mixin.json b/src/main/resources/recipe.mixin.json index be86022fa..b73244802 100644 --- a/src/main/resources/recipe.mixin.json +++ b/src/main/resources/recipe.mixin.json @@ -1,7 +1,7 @@ { "required": true, "package": "one.oktw.galaxy.mixin.recipe", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_21", "mixins": [ "MixinCustomRecipe_CraftingResultSlot", "MixinCustomRecipe_RecipeManager" diff --git a/src/main/resources/sponge.realtime.mixin.json b/src/main/resources/sponge.realtime.mixin.json index fd7ea740a..91fa1458c 100644 --- a/src/main/resources/sponge.realtime.mixin.json +++ b/src/main/resources/sponge.realtime.mixin.json @@ -1,7 +1,7 @@ { "required": true, "package": "org.spongepowered.common.mixin.realtime", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_21", "mixins": [ "accessor.AbstractFurnaceBlockEntityAccessor", "accessor.BrewingStandBlockEntityAccessor", @@ -20,7 +20,8 @@ "server.MinecraftServerMixin_RealTime", "server.network.ServerPlayerInteractionManagerMixin_RealTime", "server.network.ServerPlayNetworkHandlerMixin_RealTime", - "world.WorldMixin_RealTime" + "world.WorldMixin_RealTime", + "world.dimension.PortalManagerMixin_RealTime" ], "server": [ ], diff --git a/src/main/resources/tweak.mixin.json b/src/main/resources/tweak.mixin.json index b8c7f8b37..dc861f89d 100644 --- a/src/main/resources/tweak.mixin.json +++ b/src/main/resources/tweak.mixin.json @@ -1,27 +1,23 @@ { "required": true, "package": "one.oktw.galaxy.mixin.tweak", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_21", "mixins": [ "MixinAsyncChunk_ChunkPosDistanceLevelPropagator", "MixinAsyncChunk_RegionBasedStorage", "MixinAsyncChunk_RegionFile", + "MixinAsyncChunk_ServerChunkLoadingManager", "MixinAsyncChunk_ServerChunkManager", "MixinAsyncChunk_ServerPlayNetworkHandler", "MixinAsyncChunk_StorageIoWorker", - "MixinAsyncChunk_ThreadedAnvilChunkStorage", "MixinCustomBlockEntity_BarrierBlock", + "MixinCustomBlockEntity_ChunkData", "MixinCustomBlockEntity_Structure", "MixinFixBeacon_BeaconBlockEntity", "MixinGlobalDataPack_VanillaDataPackProvider", "MixinItemStackEqualAllowNull_ItemStack", "MixinMapExistingChunk_FilledMapItem", - "MixinOneSpawnChunk_MinecraftServer", - "MixinOneSpawnChunk_ServerWorld", "MixinOptimizeArmorStand_ArmorStandEntity", - "MixinOptimizeContainer_AvailableSlots", - "MixinOptimizeContainer_HopperBlockEntity", - "MixinOptimizeContainer_LootableContainerBlockEntity", "MixinRCON_RconBase", "MixinRCON_RconClient", "MixinSkipSyncRegistry",