diff --git a/gradle.properties b/gradle.properties index 2e67d1f61..3f84e6781 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ author = masa mod_file_name = tweakeroo-fabric # Current mod version -mod_version = 0.20.999-sakura.3 +mod_version = 0.20.999-sakura.4 # Required malilib version malilib_version = 0.19.999-sakura.2 diff --git a/src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java b/src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java index 5f22d13c5..cc00cca68 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java +++ b/src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java @@ -87,6 +87,7 @@ public enum FeatureToggle implements IHotkeyTogglable, IConfigNotifiable sculkSensorPulseLength"), + TWEAK_SERVER_ENTITY_DATA_SYNCER ("tweakServerEntityDataSyncer", false, "", "Allows Tweakeroo to attempt to use the Server Data Syncer\nto obtain various Entity Data, such as for Shulker Boxes\n\n§6NOTE: This feature requires OP privileges to work."), TWEAK_SHULKERBOX_DISPLAY ("tweakShulkerBoxDisplay", false, "", "Enables the Shulker Box contents display when hovering\nover them in an inventory and holding shift"), TWEAK_SIGN_COPY ("tweakSignCopy", false, "", "When enabled, placed signs will use the text from\nthe previously placed sign.\nCan be combined with tweakNoSignGui to quickly place copies\nof a sign, by enabling that tweak after making the first sign."), TWEAK_SNAP_AIM ("tweakSnapAim", false, "", KeybindSettings.INGAME_BOTH, "Enabled a snap aim tweak, to make the player face to pre-set exact yaw rotations"), diff --git a/src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java b/src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java index 57e0766da..89c3a7ede 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java +++ b/src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java @@ -1,6 +1,7 @@ package fi.dy.masa.tweakeroo.data; import com.mojang.datafixers.util.Either; +import fi.dy.masa.tweakeroo.Tweakeroo; import fi.dy.masa.tweakeroo.mixin.IMixinDataQueryHandler; import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; @@ -66,7 +67,10 @@ public ServerDataSyncer(ClientWorld world) { return null; } - public void handleQueryResponse(int transactionId, NbtCompound nbt) { + public void handleQueryResponse(int transactionId, NbtCompound nbt) + { + Tweakeroo.logger.warn("handleQueryResponse: id [{}] // nbt {}", transactionId, nbt.toString()); + if (nbt == null) return; if (pendingQueries.containsKey(transactionId)) { Either either = pendingQueries.remove(transactionId); @@ -96,7 +100,10 @@ public void handleQueryResponse(int transactionId, NbtCompound nbt) { } } - public Inventory getBlockInventory(World world, BlockPos pos) { + public Inventory getBlockInventory(World world, BlockPos pos) + { + Tweakeroo.logger.warn("getBlockInventory: pos [{}]", pos.toShortString()); + if (!world.isChunkLoaded(pos)) return null; var data = getCache(pos); if (data instanceof Inventory inv) { @@ -131,8 +138,12 @@ public Inventory getBlockInventory(World world, BlockPos pos) { return null; } - public void syncBlockEntity(World world, BlockPos pos) { - if (MinecraftClient.getInstance().isIntegratedServerRunning()) { + public void syncBlockEntity(World world, BlockPos pos) + { + Tweakeroo.logger.warn("syncBlockEntity: pos [{}]", pos.toShortString()); + + if (MinecraftClient.getInstance().isIntegratedServerRunning()) + { BlockEntity blockEntity = MinecraftClient.getInstance().getServer().getWorld(world.getRegistryKey()).getWorldChunk(pos).getBlockEntity(pos, WorldChunk.CreationType.CHECK); if (blockEntity != null) { blockCache.put(pos, new Pair<>(blockEntity, System.currentTimeMillis())); @@ -147,7 +158,10 @@ public void syncBlockEntity(World world, BlockPos pos) { } } - public void syncEntity(int networkId) { + public void syncEntity(int networkId) + { + Tweakeroo.logger.warn("syncEntity: pos [{}]", networkId); + Either idEither = Either.right(networkId); if (MinecraftClient.getInstance().getNetworkHandler() != null && !pendingQueries.containsValue(idEither)) { DataQueryHandler handler = MinecraftClient.getInstance().getNetworkHandler().getDataQueryHandler(); @@ -156,7 +170,8 @@ public void syncEntity(int networkId) { } } - public @Nullable Entity getServerEntity(Entity entity) { + public @Nullable Entity getServerEntity(Entity entity) + { Entity serverEntity = getCache(entity.getId()); if (serverEntity == null) { syncEntity(entity.getId()); diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinDataQueryHandler.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinDataQueryHandler.java index db1608dd4..6fb92da76 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinDataQueryHandler.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinDataQueryHandler.java @@ -1,5 +1,7 @@ package fi.dy.masa.tweakeroo.mixin; +import fi.dy.masa.tweakeroo.Tweakeroo; +import fi.dy.masa.tweakeroo.config.FeatureToggle; import fi.dy.masa.tweakeroo.data.ServerDataSyncer; import net.minecraft.client.network.DataQueryHandler; import net.minecraft.nbt.NbtCompound; @@ -9,12 +11,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(DataQueryHandler.class) -public class MixinDataQueryHandler { +public class MixinDataQueryHandler +{ @Inject( method = "handleQueryResponse", at = @At("HEAD") ) - private void queryResponse(int transactionId, NbtCompound nbt, CallbackInfoReturnable cir) { - ServerDataSyncer.INSTANCE.handleQueryResponse(transactionId, nbt); + private void queryResponse(int transactionId, NbtCompound nbt, CallbackInfoReturnable cir) + { + Tweakeroo.logger.warn("MixinDataQueryHandler: nbt {}", nbt.toString()); + + if (FeatureToggle.TWEAK_SERVER_ENTITY_DATA_SYNCER.getBooleanValue()) + { + ServerDataSyncer.INSTANCE.handleQueryResponse(transactionId, nbt); + } } } diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinMinecraftClient.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinMinecraftClient.java index d15e443b7..d988f5a13 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinMinecraftClient.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinMinecraftClient.java @@ -138,10 +138,16 @@ private void onProcessKeybindsPre(CallbackInfo ci) ) private void onWorldChanged(ClientWorld world, CallbackInfo ci) { - if (world == null) { - ServerDataSyncer.INSTANCE = null; - } else { - ServerDataSyncer.INSTANCE = new ServerDataSyncer(world); + if (FeatureToggle.TWEAK_SERVER_ENTITY_DATA_SYNCER.getBooleanValue()) + { + if (world == null) + { + ServerDataSyncer.INSTANCE = null; + } + else + { + ServerDataSyncer.INSTANCE = new ServerDataSyncer(world); + } } } } diff --git a/src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java b/src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java index 3b7fe5fcb..641788a1a 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java +++ b/src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java @@ -1,16 +1,9 @@ package fi.dy.masa.tweakeroo.renderer; import java.util.Set; +import org.joml.Matrix4f; +import org.joml.Matrix4fStack; import com.mojang.blaze3d.systems.RenderSystem; -import fi.dy.masa.malilib.util.EntityUtils; -import fi.dy.masa.malilib.util.GuiUtils; -import fi.dy.masa.tweakeroo.config.Configs; -import fi.dy.masa.tweakeroo.data.ServerDataSyncer; -import fi.dy.masa.tweakeroo.mixin.IMixinAbstractHorseEntity; -import fi.dy.masa.tweakeroo.util.MiscUtils; -import fi.dy.masa.tweakeroo.util.RayTraceUtils; -import fi.dy.masa.tweakeroo.util.SnapAimMode; - import net.minecraft.block.Block; import net.minecraft.block.ShulkerBoxBlock; import net.minecraft.client.MinecraftClient; @@ -37,10 +30,15 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -import org.joml.Matrix4f; -import org.joml.Matrix4fStack; - -import java.util.Set; +import fi.dy.masa.malilib.util.EntityUtils; +import fi.dy.masa.malilib.util.GuiUtils; +import fi.dy.masa.tweakeroo.config.Configs; +import fi.dy.masa.tweakeroo.config.FeatureToggle; +import fi.dy.masa.tweakeroo.data.ServerDataSyncer; +import fi.dy.masa.tweakeroo.mixin.IMixinAbstractHorseEntity; +import fi.dy.masa.tweakeroo.util.MiscUtils; +import fi.dy.masa.tweakeroo.util.RayTraceUtils; +import fi.dy.masa.tweakeroo.util.SnapAimMode; public class RenderUtils { @@ -149,18 +147,25 @@ public static void renderInventoryOverlay(MinecraftClient mc, DrawContext drawCo shulkerBoxBlock = (ShulkerBoxBlock) blockTmp; } - if (world instanceof ServerWorld realWorld) { + if (world instanceof ServerWorld realWorld) + { inv = fi.dy.masa.malilib.util.InventoryUtils.getInventory(realWorld, pos); - } else { + } + else if (FeatureToggle.TWEAK_SERVER_ENTITY_DATA_SYNCER.getBooleanValue()) + { inv = ServerDataSyncer.INSTANCE.getBlockInventory(world, pos); } } else if (trace.getType() == HitResult.Type.ENTITY) { Entity entity = ((EntityHitResult) trace).getEntity(); - if (entity.getWorld().isClient) { + + if (entity.getWorld().isClient && + FeatureToggle.TWEAK_SERVER_ENTITY_DATA_SYNCER.getBooleanValue()) + { Entity serverEntity = ServerDataSyncer.INSTANCE.getServerEntity(entity); - if (serverEntity != null) { + if (serverEntity != null) + { entity = serverEntity; } }