Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Some cleanup
Dieser Commit ist enthalten in:
Ursprung
b5c718098d
Commit
182148dbe8
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_21to1_20_5.rewriter;
|
package com.viaversion.viaversion.protocols.protocol1_21to1_20_5.rewriter;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
||||||
@ -28,6 +30,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.Serverb
|
|||||||
import com.viaversion.viaversion.protocols.protocol1_21to1_20_5.Protocol1_21To1_20_5;
|
import com.viaversion.viaversion.protocols.protocol1_21to1_20_5.Protocol1_21To1_20_5;
|
||||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<ClientboundPacket1_20_5, ServerboundPacket1_20_5, Protocol1_21To1_20_5> {
|
public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<ClientboundPacket1_20_5, ServerboundPacket1_20_5, Protocol1_21To1_20_5> {
|
||||||
|
|
||||||
|
@ -47,24 +47,18 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
|
|||||||
registerMetadataRewriter(ClientboundPackets1_20_5.ENTITY_METADATA, Types1_20_5.METADATA_LIST, Types1_21.METADATA_LIST);
|
registerMetadataRewriter(ClientboundPackets1_20_5.ENTITY_METADATA, Types1_20_5.METADATA_LIST, Types1_21.METADATA_LIST);
|
||||||
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
|
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, wrapper -> {
|
||||||
@Override
|
final String type = Key.stripMinecraftNamespace(wrapper.passthrough(Type.STRING));
|
||||||
protected void register() {
|
final RegistryEntry[] entries = wrapper.passthrough(Type.REGISTRY_ENTRY_ARRAY);
|
||||||
map(Type.STRING); // Registry
|
if (Key.stripMinecraftNamespace(type).equals("damage_type")) {
|
||||||
map(Type.REGISTRY_ENTRY_ARRAY); // Data
|
// Add required damage type
|
||||||
handler(registryDataHandler1_20_5());
|
final CompoundTag campfireDamageType = new CompoundTag();
|
||||||
handler(wrapper -> {
|
campfireDamageType.putString("scaling", "when_caused_by_living_non_player");
|
||||||
// Add required damage type
|
campfireDamageType.putString("message_id", "inFire");
|
||||||
final String type = wrapper.get(Type.STRING, 0);
|
campfireDamageType.putFloat("exhaustion", 0.1F);
|
||||||
final RegistryEntry[] entries = wrapper.get(Type.REGISTRY_ENTRY_ARRAY, 0);
|
wrapper.set(Type.REGISTRY_ENTRY_ARRAY, 0, addRegistryEnties(entries, new RegistryEntry("minecraft:campfire", campfireDamageType)));
|
||||||
if (Key.stripMinecraftNamespace(type).equals("damage_type")) {
|
} else {
|
||||||
final CompoundTag campfireDamageType = new CompoundTag();
|
handleRegistryData1_20_5(wrapper.user(), type, entries);
|
||||||
campfireDamageType.putString("scaling", "when_caused_by_living_non_player");
|
|
||||||
campfireDamageType.putString("message_id", "inFire");
|
|
||||||
campfireDamageType.putFloat("exhaustion", 0.1F);
|
|
||||||
wrapper.set(Type.REGISTRY_ENTRY_ARRAY, 0, addRegistryEnties(entries, new RegistryEntry("minecraft:campfire", campfireDamageType)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -115,13 +109,10 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_5.RESPAWN, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundPackets1_20_5.RESPAWN, wrapper -> {
|
||||||
@Override
|
final int dimensionId = wrapper.passthrough(Type.VAR_INT);
|
||||||
public void register() {
|
final String world = wrapper.passthrough(Type.STRING);
|
||||||
map(Type.VAR_INT); // Dimension
|
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); // Tracks world height and name for chunk data and entity (un)tracking
|
||||||
map(Type.STRING); // World
|
|
||||||
handler(worldDataTrackerHandlerByKey1_20_5(0)); // Tracks world height and name for chunk data and entity (un)tracking
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,27 +446,32 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
|
|
||||||
public PacketHandler worldDataTrackerHandlerByKey1_20_5(final int dimensionIdIndex) {
|
public PacketHandler worldDataTrackerHandlerByKey1_20_5(final int dimensionIdIndex) {
|
||||||
return wrapper -> {
|
return wrapper -> {
|
||||||
EntityTracker tracker = tracker(wrapper.user());
|
|
||||||
int dimensionId = wrapper.get(Types.VAR_INT, dimensionIdIndex);
|
int dimensionId = wrapper.get(Types.VAR_INT, dimensionIdIndex);
|
||||||
DimensionData dimensionData = tracker.dimensionData(dimensionId);
|
|
||||||
if (dimensionData == null) {
|
|
||||||
protocol.getLogger().severe("Dimension data missing for dimension: " + dimensionId + ", falling back to overworld");
|
|
||||||
dimensionData = tracker.dimensionData("minecraft:overworld");
|
|
||||||
Preconditions.checkNotNull(dimensionData, "Overworld data missing");
|
|
||||||
}
|
|
||||||
|
|
||||||
tracker.setCurrentWorldSectionHeight(dimensionData.height() >> 4);
|
|
||||||
tracker.setCurrentMinY(dimensionData.minY());
|
|
||||||
|
|
||||||
String world = wrapper.get(Types.STRING, 0);
|
String world = wrapper.get(Types.STRING, 0);
|
||||||
if (tracker.currentWorld() != null && !tracker.currentWorld().equals(world)) {
|
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world);
|
||||||
tracker.clearEntities();
|
|
||||||
tracker.trackClientEntity();
|
|
||||||
}
|
|
||||||
tracker.setCurrentWorld(world);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void trackWorldDataByKey1_20_5(final UserConnection connection, final int dimensionId, final String world) {
|
||||||
|
// Track world height for use in chunk data
|
||||||
|
EntityTracker tracker = tracker(connection);
|
||||||
|
DimensionData dimensionData = tracker.dimensionData(dimensionId);
|
||||||
|
if (dimensionData == null) {
|
||||||
|
protocol.getLogger().severe("Dimension data missing for dimension: " + dimensionId + ", falling back to overworld");
|
||||||
|
dimensionData = tracker.dimensionData("overworld");
|
||||||
|
Preconditions.checkNotNull(dimensionData, "Overworld data missing");
|
||||||
|
}
|
||||||
|
tracker.setCurrentWorldSectionHeight(dimensionData.height() >> 4);
|
||||||
|
tracker.setCurrentMinY(dimensionData.minY());
|
||||||
|
|
||||||
|
// Clear entities if the world changes
|
||||||
|
if (tracker.currentWorld() != null && !tracker.currentWorld().equals(world)) {
|
||||||
|
tracker.clearEntities();
|
||||||
|
tracker.trackClientEntity();
|
||||||
|
}
|
||||||
|
tracker.setCurrentWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
public PacketHandler biomeSizeTracker() {
|
public PacketHandler biomeSizeTracker() {
|
||||||
return wrapper -> trackBiomeSize(wrapper.user(), wrapper.get(Types.NAMED_COMPOUND_TAG, 0));
|
return wrapper -> trackBiomeSize(wrapper.user(), wrapper.get(Types.NAMED_COMPOUND_TAG, 0));
|
||||||
}
|
}
|
||||||
@ -503,22 +508,17 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
tracker(connection).setDimensions(dimensionDataMap);
|
tracker(connection).setDimensions(dimensionDataMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketHandler registryDataHandler1_20_5() {
|
public void handleRegistryData1_20_5(final UserConnection connection, final String registryKey, final RegistryEntry[] entries) {
|
||||||
return wrapper -> {
|
if (registryKey.equals("worldgen/biome")) {
|
||||||
final String registryKey = Key.stripMinecraftNamespace(wrapper.get(Types.STRING, 0));
|
tracker(connection).setBiomesSent(entries.length);
|
||||||
if (registryKey.equals("worldgen/biome")) {
|
} else if (registryKey.equals("dimension_type")) {
|
||||||
final RegistryEntry[] entries = wrapper.get(Types.REGISTRY_ENTRY_ARRAY, 0);
|
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(entries.length);
|
||||||
tracker(wrapper.user()).setBiomesSent(entries.length);
|
for (int i = 0; i < entries.length; i++) {
|
||||||
} else if (registryKey.equals("dimension_type")) {
|
final RegistryEntry entry = entries[i];
|
||||||
final RegistryEntry[] entries = wrapper.get(Types.REGISTRY_ENTRY_ARRAY, 0);
|
dimensionDataMap.put(Key.stripMinecraftNamespace(entry.key()), new DimensionDataImpl(i, (CompoundTag) entry.tag()));
|
||||||
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(entries.length);
|
|
||||||
for (int i = 0; i < entries.length; i++) {
|
|
||||||
final RegistryEntry entry = entries[i];
|
|
||||||
dimensionDataMap.put(Key.stripMinecraftNamespace(entry.key()), new DimensionDataImpl(i, (CompoundTag) entry.tag()));
|
|
||||||
}
|
|
||||||
tracker(wrapper.user()).setDimensions(dimensionDataMap);
|
|
||||||
}
|
}
|
||||||
};
|
tracker(connection).setDimensions(dimensionDataMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.template.protocols.rewriter;
|
package com.viaversion.viaversion.template.protocols.rewriter;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||||
@ -27,6 +28,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPac
|
|||||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
|
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import com.viaversion.viaversion.template.protocols.Protocol1_99To_98;
|
import com.viaversion.viaversion.template.protocols.Protocol1_99To_98;
|
||||||
|
import com.viaversion.viaversion.util.Key;
|
||||||
|
|
||||||
// Replace if needed
|
// Replace if needed
|
||||||
// Types1_OLD
|
// Types1_OLD
|
||||||
@ -44,13 +46,10 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
|
|||||||
registerSetEntityData(ClientboundPackets1_20_5.SET_ENTITY_DATA, /*Types1_OLD_ENTITY_DATA_LIST, */Types1_20_5.ENTITY_DATA_LIST); // Specify old and new entity data list if changed
|
registerSetEntityData(ClientboundPackets1_20_5.SET_ENTITY_DATA, /*Types1_OLD_ENTITY_DATA_LIST, */Types1_20_5.ENTITY_DATA_LIST); // Specify old and new entity data list if changed
|
||||||
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
|
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, wrapper -> {
|
||||||
@Override
|
final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
|
||||||
protected void register() {
|
final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY);
|
||||||
map(Types.STRING); // Registry
|
handleRegistryData1_20_5(wrapper.user(), registryKey, entries); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data
|
||||||
map(Types.REGISTRY_ENTRY_ARRAY); // Data
|
|
||||||
handler(registryDataHandler1_20_5()); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_5.LOGIN, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundPackets1_20_5.LOGIN, new PacketHandlers() {
|
||||||
@ -72,13 +71,10 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_5.RESPAWN, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundPackets1_20_5.RESPAWN, wrapper -> {
|
||||||
@Override
|
final int dimensionId = wrapper.passthrough(Types.VAR_INT);
|
||||||
public void register() {
|
final String world = wrapper.passthrough(Types.STRING);
|
||||||
map(Types.VAR_INT); // Dimension
|
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); // Tracks world height and name for chunk data and entity (un)tracking
|
||||||
map(Types.STRING); // World
|
|
||||||
handler(worldDataTrackerHandlerByKey1_20_5(0)); // Tracks world height and name for chunk data and entity (un)tracking
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren