mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-02 08:59:31 +01:00
Added support for configuration state to ProtocolHack#createFakerUserConnection and implemented proper logging to Translator utils
This commit is contained in:
parent
e887116078
commit
9a26ac9782
@ -39,6 +39,26 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/*
|
||||
PORTING TO 1.20.2
|
||||
|
||||
- ClientPacketListener#handleAddObjective, new if added that could break behavior?
|
||||
- Same for handleSetScore
|
||||
- ClientHandshakePacketListenerImpl#handleGameProfile now sends brand payload and clientInformation packet.
|
||||
- NBT: "ActiveEffects" is now called "active_effects" and also does not use IDs anymore but names
|
||||
- Riding / Entity hitboxes have changed completely again
|
||||
- Player#getMyRidingOffset default value: -0.35 -> -0.6
|
||||
- AbstractMinecart#getPassengerAttachmentPoint() now no longer always returns 0 (I think we can just inject there?)
|
||||
- Boat attachnment points are completely different
|
||||
- Equipable#swapWithEquipmentSlot now has a swapWithEquipmentSlot check, looks important
|
||||
- NBT: "CustomPotionEffects" is now called "custom_potion_effects
|
||||
- ChorusFlowerBlock: has now a block-support-shape
|
||||
- DaylightDetector#use constant from 4 -> 2 ???? No idea what MS is doing there
|
||||
- PinkPetalsBlock: has no constant shape anymore, but is based on property (ka if this is important, you have to see, depending on how Via remapped this state)
|
||||
- PitcherCrop Shape calculation has changed
|
||||
- RepeaterBlock#updateShape now handles conditions that are also present clientside (do some blocks, not sure if this whole updateShape system is so important for us / that is detectable)
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO | General
|
||||
* - Check if relevant for protocol translation: TakeItemEntityPacket isEmpty case (1.20 -> 1.20.1 change)
|
||||
|
@ -25,6 +25,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.connection.UserConnectionImpl;
|
||||
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.base.event.ChangeProtocolVersionCallback;
|
||||
import de.florianmichael.viafabricplus.base.event.FinishViaVersionStartupCallback;
|
||||
@ -186,13 +187,24 @@ public class ProtocolHack {
|
||||
* @return Creates a Fake UserConnection class with a valid protocol pipeline to emulate packets
|
||||
*/
|
||||
public static UserConnection createFakerUserConnection() {
|
||||
final var current = getMainUserConnection();
|
||||
return createFakerUserConnection(getMainUserConnection().getChannel());
|
||||
}
|
||||
|
||||
final var userConnection = new UserConnectionImpl(current.getChannel(), true);
|
||||
userConnection.getProtocolInfo().setPipeline(new ProtocolPipelineImpl(userConnection));
|
||||
userConnection.put(new InventoryTracker1_16());
|
||||
/**
|
||||
* @param channel the current channel
|
||||
* @return Creates a Fake UserConnection class with a valid protocol pipeline to emulate packets
|
||||
*/
|
||||
public static UserConnection createFakerUserConnection(final Channel channel) {
|
||||
final var fake = new UserConnectionImpl(channel, true);
|
||||
fake.getProtocolInfo().setPipeline(new ProtocolPipelineImpl(fake));
|
||||
|
||||
return userConnection;
|
||||
fake.put(new InventoryTracker1_16());
|
||||
fake.put(new ConfigurationState());
|
||||
|
||||
//noinspection DataFlowIssue
|
||||
fake.get(ConfigurationState.class).setBridgePhase(ConfigurationState.BridgePhase.NONE);
|
||||
|
||||
return fake;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,8 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.connection.UserConnectionImpl;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
@ -36,7 +38,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BlockStateTranslator {
|
||||
private final static UserConnection DUMMY_USER_CONNECTION = new UserConnectionImpl(null, false);
|
||||
private final static UserConnection DUMMY_USER_CONNECTION = ProtocolHack.createFakerUserConnection(null);
|
||||
|
||||
public static int translateBlockState1_18(int oldId) {
|
||||
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(SharedConstants.getProtocolVersion(), ProtocolVersion.v1_18_2.getVersion());
|
||||
@ -53,7 +55,7 @@ public class BlockStateTranslator {
|
||||
wrapper.read(Type.POSITION1_14);
|
||||
return wrapper.read(Type.VAR_INT);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ViaFabricPlus.LOGGER.error("Failed to translate block state " + oldId + " to 1.18.2", e);
|
||||
}
|
||||
|
||||
return oldId;
|
||||
|
@ -24,11 +24,11 @@ import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.connection.UserConnectionImpl;
|
||||
import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.InventoryTracker;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.NetworkState;
|
||||
@ -45,10 +45,10 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemTranslator {
|
||||
private final static UserConnection DUMMY_USER_CONNECTION = new UserConnectionImpl(null, false);
|
||||
private final static UserConnection DUMMY_USER_CONNECTION = ProtocolHack.createFakerUserConnection(null);
|
||||
|
||||
public static Item MC_TO_VIA_LATEST_TO_TARGET(final ItemStack stack, final VersionEnum targetVersion) {
|
||||
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(SharedConstants.getProtocolVersion(), targetVersion.getVersion());
|
||||
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(ViaFabricPlus.NATIVE_VERSION.getVersion(), targetVersion.getVersion());
|
||||
if (protocolPath == null) return null;
|
||||
|
||||
final var dummyPacket = new CreativeInventoryActionC2SPacket(36, stack);
|
||||
@ -68,15 +68,16 @@ public class ItemTranslator {
|
||||
return wrapper.read(Type.ITEM);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ViaFabricPlus.LOGGER.error("Failed to translate item", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack VIA_TO_MC_B1_8_TO_LATEST(final Item item) {
|
||||
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(SharedConstants.getProtocolVersion(), VersionEnum.b1_8tob1_8_1.getVersion());
|
||||
final List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(ViaFabricPlus.NATIVE_VERSION.getVersion(), VersionEnum.b1_8tob1_8_1.getVersion());
|
||||
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 InventoryTracker());
|
||||
|
||||
@ -97,7 +98,8 @@ public class ItemTranslator {
|
||||
final var viaItem = wrapper.read(Type.FLAT_VAR_INT_ITEM);
|
||||
return new ItemStack(() -> Registries.ITEM.get(viaItem.identifier()), viaItem.amount());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
ViaFabricPlus.LOGGER.error("Failed to translate item", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user