Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 00:00:28 +01:00
Small cleanup
Dieser Commit ist enthalten in:
Ursprung
c13b40a373
Commit
f914d57678
@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.template;
|
package com.viaversion.viaversion.protocols.template;
|
||||||
|
|
||||||
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.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
@ -26,7 +25,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfi
|
|||||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
|
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
|
||||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
|
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import com.viaversion.viaversion.util.Key;
|
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
|
||||||
|
|
||||||
// Replace if needed
|
// Replace if needed
|
||||||
// Types1_OLD
|
// Types1_OLD
|
||||||
@ -44,11 +43,8 @@ final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_2
|
|||||||
registerSetEntityData(ClientboundPackets1_21.SET_ENTITY_DATA, /*Types1_OLD_ENTITY_DATA_LIST, */Types1_21.ENTITY_DATA_LIST); // Specify old and new entity data list if changed
|
registerSetEntityData(ClientboundPackets1_21.SET_ENTITY_DATA, /*Types1_OLD_ENTITY_DATA_LIST, */Types1_21.ENTITY_DATA_LIST); // Specify old and new entity data list if changed
|
||||||
registerRemoveEntities(ClientboundPackets1_21.REMOVE_ENTITIES);
|
registerRemoveEntities(ClientboundPackets1_21.REMOVE_ENTITIES);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> {
|
final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol);
|
||||||
final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
|
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle);
|
||||||
final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY);
|
|
||||||
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
|
|
||||||
});
|
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_21.LOGIN, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_21.LOGIN, wrapper -> {
|
||||||
final int entityId = wrapper.passthrough(Types.INT); // Entity id
|
final int entityId = wrapper.passthrough(Types.INT); // Entity id
|
||||||
|
@ -40,8 +40,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5;
|
|||||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage;
|
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage;
|
||||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.OnGroundTracker;
|
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.OnGroundTracker;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import com.viaversion.viaversion.util.ArrayUtil;
|
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
|
||||||
import com.viaversion.viaversion.util.Key;
|
|
||||||
|
|
||||||
public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPacket1_20_5, Protocol1_20_5To1_21> {
|
public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPacket1_20_5, Protocol1_20_5To1_21> {
|
||||||
|
|
||||||
@ -55,20 +54,13 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
|
|||||||
registerSetEntityData(ClientboundPackets1_20_5.SET_ENTITY_DATA, Types1_20_5.ENTITY_DATA_LIST, Types1_21.ENTITY_DATA_LIST);
|
registerSetEntityData(ClientboundPackets1_20_5.SET_ENTITY_DATA, Types1_20_5.ENTITY_DATA_LIST, Types1_21.ENTITY_DATA_LIST);
|
||||||
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
|
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, wrapper -> {
|
final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol);
|
||||||
final String type = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
|
final CompoundTag campfireDamageType = new CompoundTag();
|
||||||
final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY);
|
campfireDamageType.putString("scaling", "when_caused_by_living_non_player");
|
||||||
if (type.equals("damage_type")) {
|
campfireDamageType.putString("message_id", "inFire");
|
||||||
// Add required damage type
|
campfireDamageType.putFloat("exhaustion", 0.1F);
|
||||||
final CompoundTag campfireDamageType = new CompoundTag();
|
registryDataRewriter.addEntries("damage_type", new RegistryEntry("minecraft:campfire", campfireDamageType));
|
||||||
campfireDamageType.putString("scaling", "when_caused_by_living_non_player");
|
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, registryDataRewriter::handle);
|
||||||
campfireDamageType.putString("message_id", "inFire");
|
|
||||||
campfireDamageType.putFloat("exhaustion", 0.1F);
|
|
||||||
wrapper.set(Types.REGISTRY_ENTRY_ARRAY, 0, ArrayUtil.add(entries, new RegistryEntry("minecraft:campfire", campfireDamageType)));
|
|
||||||
} else {
|
|
||||||
handleRegistryData1_20_5(wrapper.user(), type, entries);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
protocol.registerFinishConfiguration(ClientboundConfigurationPackets1_20_5.FINISH_CONFIGURATION, wrapper -> {
|
protocol.registerFinishConfiguration(ClientboundConfigurationPackets1_20_5.FINISH_CONFIGURATION, wrapper -> {
|
||||||
// Add new registries
|
// Add new registries
|
||||||
|
@ -31,7 +31,6 @@ import com.viaversion.viaversion.api.data.entity.DimensionData;
|
|||||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||||
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
|
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
|
||||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||||
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.entitydata.EntityData;
|
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||||
@ -50,7 +49,6 @@ import com.viaversion.viaversion.rewriter.entitydata.EntityDataHandlerEventImpl;
|
|||||||
import com.viaversion.viaversion.util.Key;
|
import com.viaversion.viaversion.util.Key;
|
||||||
import com.viaversion.viaversion.util.TagUtil;
|
import com.viaversion.viaversion.util.TagUtil;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -505,23 +503,6 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
tracker(connection).setDimensions(dimensionDataMap);
|
tracker(connection).setDimensions(dimensionDataMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRegistryData1_20_5(final UserConnection connection, final String registryKey, final RegistryEntry[] entries) {
|
|
||||||
if (registryKey.equals("worldgen/biome")) {
|
|
||||||
tracker(connection).setBiomesSent(entries.length);
|
|
||||||
} else if (registryKey.equals("dimension_type")) {
|
|
||||||
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(entries.length);
|
|
||||||
for (int i = 0; i < entries.length; i++) {
|
|
||||||
final RegistryEntry entry = entries[i];
|
|
||||||
final String key = Key.stripMinecraftNamespace(entry.key());
|
|
||||||
final DimensionData dimensionData = entry.tag() != null
|
|
||||||
? new DimensionDataImpl(i, (CompoundTag) entry.tag())
|
|
||||||
: DimensionDataImpl.withDefaultsFor(key, i);
|
|
||||||
dimensionDataMap.put(key, dimensionData);
|
|
||||||
}
|
|
||||||
tracker(connection).setDimensions(dimensionDataMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityType trackAndRewrite(final PacketWrapper wrapper, final int typeId, final int entityId) {
|
public EntityType trackAndRewrite(final PacketWrapper wrapper, final int typeId, final int entityId) {
|
||||||
final int mappedTypeId = newEntityId(typeId);
|
final int mappedTypeId = newEntityId(typeId);
|
||||||
if (mappedTypeId != typeId) {
|
if (mappedTypeId != typeId) {
|
||||||
@ -583,13 +564,6 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
public RegistryEntry[] addRegistryEntries(final RegistryEntry[] entries, final RegistryEntry... toAdd) {
|
|
||||||
final int length = entries.length;
|
|
||||||
final RegistryEntry[] newEntries = Arrays.copyOf(entries, length + toAdd.length);
|
|
||||||
System.arraycopy(toAdd, 0, newEntries, length, toAdd.length);
|
|
||||||
return newEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logException(Exception e, @Nullable EntityType type, List<EntityData> entityDataList, EntityData entityData) {
|
private void logException(Exception e, @Nullable EntityType type, List<EntityData> entityDataList, EntityData entityData) {
|
||||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||||
protocol.getLogger().severe("An error occurred in entity data handler " + this.getClass().getSimpleName()
|
protocol.getLogger().severe("An error occurred in entity data handler " + this.getClass().getSimpleName()
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren