Codestyle changes on mixin files:

- Use else block and ternary operator when possible
- Rely more on MixinExtras annotations (e.g. WrapWithCondition)
- Prevent not needed local fields
- Only use var if field type is clear or to prevent lines from getting to long
- Use VersionEnum#isNewerThan in disabling/removal injections
This commit is contained in:
FlorianMichael 2024-01-23 20:41:05 +01:00
parent 3fd3bd8a53
commit cb31189cb8
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
58 changed files with 288 additions and 376 deletions

View File

@ -19,6 +19,7 @@
package de.florianmichael.viafabricplus.injection.mixin.base.connect;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
@ -108,17 +109,14 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler<
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
super.channelRegistered(ctx);
if (VersionEnum.bedrockLatest.equals(this.viaFabricPlus$serverVersion)) {
// Call channelActive manually when the channel is registered
if (VersionEnum.bedrockLatest.equals(this.viaFabricPlus$serverVersion)) { // Call channelActive manually when the channel is registered
this.channelActive(ctx);
}
}
@Redirect(method = "channelActive", at = @At(value = "INVOKE", target = "Lio/netty/channel/SimpleChannelInboundHandler;channelActive(Lio/netty/channel/ChannelHandlerContext;)V"), remap = false)
private void dontCallChannelActive(SimpleChannelInboundHandler<Packet<?>> instance, ChannelHandlerContext ctx) throws Exception {
if (!VersionEnum.bedrockLatest.equals(this.viaFabricPlus$serverVersion)) { // Don't call channelActive twice
super.channelActive(ctx);
}
@WrapWithCondition(method = "channelActive", at = @At(value = "INVOKE", target = "Lio/netty/channel/SimpleChannelInboundHandler;channelActive(Lio/netty/channel/ChannelHandlerContext;)V", remap = false))
private boolean dontCallChannelActiveTwice(SimpleChannelInboundHandler<Packet<?>> instance, ChannelHandlerContext channelHandlerContext) {
return !VersionEnum.bedrockLatest.equals(this.viaFabricPlus$serverVersion);
}
@Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/util/profiler/PerformanceLog;)Lnet/minecraft/network/ClientConnection;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", shift = At.Shift.BEFORE))
@ -129,14 +127,10 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler<
}
}
@Redirect(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/util/profiler/PerformanceLog;)Lnet/minecraft/network/ClientConnection;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;resetPacketSizeLog(Lnet/minecraft/util/profiler/PerformanceLog;)V"))
private static void dontSetPerformanceLog(ClientConnection instance, PerformanceLog performanceLog) {
// Since the PerformanceLog is never null due to our changes, we need to restore vanilla behavior
if (performanceLog instanceof IPerformanceLog mixinPerformanceLog && mixinPerformanceLog.viaFabricPlus$getForcedVersion() != null) {
return;
}
instance.resetPacketSizeLog(performanceLog);
@WrapWithCondition(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/util/profiler/PerformanceLog;)Lnet/minecraft/network/ClientConnection;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;resetPacketSizeLog(Lnet/minecraft/util/profiler/PerformanceLog;)V"))
private static boolean dontSetPerformanceLog(ClientConnection instance, PerformanceLog log) {
// We need to restore vanilla behaviour since we use the PerformanceLog as a way to store the target version
return !(log instanceof IPerformanceLog mixinPerformanceLog) || mixinPerformanceLog.viaFabricPlus$getForcedVersion() == null;
}
@Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At("HEAD"))
@ -155,34 +149,30 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler<
@Redirect(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;channel(Ljava/lang/Class;)Lio/netty/bootstrap/AbstractBootstrap;", remap = false))
private static AbstractBootstrap<?, ?> useRakNetChannelFactory(Bootstrap instance, Class<? extends Channel> channelTypeClass, @Local(argsOnly = true) ClientConnection clientConnection) {
if (VersionEnum.bedrockLatest.equals(((IClientConnection) clientConnection).viaFabricPlus$getTargetVersion())) {
return instance.channelFactory(channelTypeClass == EpollSocketChannel.class ?
RakChannelFactory.client(EpollDatagramChannel.class) :
RakChannelFactory.client(NioDatagramChannel.class)
);
return instance.channelFactory(channelTypeClass == EpollSocketChannel.class ? RakChannelFactory.client(EpollDatagramChannel.class) : RakChannelFactory.client(NioDatagramChannel.class));
} else {
return instance.channel(channelTypeClass);
}
return instance.channel(channelTypeClass);
}
@Redirect(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;connect(Ljava/net/InetAddress;I)Lio/netty/channel/ChannelFuture;", remap = false))
private static ChannelFuture useRakNetPingHandlers(Bootstrap instance, InetAddress inetHost, int inetPort, @Local(argsOnly = true) ClientConnection clientConnection, @Local(argsOnly = true) boolean isConnecting) {
if (VersionEnum.bedrockLatest.equals(((IClientConnection) clientConnection).viaFabricPlus$getTargetVersion()) && !isConnecting) {
// Bedrock edition / RakNet has different handlers for pinging a server
return instance.register().syncUninterruptibly().channel().bind(new InetSocketAddress(0)).
addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, (ChannelFutureListener) f -> {
if (f.isSuccess()) {
f.channel().pipeline().replace(
VLPipeline.VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME,
ViaFabricPlusVLLegacyPipeline.VIABEDROCK_PING_ENCAPSULATION_HANDLER_NAME,
new PingEncapsulationCodec(new InetSocketAddress(inetHost, inetPort))
);
f.channel().pipeline().remove(VLPipeline.VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME);
f.channel().pipeline().remove("splitter");
}
});
return instance.register().syncUninterruptibly().channel().bind(new InetSocketAddress(0)).addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, (ChannelFutureListener) f -> {
if (f.isSuccess()) {
f.channel().pipeline().replace(
VLPipeline.VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME,
ViaFabricPlusVLLegacyPipeline.VIABEDROCK_PING_ENCAPSULATION_HANDLER_NAME,
new PingEncapsulationCodec(new InetSocketAddress(inetHost, inetPort))
);
f.channel().pipeline().remove(VLPipeline.VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME);
f.channel().pipeline().remove("splitter");
}
});
} else {
return instance.connect(inetHost, inetPort);
}
return instance.connect(inetHost, inetPort);
}
@Override

View File

