mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-12-25 17:18:04 +01:00
Cleaned up ItemTranslator base
This commit is contained in:
parent
884e05f3d6
commit
cd34aa7d7a
@ -135,7 +135,7 @@ public abstract class MixinClientPlayerInteractionManager {
|
|||||||
final byte button = (byte) clickSlot.getButton();
|
final byte button = (byte) clickSlot.getButton();
|
||||||
final short lastActionId = ((IScreenHandler) client.player.currentScreenHandler).viafabricplus_getAndIncrementLastActionId();
|
final short lastActionId = ((IScreenHandler) client.player.currentScreenHandler).viafabricplus_getAndIncrementLastActionId();
|
||||||
final int actionType = clickSlot.getActionType().ordinal();
|
final int actionType = clickSlot.getActionType().ordinal();
|
||||||
final Item item = ItemTranslator.minecraftToViaVersion(slotItemBeforeModification, VersionEnum.r1_16.getVersion());
|
final Item item = ItemTranslator.MC_TO_VIA_LATEST_TO_TARGET(slotItemBeforeModification, VersionEnum.r1_16);
|
||||||
|
|
||||||
userConnection.getChannel().eventLoop().submit(() -> {
|
userConnection.getChannel().eventLoop().submit(() -> {
|
||||||
final PacketWrapper clickSlotPacket = PacketWrapper.create(ServerboundPackets1_16_2.CLICK_WINDOW, userConnection);
|
final PacketWrapper clickSlotPacket = PacketWrapper.create(ServerboundPackets1_16_2.CLICK_WINDOW, userConnection);
|
||||||
|
@ -24,7 +24,6 @@ import net.minecraft.client.MinecraftClient;
|
|||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.AlphaInventoryProvider;
|
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.AlphaInventoryProvider;
|
||||||
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.types.Typesb1_8_0_1;
|
|
||||||
import net.raphimc.vialoader.util.VersionEnum;
|
import net.raphimc.vialoader.util.VersionEnum;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -45,7 +44,7 @@ public class ViaFabricPlusAlphaInventoryProvider extends AlphaInventoryProvider
|
|||||||
final var alphaItem = trackingItems.get(i);
|
final var alphaItem = trackingItems.get(i);
|
||||||
if (alphaItem.isEmpty()) continue;
|
if (alphaItem.isEmpty()) continue;
|
||||||
|
|
||||||
items[i] = ItemTranslator.minecraftToViaVersion(alphaItem, Typesb1_8_0_1.CREATIVE_ITEM, VersionEnum.b1_8tob1_8_1.getVersion());
|
items[i] = ItemTranslator.MC_TO_VIA_LATEST_TO_TARGET(alphaItem, VersionEnum.b1_8tob1_8_1);
|
||||||
}
|
}
|
||||||
return copyItems(items);
|
return copyItems(items);
|
||||||
}
|
}
|
||||||
@ -80,7 +79,7 @@ public class ViaFabricPlusAlphaInventoryProvider extends AlphaInventoryProvider
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToInventory(UserConnection user, Item item) {
|
public void addToInventory(UserConnection user, Item item) {
|
||||||
getPlayer().getInventory().insertStack(ItemTranslator.viaVersionToMinecraft(item, VersionEnum.b1_8tob1_8_1.getVersion()));
|
getPlayer().getInventory().insertStack(ItemTranslator.VIA_TO_MC_B1_8_TO_LATEST(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ClientPlayerEntity getPlayer() {
|
protected ClientPlayerEntity getPlayer() {
|
||||||
|
@ -32,6 +32,6 @@ public class ViaFabricPlusHandItemProvider extends HandItemProvider {
|
|||||||
if (lastUsedItem == null) {
|
if (lastUsedItem == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ItemTranslator.minecraftToViaVersion(lastUsedItem, VersionEnum.r1_8.getVersion());
|
return ItemTranslator.MC_TO_VIA_LATEST_TO_TARGET(lastUsedItem, VersionEnum.r1_8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,10 @@ import net.minecraft.network.PacketByteBuf;
|
|||||||
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
|
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.ClientboundPacketsb1_8;
|
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.ClientboundPacketsb1_8;
|
||||||
|
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.types.Typesb1_8_0_1;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
|
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.storage.WindowTracker;
|
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.storage.WindowTracker;
|
||||||
|
import net.raphimc.vialoader.util.VersionEnum;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -45,12 +47,8 @@ import java.util.stream.Collectors;
|
|||||||
public class ItemTranslator {
|
public class ItemTranslator {
|
||||||
private final static UserConnection DUMMY_USER_CONNECTION = new UserConnectionImpl(null, false);
|
private final static UserConnection DUMMY_USER_CONNECTION = new UserConnectionImpl(null, false);
|
||||||
|
|
||||||
public static Item minecraftToViaVersion(final ItemStack stack, final int targetVersion) {
|
public static Item MC_TO_VIA_LATEST_TO_TARGET(final ItemStack stack, final VersionEnum targetVersion) {
|
||||||
return minecraftToViaVersion(stack, Type.ITEM, targetVersion);
|
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(SharedConstants.getProtocolVersion(), targetVersion.getVersion());
|
||||||
}
|
|
||||||
|
|
||||||
public static Item minecraftToViaVersion(final ItemStack stack, final Type<Item> item, final int targetVersion) {
|
|
||||||
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(SharedConstants.getProtocolVersion(), targetVersion);
|
|
||||||
if (protocolPath == null) return null;
|
if (protocolPath == null) return null;
|
||||||
|
|
||||||
final var dummyPacket = new CreativeInventoryActionC2SPacket(36, stack);
|
final var dummyPacket = new CreativeInventoryActionC2SPacket(36, stack);
|
||||||
@ -64,15 +62,19 @@ public class ItemTranslator {
|
|||||||
wrapper.apply(Direction.SERVERBOUND, State.PLAY, 0, protocolPath.stream().map(ProtocolPathEntry::protocol).collect(Collectors.toList()));
|
wrapper.apply(Direction.SERVERBOUND, State.PLAY, 0, protocolPath.stream().map(ProtocolPathEntry::protocol).collect(Collectors.toList()));
|
||||||
|
|
||||||
wrapper.read(Type.SHORT);
|
wrapper.read(Type.SHORT);
|
||||||
return wrapper.read(item);
|
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.b1_8tob1_8_1)) {
|
||||||
|
return wrapper.read(Typesb1_8_0_1.CREATIVE_ITEM);
|
||||||
|
} else {
|
||||||
|
return wrapper.read(Type.ITEM);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack viaVersionToMinecraft(final Item item, final int targetVersion) {
|
public static ItemStack VIA_TO_MC_B1_8_TO_LATEST(final Item item) {
|
||||||
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(SharedConstants.getProtocolVersion(), targetVersion);
|
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(SharedConstants.getProtocolVersion(), VersionEnum.b1_8tob1_8_1.getVersion());
|
||||||
if (protocolPath == null) return null;
|
if (protocolPath == null) return null;
|
||||||
|
|
||||||
DUMMY_USER_CONNECTION.put(new WindowTracker(DUMMY_USER_CONNECTION));
|
DUMMY_USER_CONNECTION.put(new WindowTracker(DUMMY_USER_CONNECTION));
|
||||||
|
Loading…
Reference in New Issue
Block a user