Skip to content

Commit

Permalink
Sort injection methods in fixes package by version
Browse files Browse the repository at this point in the history
Added new debug settings
  • Loading branch information
FlorianMichael committed Nov 26, 2023
1 parent a2a2a56 commit a19c708
Show file tree
Hide file tree
Showing 34 changed files with 602 additions and 502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
* - Fix MixinAbstractDonkeyEntity
* - Boats are probably broken. Check entity height offset fix
* - Check TO DO in MixinEntity
* - Sort injection methods in fixes package by version
* - Add setting for revertOnlyPlayerCramming
* - Add setting for MixinLockableContainerBlockEntity
* - Diff ItemRegistryDiff from projects and add missing items
* - Fix third party implementations properly
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD
* Copyright (C) 2023 RK_01/RaphiMC 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 <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.injection.mixin.base.integration;

import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.protocolhack.provider.vialegacy.ViaFabricPlusClassicMPPassProvider;
import de.florianmichael.viafabricplus.settings.impl.AuthenticationSettings;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(targets = "net.minecraft.client.gui.screen.ConnectScreen$1")
public abstract class MixinConnectScreen_1 {

@Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/packet/Packet;)V"))
private void spoofUserName(ClientConnection instance, Packet<?> packet) {
if (AuthenticationSettings.global().setSessionNameToClassiCubeNameInServerList.getValue() && ViaFabricPlusClassicMPPassProvider.classiCubeMPPass != null) {
final var account = ViaFabricPlus.global().getSaveManager().getAccountsSave().getClassicubeAccount();
if (account != null) {
instance.send(new LoginHelloC2SPacket(account.username(), MinecraftClient.getInstance().getSession().getUuidOrNull()));
return;
}
}

instance.send(packet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.input;
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft;

import de.florianmichael.viafabricplus.settings.impl.DebugSettings;
import net.minecraft.client.render.Camera;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ public abstract class MixinClientPlayerInteractionManager {
@Unique
private List<ItemStack> viaFabricPlus$oldItems;

@Inject(method = "breakBlock", at = @At("TAIL"))
private void resetBlockBreaking(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_3)) {
this.currentBreakingPos = new BlockPos(this.currentBreakingPos.getX(), -1, this.currentBreakingPos.getZ());
@Inject(method = "getBlockBreakingProgress", at = @At("HEAD"), cancellable = true)
private void changeCalculation(CallbackInfoReturnable<Integer> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4)) {
cir.setReturnValue((int)(this.currentBreakingProgress * 10.0F) - 1);
}
}

@Inject(method = "sendSequencedPacket", at = @At("HEAD"))
private void handleBlockAcknowledgements(ClientWorld world, SequencedPacketCreator packetCreator, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isBetweenInclusive(VersionEnum.r1_14_4, VersionEnum.r1_18_2) && packetCreator instanceof PlayerActionC2SPacket playerActionC2SPacket) {
ClientPlayerInteractionManager1_18_2.trackBlockAction(playerActionC2SPacket.getAction(), playerActionC2SPacket.getPos());
}
}

Expand Down Expand Up @@ -151,14 +158,11 @@ private boolean redirectInteractItem(ClientPlayNetworkHandler instance, Packet<?
return ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(VersionEnum.r1_17);
}

@Inject(method = "interactItem", at = @At("HEAD"))
private void trackLastUsedItem(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
ViaFabricPlusHandItemProvider.lastUsedItem = player.getStackInHand(hand).copy();
}

@Inject(method = "interactBlock", at = @At("HEAD"))
private void trackLastUsedBlock(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
ViaFabricPlusHandItemProvider.lastUsedItem = player.getStackInHand(hand).copy();
@Inject(method = "breakBlock", at = @At("TAIL"))
private void resetBlockBreaking(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_3)) {
this.currentBreakingPos = new BlockPos(this.currentBreakingPos.getX(), -1, this.currentBreakingPos.getZ());
}
}

@Unique
Expand All @@ -183,18 +187,14 @@ private ActionResult provideCachedResult(ClientPlayerInteractionManager instance
return interactBlockInternal(player, hand, hitResult);
}

@Inject(method = "sendSequencedPacket", at = @At("HEAD"))
private void handleBlockAcknowledgements(ClientWorld world, SequencedPacketCreator packetCreator, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isBetweenInclusive(VersionEnum.r1_14_4, VersionEnum.r1_18_2) && packetCreator instanceof PlayerActionC2SPacket playerActionC2SPacket) {
ClientPlayerInteractionManager1_18_2.trackBlockAction(playerActionC2SPacket.getAction(), playerActionC2SPacket.getPos());
}
@Inject(method = "interactItem", at = @At("HEAD"))
private void trackLastUsedItem(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
ViaFabricPlusHandItemProvider.lastUsedItem = player.getStackInHand(hand).copy();
}

