Skip to content

Commit

Permalink
Added and fixed tons of clientside fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Nov 26, 2023
1 parent 3cd08a8 commit a4794e3
Show file tree
Hide file tree
Showing 129 changed files with 7,135 additions and 1,488 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ dependencies {

// Lenni0451 Libraries
jij "net.lenni0451:Reflect:${project.reflect_version}"
jij("net.lenni0451:MCPing:${project.mcping_version}") {
exclude group: "com.google.code.gson", module: "gson"
}

// Misc Libraries
jij("org.cloudburstmc.netty:netty-transport-raknet:${project.raknet_transport_version}") {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ raknet_transport_version=1.0.0.CR1-SNAPSHOT

# Lenni0451 Libraries
reflect_version=1.3.0
mcping_version=1.3.0

# Misc Libraries
mod_menu_version=8.0.0
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
package de.florianmichael.viafabricplus;

import de.florianmichael.viafabricplus.event.PostGameLoadCallback;
import de.florianmichael.viafabricplus.event.LoadCallback;
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.util.ClassLoaderPriorityUtil;
import de.florianmichael.viafabricplus.save.SaveManager;
import de.florianmichael.viafabricplus.settings.SettingsManager;
import de.florianmichael.viafabricplus.util.ClassLoaderPriorityUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -38,21 +37,24 @@
* - Window interactions in <= 1.16.5 has changed and can be detected by the server
* - Most CTS protocol features aren't supported (see https://github.com/ViaVersion/ViaFabricPlus/issues/181)
* - Most CPE features aren't implemented correctly (see https://github.com/ViaVersion/ViaFabricPlus/issues/152)
* - Bedrock scaffolding should be added as soon as ViaBedrock supports block placement (see https://github.com/ViaVersion/ViaFabricPlus/issues/204)
* - Check if MixinPlayerScreenHandler.injectTransferSlot is needed? Check git log
*
* TODO | Movement
* - X/Z Face based jump movement in <= 1.13.2 is broken (https://github.com/ViaVersion/ViaFabricPlus/issues/189)
* - Collision hit boxes has been changed (https://github.com/ViaVersion/ViaFabricPlus/issues/195)
* - Blit-jump is not supported in <= 1.8.9 (https://github.com/ViaVersion/ViaFabricPlus/issues/225)
*
* TODO | Migration v3
* - Rename all methods
* - Use ViaProxy config patch for some clientside fixes options (Remove ViaFabricPlusVLViaConfig and MixinViaLegacyConfig)
* - Fix auto detect to not be a huge mess
* - Add setting for VFP AlphaInventoryProvider
* - Fix MixinAbstractDonkeyEntity
* - Boats are probably broken. Check entity height offset fix
* - Check TO DO in MixinEntity
* - Diff ItemRegistryDiff from projects and add missing items
* - Fix MixinMultiplayerServerListWidget_ServerEntry
* - Test villagers
* - Test offhand
* - Check if attack cooldown is there or not
* - Test very large 1.8 chests
* - Test block ack
*/
public class ViaFabricPlus {
private static final ViaFabricPlus instance = new ViaFabricPlus();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.fixes;

import net.minecraft.util.ActionResult;

public class ActionResultException extends RuntimeException {

private final ActionResult actionResult;

public ActionResultException(final ActionResult actionResult) {
this.actionResult = actionResult;
}

public ActionResult getActionResult() {
return this.actionResult;
}

@Override
public synchronized Throwable fillInStackTrace() {
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.fixes;

import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;

public class ArmorUpdateListener {

public static void init() {
ClientTickEvents.START_WORLD_TICK.register(world -> {
if (MinecraftClient.getInstance().player != null) {
try {
sendArmorUpdate();
} catch (Throwable t) {
ViaFabricPlus.global().getLogger().error("Error sending armor update", t);
}
}
});
}

public static void sendArmorUpdate() throws Exception {
int armor = 0;
for (final ItemStack stack : MinecraftClient.getInstance().player.getInventory().armor) {
armor += ArmorType.findByType(Registries.ITEM.getId(stack.getItem()).toString()).getArmorPoints();
}
if (armor == this.oldArmor) return;

this.oldArmor = armor;
final PacketWrapper properties = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, MinecraftClient.getInstance().getNetworkHandler().getConnection().getUserConnection());
properties.write(Type.VAR_INT, MinecraftClient.getInstance().player.getId());
properties.write(Type.INT, 1);
properties.write(Type.STRING, "generic.armor");
properties.write(Type.DOUBLE, 0D);
properties.write(Type.VAR_INT, 1);
properties.write(Type.UUID, ARMOR_POINTS_UUID);
properties.write(Type.DOUBLE, (double) armor);
properties.write(Type.BYTE, (byte) 0);
properties.scheduleSend(Protocol1_9To1_8.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.fixes;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;

import java.util.function.Consumer;

public class ChestHandler1_13_2 {

public static final Consumer<PacketByteBuf> OLD_PACKET_HANDLER = data -> {
final MinecraftClient mc = MinecraftClient.getInstance();

try {
final int windowId = data.readUnsignedByte();
final int slots = data.readUnsignedByte();
final Text title = data.readText();

final GenericContainerScreenHandler screenHandler = new GenericContainerScreenHandler(null, windowId, mc.player.getInventory(), new SimpleInventory(slots), MathHelper.ceil(slots / 9F));
mc.player.currentScreenHandler = screenHandler;
mc.setScreen(new GenericContainerScreen(screenHandler, mc.player.getInventory(), title));
} catch (Throwable t) {
throw new RuntimeException("Failed to handle OpenWindow packet data", t);
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocolhack.util.BlockStateTranslator;
import de.florianmichael.viafabricplus.protocolhack.translator.BlockStateTranslator;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -33,62 +33,62 @@
import net.minecraft.util.math.Vec2f;
import net.raphimc.vialoader.util.VersionEnum;

import java.util.Objects;
import java.util.function.Consumer;

public class ClientPlayerInteractionManager1_18_2 {

public static final Consumer<PacketByteBuf> OLD_PACKET_HANDLER = data -> {
try {
final var pos = data.readBlockPos();
final var blockState = Block.STATE_IDS.get(BlockStateTranslator.translateBlockState1_18(data.readVarInt()));
final var blockState = BlockStateTranslator.via1_18_2toMc(data.readVarInt());
final var action = data.readEnumConstant(PlayerActionC2SPacket.Action.class);
final var allGood = data.readBoolean();

ClientPlayerInteractionManager1_18_2.handleBlockBreakAck(pos, blockState, action, allGood);
} catch (Exception e) {
ViaFabricPlus.global().getLogger().error("Failed to read BlockBreakAck packet data", e);
} catch (Throwable t) {
throw new RuntimeException("Failed to handle BlockBreakAck packet data", t);
}
};

private static final Object2ObjectLinkedOpenHashMap<Pair<BlockPos, PlayerActionC2SPacket.Action>, PositionAndRotation> UN_ACKED_ACTIONS = new Object2ObjectLinkedOpenHashMap<>();
private static final Object2ObjectLinkedOpenHashMap<Pair<BlockPos, PlayerActionC2SPacket.Action>, PositionAndRotation> UNACKED_ACTIONS = new Object2ObjectLinkedOpenHashMap<>();

public static void trackBlockAction(final PlayerActionC2SPacket.Action action, final BlockPos blockPos) {
public static void trackPlayerAction(final PlayerActionC2SPacket.Action action, final BlockPos blockPos) {
final var player = MinecraftClient.getInstance().player;
if (player == null) return;

var rotation = new Vec2f(player.getYaw(), player.getPitch());
if (ProtocolHack.getTargetVersion().isNewerThan(VersionEnum.r1_16_2)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_1)) {
rotation = null;
}
UN_ACKED_ACTIONS.put(new Pair<>(blockPos, action), new PositionAndRotation(player.getPos().x, player.getPos().y, player.getPos().z, rotation));
UNACKED_ACTIONS.put(new Pair<>(blockPos, action), new PositionAndRotation(player.getPos().x, player.getPos().y, player.getPos().z, rotation));
}

public static void handleBlockBreakAck(final BlockPos blockPos, final BlockState blockState, final PlayerActionC2SPacket.Action action, final boolean allGood) {
public static void handleBlockBreakAck(final BlockPos blockPos, final BlockState expectedState, final PlayerActionC2SPacket.Action action, final boolean allGood) {
final var player = MinecraftClient.getInstance().player;
if (player == null) return;
final var world = MinecraftClient.getInstance().getNetworkHandler().getWorld();

final var world = Objects.requireNonNull(MinecraftClient.getInstance().getNetworkHandler()).getWorld();

final var next = UN_ACKED_ACTIONS.remove(new Pair<>(blockPos, action));
final var blockStateFromPos = world.getBlockState(blockPos);
final var oldPlayerState = UNACKED_ACTIONS.remove(new Pair<>(blockPos, action));
final var actualState = world.getBlockState(blockPos);

if ((next == null || !allGood || action != PlayerActionC2SPacket.Action.START_DESTROY_BLOCK && blockStateFromPos != blockState) && blockStateFromPos != blockState) {
world.setBlockState(blockPos, blockState);
if (next != null && world == player.getWorld() && player.collidesWithStateAtPos(blockPos, blockState)) {
if (next.rotation != null) {
player.updatePositionAndAngles(next.x, next.y, next.z, next.rotation.x, next.rotation.y);
if ((oldPlayerState == null || !allGood || action != PlayerActionC2SPacket.Action.START_DESTROY_BLOCK && actualState != expectedState) && (actualState != expectedState || ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2))) {
world.setBlockState(blockPos, expectedState, Block.NOTIFY_ALL | Block.FORCE_STATE);
if (oldPlayerState != null && ((ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_1) || (world == player.getWorld() && player.collidesWithStateAtPos(blockPos, expectedState))))) {
if (oldPlayerState.rotation != null) {
player.updatePositionAndAngles(oldPlayerState.x, oldPlayerState.y, oldPlayerState.z, oldPlayerState.rotation.x, oldPlayerState.rotation.y);
} else {
player.updatePosition(next.x, next.y, next.z);
player.updatePosition(oldPlayerState.x, oldPlayerState.y, oldPlayerState.z);
}
}
}

while (UN_ACKED_ACTIONS.size() >= 50) {
ViaFabricPlus.global().getLogger().error("Too many unacked block actions, dropping {}", UN_ACKED_ACTIONS.firstKey());
UN_ACKED_ACTIONS.removeFirst();
while (UNACKED_ACTIONS.size() >= 50) {
ViaFabricPlus.global().getLogger().warn("Too many unacked block actions, dropping {}", UNACKED_ACTIONS.firstKey());
UNACKED_ACTIONS.removeFirst();
}
}

public record PositionAndRotation(double x, double y, double z, Vec2f rotation) {
}

}
Loading

0 comments on commit a4794e3

Please sign in to comment.