From 396f2c80df657b50db8c93367ee958cda02dfc6e Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Wed, 25 Dec 2024 15:51:48 +0100 Subject: [PATCH] Work --- .../connection/MixinClientConnection.java | 1 + .../bedrock}/MixinConfirmScreen.java | 2 +- .../MixinMultiplayerServerListPinger.java | 2 +- .../{ => event}/MixinMinecraftClient.java | 2 +- .../MixinEntityPacketRewriter1_17.java | 8 ++- .../MixinWorldPacketRewriter1_17.java | 8 ++- .../interactions/MixinAbstractBoatEntity.java | 57 +++++++++++++++++++ .../MixinAbstractBoatEntity.java | 54 ++++++++++++++++++ .../entity}/MixinAbstractBoatEntity.java | 24 +------- src/main/resources/viafabricplus.mixins.json | 28 +++++---- 10 files changed, 144 insertions(+), 42 deletions(-) rename src/main/java/com/viaversion/viafabricplus/injection/mixin/base/{ui => integration/bedrock}/MixinConfirmScreen.java (96%) rename src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/{ => bedrock}/MixinMultiplayerServerListPinger.java (99%) rename src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/{ => event}/MixinMinecraftClient.java (99%) create mode 100644 src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/interactions/MixinAbstractBoatEntity.java create mode 100644 src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/riding_offsets/MixinAbstractBoatEntity.java rename src/main/java/com/viaversion/viafabricplus/injection/mixin/features/{entity/v1_8_boat => movement/entity}/MixinAbstractBoatEntity.java (91%) diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/connection/MixinClientConnection.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/connection/MixinClientConnection.java index 3e630592b..281ad388a 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/connection/MixinClientConnection.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/connection/MixinClientConnection.java @@ -87,6 +87,7 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler< @Inject(method = "setCompressionThreshold", at = @At("RETURN")) private void reorderCompression(int compressionThreshold, boolean rejectBad, CallbackInfo ci) { + // Compression enabled and elements put into pipeline, move via handlers channel.pipeline().fireUserEventTriggered(CompressionReorderEvent.INSTANCE); } diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/ui/MixinConfirmScreen.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/bedrock/MixinConfirmScreen.java similarity index 96% rename from src/main/java/com/viaversion/viafabricplus/injection/mixin/base/ui/MixinConfirmScreen.java rename to src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/bedrock/MixinConfirmScreen.java index 70654e0cb..9e78cbfcc 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/ui/MixinConfirmScreen.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/bedrock/MixinConfirmScreen.java @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -package com.viaversion.viafabricplus.injection.mixin.base.ui; +package com.viaversion.viafabricplus.injection.mixin.base.integration.bedrock; import com.viaversion.viafabricplus.injection.access.base.bedrock.IConfirmScreen; import net.minecraft.client.gui.screen.ConfirmScreen; diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/MixinMultiplayerServerListPinger.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/bedrock/MixinMultiplayerServerListPinger.java similarity index 99% rename from src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/MixinMultiplayerServerListPinger.java rename to src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/bedrock/MixinMultiplayerServerListPinger.java index 30ea234ab..797fa71c3 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/MixinMultiplayerServerListPinger.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/bedrock/MixinMultiplayerServerListPinger.java @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -package com.viaversion.viafabricplus.injection.mixin.base.integration; +package com.viaversion.viafabricplus.injection.mixin.base.integration.bedrock; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/MixinMinecraftClient.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/event/MixinMinecraftClient.java similarity index 99% rename from src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/MixinMinecraftClient.java rename to src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/event/MixinMinecraftClient.java index 75310a003..ae121eea1 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/MixinMinecraftClient.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/base/integration/event/MixinMinecraftClient.java @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -package com.viaversion.viafabricplus.injection.mixin.base.integration; +package com.viaversion.viafabricplus.injection.mixin.base.integration.event; import com.viaversion.viafabricplus.api.events.LoadingCycleCallback; import com.viaversion.viafabricplus.base.Events; diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/classic_world_height/MixinEntityPacketRewriter1_17.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/classic_world_height/MixinEntityPacketRewriter1_17.java index db1e16f7f..de8d56ce1 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/classic_world_height/MixinEntityPacketRewriter1_17.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/classic_world_height/MixinEntityPacketRewriter1_17.java @@ -38,8 +38,12 @@ public abstract class MixinEntityPacketRewriter1_17 { @Redirect(method = "registerPackets", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/protocols/v1_16_4to1_17/Protocol1_16_4To1_17;registerClientbound(Lcom/viaversion/viaversion/api/protocol/packet/ClientboundPacketType;Lcom/viaversion/viaversion/api/protocol/remapper/PacketHandler;)V")) private void handleClassicWorldHeight(Protocol1_16_4To1_17 instance, ClientboundPacketType packetType, PacketHandler packetHandler) { - if (packetType == ClientboundPackets1_16_2.LOGIN) packetHandler = WorldHeightSupport.handleJoinGame(packetHandler); - if (packetType == ClientboundPackets1_16_2.RESPAWN) packetHandler = WorldHeightSupport.handleRespawn(packetHandler); + if (packetType == ClientboundPackets1_16_2.LOGIN) { + packetHandler = WorldHeightSupport.handleJoinGame(packetHandler); + } + if (packetType == ClientboundPackets1_16_2.RESPAWN) { + packetHandler = WorldHeightSupport.handleRespawn(packetHandler); + } ((Protocol) instance).registerClientbound(packetType, packetHandler); } diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/classic_world_height/MixinWorldPacketRewriter1_17.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/classic_world_height/MixinWorldPacketRewriter1_17.java index 3250b2673..618cdc7ad 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/classic_world_height/MixinWorldPacketRewriter1_17.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/classic_world_height/MixinWorldPacketRewriter1_17.java @@ -38,8 +38,12 @@ public abstract class MixinWorldPacketRewriter1_17 { @Redirect(method = "register", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/protocols/v1_16_4to1_17/Protocol1_16_4To1_17;registerClientbound(Lcom/viaversion/viaversion/api/protocol/packet/ClientboundPacketType;Lcom/viaversion/viaversion/api/protocol/remapper/PacketHandler;)V")) private static void handleClassicWorldHeight(Protocol1_16_4To1_17 instance, ClientboundPacketType packetType, PacketHandler packetHandler) { - if (packetType == ClientboundPackets1_16_2.LEVEL_CHUNK) packetHandler = WorldHeightSupport.handleChunkData(packetHandler); - if (packetType == ClientboundPackets1_16_2.LIGHT_UPDATE) packetHandler = WorldHeightSupport.handleUpdateLight(packetHandler); + if (packetType == ClientboundPackets1_16_2.LEVEL_CHUNK) { + packetHandler = WorldHeightSupport.handleChunkData(packetHandler); + } + if (packetType == ClientboundPackets1_16_2.LIGHT_UPDATE) { + packetHandler = WorldHeightSupport.handleUpdateLight(packetHandler); + } ((Protocol) instance).registerClientbound(packetType, packetHandler); } diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/interactions/MixinAbstractBoatEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/interactions/MixinAbstractBoatEntity.java new file mode 100644 index 000000000..f140563c0 --- /dev/null +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/interactions/MixinAbstractBoatEntity.java @@ -0,0 +1,57 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus + * Copyright (C) 2021-2024 the original authors + * - FlorianMichael/EnZaXD + * - RK_01/RaphiMC + * Copyright (C) 2023-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viafabricplus.injection.mixin.features.entity.interactions; + +import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.vehicle.AbstractBoatEntity; +import net.minecraft.entity.vehicle.BoatEntity; +import net.minecraft.entity.vehicle.VehicleEntity; +import net.minecraft.item.Item; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.function.Supplier; + +@Mixin(AbstractBoatEntity.class) +public abstract class MixinAbstractBoatEntity extends VehicleEntity { + + public MixinAbstractBoatEntity(EntityType entityType, World world) { + super(entityType, world); + } + + @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/vehicle/VehicleEntity;interact(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")) + private ActionResult makeNotLeashable(VehicleEntity instance, PlayerEntity player, Hand hand) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { + return ActionResult.PASS; + } else { + return super.interact(player, hand); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/riding_offsets/MixinAbstractBoatEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/riding_offsets/MixinAbstractBoatEntity.java new file mode 100644 index 000000000..c9e7b1f51 --- /dev/null +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/riding_offsets/MixinAbstractBoatEntity.java @@ -0,0 +1,54 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus + * Copyright (C) 2021-2024 the original authors + * - FlorianMichael/EnZaXD + * - RK_01/RaphiMC + * Copyright (C) 2023-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viafabricplus.injection.mixin.features.entity.riding_offsets; + +import com.viaversion.viafabricplus.features.entity.riding_offsets.EntityRidingOffsetsPre1_20_2; +import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.vehicle.AbstractBoatEntity; +import net.minecraft.entity.vehicle.VehicleEntity; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +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.CallbackInfo; + +@Mixin(AbstractBoatEntity.class) +public abstract class MixinAbstractBoatEntity extends VehicleEntity { + + public MixinAbstractBoatEntity(EntityType entityType, World world) { + super(entityType, world); + } + + @Inject(method = "updatePassengerPosition", at = @At(value = "HEAD"), cancellable = true) + private void updatePassengerPosition1_8(Entity passenger, Entity.PositionUpdater positionUpdater, CallbackInfo ci) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { + final Vec3d newPosition = EntityRidingOffsetsPre1_20_2.getMountedHeightOffset(this, passenger).add(this.getPos()); + positionUpdater.accept(passenger, newPosition.x, newPosition.y + EntityRidingOffsetsPre1_20_2.getHeightOffset(passenger), newPosition.z); + ci.cancel(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/v1_8_boat/MixinAbstractBoatEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinAbstractBoatEntity.java similarity index 91% rename from src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/v1_8_boat/MixinAbstractBoatEntity.java rename to src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinAbstractBoatEntity.java index 97fc2823d..bfb0ce5b0 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/entity/v1_8_boat/MixinAbstractBoatEntity.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinAbstractBoatEntity.java @@ -19,10 +19,9 @@ * along with this program. If not, see . */ -package com.viaversion.viafabricplus.injection.mixin.features.entity.v1_8_boat; +package com.viaversion.viafabricplus.injection.mixin.features.movement.entity; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import com.viaversion.viafabricplus.features.entity.riding_offsets.EntityRidingOffsetsPre1_20_2; import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -31,14 +30,11 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.MovementType; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.vehicle.AbstractBoatEntity; import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.entity.vehicle.VehicleEntity; import net.minecraft.particle.ParticleTypes; import net.minecraft.registry.tag.FluidTags; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.MathHelper; @@ -88,15 +84,6 @@ public MixinAbstractBoatEntity(EntityType entityType, World world) { super(entityType, world); } - @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/vehicle/VehicleEntity;interact(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")) - private ActionResult makeNotLeashable(VehicleEntity instance, PlayerEntity player, Hand hand) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { - return ActionResult.PASS; - } else { - return super.interact(player, hand); - } - } - @Redirect(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isSpaceEmpty(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;)Z")) private boolean alwaysUpdatePosition(World instance, Entity entity, Box box) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { @@ -310,15 +297,6 @@ private void tick1_8(CallbackInfo ci) { } } - @Inject(method = "updatePassengerPosition", at = @At(value = "HEAD"), cancellable = true) - private void updatePassengerPosition1_8(Entity passenger, PositionUpdater positionUpdater, CallbackInfo ci) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { - final Vec3d newPosition = EntityRidingOffsetsPre1_20_2.getMountedHeightOffset(this, passenger).add(this.getPos()); - positionUpdater.accept(passenger, newPosition.x, newPosition.y + EntityRidingOffsetsPre1_20_2.getHeightOffset(passenger), newPosition.z); - ci.cancel(); - } - } - @Inject(method = "onPassengerLookAround", at = @At("HEAD"), cancellable = true) private void onPassengerLookAround1_8(Entity passenger, CallbackInfo ci) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 763187389..130cd6630 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -18,15 +18,15 @@ "base.connection.MixinMultiplayerServerListPinger", "base.integration.MixinClientConnection", "base.integration.MixinDebugHud", - "base.integration.MixinMinecraftClient", - "base.integration.MixinMultiplayerServerListPinger", "base.integration.MixinMultiplayerServerListPinger_1", "base.integration.MixinServerInfo", "base.integration.MixinUserConnectionImpl", + "base.integration.bedrock.MixinConfirmScreen", "base.integration.bedrock.MixinConnectScreen_1", + "base.integration.bedrock.MixinMultiplayerServerListPinger", + "base.integration.event.MixinMinecraftClient", "base.integration.sync_tasks.MixinClientCommonNetworkHandler", "base.ui.MixinAddServerScreen", - "base.ui.MixinConfirmScreen", "base.ui.MixinConnectScreen_1", "base.ui.MixinDirectConnectScreen", "base.ui.MixinDownloadingTerrainScreen", @@ -107,7 +107,7 @@ "features.entity.metadata_handling.MixinEntityTracker1_9", "features.entity.pose.MixinOtherClientPlayerEntity", "features.entity.riding_offsets.MixinCamelEntity", - "features.entity.v1_8_boat.MixinAbstractBoatEntity", + "features.movement.entity.MixinAbstractBoatEntity", "features.entity.v1_8_boat.MixinEntityModels", "features.entity.v1_8_boat.MixinEntityRenderDispatcher", "features.execute_inputs_sync.MixinKeyboard", @@ -167,6 +167,11 @@ "features.movement.block.MixinHoneyBlock", "features.movement.block.MixinSoulSandBlock", "features.movement.elytra.MixinFireworkRocketItem", + "features.movement.entity.MixinClientPlayerEntity", + "features.movement.entity.MixinEntity", + "features.movement.entity.MixinLivingEntity", + "features.movement.entity.MixinPlayerEntity", + "features.movement.entity.MixinPlayerEntityRenderer", "features.movement.entity.MixinSkeletonHorseEntity", "features.movement.item.MixinEnderEyeItem", "features.movement.levitation_value.MixinStatusEffectInstance", @@ -200,6 +205,7 @@ "features.networking.srv_resolving.MixinRedirectResolver", "features.networking.srv_resolving.MixinServerAddress", "features.networking.warn_feature_updates.MixinClientConfigurationNetworkHandler", + "features.open_inventory_packet.MixinMinecraftClient", "features.player_abilities.MixinUpdatePlayerAbilitiesC2SPacket", "features.recipe_emulation.MixinCraftingScreenHandler", "features.recipe_emulation.MixinEntityPacketRewriter1_12", @@ -217,18 +223,16 @@ "features.world.item_picking.MixinMinecraftClient", "features.world.remove_server_view_distance.MixinGameOptions", "integration.viabedrock.MixinJoinPackets", - "integration.vialegacy.MixinViaLegacyConfig", - "features.open_inventory_packet.MixinMinecraftClient", - "features.movement.entity.MixinClientPlayerEntity", - "features.movement.entity.MixinEntity", - "features.movement.entity.MixinLivingEntity", - "features.movement.entity.MixinPlayerEntity", - "features.movement.entity.MixinPlayerEntityRenderer" + "integration.vialegacy.MixinViaLegacyConfig" ], "injectors": { "defaultRequire": 1 }, "overwrites": { "requireAnnotations": true - } + }, + "mixins": [ + "features.entity.interactions.MixinAbstractBoatEntity", + "features.entity.riding_offsets.MixinAbstractBoatEntity" + ] }