Skip to content

Commit

Permalink
Merge pull request #421 from OKTW-Network/1.20
Browse files Browse the repository at this point in the history
1.20.1
  • Loading branch information
mergify[bot] authored Sep 7, 2023
2 parents b516c0f + fe0652b commit b8f4176
Show file tree
Hide file tree
Showing 59 changed files with 271 additions and 285 deletions.
14 changes: 7 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// "maven-publish"
kotlin("jvm") version "1.8.21"
id("fabric-loom") version "1.2-SNAPSHOT"
kotlin("jvm") version "1.9.10"
id("fabric-loom") version "1.3-SNAPSHOT"
}

val version = "0.0.1"
val group = "one.oktw"

val fabricVersion = "0.81.0+1.19.4"
val galaxyLibVersion = "63aec6ee"
val fabricVersion = "0.88.1+1.20.1"
val galaxyLibVersion = "adc1ed90"

repositories {
mavenCentral()
Expand Down Expand Up @@ -40,9 +40,9 @@ loom {

dependencies {
// Core
minecraft(group = "com.mojang", name = "minecraft", version = "1.19.4")
mappings(group = "net.fabricmc", name = "yarn", version = "1.19.4+build.2", classifier = "v2")
modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.14.19")
minecraft(group = "com.mojang", name = "minecraft", version = "1.20.1")
mappings(group = "net.fabricmc", name = "yarn", version = "1.20.1+build.10", classifier = "v2")
modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.14.22")

// fabric api
modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = fabricVersion) {
Expand Down
2 changes: 1 addition & 1 deletion docker
Submodule docker updated 1 files
+8 −8 Dockerfile
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 4 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# 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"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* OKTW Galaxy Project
* Copyright (C) 2018-2022
* 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
Expand Down Expand Up @@ -47,7 +47,7 @@ private void onPlayerInteractBlock(PlayerInteractBlockC2SPacket packet, Callback
info.cancel();
if (event.getSwing()) player.swingHand(packet.getHand(), true);
// Re-sync block & inventory
ServerWorld world = player.getWorld();
ServerWorld world = player.getServerWorld();
BlockPos blockPos = packet.getBlockHitResult().getBlockPos();
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockPos));
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockPos.offset(packet.getBlockHitResult().getSide())));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@Mixin(ChunkPosDistanceLevelPropagator.class)
public abstract class MixinAsyncChunk_ChunkPosDistanceLevelPropagator {
@Redirect(method = "propagateLevel", at = @At(value = "NEW", target = "net/minecraft/util/math/ChunkPos"))
@Redirect(method = "propagateLevel", at = @At(value = "NEW", target = "(J)Lnet/minecraft/util/math/ChunkPos;"))
private ChunkPos skipCreateChunkPos(long pos) {
return ChunkPos.ORIGIN;
}
Expand All @@ -41,7 +41,7 @@ private int getZ(ChunkPos instance, long pos, int level, boolean decrease) {
return (int) (pos >> 32);
}

@Redirect(method = "recalculateLevel", at = @At(value = "NEW", target = "net/minecraft/util/math/ChunkPos"))
@Redirect(method = "recalculateLevel", at = @At(value = "NEW", target = "(J)Lnet/minecraft/util/math/ChunkPos;"))
private ChunkPos skipCreateChunkPos2(long pos) {
return ChunkPos.ORIGIN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void noBlockingMove(PlayerMoveC2SPacket packet, CallbackInfo ci) {

int x = ChunkSectionPos.getSectionCoord(clampHorizontal(packet.getX(this.player.getX())));
int z = ChunkSectionPos.getSectionCoord(clampHorizontal(packet.getZ(this.player.getZ())));
if (!player.getWorld().getChunkManager().isTickingFutureReady(ChunkPos.toLong(x, z))) {
if (!player.getServerWorld().getChunkManager().isTickingFutureReady(ChunkPos.toLong(x, z))) {
player.setVelocity(Vec3d.ZERO);
requestTeleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYaw(), this.player.getPitch());
ci.cancel();
Expand All @@ -62,7 +62,7 @@ private void noBlockingMove(PlayerMoveC2SPacket packet, CallbackInfo ci) {

@Inject(method = "requestTeleport(DDDFFLjava/util/Set;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;updatePositionAndAngles(DDDFF)V", shift = At.Shift.AFTER))
private void onTeleport(double x, double y, double z, float yaw, float pitch, Set<PositionFlag> set, CallbackInfo ci) {
ServerWorld world = player.getWorld();
ServerWorld world = player.getServerWorld();
if (!world.getPlayers().contains(player)) return;
world.getChunkManager().updatePosition(this.player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@

package one.oktw.galaxy.mixin.tweak;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Pair;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.thread.TaskExecutor;
import net.minecraft.util.thread.TaskQueue;
import net.minecraft.world.storage.StorageIoWorker;
import net.minecraft.world.storage.StorageIoWorker.Priority;
import one.oktw.galaxy.util.KotlinCoroutineTaskExecutor;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -62,33 +67,55 @@ private void parallelExecutor(Path directory, boolean dsync, String name, Callba

/**
* @author James58899
* @reason null check and delay remove
* @reason no low priority write & bulk write
*/
@Overwrite
private void writeResult() {
if (!this.results.isEmpty() && !writeLock.getAndSet(true)) {
HashMap<Long, ArrayList<Pair<ChunkPos, StorageIoWorker.Result>>> map = new HashMap<>();
results.forEach((pos, result) -> map.computeIfAbsent(ChunkPos.toLong(pos.getRegionX(), pos.getRegionZ()), k -> new ArrayList<>()).add(new Pair<>(pos, result)));
map.values().forEach(list ->
executor.send(new TaskQueue.PrioritizedTask(1 /* BACKGROUND */, () -> list.forEach(pair -> write(pair.getLeft(), pair.getRight()))))
executor.send(new TaskQueue.PrioritizedTask(Priority.FOREGROUND.ordinal(), () -> list.forEach(pair -> write(pair.getLeft(), pair.getRight()))))
);
this.executor.send(new TaskQueue.PrioritizedTask(2 /* WRITE_DONE */, () -> {
this.executor.send(new TaskQueue.PrioritizedTask(Priority.BACKGROUND.ordinal(), () -> {
writeLock.set(false);
writeResult();
}));
}
}

@Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/storage/RegionBasedStorage;write(Lnet/minecraft/util/math/ChunkPos;Lnet/minecraft/nbt/NbtCompound;)V"), cancellable = true)
/**
* @author James58899
* @reason no low priority write
*/
@Overwrite
private void writeRemainingResults() {
writeResult();
}

/**
* @author James58899
* @reason no delay set result
*/
@Overwrite
public CompletableFuture<Void> setResult(ChunkPos pos, @Nullable NbtCompound nbt) {
StorageIoWorker.Result result = this.results.computeIfAbsent(pos, pos2 -> new StorageIoWorker.Result(nbt));
result.nbt = nbt;
return result.future;
}

@Inject(method = "readChunkData", at = @At("HEAD"), cancellable = true)
private void fastRead(ChunkPos pos, CallbackInfoReturnable<CompletableFuture<Optional<NbtCompound>>> cir) {
StorageIoWorker.Result result = this.results.get(pos);
if (result != null) {
cir.setReturnValue(CompletableFuture.completedFuture(Optional.ofNullable(result.nbt)));
}
}

@Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/storage/RegionBasedStorage;write(Lnet/minecraft/util/math/ChunkPos;Lnet/minecraft/nbt/NbtCompound;)V", shift = At.Shift.BEFORE), cancellable = true)
private void removeResults(ChunkPos pos, StorageIoWorker.Result result, CallbackInfo ci) {
if (!this.results.remove(pos, result)) { // Only write once
ci.cancel();
}
}

@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "method_27938", at = @At(value = "NEW", target = "net/minecraft/util/thread/TaskQueue$PrioritizedTask"))
private static TaskQueue.PrioritizedTask changeShutdownPriority(int priority, Runnable runnable) {
return new TaskQueue.PrioritizedTask(3 /* SHUTDOWN */, runnable);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* OKTW Galaxy Project
* Copyright (C) 2018-2022
* 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
Expand Down Expand Up @@ -45,7 +45,7 @@ public class MixinCustomBlockEntity_Structure {
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/ServerWorldAccess;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", ordinal = 1), locals = LocalCapture.CAPTURE_FAILSOFT)
private void hackPlace(ServerWorldAccess world, BlockPos pos, BlockPos pivot, StructurePlacementData placementData, Random random, int flags, CallbackInfoReturnable<Boolean> cir, List<StructureTemplate.StructureBlockInfo> list, BlockBox blockBox, List<BlockPos> list2, List<BlockPos> list3, List<Pair<BlockPos, NbtCompound>> list4, int j, int k, int l, int m, int n, int o, List<StructureTemplate.StructureBlockInfo> list5, Iterator<StructureTemplate.StructureBlockInfo> var19, StructureTemplate.StructureBlockInfo structureBlockInfo, BlockPos blockPos2, FluidState fluidState, BlockState blockState) {
// Workaround structure barrier bug
if (structureBlockInfo.state.getBlock() == Blocks.BARRIER) {
if (structureBlockInfo.state().getBlock() == Blocks.BARRIER) {
world.setBlockState(blockPos2, Blocks.AIR.getDefaultState(), Block.NO_REDRAW | Block.FORCE_STATE);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

package one.oktw.galaxy.mixin.tweak;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = RegistrySyncManager.class, remap = false)
public class MixinSkipSyncRegistry {
@Redirect(method = "createAndPopulateRegistryMap", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/Object2IntMap;put(Ljava/lang/Object;I)I", ordinal = 0))
private static int skipSyncGalaxyRegistry(Object2IntMap<Identifier> instance, Object o, int i) {
Identifier id = (Identifier) o;
if (id.getNamespace().equals("galaxy")) {
return instance.defaultReturnValue();
}
return instance.put((Identifier) o, i);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* OKTW Galaxy Project
* Copyright (C) 2018-2021
* 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
Expand Down Expand Up @@ -41,7 +41,7 @@ private HitResult addWaterHit(Entity entity, Predicate<Entity> predicate) {
if (hit.getType() == HitResult.Type.MISS && ((IThrownCountdown_Entity) this).getIntoWater() > 10) {
Vec3d pos = entity.getPos();
Vec3d velocity = pos.add(entity.getVelocity());
BlockHitResult newHit = entity.world.raycast(new RaycastContext(pos, velocity, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, entity));
BlockHitResult newHit = entity.getWorld().raycast(new RaycastContext(pos, velocity, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, entity));
if (newHit.getType() != HitResult.Type.MISS) {
hit = newHit;
}
Expand Down
Loading

0 comments on commit b8f4176

Please sign in to comment.