@ -84,11 +84,8 @@ public abstract class MixinConnectScreen_1 {
private String useClassiCubeUsername(Session instance) {
if (this.viaFabricPlus$useClassiCubeAccount) {
final var account = ViaFabricPlus.global().getSaveManager().getAccountsSave().getClassicubeAccount();
if (account != null) {
return account.username();
}
if (account != null) return account.username();
}
return instance.getUsername();
}

View File

@ -40,7 +40,7 @@ public abstract class MixinMultiplayerScreen extends Screen {
@Inject(method = "init", at = @At("RETURN"))
private void addProtocolSelectionButton(CallbackInfo ci) {
// Create the button
var builder = ButtonWidget.builder(Text.literal("ViaFabricPlus"), button -> ProtocolSelectionScreen.INSTANCE.open(this)).size(98, 20);
ButtonWidget.Builder builder = ButtonWidget.builder(Text.literal("ViaFabricPlus"), button -> ProtocolSelectionScreen.INSTANCE.open(this)).size(98, 20);
// Set the button's position according to the configured orientation
builder = GeneralSettings.withOrientation(builder, GeneralSettings.global().multiplayerScreenButtonOrientation.getIndex(), width, height);

View File

@ -19,23 +19,24 @@
package de.florianmichael.viafabricplus.injection.mixin.base.perserverversion;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.network.ServerInfo;
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;
@Mixin(MultiplayerScreen.class)
public abstract class MixinMultiplayerScreen {
@Shadow protected abstract void connect(ServerInfo entry);
@Redirect(method = "directConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;connect(Lnet/minecraft/client/network/ServerInfo;)V"))
private void storeDirectConnectionPhase(MultiplayerScreen instance, ServerInfo entry) {
@WrapOperation(method = "directConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;connect(Lnet/minecraft/client/network/ServerInfo;)V"))
private void storeDirectConnectionPhase(MultiplayerScreen instance, ServerInfo entry, Operation<Void> original) {
((IServerInfo) entry).viaFabricPlus$passDirectConnectScreen();
connect(entry);
original.call(instance, entry);
}
}

View File

@ -49,11 +49,9 @@ public abstract class MixinServerInfo implements IServerInfo {
@Inject(method = "toNbt", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
private void saveForcedVersion(CallbackInfoReturnable<NbtCompound> cir, NbtCompound nbtCompound) {
if (viaFabricPlus$forcedVersion == null) {
return;
if (viaFabricPlus$forcedVersion != null) {
nbtCompound.putInt("viafabricplus_forcedversion", viaFabricPlus$forcedVersion.getOriginalVersion());
}
nbtCompound.putInt("viafabricplus_forcedversion", viaFabricPlus$forcedVersion.getOriginalVersion());
}
@Inject(method = "fromNbt", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)

View File

@ -39,20 +39,16 @@ public abstract class MixinTextFieldWidget implements ITextFieldWidget {
@Redirect(method = "charTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/SharedConstants;isValidChar(C)Z"))
private boolean allowForbiddenCharacters(char c) {
if (this.viaFabricPlus$forbiddenCharactersUnlocked) {
return true;
}
return SharedConstants.isValidChar(c);
return this.viaFabricPlus$forbiddenCharactersUnlocked || SharedConstants.isValidChar(c);
}
@Redirect(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/SharedConstants;stripInvalidChars(Ljava/lang/String;)Ljava/lang/String;"))
private String allowForbiddenCharacters(String string) {
if (this.viaFabricPlus$forbiddenCharactersUnlocked) {
return string;
} else {
return SharedConstants.stripInvalidChars(string);
}
return SharedConstants.stripInvalidChars(string);
}
@Override

View File

@ -59,38 +59,32 @@ public abstract class MixinChatInputSuggestor {
@Inject(method = "provideRenderText", at = @At(value = "HEAD"), cancellable = true)
private void disableTextFieldColors(String original, int firstCharacterIndex, CallbackInfoReturnable<OrderedText> cir) {
if (!this.viaFabricPlus$cancelTabComplete()) {
return;
if (this.viaFabricPlus$cancelTabComplete()) {
cir.setReturnValue(OrderedText.styledForwardsVisitedString(original, Style.EMPTY));
}
cir.setReturnValue(OrderedText.styledForwardsVisitedString(original, Style.EMPTY));
}
@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
private void handle1_12_2KeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
if (!this.viaFabricPlus$cancelTabComplete()) {
return;
}
if (keyCode == GLFW.GLFW_KEY_TAB && this.window == null) {
this.refresh();
} else if (this.window != null) {
if (this.window.keyPressed(keyCode, scanCode, modifiers)) {
cir.setReturnValue(true);
return;
if (this.viaFabricPlus$cancelTabComplete()) {
if (keyCode == GLFW.GLFW_KEY_TAB && this.window == null) {
this.refresh();
} else if (this.window != null) {
if (this.window.keyPressed(keyCode, scanCode, modifiers)) {
cir.setReturnValue(true);
return;
}
this.textField.setSuggestion(null);
this.window = null;
}
this.textField.setSuggestion(null);
this.window = null;
}
}
@Inject(method = "render", at = @At("HEAD"))
private void clearMessages(DrawContext drawContext, int mouseX, int mouseY, CallbackInfo ci) {
if (!this.viaFabricPlus$cancelTabComplete()) {
return;
if (this.viaFabricPlus$cancelTabComplete()) {
this.messages.clear();
}
this.messages.clear();
}
@Unique

View File

@ -33,18 +33,18 @@ public abstract class MixinEnchantmentHelper {
private static int usePossibleMinLevel(int constant) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
return Short.MIN_VALUE;
} else {
return constant;
}
return constant;
}
@ModifyConstant(method = "getLevelFromNbt", constant = @Constant(intValue = 255))
private static int usePossibleMaxLevel(int constant) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
return Short.MAX_VALUE;
} else {
return constant;
}
return constant;
}
}

View File

@ -37,8 +37,11 @@ public abstract class MixinGameOptions {
@ModifyVariable(method = "setServerViewDistance", at = @At("HEAD"), ordinal = 0, argsOnly = true)
private int changeServerViewDistance(int viewDistance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_17_1)) return 0;
return viewDistance;
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_17_1)) {
return 0;
} else {
return viewDistance;
}
}
/**
@ -50,7 +53,6 @@ public abstract class MixinGameOptions {
if (!this.useNativeTransport) {
ViaFabricPlus.global().getLogger().error("Native transport is disabled, but enabling it anyway since we use it as an indicator if the client wants to ping a server or connect to a server.");
}
return true;
}

View File

@ -37,8 +37,9 @@ public abstract class MixinKeyboardInput extends Input {
return this.sneaking;
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
return !MinecraftClient.getInstance().player.isSpectator() && (this.sneaking || slowDown);
} else {
return slowDown;
}
return slowDown;
}
}

View File

@ -97,10 +97,9 @@ public abstract class MixinMinecraftClient {
return instance.shouldSwingHand() && ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(VersionEnum.r1_15);
}
@Redirect(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
private void disableSwing(ClientPlayerEntity instance, Hand hand) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) return;
instance.swingHand(hand);
@WrapWithCondition(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
private boolean disableSwing(ClientPlayerEntity instance, Hand hand) {
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_14_4);
}
@Inject(method = "tick",
@ -142,15 +141,16 @@ public abstract class MixinMinecraftClient {
}
@Redirect(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;attackCooldown:I", ordinal = 1))
private int dontIncrementCooldown(MinecraftClient instance) {
private int moveCooldownIncrement(MinecraftClient instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return 0;
} else {
return attackCooldown;
}
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) {
private void moveCooldownIncrement(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
if (this.attackCooldown > 0) {
--this.attackCooldown;
@ -160,10 +160,7 @@ public abstract class MixinMinecraftClient {
@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;
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_7_6tor1_7_10) && original;
}
}

View File

@ -54,9 +54,9 @@ public abstract class MixinPlayerInventory {
}
}, def) {
};
} else {
return DefaultedList.ofSize(size, def);
}
return DefaultedList.ofSize(size, def);
}
}

View File

@ -48,35 +48,33 @@ public abstract class MixinAbstractBlock_AbstractBlockState {
*/
@Overwrite
public boolean isToolRequired() {
final Block block = this.getBlock();
if (block instanceof ShulkerBoxBlock && ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_14)) {
if (this.getBlock() instanceof ShulkerBoxBlock && ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_14)) {
return true;
} else {
return this.toolRequired;
}
return this.toolRequired;
}
@Inject(method = "getHardness", at = @At("RETURN"), cancellable = true)
private void changeHardness(BlockView world, BlockPos pos, CallbackInfoReturnable<Float> cir) {
final var targetVersion = ProtocolHack.getTargetVersion();
final var block = this.getBlock();
final Block block = this.getBlock();
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 (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
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 (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
cir.setReturnValue(0.5F);
}
} else if (block instanceof InfestedBlock) {
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
cir.setReturnValue(0.75F);
} else if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
cir.setReturnValue(0F);
}
} else if (block.equals(Blocks.OBSIDIAN)) {
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.b1_8tob1_8_1)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.b1_8tob1_8_1)) {
cir.setReturnValue(10.0F);
}
}

