fixed bad packets in Anvil screen

This commit is contained in:
FlorianMichael 2023-06-03 17:17:29 +02:00
parent 7546c8812f
commit 4d82c14282
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 65 additions and 6 deletions

View File

@ -175,16 +175,18 @@ public abstract class MixinEntity {
@Inject(method = "getPosWithYOffset", at = @At("HEAD"), cancellable = true)
public void changeLogic(float offset, CallbackInfoReturnable<BlockPos> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4)) {
final BlockPos blockPos = new BlockPos(MathHelper.floor(this.pos.x), MathHelper.floor(this.pos.y - (double)offset), MathHelper.floor(this.pos.z));
int i = MathHelper.floor(this.pos.x);
int j = MathHelper.floor(this.pos.y - (double)offset);
int k = MathHelper.floor(this.pos.z);
BlockPos blockPos = new BlockPos(i, j, k);
if (this.world.getBlockState(blockPos).isAir()) {
final BlockPos downBlockPos = blockPos.down();
BlockState blockState = this.world.getBlockState(downBlockPos);
BlockPos blockPos2 = blockPos.down();
BlockState blockState = this.world.getBlockState(blockPos2);
if (blockState.isIn(BlockTags.FENCES) || blockState.isIn(BlockTags.WALLS) || blockState.getBlock() instanceof FenceGateBlock) {
cir.setReturnValue(downBlockPos);
cir.setReturnValue(blockPos2);
}
}
cir.setReturnValue(blockPos);
}
}

View File

@ -0,0 +1,56 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD 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.fixes.minecraft.screen;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.gui.screen.ingame.AnvilScreen;
import net.minecraft.client.gui.screen.ingame.ForgingScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.packet.c2s.play.RenameItemC2SPacket;
import net.minecraft.screen.AnvilScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.raphimc.vialoader.util.VersionEnum;
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(AnvilScreen.class)
public abstract class MixinAnvilScreen extends ForgingScreen<AnvilScreenHandler> {
public MixinAnvilScreen(AnvilScreenHandler handler, PlayerInventory playerInventory, Text title, Identifier texture) {
super(handler, playerInventory, title, texture);
}
@Inject(method = "onRenamed", at = @At("HEAD"), cancellable = true)
public void changePacketLogic(String name, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4) && !name.isEmpty()) {
String string = name;
Slot slot = this.handler.getSlot(0);
if (slot != null && slot.hasStack() && !slot.getStack().hasCustomName() && name.equals(slot.getStack().getName().getString())) {
string = "";
}
this.handler.setNewItemName(string);
this.client.player.networkHandler.sendPacket(new RenameItemC2SPacket(string));
ci.cancel();
}
}
}

View File

@ -106,6 +106,7 @@
"fixes.minecraft.packet.MixinChatMessageC2SPacket",
"fixes.minecraft.packet.MixinPacketByteBuf",
"fixes.minecraft.packet.MixinUpdatePlayerAbilitiesC2SPacket",
"fixes.minecraft.screen.MixinAnvilScreen",
"fixes.minecraft.screen.MixinChatHud",
"fixes.minecraft.screen.MixinChatScreen",
"fixes.minecraft.screen.MixinCommandBlockScreen",