@Inject(method = "getBlockBreakingProgress", at = @At("HEAD"), cancellable = true)
private void changeCalculation(CallbackInfoReturnable<Integer> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4)) {
cir.setReturnValue((int)(this.currentBreakingProgress * 10.0F) - 1);
}
@Inject(method = "interactBlock", at = @At("HEAD"))
private void trackLastUsedBlock(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
ViaFabricPlusHandItemProvider.lastUsedItem = player.getStackInHand(hand).copy();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.input;
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft;

import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.MinecraftClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,48 +60,6 @@ public abstract class MixinMinecraftClient {

@Shadow @Nullable public abstract ClientPlayNetworkHandler getNetworkHandler();

@WrapWithCondition(method = "doItemUse",
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;interactItem(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")),
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;resetEquipProgress(Lnet/minecraft/util/Hand;)V", ordinal = 0))
private boolean removeEquipProgressReset(HeldItemRenderer instance, Hand hand) {
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_8) || !(player.getStackInHand(hand).getItem() instanceof SwordItem);
}

@Redirect(method = "doItemUse",
slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;interactEntity(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")),
at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ActionResult;isAccepted()Z", ordinal = 0))
private boolean preventGenericInteract(ActionResult instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
return false;
}

return instance.isAccepted();
}

@ModifyExpressionValue(method = "handleBlockBreaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"))
private boolean allowBlockBreakAndItemUsageAtTheSameTime(boolean original) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
return false;
}
return original;
}

@Redirect(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;attackCooldown:I", ordinal = 1))
private int unwrapOperation(MinecraftClient instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return 0;
}
return attackCooldown;
}

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;handleInputEvents()V", shift = At.Shift.BEFORE))
private void updateCooldown(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
if (this.attackCooldown > 0) {
--this.attackCooldown;
}
}
}

@Unique
private final ConcurrentLinkedDeque<Runnable> viaFabricPlus$mouseInteractions = new ConcurrentLinkedDeque<>();
Expand Down Expand Up @@ -143,4 +101,48 @@ private void onInventoryKeyPressed(CallbackInfo ci) {
}
}

@WrapWithCondition(method = "doItemUse",
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;interactItem(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")),
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;resetEquipProgress(Lnet/minecraft/util/Hand;)V", ordinal = 0))
private boolean removeEquipProgressReset(HeldItemRenderer instance, Hand hand) {
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_8) || !(player.getStackInHand(hand).getItem() instanceof SwordItem);
}


@Redirect(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;attackCooldown:I", ordinal = 1))
private int dontIncrementCooldown(MinecraftClient instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return 0;
}
return attackCooldown;
}

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;handleInputEvents()V", shift = At.Shift.BEFORE))
private void postIncrementCooldown(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
if (this.attackCooldown > 0) {
--this.attackCooldown;
}
}
}

@Redirect(method = "doItemUse",
slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;interactEntity(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")),
at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ActionResult;isAccepted()Z", ordinal = 0))
private boolean preventGenericInteract(ActionResult instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
return false;
}

return instance.isAccepted();
}

@ModifyExpressionValue(method = "handleBlockBreaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"))
private boolean allowBlockBreakAndItemUsageAtTheSameTime(boolean original) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
return false;
}
return original;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ public boolean isToolRequired() {
@Inject(method = "getHardness", at = @At("RETURN"), cancellable = true)
private void changeHardness(BlockView world, BlockPos pos, CallbackInfoReturnable<Float> cir) {
final Block block = this.getBlock();
if (block.equals(Blocks.OBSIDIAN)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.b1_8tob1_8_1)) {
cir.setReturnValue(10.0F);
if (block.equals(Blocks.END_STONE_BRICKS) || block.equals(Blocks.END_STONE_BRICK_SLAB) || block.equals(Blocks.END_STONE_BRICK_STAIRS) || block.equals(Blocks.END_STONE_BRICK_WALL)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
cir.setReturnValue(0.8F);
}
} else if (block.equals(Blocks.PISTON) || block.equals(Blocks.STICKY_PISTON) || block.equals(Blocks.PISTON_HEAD)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
cir.setReturnValue(0.5F);
}
} else if (block instanceof InfestedBlock) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
cir.setReturnValue(0.75F);
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
cir.setReturnValue(0F);
}
} else if (block.equals(Blocks.PISTON) || block.equals(Blocks.STICKY_PISTON) || block.equals(Blocks.PISTON_HEAD)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
cir.setReturnValue(0.5F);
}
} else if (block.equals(Blocks.END_STONE_BRICKS) || block.equals(Blocks.END_STONE_BRICK_SLAB) || block.equals(Blocks.END_STONE_BRICK_STAIRS) || block.equals(Blocks.END_STONE_BRICK_WALL)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
cir.setReturnValue(0.8F);
} else if (block.equals(Blocks.OBSIDIAN)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.b1_8tob1_8_1)) {
cir.setReturnValue(10.0F);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public abstract class MixinBedBlock {
@Unique
private static final VoxelShape viaFabricPlus$shape_r1_13_2 = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 9.0D, 16.0D);

@Inject(method = "bounceEntity", at = @At("HEAD"), cancellable = true)
private void cancelEntityBounce(Entity entity, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
ci.cancel();
}
}

@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
private void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
cir.setReturnValue(viaFabricPlus$shape_r1_13_2);
}
}

@Inject(method = "bounceEntity", at = @At("HEAD"), cancellable = true)
private void cancelEntityBounce(Entity entity, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
ci.cancel();
}
}

}
Loading

0 comments on commit a19c708

Please sign in to comment.