View File

@ -49,12 +49,10 @@ public abstract class MixinAbstractSignBlock {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
// <= 1.14.4 doesn't have any sign interactions.
cir.setReturnValue(ActionResult.SUCCESS);
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4)) {
// Removes the isWaxed() condition and reverts the interaction changes from 1.19.4 -> 1.20 when signs
// got a front and back side.
final ItemStack itemStack = player.getStackInHand(hand);
final Item item = itemStack.getItem();
final boolean isSuccess = (item instanceof DyeItem || itemStack.isOf(Items.GLOW_INK_SAC) || itemStack.isOf(Items.INK_SAC)) && player.canModifyBlocks();

View File

@ -59,10 +59,7 @@ public abstract class MixinAnvilBlock extends FallingBlock {
public void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (viaFabricPlus$requireOriginalShape) {
viaFabricPlus$requireOriginalShape = false;
return;
}
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
cir.setReturnValue(state.get(FACING).getAxis() == Direction.Axis.X ? viaFabricPlus$x_axis_shape_r1_12_2 : viaFabricPlus$z_axis_shape_r1_12_2);
}
}

View File

@ -45,9 +45,9 @@ public abstract class MixinCarpetBlock extends Block {
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
return viaFabricPlus$shape_r1_7_10;
} else {
return super.getCollisionShape(state, world, pos, context);
}
return super.getCollisionShape(state, world, pos, context);
}
}

View File

@ -49,8 +49,9 @@ public abstract class MixinCauldronBlock extends AbstractCauldronBlock {
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return viaFabricPlus$shape_r1_12_2;
} else {
return super.getOutlineShape(state, world, pos, context);
}
return super.getOutlineShape(state, world, pos, context);
}
}

View File

@ -88,9 +88,9 @@ public abstract class MixinChestBlock extends AbstractChestBlock<ChestBlockEntit
default -> DOUBLE_EAST_SHAPE;
};
}
} else {
return super.getCullingShape(state, view, pos);
}
return super.getCullingShape(state, view, pos);
}
}

View File

@ -70,9 +70,9 @@ public abstract class MixinEndPortalFrameBlock extends Block {
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return state.get(EYE) ? viaFabricPlus$frame_with_eye_shape_r1_12_2 : FRAME_SHAPE;
} else {
return super.getCollisionShape(state, world, pos, context);
}
return super.getCollisionShape(state, world, pos, context);
}
}

View File

@ -58,9 +58,9 @@ public abstract class MixinEnderChestBlock extends BlockWithEntity {
public VoxelShape getCullingShape(BlockState state, BlockView view, BlockPos pos) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_4_2)) {
return SHAPE;
} else {
return super.getCullingShape(state, view, pos);
}
return super.getCullingShape(state, view, pos);
}
}

View File

@ -58,9 +58,9 @@ public abstract class MixinFarmlandBlock extends Block {
public VoxelShape getCullingShape(BlockState state, BlockView view, BlockPos pos) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_9_3tor1_9_4)) {
return SHAPE;
} else {
return super.getCullingShape(state, view, pos);
}
return super.getCullingShape(state, view, pos);
}
}

View File

@ -59,8 +59,8 @@ public abstract class MixinFenceBlock extends HorizontalConnectingBlock {
@Inject(method = "<init>", at = @At("RETURN"))
private void init1_4_7Shapes(Settings settings, CallbackInfo ci) {
this.viaFabricPlus$collision_shape_r1_4_7 = this.createShapes1_4_7(24.0F);
this.viaFabricPlus$outline_shape_r1_4_7 = this.createShapes1_4_7(16.0F);
this.viaFabricPlus$collision_shape_r1_4_7 = this.viaFabricPlus$createShapes1_4_7(24.0F);
this.viaFabricPlus$outline_shape_r1_4_7 = this.viaFabricPlus$createShapes1_4_7(16.0F);
}
@Override
@ -69,9 +69,9 @@ public abstract class MixinFenceBlock extends HorizontalConnectingBlock {
return VoxelShapes.fullCube();
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_4_6tor1_4_7)) {
return this.viaFabricPlus$outline_shape_r1_4_7[this.getShapeIndex(state)];
} else {
return super.getOutlineShape(state, world, pos, context);
}
return super.getOutlineShape(state, world, pos, context);
}
@Override
@ -80,13 +80,13 @@ public abstract class MixinFenceBlock extends HorizontalConnectingBlock {
return viaFabricPlus$shape_b1_8_1;
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_4_6tor1_4_7)) {
return this.viaFabricPlus$collision_shape_r1_4_7[this.getShapeIndex(state)];
} else {
return super.getCollisionShape(state, world, pos, context);
}
return super.getCollisionShape(state, world, pos, context);
}
@Unique
private VoxelShape[] createShapes1_4_7(final float height) {
private VoxelShape[] viaFabricPlus$createShapes1_4_7(final float height) {
final float f = 6.0F;
final float g = 10.0F;
final float h = 6.0F;

View File

@ -53,9 +53,7 @@ public abstract class MixinHopperBlock extends BlockWithEntity {
public void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (viaFabricPlus$requireOriginalShape) {
viaFabricPlus$requireOriginalShape = false;
return;
}
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
cir.setReturnValue(viaFabricPlus$hopper_shape_r1_12_2);
}
}

View File

@ -87,18 +87,18 @@ public abstract class MixinPaneBlock extends HorizontalConnectingBlock {
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return this.viaFabricPlus$shape_r1_8[this.getShapeIndex(state)];
} else {
return super.getOutlineShape(state, world, pos, context);
}
return super.getOutlineShape(state, world, pos, context);
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return this.viaFabricPlus$shape_r1_8[this.getShapeIndex(state)];
} else {
return super.getCollisionShape(state, world, pos, context);
}
return super.getCollisionShape(state, world, pos, context);
}
}

View File

@ -89,9 +89,9 @@ public abstract class MixinPistonBlock extends FacingBlock {
} else {
return VoxelShapes.fullCube();
}
} else {
return super.getCullingShape(state, world, pos);
}
return super.getCullingShape(state, world, pos);
}
}

View File

@ -108,9 +108,9 @@ public abstract class MixinPistonHeadBlock extends FacingBlock {
case WEST -> VoxelShapes.union(WEST_HEAD_SHAPE, viaFabricPlus$west_arm_shape_r1_8_x);
case EAST -> VoxelShapes.union(EAST_HEAD_SHAPE, viaFabricPlus$east_arm_shape_r1_8_x);
};
} else {
return super.getCollisionShape(state, world, pos, context);
}
return super.getCollisionShape(state, world, pos, context);
}
}

View File

@ -58,11 +58,7 @@ public abstract class MixinSoulSandBlock extends Block {
@Override
public float getVelocityMultiplier() {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
return 1F;
}
return super.getVelocityMultiplier();
return ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4) ? 1F : super.getVelocityMultiplier();
}
}

View File

