mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 08:57:39 +01:00
Resize registry data array to actual size once collected
This commit is contained in:
parent
c8d339ab30
commit
a5bd8abe93
@ -162,7 +162,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
|||||||
@Override
|
@Override
|
||||||
public PlatformTask runRepeatingAsync(final Runnable runnable, final long ticks) {
|
public PlatformTask runRepeatingAsync(final Runnable runnable, final long ticks) {
|
||||||
if (FOLIA) {
|
if (FOLIA) {
|
||||||
return new BukkitViaTaskTask(Via.getManager().getScheduler().schedule(runnable, ticks * 50, TimeUnit.MILLISECONDS));
|
return new BukkitViaTaskTask(Via.getManager().getScheduler().scheduleRepeating(runnable, 0, ticks * 50, TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
return new BukkitViaTask(getServer().getScheduler().runTaskTimerAsynchronously(this, runnable, 0, ticks));
|
return new BukkitViaTask(getServer().getScheduler().runTaskTimerAsynchronously(this, runnable, 0, ticks));
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
registerMetadataRewriter(ClientboundPackets1_20_3.ENTITY_METADATA, Types1_20_3.METADATA_LIST, Types1_20_5.METADATA_LIST);
|
registerMetadataRewriter(ClientboundPackets1_20_3.ENTITY_METADATA, Types1_20_3.METADATA_LIST, Types1_20_5.METADATA_LIST);
|
||||||
registerRemoveEntities(ClientboundPackets1_20_3.REMOVE_ENTITIES);
|
registerRemoveEntities(ClientboundPackets1_20_3.REMOVE_ENTITIES);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, wrapper -> {
|
||||||
@Override
|
|
||||||
protected void register() {
|
|
||||||
handler(wrapper -> {
|
|
||||||
final CompoundTag registryData = wrapper.read(Type.COMPOUND_TAG);
|
final CompoundTag registryData = wrapper.read(Type.COMPOUND_TAG);
|
||||||
cacheDimensionData(wrapper.user(), registryData);
|
cacheDimensionData(wrapper.user(), registryData);
|
||||||
trackBiomeSize(wrapper.user(), registryData);
|
trackBiomeSize(wrapper.user(), registryData);
|
||||||
@ -69,10 +66,12 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
final ListTag valueTag = entryTag.get("value");
|
final ListTag valueTag = entryTag.get("value");
|
||||||
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
|
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
|
||||||
boolean requiresDummyValues = false;
|
boolean requiresDummyValues = false;
|
||||||
|
int entriesLength = registryEntries.length;
|
||||||
for (final Tag tag : valueTag) {
|
for (final Tag tag : valueTag) {
|
||||||
final CompoundTag compoundTag = (CompoundTag) tag;
|
final CompoundTag compoundTag = (CompoundTag) tag;
|
||||||
final StringTag nameTag = compoundTag.get("name");
|
final StringTag nameTag = compoundTag.get("name");
|
||||||
final int id = ((NumberTag) compoundTag.get("id")).asInt();
|
final int id = ((NumberTag) compoundTag.get("id")).asInt();
|
||||||
|
entriesLength = Math.max(entriesLength, id + 1);
|
||||||
if (id >= registryEntries.length) {
|
if (id >= registryEntries.length) {
|
||||||
// It was previously possible to have arbitrary ids
|
// It was previously possible to have arbitrary ids
|
||||||
registryEntries = Arrays.copyOf(registryEntries, Math.max(registryEntries.length * 2, id + 1));
|
registryEntries = Arrays.copyOf(registryEntries, Math.max(registryEntries.length * 2, id + 1));
|
||||||
@ -83,7 +82,11 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requiresDummyValues) {
|
if (requiresDummyValues) {
|
||||||
fill(registryEntries);
|
// Truncate and replace null values
|
||||||
|
if (registryEntries.length != entriesLength) {
|
||||||
|
registryEntries = Arrays.copyOf(registryEntries, entriesLength);
|
||||||
|
}
|
||||||
|
replaceNullValues(registryEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PacketWrapper registryPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
|
final PacketWrapper registryPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
|
||||||
@ -94,8 +97,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
|
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_3.JOIN_GAME, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundPackets1_20_3.JOIN_GAME, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
||||||
@ -126,17 +127,12 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_3.RESPAWN, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundPackets1_20_3.RESPAWN, wrapper -> {
|
||||||
@Override
|
|
||||||
public void register() {
|
|
||||||
handler(wrapper -> {
|
|
||||||
final String dimensionKey = wrapper.read(Type.STRING);
|
final String dimensionKey = wrapper.read(Type.STRING);
|
||||||
final DimensionData data = tracker(wrapper.user()).dimensionData(dimensionKey);
|
final DimensionData data = tracker(wrapper.user()).dimensionData(dimensionKey);
|
||||||
wrapper.write(Type.VAR_INT, data.id());
|
wrapper.write(Type.VAR_INT, data.id());
|
||||||
});
|
wrapper.passthrough(Type.STRING); // World
|
||||||
map(Type.STRING); // World
|
worldDataTrackerHandlerByKey1_20_5(0).handle(wrapper); // Tracks world height and name for chunk data and entity (un)tracking
|
||||||
handler(worldDataTrackerHandlerByKey1_20_5(0)); // Tracks world height and name for chunk data and entity (un)tracking
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_3.ENTITY_EFFECT, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_20_3.ENTITY_EFFECT, wrapper -> {
|
||||||
@ -169,7 +165,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fill(final RegistryEntry[] entries) {
|
private void replaceNullValues(final RegistryEntry[] entries) {
|
||||||
// Find the first non-null entry and fill the array with dummy values where needed (which is easier than remapping them to different ids in a new, smaller array)
|
// Find the first non-null entry and fill the array with dummy values where needed (which is easier than remapping them to different ids in a new, smaller array)
|
||||||
RegistryEntry first = null;
|
RegistryEntry first = null;
|
||||||
for (final RegistryEntry registryEntry : entries) {
|
for (final RegistryEntry registryEntry : entries) {
|
||||||
|
@ -103,8 +103,11 @@ public class MetaFilter {
|
|||||||
&& (this.metaType == null || metadata.metaType() == this.metaType);
|
&& (this.metaType == null || metadata.metaType() == this.metaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchesType(@Nullable EntityType type) {
|
private boolean matchesType(EntityType type) {
|
||||||
return type != null && (this.filterFamily ? type.isOrHasParent(this.type) : this.type == type);
|
if (type == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.filterFamily ? type.isOrHasParent(this.type) : this.type == type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,8 +54,8 @@ public final class TaskScheduler implements Scheduler {
|
|||||||
scheduledExecutorService.shutdown();
|
scheduledExecutorService.shutdown();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executorService.awaitTermination(2, TimeUnit.SECONDS);
|
executorService.awaitTermination(1, TimeUnit.SECONDS);
|
||||||
scheduledExecutorService.awaitTermination(2, TimeUnit.SECONDS);
|
scheduledExecutorService.awaitTermination(1, TimeUnit.SECONDS);
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user