mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-22 11:56:21 +01:00
fixed bad packets in Anvil screen
This commit is contained in:
parent
7546c8812f
commit
4d82c14282
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user