@ -66,8 +66,8 @@ public abstract class MixinWallBlock extends Block {
@Inject(method = "<init>", at = @At("RETURN"))
private void initShapes1_12_2(Settings settings, CallbackInfo ci) {
this.viaFabricPlus$collision_shape_r1_12_2 = this.createShapes1_12_2(24.0F, 24.0F);
this.viaFabricPlus$outline_shape_r1_12_2 = this.createShapes1_12_2(16.0F, 14.0F);
this.viaFabricPlus$collision_shape_r1_12_2 = this.viaFabricPlus$createShapes1_12_2(24.0F, 24.0F);
this.viaFabricPlus$outline_shape_r1_12_2 = this.viaFabricPlus$createShapes1_12_2(16.0F, 14.0F);
}
@Inject(method = "getPlacementState", at = @At("RETURN"), cancellable = true)
@ -102,13 +102,13 @@ public abstract class MixinWallBlock extends Block {
public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
if (state.get(WallBlock.UP) && ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return this.shapeMap.get(state);
} else {
return super.getCullingShape(state, world, pos);
}
return super.getCullingShape(state, world, pos);
}
@Unique
private VoxelShape[] createShapes1_12_2(final float height1, final float height2) {
private VoxelShape[] viaFabricPlus$createShapes1_12_2(final float height1, final float height2) {
final float f = 4.0F;
final float g = 12.0F;
final float h = 5.0F;

View File

@ -37,10 +37,7 @@ public abstract class MixinAbstractHorseEntity {
@Redirect(method = "interactHorse", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/AbstractHorseEntity;receiveFood(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;)Z"))
private boolean decrementFoodItemClientside(AbstractHorseEntity instance, PlayerEntity player, ItemStack item) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20_2)) {
return true;
}
return this.receiveFood(player, item);
return ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20_2) || this.receiveFood(player, item);
}
}

View File

@ -19,6 +19,7 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.mojang.authlib.GameProfile;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
@ -66,70 +67,52 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity
super(world, profile);
}
@Shadow
protected abstract void sendSprintingPacket();
@Shadow
@Final
public ClientPlayNetworkHandler networkHandler;
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z", ordinal = 0))
private boolean removeVehicleRequirement(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
return false;
}
return instance.hasVehicle();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_20tor1_20_1) && instance.hasVehicle();
}
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;sendSprintingPacket()V"))
private void removeSprintingPacket(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(VersionEnum.r1_19_3)) {
sendSprintingPacket();
}
@WrapWithCondition(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;sendSprintingPacket()V"))
private boolean removeSprintingPacket(ClientPlayerEntity instance) {
return ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(VersionEnum.r1_19_3);
}
@Redirect(method = "autoJump", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;inverseSqrt(F)F"))
private float useFastInverse(float x) {
private float useFastInverseSqrt(float x) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
// fast inverse sqrt
x = Float.intBitsToFloat(1597463007 - (Float.floatToIntBits(x) >> 1));
return x * (1.5F - (0.5F * x) * x * x);
} else {
return MathHelper.inverseSqrt(x);
}
return MathHelper.inverseSqrt(x);
}
@Redirect(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z"))
private boolean removeVehicleCheck(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
return false;
}
return instance.hasVehicle();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_19_3) && instance.hasVehicle();
}
@Redirect(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isFallFlying()Z"))
private boolean removeFallFlyingCheck(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
return false;
}
return instance.isFallFlying();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_19_3) && instance.isFallFlying();
}
@Redirect(method = "canSprint", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z"))
private boolean dontAllowSprintingAsPassenger(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_1tor1_19_2)) {
return false;
}
return instance.hasVehicle();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_19_1tor1_19_2) && instance.hasVehicle();
}
@Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;square(D)D"))
private double changeMagnitude(double n) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_18tor1_18_1)) {
return 9.0E-4D;
} else {
return MathHelper.square(n);
}
return MathHelper.square(n);
}
@Inject(method = "startRiding", at = @At("RETURN"))
@ -143,26 +126,17 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isClimbing()Z"))
private boolean allowElytraWhenClimbing(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_1)) {
return false;
}
return instance.isClimbing();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_15_1) && instance.isClimbing();
}
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z", ordinal = 3))
private boolean allowElytraInVehicle(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
return false;
}
return instance.hasVehicle();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_14_4) && instance.hasVehicle();
}
@ModifyVariable(method = "tickMovement", at = @At(value = "LOAD", ordinal = 4), ordinal = 4)
private boolean removeBl8Boolean(boolean value) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
return false;
}
return value;
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_14_4) && value;
}
@Inject(method = "tickMovement()V",
@ -188,40 +162,34 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity
private boolean disableSprintSneak(Input input) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_1)) {
return input.movementForward >= 0.8F;
} else {
return input.hasForwardMovement();
}
return input.hasForwardMovement();
}
@Redirect(method = "tickMovement",
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isWalking()Z")),
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSwimming()Z", ordinal = 0))
private boolean redirectIsSneakingWhileSwimming(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_1)) {
return false;
} else {
return instance.isSwimming();
}
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_14_1) && instance.isSwimming();
}
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isTouchingWater()Z"))
private boolean redirectTickMovement(ClientPlayerEntity self) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return false; // Disable all water related movement
}
return self.isTouchingWater();
private boolean disableWaterRelatedMovement(ClientPlayerEntity self) {
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_12_2) && self.isTouchingWater();
}
@Redirect(method = "sendMovementPackets", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerEntity;ticksSinceLastPositionPacketSent:I", ordinal = 0))
private int revertLastPositionPacketSentIncrementor(ClientPlayerEntity instance) {
// Mixin calls the redirector and sets the original field to the return value of the redirector + 1, therefore the -1 results, so we truncate the + 1 again and the field does not change
private int moveLastPosPacketIncrement(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return ticksSinceLastPositionPacketSent - 1;
return ticksSinceLastPositionPacketSent - 1; // Reverting original operation
} else {
return ticksSinceLastPositionPacketSent;
}
return ticksSinceLastPositionPacketSent;
}
@Inject(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z"))
private void incrementLastPositionPacketSentCounter(CallbackInfo ci) {
private void moveLastPosPacketIncrement(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
this.ticksSinceLastPositionPacketSent++;
}
@ -231,8 +199,9 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity
private boolean sendIdlePacket(ClientPlayerEntity instance) {
if (DebugSettings.global().sendIdlePacket.isEnabled()) {
return !isOnGround();
} else {
return lastOnGround;
}
return lastOnGround;
}
@Redirect(method = "tick", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z")), at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", ordinal = 0))

View File

@ -35,8 +35,9 @@ public abstract class MixinCreeperEntity {
private SoundEvent changeSound() {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_1tor1_19_2)) {
return SoundEvents.ITEM_FLINTANDSTEEL_USE;
} else {
return SoundEvents.ITEM_FIRECHARGE_USE;
}
return SoundEvents.ITEM_FIRECHARGE_USE;
}
}

View File

