From 4a7999fe6f5a630be324995b68c6eaeca6a2e99a Mon Sep 17 00:00:00 2001 From: james58899 Date: Sat, 28 Nov 2020 18:26:04 +0800 Subject: [PATCH 01/18] 20w48a --- build.gradle.kts | 8 +- .../StorageIoWorkerAccessor.java} | 11 ++- .../event/MixinPlayerChat_SayCommand.java | 8 +- .../MixinAsyncChunk_StorageIoWorker.java | 72 -------------- ...nAsyncChunk_ThreadedAnvilChunkStorage.java | 10 +- .../tweak/MixinThrownCountdown_Entity.java | 4 +- ...MixinThrownCountdown_ProjectileEntity.java | 2 +- .../AbstractFurnaceBlockEntityAccessor.java | 41 ++++++++ .../BrewingStandBlockEntityAccessor.java | 32 +++++++ ...tractFurnaceBlockEntityMixin_RealTime.java | 95 ++++++++----------- ...BrewingStandBlockEntityMixin_RealTime.java | 46 +++++---- .../ExperienceOrbEntityMixin_RealTime.java | 39 +------- src/main/resources/accessor.mixin.json | 3 +- src/main/resources/fabric.mod.json | 2 +- src/main/resources/sponge.realtime.mixin.json | 2 + src/main/resources/tweak.mixin.json | 1 - 16 files changed, 168 insertions(+), 208 deletions(-) rename src/main/java/one/oktw/galaxy/mixin/{interfaces/AsyncChunk_StorageIoWorker.java => accessor/StorageIoWorkerAccessor.java} (71%) delete mode 100644 src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_StorageIoWorker.java create mode 100644 src/main/java/org/spongepowered/common/mixin/realtime/accessor/AbstractFurnaceBlockEntityAccessor.java create mode 100644 src/main/java/org/spongepowered/common/mixin/realtime/accessor/BrewingStandBlockEntityAccessor.java diff --git a/build.gradle.kts b/build.gradle.kts index 646b86ef7..5af77061d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,12 +39,12 @@ minecraft { dependencies { // Core - minecraft(group = "com.mojang", name = "minecraft", version = "1.16.5") - mappings(group = "net.fabricmc", name = "yarn", version = "1.16.5+build.9", classifier = "v2") - modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.11.3") + minecraft(group = "com.mojang", name = "minecraft", version = "20w48a") + mappings(group = "net.fabricmc", name = "yarn", version = "20w48a+build.2", classifier = "v2") + modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.10.8") // fabric api - modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.34.2+1.16") + modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.26.4+1.17") // galaxy api implementation(group = "one.oktw", name = "galaxy-lib", version = galaxyLibVersion) diff --git a/src/main/java/one/oktw/galaxy/mixin/interfaces/AsyncChunk_StorageIoWorker.java b/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java similarity index 71% rename from src/main/java/one/oktw/galaxy/mixin/interfaces/AsyncChunk_StorageIoWorker.java rename to src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java index de677efd0..1ee312f5f 100644 --- a/src/main/java/one/oktw/galaxy/mixin/interfaces/AsyncChunk_StorageIoWorker.java +++ b/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java @@ -16,13 +16,18 @@ * along with this program. If not, see . */ -package one.oktw.galaxy.mixin.interfaces; +package one.oktw.galaxy.mixin.accessor; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.storage.StorageIoWorker; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; import java.util.concurrent.CompletableFuture; -public interface AsyncChunk_StorageIoWorker { - CompletableFuture getNbt(ChunkPos pos); +@Mixin(StorageIoWorker.class) +public interface StorageIoWorkerAccessor { + @Invoker + CompletableFuture callMethod_31738(ChunkPos chunkPos); } diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_SayCommand.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_SayCommand.java index e2ff428a8..d4b3a4d09 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_SayCommand.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_SayCommand.java @@ -47,18 +47,18 @@ public class MixinPlayerChat_SayCommand { cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT ) - private static void onCommand(CommandContext context, CallbackInfoReturnable cir, Text text, TranslatableText translatableText, Entity entity) { + private static void onCommand(CommandContext context, CallbackInfoReturnable cir, Text text, Text text1, Entity entity) { if (!(entity instanceof ServerPlayerEntity)) return; Main main = Main.Companion.getMain(); ServerPlayerEntity player = (ServerPlayerEntity) entity; - if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, translatableText)).getCancel()) { - player.server.getPlayerManager().broadcastChatMessage(translatableText, MessageType.CHAT, entity.getUuid()); + if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, text1)).getCancel()) { + player.server.getPlayerManager().broadcastChatMessage(text1, MessageType.CHAT, entity.getUuid()); } else { cir.setReturnValue(0); cir.cancel(); - player.server.sendSystemMessage(translatableText.append(" (Canceled)"), entity.getUuid()); + player.server.sendSystemMessage(((TranslatableText) text1).append(" (Canceled)"), entity.getUuid()); } } } 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 deleted file mode 100644 index c0871c66a..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_StorageIoWorker.java +++ /dev/null @@ -1,72 +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 com.mojang.datafixers.util.Either; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.storage.RegionBasedStorage; -import net.minecraft.world.storage.StorageIoWorker; -import net.minecraft.world.storage.StorageIoWorker.Result; -import one.oktw.galaxy.mixin.interfaces.AsyncChunk_StorageIoWorker; -import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -@Mixin(StorageIoWorker.class) -public abstract class MixinAsyncChunk_StorageIoWorker implements AsyncChunk_StorageIoWorker { - - @Shadow - @Final - private static Logger LOGGER; - @Shadow - @Final - private RegionBasedStorage storage; - @Shadow - @Final - private Map results; - - @Shadow - protected abstract CompletableFuture run(Supplier> supplier); - - @Nullable - @Override - public CompletableFuture getNbt(ChunkPos pos) { - return run(() -> { - Result result = this.results.get(pos); - if (result != null) { - return Either.left(result.nbt); - } else { - try { - CompoundTag compoundTag = storage.getTagAt(pos); - return Either.left(compoundTag); - } catch (Exception var4) { - LOGGER.warn("Failed to read chunk {}", pos, var4); - return Either.right(var4); - } - } - }); - } -} diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java index b0b174791..9614abfb3 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java @@ -37,7 +37,7 @@ import net.minecraft.world.poi.PointOfInterestStorage; import net.minecraft.world.storage.VersionedChunkStorage; import one.oktw.galaxy.mixin.accessor.AsyncChunk_VersionedChunkStorage; -import one.oktw.galaxy.mixin.interfaces.AsyncChunk_StorageIoWorker; +import one.oktw.galaxy.mixin.accessor.StorageIoWorkerAccessor; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -87,10 +87,9 @@ public MixinAsyncChunk_ThreadedAnvilChunkStorage(File file, DataFixer dataFixer, */ @Overwrite private CompletableFuture> loadChunk(ChunkPos pos) { + this.world.getProfiler().visit("chunkLoad"); return getUpdatedChunkTagAsync(pos).handleAsync((compoundTag, t) -> { try { - this.world.getProfiler().visit("chunkLoad"); - if (t != null) { throw (Exception) t; } @@ -99,7 +98,6 @@ private CompletableFuture> loadChunk(ChunkPo boolean bl = compoundTag.contains("Level", 10) && compoundTag.getCompound("Level").contains("Status", 8); if (bl) { Chunk chunk = ChunkSerializer.deserialize(this.world, this.structureManager, this.pointOfInterestStorage, pos, compoundTag); - chunk.setLastSaveTime(this.world.getTime()); this.method_27053(pos, chunk.getStatus().getChunkType()); return Either.left(chunk); } @@ -119,12 +117,12 @@ private CompletableFuture> loadChunk(ChunkPo } this.method_27054(pos); - return Either.left(new ProtoChunk(pos, UpgradeData.NO_UPGRADE_DATA)); + return Either.left(new ProtoChunk(pos, UpgradeData.NO_UPGRADE_DATA, this.world)); }, this.mainThreadExecutor); } private CompletableFuture getUpdatedChunkTagAsync(ChunkPos pos) { - return ((AsyncChunk_StorageIoWorker) ((AsyncChunk_VersionedChunkStorage) this).getWorker()).getNbt(pos) + return ((StorageIoWorkerAccessor) ((AsyncChunk_VersionedChunkStorage) this).getWorker()).callMethod_31738(pos) .thenApplyAsync(compoundTag -> compoundTag == null ? null : this.updateChunkTag(world.getRegistryKey(), this.persistentStateManagerFactory, compoundTag), mainThreadExecutor); } } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinThrownCountdown_Entity.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinThrownCountdown_Entity.java index 4cc32400b..81ded9368 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinThrownCountdown_Entity.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinThrownCountdown_Entity.java @@ -33,7 +33,7 @@ public abstract class MixinThrownCountdown_Entity implements IThrownCountdown_En private int intoWater = 0; @Shadow - public abstract void remove(); + public abstract void discard(); @Inject(method = "checkWaterState", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;onSwimmingStart()V")) @@ -41,7 +41,7 @@ private void countIntoWater(CallbackInfo ci) { //noinspection ConstantConditions if (((Object) this) instanceof ArrowEntity || ((Object) this) instanceof SpectralArrowEntity) { if (intoWater > 10) { - remove(); + discard(); } } intoWater++; diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinThrownCountdown_ProjectileEntity.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinThrownCountdown_ProjectileEntity.java index 9624e34c0..ae588b367 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinThrownCountdown_ProjectileEntity.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinThrownCountdown_ProjectileEntity.java @@ -37,7 +37,7 @@ public MixinThrownCountdown_ProjectileEntity(EntityType type, World world) { @Inject(method = "tick", at = @At("HEAD")) private void maxAge(CallbackInfo ci) { - if (maxAge > 6000) remove(); + if (maxAge > 6000) discard(); maxAge++; } } diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/accessor/AbstractFurnaceBlockEntityAccessor.java b/src/main/java/org/spongepowered/common/mixin/realtime/accessor/AbstractFurnaceBlockEntityAccessor.java new file mode 100644 index 000000000..84d9953fa --- /dev/null +++ b/src/main/java/org/spongepowered/common/mixin/realtime/accessor/AbstractFurnaceBlockEntityAccessor.java @@ -0,0 +1,41 @@ +/* + * 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 org.spongepowered.common.mixin.realtime.accessor; + +import net.minecraft.block.entity.AbstractFurnaceBlockEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(AbstractFurnaceBlockEntity.class) +public interface AbstractFurnaceBlockEntityAccessor { + @Accessor + int getBurnTime(); + + @Accessor + void setBurnTime(int i); + + @Accessor + int getCookTime(); + + @Accessor + void setCookTime(int i); + + @Accessor + int getCookTimeTotal(); +} diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/accessor/BrewingStandBlockEntityAccessor.java b/src/main/java/org/spongepowered/common/mixin/realtime/accessor/BrewingStandBlockEntityAccessor.java new file mode 100644 index 000000000..01dd1611f --- /dev/null +++ b/src/main/java/org/spongepowered/common/mixin/realtime/accessor/BrewingStandBlockEntityAccessor.java @@ -0,0 +1,32 @@ +/* + * 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 org.spongepowered.common.mixin.realtime.accessor; + +import net.minecraft.block.entity.BrewingStandBlockEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(BrewingStandBlockEntity.class) +public interface BrewingStandBlockEntityAccessor { + @Accessor + int getBrewTime(); + + @Accessor + void setBrewTime(int i); +} diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/AbstractFurnaceBlockEntityMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/AbstractFurnaceBlockEntityMixin_RealTime.java index 33e95f278..82d206e70 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/AbstractFurnaceBlockEntityMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/AbstractFurnaceBlockEntityMixin_RealTime.java @@ -1,3 +1,21 @@ +/* + * 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 . + */ + /* * This file is part of Sponge, licensed under the MIT License (MIT). * @@ -25,79 +43,40 @@ package org.spongepowered.common.mixin.realtime.blockentity; import net.minecraft.block.entity.AbstractFurnaceBlockEntity; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; import net.minecraft.util.math.MathHelper; 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.Redirect; import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.common.bridge.RealTimeTrackingBridge; +import org.spongepowered.common.mixin.realtime.accessor.AbstractFurnaceBlockEntityAccessor; @Mixin(value = AbstractFurnaceBlockEntity.class, priority = 1001) -public abstract class AbstractFurnaceBlockEntityMixin_RealTime extends BlockEntity { - @Shadow - private int burnTime; - @Shadow - private int cookTime; - @Shadow - private int cookTimeTotal; - - public AbstractFurnaceBlockEntityMixin_RealTime(BlockEntityType blockEntityType_1) { - super(blockEntityType_1); - } - +public abstract class AbstractFurnaceBlockEntityMixin_RealTime { @Redirect(method = "tick", at = @At( value = "FIELD", target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;burnTime:I", - opcode = Opcodes.PUTFIELD - ), - slice = @Slice( - from = @At( - value = "INVOKE", - target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;isBurning()Z", - opcode = 1 - ), - to = @At( - value = "FIELD", - target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;world:Lnet/minecraft/world/World;", - opcode = Opcodes.GETFIELD, - ordinal = 0 - ) + opcode = Opcodes.PUTFIELD, + ordinal = 0 ) ) - private void realTimeImpl$adjustForRealTimeBurnTime(final AbstractFurnaceBlockEntity self, final int modifier) { - final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks(); - this.burnTime = Math.max(0, this.burnTime - Math.max(1, ticks - 1)); + private static void realTimeImpl$adjustForRealTimeBurnTime(AbstractFurnaceBlockEntity self, int value) { + final int ticks = (int) ((RealTimeTrackingBridge) self.getWorld()).realTimeBridge$getRealTimeTicks(); + + var accessor = (AbstractFurnaceBlockEntityAccessor) self; + accessor.setBurnTime(Math.max(0, accessor.getBurnTime() - Math.max(1, ticks - 1))); } @Redirect( method = "tick", - at = @At( - value = "FIELD", - target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;cookTime:I", - opcode = Opcodes.PUTFIELD - ), - slice = @Slice( - from = @At( - value = "INVOKE", - target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;canAcceptRecipeOutput(Lnet/minecraft/recipe/Recipe;)Z", - ordinal = 1 - ), - to = @At( - value = "FIELD", - target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;cookTimeTotal:I", - opcode = Opcodes.GETFIELD, - ordinal = 0 - ) - ) - ) - private void realTimeImpl$adjustForRealTimeCookTime(final AbstractFurnaceBlockEntity self, final int modifier) { - final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks(); - this.cookTime = Math.min(this.cookTimeTotal, this.cookTime + ticks); + at = @At(value = "FIELD", target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;cookTime:I", opcode = Opcodes.PUTFIELD, ordinal = 0)) + private static void realTimeImpl$adjustForRealTimeCookTime(final AbstractFurnaceBlockEntity self, final int modifier) { + final int ticks = (int) ((RealTimeTrackingBridge) self.getWorld()).realTimeBridge$getRealTimeTicks(); + + var accessor = (AbstractFurnaceBlockEntityAccessor) self; + accessor.setCookTime(Math.min(accessor.getCookTimeTotal(), accessor.getCookTime() + ticks)); } @Redirect( @@ -118,8 +97,10 @@ public AbstractFurnaceBlockEntityMixin_RealTime(BlockEntityType blockEntityTy ) ) ) - private void realTimeImpl$adjustForRealTimeCookTimeCooldown(final AbstractFurnaceBlockEntity self, final int modifier) { - final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks(); - this.cookTime = MathHelper.clamp(this.cookTime - (2 * ticks), 0, this.cookTimeTotal); + private static void realTimeImpl$adjustForRealTimeCookTimeCooldown(final AbstractFurnaceBlockEntity self, final int modifier) { + final int ticks = (int) ((RealTimeTrackingBridge) self.getWorld()).realTimeBridge$getRealTimeTicks(); + + var accessor = (AbstractFurnaceBlockEntityAccessor) self; + accessor.setCookTime(MathHelper.clamp(accessor.getCookTime() - (2 * ticks), 0, accessor.getCookTimeTotal())); } } diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/BrewingStandBlockEntityMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/BrewingStandBlockEntityMixin_RealTime.java index 0a4556a13..ae7fd2f20 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/BrewingStandBlockEntityMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/BrewingStandBlockEntityMixin_RealTime.java @@ -1,3 +1,21 @@ +/* + * 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 . + */ + /* * This file is part of Sponge, licensed under the MIT License (MIT). * @@ -24,35 +42,23 @@ */ package org.spongepowered.common.mixin.realtime.blockentity; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BrewingStandBlockEntity; 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.Redirect; import org.spongepowered.common.bridge.RealTimeTrackingBridge; +import org.spongepowered.common.mixin.realtime.accessor.BrewingStandBlockEntityAccessor; @Mixin(BrewingStandBlockEntity.class) -public abstract class BrewingStandBlockEntityMixin_RealTime extends BlockEntity { - @Shadow - private int brewTime; - - public BrewingStandBlockEntityMixin_RealTime(BlockEntityType blockEntityType_1) { - super(blockEntityType_1); - } - +public abstract class BrewingStandBlockEntityMixin_RealTime { @Redirect( method = "tick", - at = @At( - value = "FIELD", - target = "Lnet/minecraft/block/entity/BrewingStandBlockEntity;brewTime:I", - opcode = Opcodes.PUTFIELD, ordinal = 0 - ) - ) - private void realTimeImpl$adjustForRealTimeBrewTime(final BrewingStandBlockEntity self, final int modifier) { - final int ticks = (int) ((RealTimeTrackingBridge) this.world).realTimeBridge$getRealTimeTicks(); - this.brewTime = Math.max(0, this.brewTime - ticks); + at = @At(value = "FIELD", target = "Lnet/minecraft/block/entity/BrewingStandBlockEntity;brewTime:I", opcode = Opcodes.PUTFIELD, ordinal = 0)) + private static void realTimeImpl$adjustForRealTimeBrewTime(final BrewingStandBlockEntity self, final int modifier) { + final int ticks = (int) ((RealTimeTrackingBridge) self.getWorld()).realTimeBridge$getRealTimeTicks(); + + var accessor = (BrewingStandBlockEntityAccessor) self; + accessor.setBrewTime(Math.max(0, accessor.getBrewTime() - ticks)); } } diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/entity/ExperienceOrbEntityMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/entity/ExperienceOrbEntityMixin_RealTime.java index f7f93e5f7..5f60ebff2 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/entity/ExperienceOrbEntityMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/entity/ExperienceOrbEntityMixin_RealTime.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2019 + * 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 @@ -48,47 +48,14 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.common.bridge.RealTimeTrackingBridge; @Mixin(ExperienceOrbEntity.class) public abstract class ExperienceOrbEntityMixin_RealTime extends EntityMixin_RealTime { @Shadow - public int pickupDelay; - @Shadow - public int orbAge; - - @Redirect( - method = "tick", - at = @At( - value = "FIELD", - target = "Lnet/minecraft/entity/ExperienceOrbEntity;pickupDelay:I", - opcode = Opcodes.PUTFIELD - ) - ) - private void realTimeImpl$adjustForRealTimePickupDelay(final ExperienceOrbEntity self, final int modifier) { - final int ticks = (int) ((RealTimeTrackingBridge) this.world).realTimeBridge$getRealTimeTicks(); - this.pickupDelay = Math.max(0, this.pickupDelay - ticks); - } + private int orbAge; - @Redirect( - method = "tick", - at = @At(value = "FIELD", - target = "Lnet/minecraft/entity/ExperienceOrbEntity;orbAge:I", - opcode = Opcodes.PUTFIELD - ), - slice = @Slice( - from = @At( - value = "FIELD", - target = "Lnet/minecraft/entity/ExperienceOrbEntity;renderTicks:I", - opcode = Opcodes.PUTFIELD - ), - to = @At( - value = "CONSTANT", - args = "intValue=6000" - ) - ) - ) + @Redirect(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/ExperienceOrbEntity;orbAge:I", opcode = Opcodes.PUTFIELD)) private void realTimeImpl$adjustForRealTimeAge(final ExperienceOrbEntity self, final int modifier) { final int ticks = (int) ((RealTimeTrackingBridge) self.getEntityWorld()).realTimeBridge$getRealTimeTicks(); this.orbAge += ticks; diff --git a/src/main/resources/accessor.mixin.json b/src/main/resources/accessor.mixin.json index 63211bc59..9c29428ec 100644 --- a/src/main/resources/accessor.mixin.json +++ b/src/main/resources/accessor.mixin.json @@ -5,7 +5,8 @@ "mixins": [ "AsyncChunk_VersionedChunkStorage", "PlayerAbilitiesAccessor", - "ServerPlayerEntityFunctionAccessor" + "ServerPlayerEntityFunctionAccessor", + "StorageIoWorkerAccessor" ], "client": [], "injectors": { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6af966c4d..9eca8bd3b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,7 @@ "recipe.mixin.json" ], "depends": { - "minecraft": "1.16.x", + "minecraft": "1.17.x", "fabricloader": ">=0.8.8" }, "suggests": {} diff --git a/src/main/resources/sponge.realtime.mixin.json b/src/main/resources/sponge.realtime.mixin.json index 5bbc075e0..fd7ea740a 100644 --- a/src/main/resources/sponge.realtime.mixin.json +++ b/src/main/resources/sponge.realtime.mixin.json @@ -3,6 +3,8 @@ "package": "org.spongepowered.common.mixin.realtime", "compatibilityLevel": "JAVA_16", "mixins": [ + "accessor.AbstractFurnaceBlockEntityAccessor", + "accessor.BrewingStandBlockEntityAccessor", "blockentity.AbstractFurnaceBlockEntityMixin_RealTime", "blockentity.BrewingStandBlockEntityMixin_RealTime", "entity.EntityMixin_RealTime", diff --git a/src/main/resources/tweak.mixin.json b/src/main/resources/tweak.mixin.json index 1a08c500b..4b6cf6f8b 100644 --- a/src/main/resources/tweak.mixin.json +++ b/src/main/resources/tweak.mixin.json @@ -3,7 +3,6 @@ "package": "one.oktw.galaxy.mixin.tweak", "compatibilityLevel": "JAVA_16", "mixins": [ - "MixinAsyncChunk_StorageIoWorker", "MixinAsyncChunk_ThreadedAnvilChunkStorage", "MixinCustomBlockEntity_BarrierBlock", "MixinCustomBlockEntity_Structure", From 43c3eb16fbe80ec1f16e8e5bc397a84cba30e019 Mon Sep 17 00:00:00 2001 From: james58899 Date: Sat, 28 Nov 2020 20:41:06 +0800 Subject: [PATCH 02/18] Fix crafting map de-sync --- .../mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java index c3312580b..07844183c 100644 --- a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java +++ b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java @@ -20,6 +20,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.InventoryS2CPacket; import net.minecraft.screen.slot.CraftingResultSlot; import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Mixin; @@ -31,6 +32,7 @@ public class MixinCustomRecipe_CraftingResultSlot { @Inject(method = "onTakeItem", at = @At("RETURN")) private void consumeInput(PlayerEntity player, ItemStack stack, CallbackInfoReturnable cir) { - ((ServerPlayerEntity) player).refreshScreenHandler(player.currentScreenHandler); + var handler = player.currentScreenHandler; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new InventoryS2CPacket(handler.syncId, handler.getStacks())); } } From 384132369086cfbb0b0238f630ef2d02d5f71ce0 Mon Sep 17 00:00:00 2001 From: james58899 Date: Thu, 3 Dec 2020 13:50:09 +0800 Subject: [PATCH 03/18] 20w49a --- build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5af77061d..138eafddb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,12 +39,12 @@ minecraft { dependencies { // Core - minecraft(group = "com.mojang", name = "minecraft", version = "20w48a") - mappings(group = "net.fabricmc", name = "yarn", version = "20w48a+build.2", classifier = "v2") + minecraft(group = "com.mojang", name = "minecraft", version = "20w49a") + mappings(group = "net.fabricmc", name = "yarn", version = "20w49a+build.1", classifier = "v2") modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.10.8") // fabric api - modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.26.4+1.17") + modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.27.2+1.17") // galaxy api implementation(group = "one.oktw", name = "galaxy-lib", version = galaxyLibVersion) From e81d78221a74207d68fe64778262545471617d59 Mon Sep 17 00:00:00 2001 From: james58899 Date: Thu, 7 Jan 2021 17:20:35 +0800 Subject: [PATCH 04/18] Replace all 'var' with explicit type It cause migrate mapping try import 'var' --- .../recipe/MixinCustomRecipe_CraftingResultSlot.java | 5 +++-- .../AbstractFurnaceBlockEntityMixin_RealTime.java | 8 ++++---- .../BrewingStandBlockEntityMixin_RealTime.java | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java index 07844183c..6f459a5d7 100644 --- a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java +++ b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -21,6 +21,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.s2c.play.InventoryS2CPacket; +import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.CraftingResultSlot; import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Mixin; @@ -32,7 +33,7 @@ public class MixinCustomRecipe_CraftingResultSlot { @Inject(method = "onTakeItem", at = @At("RETURN")) private void consumeInput(PlayerEntity player, ItemStack stack, CallbackInfoReturnable cir) { - var handler = player.currentScreenHandler; + ScreenHandler handler = player.currentScreenHandler; ((ServerPlayerEntity) player).networkHandler.sendPacket(new InventoryS2CPacket(handler.syncId, handler.getStacks())); } } diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/AbstractFurnaceBlockEntityMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/AbstractFurnaceBlockEntityMixin_RealTime.java index 82d206e70..343b086ce 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/AbstractFurnaceBlockEntityMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/AbstractFurnaceBlockEntityMixin_RealTime.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -65,7 +65,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_RealTime { private static void realTimeImpl$adjustForRealTimeBurnTime(AbstractFurnaceBlockEntity self, int value) { final int ticks = (int) ((RealTimeTrackingBridge) self.getWorld()).realTimeBridge$getRealTimeTicks(); - var accessor = (AbstractFurnaceBlockEntityAccessor) self; + AbstractFurnaceBlockEntityAccessor accessor = (AbstractFurnaceBlockEntityAccessor) self; accessor.setBurnTime(Math.max(0, accessor.getBurnTime() - Math.max(1, ticks - 1))); } @@ -75,7 +75,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_RealTime { private static void realTimeImpl$adjustForRealTimeCookTime(final AbstractFurnaceBlockEntity self, final int modifier) { final int ticks = (int) ((RealTimeTrackingBridge) self.getWorld()).realTimeBridge$getRealTimeTicks(); - var accessor = (AbstractFurnaceBlockEntityAccessor) self; + AbstractFurnaceBlockEntityAccessor accessor = (AbstractFurnaceBlockEntityAccessor) self; accessor.setCookTime(Math.min(accessor.getCookTimeTotal(), accessor.getCookTime() + ticks)); } @@ -100,7 +100,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_RealTime { private static void realTimeImpl$adjustForRealTimeCookTimeCooldown(final AbstractFurnaceBlockEntity self, final int modifier) { final int ticks = (int) ((RealTimeTrackingBridge) self.getWorld()).realTimeBridge$getRealTimeTicks(); - var accessor = (AbstractFurnaceBlockEntityAccessor) self; + AbstractFurnaceBlockEntityAccessor accessor = (AbstractFurnaceBlockEntityAccessor) self; accessor.setCookTime(MathHelper.clamp(accessor.getCookTime() - (2 * ticks), 0, accessor.getCookTimeTotal())); } } diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/BrewingStandBlockEntityMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/BrewingStandBlockEntityMixin_RealTime.java index ae7fd2f20..dabc5356a 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/BrewingStandBlockEntityMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/blockentity/BrewingStandBlockEntityMixin_RealTime.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -58,7 +58,7 @@ public abstract class BrewingStandBlockEntityMixin_RealTime { private static void realTimeImpl$adjustForRealTimeBrewTime(final BrewingStandBlockEntity self, final int modifier) { final int ticks = (int) ((RealTimeTrackingBridge) self.getWorld()).realTimeBridge$getRealTimeTicks(); - var accessor = (BrewingStandBlockEntityAccessor) self; + BrewingStandBlockEntityAccessor accessor = (BrewingStandBlockEntityAccessor) self; accessor.setBrewTime(Math.max(0, accessor.getBrewTime() - ticks)); } } From 6b99a0c6ff9ac84099036fee2b4e4495f6f427fe Mon Sep 17 00:00:00 2001 From: james58899 Date: Thu, 7 Jan 2021 17:52:14 +0800 Subject: [PATCH 05/18] 20w51a --- build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 138eafddb..d914d17b4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,12 +39,12 @@ minecraft { dependencies { // Core - minecraft(group = "com.mojang", name = "minecraft", version = "20w49a") - mappings(group = "net.fabricmc", name = "yarn", version = "20w49a+build.1", classifier = "v2") + minecraft(group = "com.mojang", name = "minecraft", version = "20w51a") + mappings(group = "net.fabricmc", name = "yarn", version = "20w51a+build.28", classifier = "v2") modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.10.8") // fabric api - modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.27.2+1.17") + modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.29.3+1.17") // galaxy api implementation(group = "one.oktw", name = "galaxy-lib", version = galaxyLibVersion) From e817636cadfd7e1685933fb225ffd106e3122382 Mon Sep 17 00:00:00 2001 From: james58899 Date: Thu, 7 Jan 2021 18:09:16 +0800 Subject: [PATCH 06/18] Clean up access widener --- build.gradle.kts | 1 - src/main/resources/fabric.mod.json | 1 - src/main/resources/galaxy-tweak.accesswidener | 5 ----- 3 files changed, 7 deletions(-) delete mode 100644 src/main/resources/galaxy-tweak.accesswidener diff --git a/build.gradle.kts b/build.gradle.kts index d914d17b4..460a6d00c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,7 +34,6 @@ tasks.withType { } minecraft { - accessWidener("src/main/resources/galaxy-tweak.accesswidener") } dependencies { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9eca8bd3b..009a75b4e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -12,7 +12,6 @@ "sources": "https://github.com/OKTW-Network/Galaxy" }, "license": "AGPL-3.0-or-later", - "accessWidener": "galaxy-tweak.accesswidener", "environment": "server", "entrypoints": { "server": [ diff --git a/src/main/resources/galaxy-tweak.accesswidener b/src/main/resources/galaxy-tweak.accesswidener deleted file mode 100644 index 7e61d268d..000000000 --- a/src/main/resources/galaxy-tweak.accesswidener +++ /dev/null @@ -1,5 +0,0 @@ -accessWidener v1 named - -# Async chunk load -accessible class net/minecraft/world/storage/StorageIoWorker$Result -accessible field net/minecraft/world/storage/StorageIoWorker$Result nbt Lnet/minecraft/nbt/CompoundTag; From cf2423b800c45e65576ed707b5726885ee4cbed3 Mon Sep 17 00:00:00 2001 From: James58899 Date: Sat, 6 Mar 2021 17:15:56 +0800 Subject: [PATCH 07/18] 21w08b Refactor block entity create and tick --- build.gradle.kts | 8 ++-- .../BeaconLevelAccessor.java} | 19 +++----- .../accessor/StorageIoWorkerAccessor.java | 4 +- .../event/MixinPlayerChat_NetworkHandler.java | 13 +++--- ...inPlayerInteractEntity_NetworkHandler.java | 46 ------------------- .../MixinPlayerUpdateSign_NetworkHandler.java | 4 +- ...nAsyncChunk_ThreadedAnvilChunkStorage.java | 6 +-- .../MixinCustomBlockEntity_BarrierBlock.java | 14 ++++-- .../MixinCustomBlockEntity_Structure.java | 4 +- .../MixinFixBeacon_BeaconBlockEntity.java | 28 +++++------ .../MixinMapExistingChunk_FilledMapItem.java | 2 +- ...inOptimizeContainer_HopperBlockEntity.java | 23 ++++++---- .../one/oktw/galaxy/block/CustomBlock.kt | 10 +++- .../galaxy/block/CustomBlockEntityTicker.kt | 32 +++++++++++++ .../oktw/galaxy/block/CustomBlockHelper.kt | 2 +- .../one/oktw/galaxy/block/DummyBlock.kt | 3 +- .../one/oktw/galaxy/block/ModelCustomBlock.kt | 5 +- .../galaxy/block/entity/CustomBlockEntity.kt | 4 +- .../galaxy/block/entity/DummyBlockEntity.kt | 10 ++-- .../block/entity/ModelCustomBlockEntity.kt | 17 +++---- .../listener/CustomBlockTickListener.kt} | 11 ++--- .../command/commands/admin/RegisterBlock.kt | 2 +- src/main/resources/accessor.mixin.json | 1 + src/main/resources/galaxy.mixin.json | 1 - src/main/resources/tweak.mixin.json | 1 - 25 files changed, 137 insertions(+), 133 deletions(-) rename src/main/java/one/oktw/galaxy/mixin/{tweak/MixinSkipEnchantingTableTick.java => accessor/BeaconLevelAccessor.java} (67%) delete mode 100644 src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractEntity_NetworkHandler.java create mode 100644 src/main/kotlin/one/oktw/galaxy/block/CustomBlockEntityTicker.kt rename src/main/kotlin/one/oktw/galaxy/{event/type/PlayerInteractEntityEvent.kt => block/listener/CustomBlockTickListener.kt} (69%) diff --git a/build.gradle.kts b/build.gradle.kts index 460a6d00c..b30f2112c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,12 +38,12 @@ minecraft { dependencies { // Core - minecraft(group = "com.mojang", name = "minecraft", version = "20w51a") - mappings(group = "net.fabricmc", name = "yarn", version = "20w51a+build.28", classifier = "v2") - modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.10.8") + minecraft(group = "com.mojang", name = "minecraft", version = "21w08b") + mappings(group = "net.fabricmc", name = "yarn", version = "21w08b+build.20", classifier = "v2") + modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.11.2") // fabric api - modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.29.3+1.17") + modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.31.2+1.17") // galaxy api implementation(group = "one.oktw", name = "galaxy-lib", version = galaxyLibVersion) diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinSkipEnchantingTableTick.java b/src/main/java/one/oktw/galaxy/mixin/accessor/BeaconLevelAccessor.java similarity index 67% rename from src/main/java/one/oktw/galaxy/mixin/tweak/MixinSkipEnchantingTableTick.java rename to src/main/java/one/oktw/galaxy/mixin/accessor/BeaconLevelAccessor.java index 220a7f408..abe62a86c 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinSkipEnchantingTableTick.java +++ b/src/main/java/one/oktw/galaxy/mixin/accessor/BeaconLevelAccessor.java @@ -16,19 +16,14 @@ * along with this program. If not, see . */ -package one.oktw.galaxy.mixin.tweak; +package one.oktw.galaxy.mixin.accessor; -import net.minecraft.block.entity.EnchantingTableBlockEntity; +import net.minecraft.block.entity.BeaconBlockEntity; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.gen.Accessor; -@Mixin(EnchantingTableBlockEntity.class) -public class MixinSkipEnchantingTableTick { - /** - * @author James58899 - * @reason No need tick at server side - */ - @Overwrite - public void tick() { - } +@Mixin(BeaconBlockEntity.class) +public interface BeaconLevelAccessor { + @Accessor + int getLevel(); } diff --git a/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java b/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java index 1ee312f5f..d51c59de6 100644 --- a/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java +++ b/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -29,5 +29,5 @@ @Mixin(StorageIoWorker.class) public interface StorageIoWorkerAccessor { @Invoker - CompletableFuture callMethod_31738(ChunkPos chunkPos); + CompletableFuture callReadChunkData(ChunkPos chunkPos); } diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_NetworkHandler.java index 9ab82489d..2eeefea67 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerChat_NetworkHandler.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -34,6 +34,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; import java.util.UUID; +import java.util.function.Function; @Mixin(ServerPlayNetworkHandler.class) public class MixinPlayerChat_NetworkHandler { @@ -44,14 +45,14 @@ public class MixinPlayerChat_NetworkHandler { @Final private MinecraftServer server; - @Redirect(method = "method_31286", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) - private void onChat(PlayerManager playerManager, Text message, MessageType type, UUID senderUuid) { + @Redirect(method = "method_31286", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) + private void onChat(PlayerManager playerManager, Text serverMessage, Function playerMessageFactory, MessageType playerMessageType, UUID sender) { Main main = Main.Companion.getMain(); - if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, message)).getCancel()) { - playerManager.broadcastChatMessage(message, type, senderUuid); + if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, serverMessage)).getCancel()) { + playerManager.broadcastChatMessage(serverMessage, playerMessageType, sender); } else { - server.sendSystemMessage(((BaseText) message).append(" (Canceled)"), senderUuid); + server.sendSystemMessage(((BaseText) serverMessage).append(" (Canceled)"), sender); } } } diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractEntity_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractEntity_NetworkHandler.java deleted file mode 100644 index 8bed7f8b0..000000000 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractEntity_NetworkHandler.java +++ /dev/null @@ -1,46 +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.event; - -import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; -import one.oktw.galaxy.Main; -import one.oktw.galaxy.event.type.PlayerInteractEntityEvent; -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.CallbackInfo; - -@Mixin(ServerPlayNetworkHandler.class) -public class MixinPlayerInteractEntity_NetworkHandler { - @Shadow - public ServerPlayerEntity player; - - @Inject(method = "onPlayerInteractEntity", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;" - )) - private void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo ci) { - Main main = Main.Companion.getMain(); - if (main == null) return; - main.getEventManager().emit(new PlayerInteractEntityEvent(packet, player)); - } -} diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerUpdateSign_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerUpdateSign_NetworkHandler.java index af1fdaa7a..7564b1e0b 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerUpdateSign_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerUpdateSign_NetworkHandler.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -42,7 +42,7 @@ public class MixinPlayerUpdateSign_NetworkHandler { @Shadow public ServerPlayerEntity player; - @Inject(method = "method_31282", + @Inject(method = "onSignUpdate(Lnet/minecraft/network/packet/c2s/play/UpdateSignC2SPacket;Ljava/util/List;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/SignBlockEntity;isEditable()Z"), cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT) diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java index 9614abfb3..61805f426 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -122,7 +122,7 @@ private CompletableFuture> loadChunk(ChunkPo } private CompletableFuture getUpdatedChunkTagAsync(ChunkPos pos) { - return ((StorageIoWorkerAccessor) ((AsyncChunk_VersionedChunkStorage) this).getWorker()).callMethod_31738(pos) - .thenApplyAsync(compoundTag -> compoundTag == null ? null : this.updateChunkTag(world.getRegistryKey(), this.persistentStateManagerFactory, compoundTag), mainThreadExecutor); + return ((StorageIoWorkerAccessor) ((AsyncChunk_VersionedChunkStorage) this).getWorker()).callReadChunkData(pos) + .thenApplyAsync(compoundTag -> compoundTag == null ? null : this.updateChunkNbt(world.getRegistryKey(), this.persistentStateManagerFactory, compoundTag), mainThreadExecutor); } } 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 15c7554ec..eeef7c56d 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 @@ -23,11 +23,13 @@ import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityTicker; +import net.minecraft.block.entity.BlockEntityType; import net.minecraft.screen.ScreenHandler; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; import net.minecraft.world.World; import one.oktw.galaxy.block.CustomBlock; +import one.oktw.galaxy.block.CustomBlockEntityTicker; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -39,8 +41,8 @@ public MixinCustomBlockEntity_BarrierBlock(Settings settings) { @Nullable @Override - public BlockEntity createBlockEntity(BlockView world) { - return CustomBlock.Companion.getDUMMY().createBlockEntity(); + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return CustomBlock.Companion.getDUMMY().createBlockEntity(pos); } @Override @@ -52,4 +54,10 @@ public boolean hasComparatorOutput(BlockState state) { public int getComparatorOutput(BlockState state, World world, BlockPos pos) { return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos)); } + + @Nullable + @Override + public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { + return new CustomBlockEntityTicker<>(); + } } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_Structure.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_Structure.java index aa462bab1..d31e65876 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_Structure.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_Structure.java @@ -42,8 +42,8 @@ public class MixinCustomBlockEntity_Structure { @Inject(method = "place(Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/structure/StructurePlacementData;Ljava/util/Random;I)Z", 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 serverWorldAccess, BlockPos pos, BlockPos blockPos, StructurePlacementData placementData, Random random, int i, CallbackInfoReturnable cir, List list, BlockBox blockBox, List list2, List> list3, int j, int k, int l, int m, int n, int o, List list4, Iterator var18, Structure.StructureBlockInfo structureBlockInfo, BlockPos blockPos2, FluidState fluidState, BlockState blockState) { + private void hackPlace(ServerWorldAccess world, BlockPos pos, BlockPos blockPos, StructurePlacementData placementData, Random random, int i, CallbackInfoReturnable cir, List list, BlockBox blockBox, List list2, List list3, List> list4, int j, int k, int l, int m, int n, int o, List list5, Iterator var19, Structure.StructureBlockInfo structureBlockInfo, BlockPos blockPos2, FluidState fluidState, BlockState blockState) { // Workaround structure barrier bug - if (structureBlockInfo.state.getBlock() == Blocks.BARRIER) serverWorldAccess.setBlockState(blockPos2, Blocks.AIR.getDefaultState(), 20); + if (structureBlockInfo.state.getBlock() == Blocks.BARRIER) world.setBlockState(blockPos2, Blocks.AIR.getDefaultState(), 20); } } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinFixBeacon_BeaconBlockEntity.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinFixBeacon_BeaconBlockEntity.java index 3da463f9d..46b26fe36 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinFixBeacon_BeaconBlockEntity.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinFixBeacon_BeaconBlockEntity.java @@ -19,6 +19,7 @@ package one.oktw.galaxy.mixin.tweak; import net.minecraft.advancement.criterion.Criteria; +import net.minecraft.block.BlockState; import net.minecraft.block.entity.BeaconBlockEntity; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; @@ -27,6 +28,8 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; +import net.minecraft.world.World; +import one.oktw.galaxy.mixin.accessor.BeaconLevelAccessor; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -37,34 +40,33 @@ @Mixin(BeaconBlockEntity.class) public abstract class MixinFixBeacon_BeaconBlockEntity extends BlockEntity { - @Shadow - private int level; - - public MixinFixBeacon_BeaconBlockEntity(BlockEntityType type) { - super(type); + public MixinFixBeacon_BeaconBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); } @Shadow - public abstract void playSound(SoundEvent soundEvent); + public static void playSound(World world, BlockPos pos, SoundEvent sound) { + } @Inject(method = "tick", at = @At(value = "FIELD", opcode = Opcodes.GETSTATIC, target = "Lnet/minecraft/sound/SoundEvents;BLOCK_BEACON_AMBIENT:Lnet/minecraft/sound/SoundEvent;"), locals = LocalCapture.CAPTURE_FAILSOFT) - private void fixBeaconActivate(CallbackInfo ci, int i, int j, int k, BlockPos blockPos2, BeaconBlockEntity.BeamSegment beamSegment, int l, int n) { + // TODO check local capture + private static void fixBeaconActivate(World world, BlockPos pos, BlockState state, BeaconBlockEntity blockEntity, CallbackInfo ci, int i, int j, int k, BlockPos blockPos2, BeaconBlockEntity.BeamSegment beamSegment, int l, int n) { + BeaconLevelAccessor accessor = (BeaconLevelAccessor) blockEntity; boolean bl = n > 0; - boolean bl2 = level > 0; + boolean bl2 = accessor.getLevel() > 0; if (!bl && bl2) { - playSound(SoundEvents.BLOCK_BEACON_ACTIVATE); + playSound(world, pos, SoundEvents.BLOCK_BEACON_ACTIVATE); - //noinspection ConstantConditions for (ServerPlayerEntity serverPlayerEntity : world.getNonSpectatingEntities(ServerPlayerEntity.class, (new Box(i, j, k, i, j - 4, k)).expand(10.0D, 5.0D, 10.0D))) { - Criteria.CONSTRUCT_BEACON.trigger(serverPlayerEntity, (BeaconBlockEntity) (Object) this); + Criteria.CONSTRUCT_BEACON.trigger(serverPlayerEntity, accessor.getLevel()); } } else if (bl && !bl2) { - this.playSound(SoundEvents.BLOCK_BEACON_DEACTIVATE); + playSound(world, pos, SoundEvents.BLOCK_BEACON_DEACTIVATE); } } @Inject(method = "tick", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lnet/minecraft/world/World;isClient:Z"), cancellable = true) - private void skipBugActivate(CallbackInfo ci) { + private static void skipBugActivate(CallbackInfo ci) { ci.cancel(); } } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinMapExistingChunk_FilledMapItem.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinMapExistingChunk_FilledMapItem.java index 31cb40676..8e92d3c28 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinMapExistingChunk_FilledMapItem.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinMapExistingChunk_FilledMapItem.java @@ -33,7 +33,7 @@ public abstract class MixinMapExistingChunk_FilledMapItem { @Redirect(method = "updateColors", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getWorldChunk(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/world/chunk/WorldChunk;")) private WorldChunk getExistingChunk(World world, BlockPos pos) { ChunkPos chunkPos = new ChunkPos(pos); - WorldChunk chunk = (WorldChunk) world.getExistingChunk(chunkPos.x, chunkPos.z); + WorldChunk chunk = (WorldChunk) world.getChunkAsView(chunkPos.x, chunkPos.z); if (chunk == null) chunk = new EmptyChunk(world, chunkPos); return chunk; } 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 index a8993393f..03ac999aa 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_HopperBlockEntity.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinOptimizeContainer_HopperBlockEntity.java @@ -18,6 +18,7 @@ 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; @@ -25,7 +26,9 @@ 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; @@ -39,8 +42,8 @@ @Mixin(HopperBlockEntity.class) public abstract class MixinOptimizeContainer_HopperBlockEntity extends LootableContainerBlockEntity { - protected MixinOptimizeContainer_HopperBlockEntity(BlockEntityType blockEntityType) { - super(blockEntityType); + protected MixinOptimizeContainer_HopperBlockEntity(BlockEntityType blockEntityType, BlockPos blockPos, BlockState blockState) { + super(blockEntityType, blockPos, blockState); } @Shadow @@ -71,7 +74,7 @@ private static boolean isInventoryEmpty(Inventory inv, Direction facing) { * @reason No stream forEach */ @Overwrite - private boolean isInventoryFull(Inventory inv, Direction direction) { + 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; @@ -93,23 +96,23 @@ private static void extract_EarlyCheck(Hopper hopper, Inventory inventory, int s } @Inject(method = "insert", - at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/HopperBlockEntity;getStack(I)Lnet/minecraft/item/ItemStack;", shift = At.Shift.BEFORE), + at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", shift = At.Shift.BEFORE, ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) - private void insert_EarlyCheck(CallbackInfoReturnable cir, Inventory inventory, Direction direction, int slot) { - ItemStack itemStack = getStack(slot); - for (int i : getAvailableSlots_NoStream(inventory, direction)) { - ItemStack slotItem = inventory.getStack(i); + 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/block/entity/Hopper;)Z", + @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(Hopper hopper, CallbackInfoReturnable cir, Inventory inventory, Direction direction) { + 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)) { diff --git a/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt b/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt index 5532111c2..41c75ea22 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt @@ -20,8 +20,10 @@ package one.oktw.galaxy.block import net.minecraft.block.Block import net.minecraft.block.Blocks.* +import net.minecraft.block.entity.BlockEntityType import net.minecraft.block.entity.BlockEntityType.Builder import net.minecraft.util.Identifier +import net.minecraft.util.math.BlockPos import net.minecraft.util.registry.Registry import one.oktw.galaxy.block.entity.CustomBlockEntity import one.oktw.galaxy.item.CustomBlockItem @@ -31,7 +33,11 @@ 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) - protected val blockEntityType = Registry.register(Registry.BLOCK_ENTITY_TYPE, identifier, Builder.create({ createBlockEntity() }, baseBlock).build(null))!! + protected val blockEntityType: BlockEntityType = Registry.register( + Registry.BLOCK_ENTITY_TYPE, + identifier, + Builder.create({ pos, _ -> createBlockEntity(pos) }, BARRIER).build(null) + ) companion object { val registry = CustomRegistry() @@ -49,5 +55,5 @@ open class CustomBlock(final override val identifier: Identifier, val baseBlock: open fun toItem(): CustomBlockItem? = null - open fun createBlockEntity(): CustomBlockEntity = CustomBlockEntity(blockEntityType) + open fun createBlockEntity(pos: BlockPos): CustomBlockEntity = CustomBlockEntity(blockEntityType, pos) } diff --git a/src/main/kotlin/one/oktw/galaxy/block/CustomBlockEntityTicker.kt b/src/main/kotlin/one/oktw/galaxy/block/CustomBlockEntityTicker.kt new file mode 100644 index 000000000..e19c70f3c --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/block/CustomBlockEntityTicker.kt @@ -0,0 +1,32 @@ +/* + * 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.block + +import net.minecraft.block.BlockState +import net.minecraft.block.entity.BlockEntity +import net.minecraft.block.entity.BlockEntityTicker +import net.minecraft.util.math.BlockPos +import net.minecraft.world.World +import one.oktw.galaxy.block.listener.CustomBlockTickListener + +class CustomBlockEntityTicker : BlockEntityTicker { + override fun tick(world: World, pos: BlockPos, state: BlockState, blockEntity: T) { + if (blockEntity is CustomBlockTickListener) blockEntity.tick() + } +} diff --git a/src/main/kotlin/one/oktw/galaxy/block/CustomBlockHelper.kt b/src/main/kotlin/one/oktw/galaxy/block/CustomBlockHelper.kt index 921699851..c05bac706 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/CustomBlockHelper.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/CustomBlockHelper.kt @@ -59,7 +59,7 @@ object CustomBlockHelper { * Set BlockEntity and ARMOR_STAND and play sound */ private fun postPlace(world: ServerWorld, pos: BlockPos, block: CustomBlock) { - world.setBlockEntity(pos, block.createBlockEntity()) + world.addBlockEntity(block.createBlockEntity(pos)) world.playSound(null, pos, SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F) } diff --git a/src/main/kotlin/one/oktw/galaxy/block/DummyBlock.kt b/src/main/kotlin/one/oktw/galaxy/block/DummyBlock.kt index 5fec7ba34..de964d7d9 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/DummyBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/DummyBlock.kt @@ -19,8 +19,9 @@ package one.oktw.galaxy.block 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")) { - override fun createBlockEntity() = DummyBlockEntity(blockEntityType) + 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 648083f65..889c74e4f 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/ModelCustomBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/ModelCustomBlock.kt @@ -21,6 +21,7 @@ package one.oktw.galaxy.block import net.minecraft.block.Blocks.BARRIER import net.minecraft.item.ItemStack import net.minecraft.util.Identifier +import net.minecraft.util.math.BlockPos import one.oktw.galaxy.block.entity.CustomBlockEntity import one.oktw.galaxy.block.entity.ModelCustomBlockEntity import one.oktw.galaxy.item.CustomBlockItem @@ -31,7 +32,7 @@ class ModelCustomBlock(identifier: Identifier, private val modelItem: ItemStack) override fun toItem() = modelItem.let { CustomItemHelper.getItem(it) as? CustomBlockItem } - override fun createBlockEntity(): CustomBlockEntity { - return ModelCustomBlockEntity(blockEntityType, modelItem) + override fun createBlockEntity(pos: BlockPos): CustomBlockEntity { + return ModelCustomBlockEntity(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 b2e479129..c8652c4f1 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/CustomBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/CustomBlockEntity.kt @@ -18,10 +18,12 @@ package one.oktw.galaxy.block.entity +import net.minecraft.block.Blocks import net.minecraft.block.entity.BlockEntity import net.minecraft.block.entity.BlockEntityType +import net.minecraft.util.math.BlockPos // BlockEntity need extend -open class CustomBlockEntity(type: BlockEntityType<*>) : BlockEntity(type) { +open class CustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos) : BlockEntity(type, pos, Blocks.BARRIER.defaultState) { fun getId() = BlockEntityType.getId(type)!! } 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 76f5df91f..eee534926 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/DummyBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/DummyBlockEntity.kt @@ -18,19 +18,19 @@ package one.oktw.galaxy.block.entity -import net.minecraft.block.BlockState import net.minecraft.block.entity.BlockEntityType import net.minecraft.nbt.CompoundTag import net.minecraft.util.Identifier +import net.minecraft.util.math.BlockPos import one.oktw.galaxy.block.CustomBlock -class DummyBlockEntity(type: BlockEntityType<*>) : CustomBlockEntity(type) { - override fun fromTag(state: BlockState, tag: CompoundTag) { - super.fromTag(state, tag) +class DummyBlockEntity(type: BlockEntityType<*>, pos: BlockPos) : CustomBlockEntity(type, pos) { + override fun readNbt(tag: CompoundTag) { + super.readNbt(tag) tag.getString("id")?.let(Identifier::tryParse)?.let(CustomBlock.registry::get)?.let { if (it != CustomBlock.DUMMY) { world?.removeBlockEntity(pos) - world?.setBlockEntity(pos, it.createBlockEntity()) + world?.addBlockEntity(it.createBlockEntity(pos)) } } } 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 c9b307de0..127ed764b 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt @@ -18,7 +18,6 @@ package one.oktw.galaxy.block.entity -import net.minecraft.block.BlockState import net.minecraft.block.entity.BlockEntityType import net.minecraft.entity.Entity import net.minecraft.entity.EntityType @@ -27,10 +26,12 @@ import net.minecraft.entity.decoration.ArmorStandEntity import net.minecraft.item.ItemStack import net.minecraft.nbt.CompoundTag import net.minecraft.server.world.ServerWorld -import net.minecraft.util.Tickable +import net.minecraft.util.math.BlockPos +import one.oktw.galaxy.block.listener.CustomBlockTickListener import java.util.* -open class ModelCustomBlockEntity(type: BlockEntityType<*>, private val modelItem: ItemStack) : CustomBlockEntity(type), Tickable { +open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, private val modelItem: ItemStack) : CustomBlockEntity(type, pos), + CustomBlockTickListener { companion object { private val armorStandTag = CompoundTag().apply { putString("id", "minecraft:armor_stand") @@ -55,13 +56,13 @@ open class ModelCustomBlockEntity(type: BlockEntityType<*>, private val modelIte } } - override fun fromTag(state: BlockState?, tag: CompoundTag) { - super.fromTag(state, tag) + override fun readNbt(tag: CompoundTag) { + super.readNbt(tag) entityUUID = (tag.get("GalaxyData") as? CompoundTag)?.getUuid("ModelEntity") ?: return } - override fun toTag(tag: CompoundTag): CompoundTag { - super.toTag(tag) + override fun writeNbt(tag: CompoundTag): CompoundTag { + super.writeNbt(tag) entityUUID?.let { tag.put("GalaxyData", CompoundTag().apply { putUuid("ModelEntity", it) }) } return tag } @@ -72,7 +73,7 @@ open class ModelCustomBlockEntity(type: BlockEntityType<*>, private val modelIte } private fun spawnEntity() { - val entity: ArmorStandEntity = EntityType.getEntityFromTag(armorStandTag, world).get() as ArmorStandEntity + val entity: ArmorStandEntity = EntityType.getEntityFromNbt(armorStandTag, world).get() as ArmorStandEntity entity.refreshPositionAndAngles(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, 0.0F, 0.0F) entity.equipStack(EquipmentSlot.HEAD, modelItem) entity.addScoreboardTag("BLOCK") diff --git a/src/main/kotlin/one/oktw/galaxy/event/type/PlayerInteractEntityEvent.kt b/src/main/kotlin/one/oktw/galaxy/block/listener/CustomBlockTickListener.kt similarity index 69% rename from src/main/kotlin/one/oktw/galaxy/event/type/PlayerInteractEntityEvent.kt rename to src/main/kotlin/one/oktw/galaxy/block/listener/CustomBlockTickListener.kt index 6826c5f53..8e4583f2f 100644 --- a/src/main/kotlin/one/oktw/galaxy/event/type/PlayerInteractEntityEvent.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/listener/CustomBlockTickListener.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -16,9 +16,8 @@ * along with this program. If not, see . */ -package one.oktw.galaxy.event.type +package one.oktw.galaxy.block.listener -import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket -import net.minecraft.server.network.ServerPlayerEntity - -class PlayerInteractEntityEvent(val packet: PlayerInteractEntityC2SPacket, val player: ServerPlayerEntity) : Event +interface CustomBlockTickListener { + fun tick() +} diff --git a/src/main/kotlin/one/oktw/galaxy/command/commands/admin/RegisterBlock.kt b/src/main/kotlin/one/oktw/galaxy/command/commands/admin/RegisterBlock.kt index 070681eda..54930d58c 100644 --- a/src/main/kotlin/one/oktw/galaxy/command/commands/admin/RegisterBlock.kt +++ b/src/main/kotlin/one/oktw/galaxy/command/commands/admin/RegisterBlock.kt @@ -59,7 +59,7 @@ class RegisterBlock { val blockPos = BlockPosArgumentType.getLoadedBlockPos(it, "pos") it.source.world.removeBlockEntity(blockPos) - it.source.world.setBlockEntity(blockPos, block.createBlockEntity()) + it.source.world.addBlockEntity(block.createBlockEntity(blockPos)) it.source.sendFeedback(LiteralText("Registered block at ${blockPos.x}, ${blockPos.y}, ${blockPos.z} to ${block.identifier}"), true) return@executes Command.SINGLE_SUCCESS diff --git a/src/main/resources/accessor.mixin.json b/src/main/resources/accessor.mixin.json index 9c29428ec..0e2595799 100644 --- a/src/main/resources/accessor.mixin.json +++ b/src/main/resources/accessor.mixin.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_16", "mixins": [ "AsyncChunk_VersionedChunkStorage", + "BeaconLevelAccessor", "PlayerAbilitiesAccessor", "ServerPlayerEntityFunctionAccessor", "StorageIoWorkerAccessor" diff --git a/src/main/resources/galaxy.mixin.json b/src/main/resources/galaxy.mixin.json index 0e7d9710c..1d0f2d23d 100644 --- a/src/main/resources/galaxy.mixin.json +++ b/src/main/resources/galaxy.mixin.json @@ -8,7 +8,6 @@ "MixinPlayerChat_NetworkHandler", "MixinPlayerChat_SayCommand", "MixinPlayerInteractBlock_NetworkHandler", - "MixinPlayerInteractEntity_NetworkHandler", "MixinPlayerInteractItem_NetworkHandler", "MixinPlayerJump_NetworkHandler", "MixinPlayerSneak_NetworkHandler", diff --git a/src/main/resources/tweak.mixin.json b/src/main/resources/tweak.mixin.json index 4b6cf6f8b..db3daf168 100644 --- a/src/main/resources/tweak.mixin.json +++ b/src/main/resources/tweak.mixin.json @@ -16,7 +16,6 @@ "MixinOptimizeContainer_LootableContainerBlockEntity", "MixinRCON_RconBase", "MixinRCON_RconClient", - "MixinSkipEnchantingTableTick", "MixinThrownCountdown_Entity", "MixinThrownCountdown_ProjectileEntity", "MixinThrownCountdown_ThrownEntity" From 49ecb4b9319dcd5ccc31749bd12ea4d7fc562d0d Mon Sep 17 00:00:00 2001 From: James58899 Date: Sat, 13 Mar 2021 23:43:36 +0800 Subject: [PATCH 08/18] 21w10a --- build.gradle.kts | 8 ++++---- .../event/MixinPlayerInteractBlock_NetworkHandler.java | 4 ++-- .../event/MixinPlayerInteractItem_NetworkHandler.java | 2 +- .../recipe/MixinCustomRecipe_CraftingResultSlot.java | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b30f2112c..846839e3e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,12 +38,12 @@ minecraft { dependencies { // Core - minecraft(group = "com.mojang", name = "minecraft", version = "21w08b") - mappings(group = "net.fabricmc", name = "yarn", version = "21w08b+build.20", classifier = "v2") - modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.11.2") + minecraft(group = "com.mojang", name = "minecraft", version = "21w10a") + mappings(group = "net.fabricmc", name = "yarn", version = "21w10a+build.10", classifier = "v2") + modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.11.3") // fabric api - modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.31.2+1.17") + modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.32.2+1.17") // galaxy api implementation(group = "one.oktw", name = "galaxy-lib", version = galaxyLibVersion) diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java index 23951fad2..cd665fb43 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -51,7 +51,7 @@ private void onPlayerInteractBlock(PlayerInteractBlockC2SPacket packet, Callback BlockPos blockPos = packet.getBlockHitResult().getBlockPos(); player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockPos)); player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockPos.offset(packet.getBlockHitResult().getSide()))); - player.refreshScreenHandler(player.currentScreenHandler); + player.currentScreenHandler.method_34252(); } } } diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java index e68aa5d4f..7acbe398a 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java @@ -44,7 +44,7 @@ private void onPlayerInteractItem(PlayerInteractItemC2SPacket packet, CallbackIn PlayerInteractItemEvent event = main.getEventManager().emit(new PlayerInteractItemEvent(packet, player)); if (event.getCancel()) { info.cancel(); - player.refreshScreenHandler(player.currentScreenHandler); + player.currentScreenHandler.method_34252(); } if (event.getSwing()) this.player.swingHand(packet.getHand(), true); } diff --git a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java index 6f459a5d7..64b52204d 100644 --- a/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java +++ b/src/main/java/one/oktw/galaxy/mixin/recipe/MixinCustomRecipe_CraftingResultSlot.java @@ -27,12 +27,12 @@ import org.spongepowered.asm.mixin.Mixin; 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.CallbackInfo; @Mixin(CraftingResultSlot.class) public class MixinCustomRecipe_CraftingResultSlot { @Inject(method = "onTakeItem", at = @At("RETURN")) - private void consumeInput(PlayerEntity player, ItemStack stack, CallbackInfoReturnable cir) { + private void consumeInput(PlayerEntity player, ItemStack stack, CallbackInfo ci) { ScreenHandler handler = player.currentScreenHandler; ((ServerPlayerEntity) player).networkHandler.sendPacket(new InventoryS2CPacket(handler.syncId, handler.getStacks())); } From d1231dfc04c03d0994ab9fb3b3c50ea1d6b117dc Mon Sep 17 00:00:00 2001 From: James58899 Date: Thu, 27 May 2021 16:38:59 +0800 Subject: [PATCH 09/18] 21w20a --- build.gradle.kts | 6 +++--- .../mixin/accessor/StorageIoWorkerAccessor.java | 4 ++-- .../MixinPlayerInteractBlock_NetworkHandler.java | 2 +- .../MixinPlayerInteractItem_NetworkHandler.java | 2 +- .../MixinAsyncChunk_ThreadedAnvilChunkStorage.java | 4 ++-- .../tweak/MixinCustomBlockEntity_Structure.java | 4 ++-- .../realtime/entity/ItemEntityMixin_RealTime.java | 8 ++++---- .../one/oktw/galaxy/block/entity/DummyBlockEntity.kt | 4 ++-- .../galaxy/block/entity/ModelCustomBlockEntity.kt | 12 ++++++------ src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt | 11 +++++------ src/main/kotlin/one/oktw/galaxy/item/Tool.kt | 6 +++--- src/main/kotlin/one/oktw/galaxy/item/Weapon.kt | 6 +++--- 12 files changed, 34 insertions(+), 35 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 846839e3e..fdb404475 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,12 +38,12 @@ minecraft { dependencies { // Core - minecraft(group = "com.mojang", name = "minecraft", version = "21w10a") - mappings(group = "net.fabricmc", name = "yarn", version = "21w10a+build.10", classifier = "v2") + minecraft(group = "com.mojang", name = "minecraft", version = "21w20a") + mappings(group = "net.fabricmc", name = "yarn", version = "21w20a+build.7", classifier = "v2") modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.11.3") // fabric api - modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.32.2+1.17") + modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.34.5+1.17") // galaxy api implementation(group = "one.oktw", name = "galaxy-lib", version = galaxyLibVersion) diff --git a/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java b/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java index d51c59de6..f3ec4afa9 100644 --- a/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java +++ b/src/main/java/one/oktw/galaxy/mixin/accessor/StorageIoWorkerAccessor.java @@ -18,7 +18,7 @@ package one.oktw.galaxy.mixin.accessor; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.storage.StorageIoWorker; import org.spongepowered.asm.mixin.Mixin; @@ -29,5 +29,5 @@ @Mixin(StorageIoWorker.class) public interface StorageIoWorkerAccessor { @Invoker - CompletableFuture callReadChunkData(ChunkPos chunkPos); + CompletableFuture callReadChunkData(ChunkPos chunkPos); } diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java index cd665fb43..4c2d0cdd6 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractBlock_NetworkHandler.java @@ -51,7 +51,7 @@ private void onPlayerInteractBlock(PlayerInteractBlockC2SPacket packet, Callback BlockPos blockPos = packet.getBlockHitResult().getBlockPos(); player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockPos)); player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockPos.offset(packet.getBlockHitResult().getSide()))); - player.currentScreenHandler.method_34252(); + player.currentScreenHandler.syncState(); } } } diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java index 7acbe398a..edc7dbde8 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerInteractItem_NetworkHandler.java @@ -44,7 +44,7 @@ private void onPlayerInteractItem(PlayerInteractItemC2SPacket packet, CallbackIn PlayerInteractItemEvent event = main.getEventManager().emit(new PlayerInteractItemEvent(packet, player)); if (event.getCancel()) { info.cancel(); - player.currentScreenHandler.method_34252(); + player.currentScreenHandler.syncState(); } if (event.getSwing()) this.player.swingHand(packet.getHand(), true); } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java index 61805f426..7242dde29 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinAsyncChunk_ThreadedAnvilChunkStorage.java @@ -20,7 +20,7 @@ import com.mojang.datafixers.DataFixer; import com.mojang.datafixers.util.Either; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.server.world.ChunkHolder; import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ThreadedAnvilChunkStorage; @@ -121,7 +121,7 @@ private CompletableFuture> loadChunk(ChunkPo }, this.mainThreadExecutor); } - private CompletableFuture getUpdatedChunkTagAsync(ChunkPos pos) { + private CompletableFuture getUpdatedChunkTagAsync(ChunkPos pos) { return ((StorageIoWorkerAccessor) ((AsyncChunk_VersionedChunkStorage) this).getWorker()).callReadChunkData(pos) .thenApplyAsync(compoundTag -> compoundTag == null ? null : this.updateChunkNbt(world.getRegistryKey(), this.persistentStateManagerFactory, compoundTag), mainThreadExecutor); } diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_Structure.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_Structure.java index d31e65876..e9eab5bfd 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_Structure.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinCustomBlockEntity_Structure.java @@ -22,7 +22,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.fluid.FluidState; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.structure.Structure; import net.minecraft.structure.StructurePlacementData; import net.minecraft.util.math.BlockBox; @@ -42,7 +42,7 @@ public class MixinCustomBlockEntity_Structure { @Inject(method = "place(Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/structure/StructurePlacementData;Ljava/util/Random;I)Z", 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 blockPos, StructurePlacementData placementData, Random random, int i, CallbackInfoReturnable cir, List list, BlockBox blockBox, List list2, List list3, List> list4, int j, int k, int l, int m, int n, int o, List list5, Iterator var19, Structure.StructureBlockInfo structureBlockInfo, BlockPos blockPos2, FluidState fluidState, BlockState blockState) { + private void hackPlace(ServerWorldAccess world, BlockPos pos, BlockPos blockPos, StructurePlacementData placementData, Random random, int i, CallbackInfoReturnable cir, List list, BlockBox blockBox, List list2, List list3, List> list4, int j, int k, int l, int m, int n, int o, List list5, Iterator var19, Structure.StructureBlockInfo structureBlockInfo, BlockPos blockPos2, FluidState fluidState, BlockState blockState) { // Workaround structure barrier bug if (structureBlockInfo.state.getBlock() == Blocks.BARRIER) world.setBlockState(blockPos2, Blocks.AIR.getDefaultState(), 20); } diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/entity/ItemEntityMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/entity/ItemEntityMixin_RealTime.java index 9e80e8ecd..323fe43ea 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/entity/ItemEntityMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/entity/ItemEntityMixin_RealTime.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2019 + * 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 @@ -55,7 +55,7 @@ public abstract class ItemEntityMixin_RealTime extends EntityMixin_RealTime { @Shadow private int pickupDelay; @Shadow - private int age; + private int itemAge; @Redirect(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/ItemEntity;pickupDelay:I", opcode = Opcodes.PUTFIELD, ordinal = 0)) @@ -65,9 +65,9 @@ public abstract class ItemEntityMixin_RealTime extends EntityMixin_RealTime { } @Redirect(method = "tick", - at = @At(value = "FIELD", target = "Lnet/minecraft/entity/ItemEntity;age:I", opcode = Opcodes.PUTFIELD, ordinal = 0)) + at = @At(value = "FIELD", target = "Lnet/minecraft/entity/ItemEntity;itemAge:I", opcode = Opcodes.PUTFIELD, ordinal = 0)) private void realTimeImpl$adjustForRealTimeAge(final ItemEntity self, final int modifier) { final int ticks = (int) ((RealTimeTrackingBridge) self.getEntityWorld()).realTimeBridge$getRealTimeTicks(); - this.age += ticks; + this.itemAge += ticks; } } 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 eee534926..f2a3b73c2 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/DummyBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/DummyBlockEntity.kt @@ -19,13 +19,13 @@ package one.oktw.galaxy.block.entity import net.minecraft.block.entity.BlockEntityType -import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.NbtCompound 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(tag: CompoundTag) { + override fun readNbt(tag: NbtCompound) { super.readNbt(tag) tag.getString("id")?.let(Identifier::tryParse)?.let(CustomBlock.registry::get)?.let { if (it != CustomBlock.DUMMY) { 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 127ed764b..91e5bdce4 100644 --- a/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt +++ b/src/main/kotlin/one/oktw/galaxy/block/entity/ModelCustomBlockEntity.kt @@ -24,7 +24,7 @@ import net.minecraft.entity.EntityType import net.minecraft.entity.EquipmentSlot import net.minecraft.entity.decoration.ArmorStandEntity import net.minecraft.item.ItemStack -import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.NbtCompound import net.minecraft.server.world.ServerWorld import net.minecraft.util.math.BlockPos import one.oktw.galaxy.block.listener.CustomBlockTickListener @@ -33,7 +33,7 @@ import java.util.* open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, private val modelItem: ItemStack) : CustomBlockEntity(type, pos), CustomBlockTickListener { companion object { - private val armorStandTag = CompoundTag().apply { + private val armorStandTag = NbtCompound().apply { putString("id", "minecraft:armor_stand") putBoolean("Invisible", true) putBoolean("Invulnerable", true) @@ -56,14 +56,14 @@ open class ModelCustomBlockEntity(type: BlockEntityType<*>, pos: BlockPos, priva } } - override fun readNbt(tag: CompoundTag) { + override fun readNbt(tag: NbtCompound) { super.readNbt(tag) - entityUUID = (tag.get("GalaxyData") as? CompoundTag)?.getUuid("ModelEntity") ?: return + entityUUID = (tag.get("GalaxyData") as? NbtCompound)?.getUuid("ModelEntity") ?: return } - override fun writeNbt(tag: CompoundTag): CompoundTag { + override fun writeNbt(tag: NbtCompound): NbtCompound { super.writeNbt(tag) - entityUUID?.let { tag.put("GalaxyData", CompoundTag().apply { putUuid("ModelEntity", it) }) } + entityUUID?.let { tag.put("GalaxyData", NbtCompound().apply { putUuid("ModelEntity", it) }) } return tag } diff --git a/src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt b/src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt index adb82ea90..a65fddfc4 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt @@ -20,13 +20,12 @@ package one.oktw.galaxy.item import net.minecraft.item.Item import net.minecraft.item.ItemStack -import net.minecraft.nbt.CompoundTag -import net.minecraft.nbt.ListTag +import net.minecraft.nbt.NbtCompound +import net.minecraft.nbt.NbtList import net.minecraft.text.Text import net.minecraft.util.Identifier import one.oktw.galaxy.util.CustomRegistry import one.oktw.galaxy.util.Registrable -import java.util.* abstract class CustomItem(override val identifier: Identifier, private val baseItem: Item, private val modelData: Int) : Registrable { companion object { @@ -48,11 +47,11 @@ abstract class CustomItem(override val identifier: Identifier, private val baseI abstract fun getName(): Text? - open fun writeCustomNbt(tag: CompoundTag) { + open fun writeCustomNbt(tag: NbtCompound) { tag.putString("CustomItemIdentifier", identifier.toString()) } - open fun readCustomNbt(tag: CompoundTag): CustomItem { + open fun readCustomNbt(tag: NbtCompound): CustomItem { require(tag.getString("CustomItemIdentifier") == identifier.toString()) return this @@ -66,7 +65,7 @@ abstract class CustomItem(override val identifier: Identifier, private val baseI putInt("HideFlags", ItemStack.TooltipSection.values().map(ItemStack.TooltipSection::getFlag).reduce { acc, i -> acc or i }) // ALL putInt("CustomModelData", modelData) putBoolean("Unbreakable", true) - put("AttributeModifiers", ListTag()) + put("AttributeModifiers", NbtList()) } setCustomName(this@CustomItem.getName()) writeCustomNbt(getOrCreateSubTag("GalaxyData")) diff --git a/src/main/kotlin/one/oktw/galaxy/item/Tool.kt b/src/main/kotlin/one/oktw/galaxy/item/Tool.kt index b2c79aa8d..f7a7868a7 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Tool.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Tool.kt @@ -19,7 +19,7 @@ package one.oktw.galaxy.item import net.minecraft.item.Items.COMMAND_BLOCK -import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.NbtCompound import net.minecraft.text.Text import net.minecraft.text.TranslatableText import net.minecraft.util.Formatting @@ -36,8 +36,8 @@ class Tool private constructor(id: String, modelData: Int, private val name: Str override fun getName(): Text = TranslatableText(name).styled { it.withColor(Formatting.WHITE).withItalic(false) } - override fun writeCustomNbt(tag: CompoundTag) { + override fun writeCustomNbt(tag: NbtCompound) { super.writeCustomNbt(tag) - tag.put("ToolData", CompoundTag().apply { putUuid("id", MathHelper.randomUuid()) }) + tag.put("ToolData", NbtCompound().apply { putUuid("id", MathHelper.randomUuid()) }) } } diff --git a/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt b/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt index ad83b767b..d5ef1078c 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt @@ -19,7 +19,7 @@ package one.oktw.galaxy.item import net.minecraft.item.Items.COMMAND_BLOCK -import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.NbtCompound import net.minecraft.text.Text import net.minecraft.text.TranslatableText import net.minecraft.util.Formatting @@ -59,8 +59,8 @@ class Weapon private constructor(id: String, modelData: Int, private val name: S override fun getName(): Text = TranslatableText(name).styled { it.withColor(Formatting.WHITE).withItalic(false) } - override fun writeCustomNbt(tag: CompoundTag) { + override fun writeCustomNbt(tag: NbtCompound) { super.writeCustomNbt(tag) - tag.put("WeaponData", CompoundTag().apply { putUuid("id", MathHelper.randomUuid()) }) + tag.put("WeaponData", NbtCompound().apply { putUuid("id", MathHelper.randomUuid()) }) } } From bac8f5a4f92b3400b5037d2e72421bc54bc737a4 Mon Sep 17 00:00:00 2001 From: James58899 Date: Sat, 29 May 2021 15:52:22 +0800 Subject: [PATCH 10/18] Fix mixin --- .../one/oktw/galaxy/mixin/tweak/MixinRCON_RconClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinRCON_RconClient.java b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinRCON_RconClient.java index 3693673e0..47a72a52e 100644 --- a/src/main/java/one/oktw/galaxy/mixin/tweak/MixinRCON_RconClient.java +++ b/src/main/java/one/oktw/galaxy/mixin/tweak/MixinRCON_RconClient.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2020 + * 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 @@ -36,7 +36,7 @@ private void checkLocal(DedicatedServer server, String password, Socket socket, if (socket.getInetAddress().isLoopbackAddress()) isLocal = true; } - @Redirect(method = "run", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", remap = false)) + @Redirect(method = "run", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V"), remap = false) private void noLocalLog(Logger logger, String message, Object description) { if (!isLocal) logger.info(message, description); } From 3fe9555d65c0fb9022845800863b9b99c2cda5b6 Mon Sep 17 00:00:00 2001 From: James58899 Date: Sat, 29 May 2021 15:52:53 +0800 Subject: [PATCH 11/18] XML --- .idea/codeStyles/Project.xml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index a0804c8fc..27ac19a76 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -6,15 +6,7 @@