Skip to content

Commit

Permalink
Updated Via API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Oct 20, 2023
1 parent 2537ef5 commit 4d1e1b9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.ClientPlayerInteractionManager1_18_2;
import net.minecraft.client.network.SequencedPacketCreator;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.ClientPlayerInteractionManager1_18_2;
import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity;
import de.florianmichael.viafabricplus.injection.access.IScreenHandler;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
Expand All @@ -37,16 +33,20 @@
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.client.network.SequencedPacketCreator;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -135,7 +135,7 @@ else if (clickSlot.getSlot() < 0 || clickSlot.getSlot() >= viafabricplus_oldItem
clickSlotPacket.write(Type.BYTE, (byte) clickSlot.getButton());
clickSlotPacket.write(Type.SHORT, ((IScreenHandler) client.player.currentScreenHandler).viafabricplus_getAndIncrementLastActionId());
clickSlotPacket.write(Type.VAR_INT, clickSlot.getActionType().ordinal());
clickSlotPacket.write(Type.FLAT_VAR_INT_ITEM, ItemTranslator.MC_TO_VIA_LATEST_TO_TARGET(slotItemBeforeModification, VersionEnum.r1_16));
clickSlotPacket.write(Type.ITEM1_13_2, ItemTranslator.MC_TO_VIA_LATEST_TO_TARGET(slotItemBeforeModification, VersionEnum.r1_16));

try {
clickSlotPacket.sendToServer(Protocol1_17To1_16_4.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MixinProtocol1_9_1To1_9 extends AbstractProtocol<ClientboundPackets
@Inject(method = "registerPackets", at = @At("RETURN"))
public void clearInputBuffer(CallbackInfo ci) {
registerClientbound(ClientboundPackets1_9.CHUNK_DATA, wrapper -> {
wrapper.passthrough(new ChunkType1_9_1(wrapper.user().get(ClientWorld.class)));
wrapper.passthrough(ChunkType1_9_1.forEnvironment(wrapper.user().get(ClientWorld.class).getEnvironment()));
wrapper.clearInputBuffer();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Chunk deserialize(int chunkX, int chunkZ, boolean fullChunk, boole
return null;
}

@Redirect(method = "read(Lio/netty/buffer/ByteBuf;Lcom/viaversion/viaversion/api/minecraft/ClientWorld;)Lcom/viaversion/viaversion/api/minecraft/chunks/Chunk;", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/type/types/chunk/ChunkType1_8;deserialize(IIZZI[B)Lcom/viaversion/viaversion/api/minecraft/chunks/Chunk;"))
@Redirect(method = "read(Lio/netty/buffer/ByteBuf;)Lcom/viaversion/viaversion/api/minecraft/chunks/Chunk;", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/type/types/chunk/ChunkType1_8;deserialize(IIZZI[B)Lcom/viaversion/viaversion/api/minecraft/chunks/Chunk;"))
private Chunk fixAegis(int chunkX, int chunkZ, boolean fullChunk, boolean skyLight, int bitmask, byte[] data) {
try {
return deserialize(chunkX, chunkZ, fullChunk, skyLight, bitmask, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static Item MC_TO_VIA_LATEST_TO_TARGET(final ItemStack stack, final Versi
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.b1_8tob1_8_1)) {
return wrapper.read(Typesb1_8_0_1.CREATIVE_ITEM);
} else {
return wrapper.read(Type.ITEM);
return wrapper.read(Type.ITEM1_8);
}
} catch (Exception e) {
ViaFabricPlus.LOGGER.error("Failed to translate item", e);
Expand All @@ -78,7 +78,7 @@ public static ItemStack VIA_TO_MC_B1_8_TO_LATEST(final Item item) {
if (protocolPath == null) return null;

// Make sure that ViaVersion doesn't track stuff and change its behaviour
DUMMY_USER_CONNECTION.put(new WindowTracker(DUMMY_USER_CONNECTION));
DUMMY_USER_CONNECTION.put(new WindowTracker());
DUMMY_USER_CONNECTION.put(new InventoryTracker());

try {
Expand All @@ -95,7 +95,7 @@ public static ItemStack VIA_TO_MC_B1_8_TO_LATEST(final Item item) {
wrapper.read(Type.VAR_INT);
wrapper.read(Type.SHORT);

final var viaItem = wrapper.read(Type.FLAT_VAR_INT_ITEM);
final var viaItem = wrapper.read(Type.ITEM1_13_2);
return new ItemStack(() -> Registries.ITEM.get(viaItem.identifier()), viaItem.amount());
} catch (Exception e) {
ViaFabricPlus.LOGGER.error("Failed to translate item", e);
Expand Down

0 comments on commit 4d1e1b9

Please sign in to comment.