@ -86,17 +86,16 @@ public abstract class MixinEntity implements IEntity {
private Vector3f getPassengerRidingPos1_20_1(Entity instance, Entity passenger, EntityDimensions dimensions, float scaleFactor) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
return EntityRidingOffsetsPre1_20_2.getMountedHeightOffset(instance, passenger);
} else {
return getPassengerAttachmentPos(passenger, dimensions, scaleFactor);
}
return getPassengerAttachmentPos(passenger, dimensions, scaleFactor);
}
@Inject(method = "getPosWithYOffset", at = @At("HEAD"), cancellable = true)
private void modifyPosWithYOffset(float offset, CallbackInfoReturnable<BlockPos> cir) {
final VersionEnum target = ProtocolHack.getTargetVersion();
if (target.isOlderThanOrEqualTo(VersionEnum.r1_19_4)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4)) {
int i = MathHelper.floor(this.pos.x);
int j = MathHelper.floor(this.pos.y - (double) (target.isOlderThanOrEqualTo(VersionEnum.r1_18_2) && offset == 1.0E-5F ? 0.2F : offset));
int j = MathHelper.floor(this.pos.y - (double) (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_18_2) && offset == 1.0E-5F ? 0.2F : offset));
int k = MathHelper.floor(this.pos.z);
BlockPos blockPos = new BlockPos(i, j, k);
if (this.world.getBlockState(blockPos).isAir()) {
@ -116,9 +115,9 @@ public abstract class MixinEntity implements IEntity {
private double fixBlockCollisionMargin(double constant) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_1tor1_19_2)) {
return 1E-3;
} else {
return constant;
}
return constant;
}
@Inject(method = "getVelocityAffectingPos", at = @At("HEAD"), cancellable = true)

View File

@ -84,18 +84,18 @@ public abstract class MixinLivingEntity extends Entity {
private Vector3f getPassengerRidingPos1_20_1(LivingEntity instance, Entity entity, EntityDimensions entityDimensions, float v) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
return EntityRidingOffsetsPre1_20_2.getMountedHeightOffset(instance, entity);
} else {
return getPassengerAttachmentPos(entity, entityDimensions, v);
}
return getPassengerAttachmentPos(entity, entityDimensions, v);
}
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isLogicalSideForUpdatingMovement()Z"))
private boolean allowPlayerToBeMovedByEntityPackets(LivingEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3) || ProtocolHack.getTargetVersion().equals(VersionEnum.bedrockLatest)) {
return instance.getControllingPassenger() instanceof PlayerEntity player ? player.isMainPlayer() : !instance.getWorld().isClient;
} else {
return instance.isLogicalSideForUpdatingMovement();
}
return instance.isLogicalSideForUpdatingMovement();
}
@Inject(method = "tickCramming", at = @At("HEAD"), cancellable = true)
@ -109,16 +109,18 @@ public abstract class MixinLivingEntity extends Entity {
private double fixCosTable(double a) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_18tor1_18_1)) {
return MathHelper.cos((float) a);
} else {
return Math.cos(a);
}
return Math.cos(a);
}
@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getFluidHeight(Lnet/minecraft/registry/tag/TagKey;)D"))
private double fixLavaMovement(LivingEntity instance, TagKey<Fluid> tagKey) {
private double dontApplyLavaMovement(LivingEntity instance, TagKey<Fluid> tagKey) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
return Double.MAX_VALUE;
} else {
return instance.getFluidHeight(tagKey);
}
return instance.getFluidHeight(tagKey);
}
@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isChunkLoaded(Lnet/minecraft/util/math/BlockPos;)Z"))
@ -132,52 +134,37 @@ public abstract class MixinLivingEntity extends Entity {
@Redirect(method = "applyMovementInput", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/LivingEntity;jumping:Z"))
private boolean disableJumpOnLadder(LivingEntity self) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
return false;
}
return jumping;
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_13_2) && jumping;
}
@Redirect(method = "travel",
slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/entity/effect/StatusEffects;DOLPHINS_GRACE:Lnet/minecraft/entity/effect/StatusEffect;")),
at = @At(value = "FIELD", target = "Lnet/minecraft/entity/LivingEntity;horizontalCollision:Z", ordinal = 0))
private boolean disableClimbing(LivingEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
return false;
}
return instance.horizontalCollision;
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_13_2) && instance.horizontalCollision;
}
@ModifyVariable(method = "applyFluidMovingSpeed", ordinal = 0, at = @At("HEAD"), argsOnly = true)
private boolean modifyMovingDown(boolean movingDown) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
return true;
}
return movingDown;
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_13_2) && movingDown;
}
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;onLanding()V"))
private void dontResetLevitationFallDistance(LivingEntity instance) {
if (!this.hasStatusEffect(StatusEffects.SLOW_FALLING) && ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return;
if (this.hasStatusEffect(StatusEffects.SLOW_FALLING) || ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_12_2)) {
instance.onLanding();
}
instance.onLanding();
}
@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isSprinting()Z", ordinal = 0))
private boolean modifySwimSprintSpeed(LivingEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return false;
}
return instance.isSprinting();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_12_2) && instance.isSprinting();
}
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getFluidHeight(Lnet/minecraft/registry/tag/TagKey;)D"))
private double redirectFluidHeight(LivingEntity instance, TagKey<Fluid> tagKey) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2) && tagKey == FluidTags.WATER) {
if (instance.getFluidHeight(tagKey) > 0) {
return 1;
}
if (instance.getFluidHeight(tagKey) > 0) return 1;
}
return instance.getFluidHeight(tagKey);
}
@ -193,8 +180,9 @@ public abstract class MixinLivingEntity extends Entity {
private float modifySwimFriction(float constant) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return this.getBaseMovementSpeedMultiplier();
} else {
return constant;
}
return constant;
}
@Inject(method = "getPreferredEquipmentSlot", at = @At("HEAD"), cancellable = true)
@ -208,8 +196,9 @@ public abstract class MixinLivingEntity extends Entity {
private double modifyVelocityZero(final double constant) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return 0.005D;
} else {
return constant;
}
return constant;
}
@Inject(method = "canEnterTrapdoor", at = @At("HEAD"), cancellable = true)

View File

@ -76,10 +76,7 @@ public abstract class MixinPlayerEntity extends LivingEntity {
@Redirect(method = "getMaxRelativeHeadRotation", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isBlocking()Z"))
private boolean dontModifyHeadRotationWhenBlocking(PlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20_2)) {
return false;
}
return instance.isBlocking();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_20_2) && instance.isBlocking();
}
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;setMovementSpeed(F)V"))
@ -91,8 +88,9 @@ public abstract class MixinPlayerEntity extends LivingEntity {
private boolean useLastSprintingState(PlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
return viaFabricPlus$isSprinting;
} else {
return instance.isSprinting();
}
return instance.isSprinting();
}
@WrapWithCondition(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
@ -102,10 +100,7 @@ public abstract class MixinPlayerEntity extends LivingEntity {
@Redirect(method = "checkFallFlying", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;hasStatusEffect(Lnet/minecraft/entity/effect/StatusEffect;)Z"))
private boolean allowElytraWhenLevitating(PlayerEntity instance, StatusEffect statusEffect) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
return false;
}
return instance.hasStatusEffect(statusEffect);
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_15_2) && instance.hasStatusEffect(statusEffect);
}
@Inject(method = "checkFallFlying", at = @At("HEAD"), cancellable = true)
@ -126,8 +121,9 @@ public abstract class MixinPlayerEntity extends LivingEntity {
private float modifySneakEyeHeight(float prevEyeHeight) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
return 1.54F;
} else {
return prevEyeHeight;
}
return prevEyeHeight;
}
@Inject(method = "updatePose", at = @At("HEAD"), cancellable = true)
@ -167,14 +163,15 @@ public abstract class MixinPlayerEntity extends LivingEntity {
private float modifyStepHeight1_10(PlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_10)) {
return 1.0F;
} else {
return instance.getStepHeight();
}
return instance.getStepHeight();
}
@Inject(method = "getAttackCooldownProgress", at = @At("HEAD"), cancellable = true)
private void removeAttackCooldown(CallbackInfoReturnable<Float> ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
ci.setReturnValue(1f);
ci.setReturnValue(1F);
}
}

View File

@ -92,8 +92,9 @@ public abstract class MixinWolfEntity extends TameableEntity implements Angerabl
private float fixWolfHealth(WolfEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
return this.viaFabricPlus$getWolfHealth();
} else {
return instance.getHealth();
}
return instance.getHealth();
}
@Unique

View File

@ -57,8 +57,9 @@ public abstract class MixinAxeItem extends MiningToolItem {
public boolean isSuitableFor(BlockState state) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
return false;
} else {
return super.isSuitableFor(state);
}
return super.isSuitableFor(state);
}
@Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true)
@ -74,8 +75,9 @@ public abstract class MixinAxeItem extends MiningToolItem {
return viaFabricPlus$effective_blocks_b1_8_1.contains(state.getBlock()) ? this.miningSpeed : 1.0F;
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
return viaFabricPlus$effective_materials_r1_16_5.contains(Material1_19_4.getMaterial(state)) ? this.miningSpeed : viaFabricPlus$effective_blocks_r1_16_5.contains(state.getBlock()) ? this.miningSpeed : 1.0F;
} else {
return super.getMiningSpeedMultiplier(stack, state);
}
return super.getMiningSpeedMultiplier(stack, state);
}
}

View File

@ -34,8 +34,9 @@ public abstract class MixinBrushItem {
private float modifyReachDistance(boolean creative) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20_2)) {
return 5F;
} else {
return PlayerEntity.getReachDistance(creative);
}
return PlayerEntity.getReachDistance(creative);
}
}

View File

@ -34,16 +34,18 @@ public abstract class MixinDrawContext {
private int handleNegativeItemCount(ItemStack instance) {
if (((IItemStack) (Object) instance).viaFabricPlus$has1_10Tag()) {
return ((IItemStack) (Object) instance).viaFabricPlus$get1_10Count();
} else {
return instance.getCount();
}
return instance.getCount();
}
@Redirect(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Ljava/lang/String;valueOf(I)Ljava/lang/String;", remap = false))
private String makeTextRed(int count) {
if (count <= 0) {
return Formatting.RED.toString() + count;
} else {
return String.valueOf(count);
}
return String.valueOf(count);
}
}

View File

@ -41,10 +41,7 @@ public interface MixinEquipment {
@Redirect(method = "equipAndSwap", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isCreative()Z"))
default boolean removeCreativeCondition(PlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
return false;
}
return instance.isCreative();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_20tor1_20_1) && instance.isCreative();
}
@Inject(method = "equipAndSwap", at = @At("HEAD"), cancellable = true)

View File

@ -32,11 +32,7 @@ public abstract class MixinFireworkRocketItem {
@Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isFallFlying()Z", ordinal = 0))
private boolean disableFireworkElytraBoost(PlayerEntity player) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_11)) {
return false;
}
return player.isFallFlying();
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_11) && player.isFallFlying();
}
}

View File

@ -62,11 +62,7 @@ public abstract class MixinHoeItem extends MiningToolItem {
@Override
public boolean isSuitableFor(BlockState state) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
return false;
}
return super.isSuitableFor(state);
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_16_4tor1_16_5) && super.isSuitableFor(state);
}
@Override

View File

@ -46,8 +46,9 @@ public abstract class MixinItem {
private int changeCrossbowDamage(Item instance) {
if (instance instanceof CrossbowItem && ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_17_1)) {
return 326;
} else {
return maxDamage;
}
return maxDamage;
}
@Inject(method = "getMaxCount", at = @At("HEAD"), cancellable = true)
@ -61,8 +62,9 @@ public abstract class MixinItem {
private boolean makeFoodInstantConsumable(boolean original) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.b1_7tob1_7_3)) {
return false;
} else {
return original;
}
return original;
}
}

View File

@ -41,7 +41,7 @@ public abstract class MixinItemGroup_EntriesImpl {
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isEnabled(Lnet/minecraft/resource/featuretoggle/FeatureSet;)Z"))
private boolean removeUnknownItems(Item instance, FeatureSet featureSet) {
final var index = GeneralSettings.global().removeNotAvailableItemsFromCreativeTab.getIndex();
final int index = GeneralSettings.global().removeNotAvailableItemsFromCreativeTab.getIndex();
if (index == 2 || MinecraftClient.getInstance().isInSingleplayer()) return instance.isEnabled(featureSet);
if (index == 1 && !Registries.ITEM_GROUP.getId(this.group).getNamespace().equals("minecraft")) return instance.isEnabled(featureSet);

View File

@ -69,9 +69,9 @@ public abstract class MixinPickaxeItem extends MiningToolItem {
} else {
return viaFabricPlus$effective_materials_r1_16_5.contains(Material1_19_4.getMaterial(state)) || state.isOf(Blocks.NETHER_GOLD_ORE);
}
} else {
return super.isSuitableFor(state);
}
return super.isSuitableFor(state);
}
@Override

View File

@ -53,14 +53,18 @@ public abstract class MixinShovelItem extends MiningToolItem {
public boolean isSuitableFor(BlockState state) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
return state.isOf(Blocks.SNOW) || state.isOf(Blocks.SNOW_BLOCK);
} else {
return super.isSuitableFor(state);
}
return super.isSuitableFor(state);
}
@Redirect(method = "useOnBlock", slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/item/ShovelItem;PATH_STATES:Ljava/util/Map;")), at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 0, remap = false))
private Object disablePathAction(Map<Object, Object> instance, Object grassBlock) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) return null;
return instance.get(grassBlock);
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return null;
} else {
return instance.get(grassBlock);
}
}
@Override

View File

@ -50,24 +50,27 @@ public abstract class MixinSwordItem extends ToolItem {
ItemStack itemStack = user.getStackInHand(hand);
user.setCurrentHand(hand);
return TypedActionResult.consume(itemStack);
} else {
return super.use(world, user, hand);
}
return super.use(world, user, hand);
}
@Override
public UseAction getUseAction(ItemStack stack) {
if (ProtocolHack.getTargetVersion().isBetweenInclusive(VersionEnum.b1_8tob1_8_1, VersionEnum.r1_8)) {
return UseAction.BLOCK;
} else {
return super.getUseAction(stack);
}
return super.getUseAction(stack);
}
@Override
public int getMaxUseTime(ItemStack stack) {
if (ProtocolHack.getTargetVersion().isBetweenInclusive(VersionEnum.b1_8tob1_8_1, VersionEnum.r1_8)) {
return 72000;
} else {
return super.getMaxUseTime(stack);
}
return super.getMaxUseTime(stack);
}
@Inject(method = "getMiningSpeedMultiplier", at = @At("HEAD"), cancellable = true)

View File

@ -77,10 +77,9 @@ public abstract class MixinClientCommonNetworkHandler {
private void forceSendKeepAlive(ClientCommonNetworkHandler instance, Packet<? extends ServerPacketListener> packet, BooleanSupplier sendCondition, Duration expiry) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
sendPacket(packet);
return;
} else {
send(packet, sendCondition, expiry);
}
send(packet, sendCondition, expiry);
}
@Inject(method = "onPing", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER), cancellable = true)

View File

@ -102,9 +102,9 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
private boolean allowPlayerToBeMovedByEntityPackets(Entity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3) || ProtocolHack.getTargetVersion().equals(VersionEnum.bedrockLatest)) {
return instance.getControllingPassenger() instanceof PlayerEntity player ? player.isMainPlayer() : !instance.getWorld().isClient;
} else {
return instance.isLogicalSideForUpdatingMovement();
}
return instance.isLogicalSideForUpdatingMovement();
}
@Inject(method = "<init>", at = @At("RETURN"))
@ -137,9 +137,10 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
@ModifyConstant(method = "onEntityPassengersSet", constant = @Constant(classValue = BoatEntity.class))
private Class<?> dontChangeYawWhenMountingBoats(Object entity, Class<?> boatClass) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_18tor1_18_1)) {
return Integer.class;
return Integer.class; // Dummy class file to false the instanceof check
} else {
return boatClass;
}
return boatClass;
}
@Inject(method = "onChunkLoadDistance", at = @At("RETURN"))
@ -160,18 +161,17 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
@Inject(method = "onGameJoin", at = @At("RETURN"))
private void sendAdditionalData(CallbackInfo ci) {
final VersionEnum targetVersion = ProtocolHack.getTargetVersion();
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
final List<RecipeEntry<?>> recipes = new ArrayList<>();
final List<RecipeInfo> recipeInfos = Recipes1_11_2.getRecipes(targetVersion);
final List<RecipeInfo> recipeInfos = Recipes1_11_2.getRecipes(ProtocolHack.getTargetVersion());
for (int i = 0; i < recipeInfos.size(); i++) {
recipes.add(recipeInfos.get(i).create(new Identifier("viafabricplus", "recipe/" + i)));
}
this.onSynchronizeRecipes(new SynchronizeRecipesS2CPacket(recipes));
}
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_8)) {
this.onEntityStatus(new EntityStatusS2CPacket(this.client.player, (byte) 28)); // Op-level 4
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
this.onEntityStatus(new EntityStatusS2CPacket(this.client.player, (byte) 28)); // Op-level 4
}
}
}

View File

@ -154,7 +154,7 @@ public abstract class MixinClientPlayerInteractionManager implements IClientPlay
else
slotItemBeforeModification = viaFabricPlus$oldItems.get(clickSlot.getSlot());
final var clickWindowPacket = PacketWrapper.create(ServerboundPackets1_16_2.CLICK_WINDOW, ((IClientConnection) networkHandler.getConnection()).viaFabricPlus$getUserConnection());
final PacketWrapper clickWindowPacket = PacketWrapper.create(ServerboundPackets1_16_2.CLICK_WINDOW, ((IClientConnection) networkHandler.getConnection()).viaFabricPlus$getUserConnection());
clickWindowPacket.write(Type.UNSIGNED_BYTE, (short) clickSlot.getSyncId());
clickWindowPacket.write(Type.SHORT, (short) clickSlot.getSlot());
clickWindowPacket.write(Type.BYTE, (byte) clickSlot.getButton());
@ -174,14 +174,10 @@ public abstract class MixinClientPlayerInteractionManager implements IClientPlay
@Redirect(method = {"method_41936", "method_41935"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;breakBlock(Lnet/minecraft/util/math/BlockPos;)Z"))
private boolean checkFireBlock(ClientPlayerInteractionManager instance, BlockPos pos, @Local Direction direction) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
if (!this.extinguishFire(pos, direction)) {
return instance.breakBlock(pos);
} else {
return false;
}
return !this.viaFabricPlus$extinguishFire(pos, direction) && instance.breakBlock(pos);
} else {
return instance.breakBlock(pos);
}
return instance.breakBlock(pos);
}
@Inject(method = "breakBlock", at = @At("TAIL"))
@ -239,12 +235,16 @@ public abstract class MixinClientPlayerInteractionManager implements IClientPlay
@Inject(method = "interactItem", at = @At("HEAD"), cancellable = true)
private void cancelOffHandItemInteract(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8) && !Hand.MAIN_HAND.equals(hand)) cir.setReturnValue(ActionResult.PASS);
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8) && !Hand.MAIN_HAND.equals(hand)) {
cir.setReturnValue(ActionResult.PASS);
}
}
@Inject(method = "interactBlock", at = @At("HEAD"), cancellable = true)
private void cancelOffHandBlockPlace(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8) && !Hand.MAIN_HAND.equals(hand)) cir.setReturnValue(ActionResult.PASS);
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8) && !Hand.MAIN_HAND.equals(hand)) {
cir.setReturnValue(ActionResult.PASS);
}
}
/**
@ -293,7 +293,7 @@ public abstract class MixinClientPlayerInteractionManager implements IClientPlay
}
@Unique
private boolean extinguishFire(BlockPos blockPos, final Direction direction) {
private boolean viaFabricPlus$extinguishFire(BlockPos blockPos, final Direction direction) {
blockPos = blockPos.offset(direction);
if (this.client.world.getBlockState(blockPos).getBlock() == Blocks.FIRE) {
this.client.world.syncWorldEvent(this.client.player, 1009, blockPos, 0);

View File

@ -19,6 +19,7 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
@ -57,42 +58,41 @@ public abstract class MixinChatScreen {
private MessageIndicator removeIndicator(ChatHud instance, double mouseX, double mouseY) {
if (VisualSettings.global().hideSignatureIndicator.isEnabled()) {
return null;
} else {
return instance.getIndicatorAt(mouseX, mouseY);
}
return instance.getIndicatorAt(mouseX, mouseY);
}
@Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;setText(Ljava/lang/String;)V"))
private void moveSetTextDown(TextFieldWidget instance, String text) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) return;
instance.setText(text);
@WrapWithCondition(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;setText(Ljava/lang/String;)V"))
public boolean moveSetTextDown(TextFieldWidget instance, String text) {
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_12_2);
}
@Inject(method = "init", at = @At("RETURN"))
private void moveSetTextDown(CallbackInfo ci) {
if (!ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) return;
this.chatField.setText(this.originalChatText);
this.chatInputSuggestor.refresh();
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
this.chatField.setText(this.originalChatText);
this.chatInputSuggestor.refresh();
}
}
@Redirect(method = "onChatFieldUpdate", at = @At(value = "INVOKE", target = "Ljava/lang/String;equals(Ljava/lang/Object;)Z"))
private boolean fixCommandKey(String instance, Object other) {
if (!this.viaFabricPlus$cancelTabComplete()) return instance.equals(other);
return instance.isEmpty();
if (this.viaFabricPlus$keepTabComplete()) {
return instance.equals(other);
} else {
return instance.isEmpty();
}
}
@Redirect(method = "onChatFieldUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ChatInputSuggestor;refresh()V"))
private void disableAutoTabComplete(ChatInputSuggestor instance) {
if (this.viaFabricPlus$cancelTabComplete()) return;
instance.refresh();
@WrapWithCondition(method = "onChatFieldUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ChatInputSuggestor;refresh()V"))
private boolean disableAutoTabComplete(ChatInputSuggestor instance) {
return this.viaFabricPlus$keepTabComplete();
}
@Unique
private boolean viaFabricPlus$cancelTabComplete() {
return ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2) && this.chatField.getText().startsWith("/");
private boolean viaFabricPlus$keepTabComplete() {
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_12_2) || !this.chatField.getText().startsWith("/");
}
}

View File

@ -20,6 +20,7 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen;
import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1;
@ -57,26 +58,25 @@ public abstract class MixinConnectScreen_1 {
private String getRealAddress(InetSocketAddress instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_17)) {
return field_33737.getAddress();
} else {
return instance.getHostName();
}
return instance.getHostName();
}
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/net/InetSocketAddress;getPort()I", remap = false))
private int getRealPort(InetSocketAddress instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_17)) {
return field_33737.getPort();
} else {
return instance.getPort();
}
return instance.getPort();
}
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lio/netty/channel/ChannelFuture;syncUninterruptibly()Lio/netty/channel/ChannelFuture;", remap = false, shift = At.Shift.AFTER))
private void setupConnectionSessions(CallbackInfo ci, @Local ClientConnection clientConnection) {
final var userConnection = ((IClientConnection) clientConnection).viaFabricPlus$getUserConnection();
final var targetVersion = ProtocolHack.getTargetVersion();
final UserConnection userConnection = ((IClientConnection) clientConnection).viaFabricPlus$getUserConnection();
if (targetVersion.isBetweenInclusive(VersionEnum.r1_19, VersionEnum.r1_19_1tor1_19_2)) {
if (ProtocolHack.getTargetVersion().isBetweenInclusive(VersionEnum.r1_19, VersionEnum.r1_19_1tor1_19_2)) {
final var keyPair = MinecraftClient.getInstance().getProfileKeys().fetchKeyPair().join().orElse(null);
if (keyPair != null) {
final var publicKeyData = keyPair.publicKey().data();
@ -86,7 +86,7 @@ public abstract class MixinConnectScreen_1 {
final var uuid = this.field_33738.getSession().getUuidOrNull();
userConnection.put(new ChatSession1_19_1(uuid, privateKey, new ProfileKey(expiresAt, publicKey, publicKeyData.keySignature())));
if (targetVersion == VersionEnum.r1_19) {
if (ProtocolHack.getTargetVersion() == VersionEnum.r1_19) {
final var legacyKeySignature = ((ILegacyKeySignatureStorage) (Object) publicKeyData).viafabricplus$getLegacyPublicKeySignature();
if (legacyKeySignature != null) {
userConnection.put(new ChatSession1_19_0(uuid, privateKey, new ProfileKey(expiresAt, publicKey, legacyKeySignature)));
@ -95,7 +95,7 @@ public abstract class MixinConnectScreen_1 {
} else {
ViaFabricPlus.global().getLogger().error("Could not get public key signature. Joining servers with enforce-secure-profiles enabled will not work!");
}
} else if (targetVersion == VersionEnum.bedrockLatest) {
} else if (ProtocolHack.getTargetVersion() == VersionEnum.bedrockLatest) {
final var bedrockSession = ViaFabricPlus.global().getSaveManager().getAccountsSave().refreshAndGetBedrockAccount();
if (bedrockSession != null) {
final var mcChain = bedrockSession.getMcChain();

View File

@ -52,7 +52,7 @@ public abstract class MixinGameModeSelectionScreen extends Screen {
@Inject(method = "<init>", at = @At("RETURN"))
private void fixUIWidth(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
final List<GameModeSelectionScreen.GameModeSelection> gameModeSelections = new ArrayList<>(Arrays.stream(GameModeSelectionScreen.GameModeSelection.values()).toList());
final var gameModeSelections = new ArrayList<>(Arrays.stream(GameModeSelectionScreen.GameModeSelection.values()).toList());
gameModeSelections.remove(GameModeSelectionScreen.GameModeSelection.SPECTATOR);
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_2_4tor1_2_5)) {
@ -68,9 +68,9 @@ public abstract class MixinGameModeSelectionScreen extends Screen {
private GameModeSelectionScreen.GameModeSelection[] removeNewerGameModes() {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
return viaFabricPlus$unwrappedGameModes;
} else {
return GameModeSelectionScreen.GameModeSelection.values();
}
return GameModeSelectionScreen.GameModeSelection.values();
}
@Inject(method = "init", at = @At("HEAD"))

View File

@ -31,11 +31,7 @@ public abstract class MixinChatHud {
@ModifyVariable(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", at = @At("HEAD"), ordinal = 0, argsOnly = true)
private MessageIndicator removeIndicator(MessageIndicator instance) {
if (VisualSettings.global().hideSignatureIndicator.isEnabled()) {
return null;
}
return instance;
return VisualSettings.global().hideSignatureIndicator.isEnabled() ? null : instance;
}
}

View File

@ -62,8 +62,9 @@ public abstract class MixinInGameHud {
private int moveHealthDown(int originalValue) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
return originalValue + 6;
} else {
return originalValue;
}
return originalValue;
}
@ModifyArg(method = "renderStatusBars", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"), slice = @Slice(
@ -73,8 +74,9 @@ public abstract class MixinInGameHud {
private int moveArmorNextToHealth(int oldX) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
return scaledWidth - oldX - 9;
} else {
return oldX;
}
return oldX;
}
@ModifyArg(method = "renderStatusBars", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"), slice = @Slice(
@ -84,8 +86,9 @@ public abstract class MixinInGameHud {
private int moveArmorDown(int oldY) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
return oldY + 9;
} else {
return oldY;
}
return oldY;
}
@ModifyArg(method = "renderStatusBars", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"), slice = @Slice(
@ -95,8 +98,9 @@ public abstract class MixinInGameHud {
private int moveAir(int oldY) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
return scaledWidth - oldY - 9;
} else {
return oldY;
}
return oldY;
}
}

View File

@ -49,8 +49,7 @@ public abstract class MixinCraftingScreenHandler extends AbstractRecipeScreenHan
@Redirect(method = "quickMove", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/CraftingScreenHandler;insertItem(Lnet/minecraft/item/ItemStack;IIZ)Z", ordinal = 1))
private boolean noShiftClickMoveIntoCraftingTable(CraftingScreenHandler instance, ItemStack itemStack, int startIndex, int endIndex, boolean fromLast) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) return false;
return this.insertItem(itemStack, startIndex, endIndex, fromLast);
return ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_14_4) && this.insertItem(itemStack, startIndex, endIndex, fromLast);
}
@Inject(method = "onContentChanged", at = @At("HEAD"))

View File

@ -50,7 +50,7 @@ public abstract class MixinPlayerScreenHandler extends AbstractRecipeScreenHandl
}
@Inject(method = "onContentChanged", at = @At("HEAD"))
public void clientSideCrafting(Inventory inventory, CallbackInfo ci) {
private void clientSideCrafting(Inventory inventory, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
Recipes1_11_2.setCraftingResultSlot(syncId, this, craftingInput);
}
@ -60,9 +60,7 @@ public abstract class MixinPlayerScreenHandler extends AbstractRecipeScreenHandl
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/screen/PlayerScreenHandler$2;<init>(Lnet/minecraft/screen/PlayerScreenHandler;Lnet/minecraft/inventory/Inventory;IIILnet/minecraft/entity/player/PlayerEntity;)V")),
at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/PlayerScreenHandler;addSlot(Lnet/minecraft/screen/slot/Slot;)Lnet/minecraft/screen/slot/Slot;", ordinal = 0))
private Slot removeOffhandSlot(PlayerScreenHandler screenHandler, Slot slot) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8))
return null;
return addSlot(slot);
return ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8) ? null : addSlot(slot);
}
}

View File

@ -43,9 +43,9 @@ public abstract class MixinEntityTracker1_9 {
private Object remapNaNToZero(Metadata instance) {
if (instance.getValue() instanceof Float && ((Float) instance.getValue()).isNaN()) {
return 0F;
} else {
return instance.getValue();
}
return instance.getValue();
}
}

View File

@ -32,11 +32,7 @@ public abstract class MixinConfig {
@Redirect(method = "loadConfig(Ljava/io/File;Ljava/net/URL;)Ljava/util/Map;", at = @At(value = "INVOKE", target = "Ljava/util/Map;containsKey(Ljava/lang/Object;)Z"))
private boolean allowConfigPatching(final Map<String, Object> map, final Object key) {
if (((Object) this) instanceof ConfigPatcher) {
return true;
}
return map.containsKey(key);
return ((Object) this) instanceof ConfigPatcher || map.containsKey(key);
}
}