Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix area effect cloud particle type for 1.16.220 #2226

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>com.github.CloudburstMC.Protocol</groupId>
<artifactId>bedrock-v431</artifactId>
<version>9947665</version>
<version>530a0e3</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
metadata.put(EntityData.EFFECT_COLOR, entityMetadata.getValue());
} else if (entityMetadata.getId() == 10) {
Particle particle = (Particle) entityMetadata.getValue();
int particleId = EffectRegistry.getParticleId(particle.getType());
int particleId = EffectRegistry.getParticleId(session, particle.getType());
if (particleId != -1) {
metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, particleId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
import com.nukkitx.protocol.bedrock.data.SoundEvent;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import lombok.NonNull;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.FileUtils;

import java.io.InputStream;
Expand All @@ -51,11 +50,6 @@ public class EffectRegistry {
public static final Map<SoundEffect, Effect> SOUND_EFFECTS = new HashMap<>();
public static final Int2ObjectMap<SoundEvent> RECORDS = new Int2ObjectOpenHashMap<>();

/**
* Java particle type to Bedrock particle ID
* Used for area effect clouds.
*/
private static final Object2IntMap<ParticleType> PARTICLE_TO_ID = new Object2IntOpenHashMap<>();
/**
* Java particle type to Bedrock level event
*/
Expand Down Expand Up @@ -84,11 +78,7 @@ public static void init() {
while (particlesIterator.hasNext()) {
Map.Entry<String, JsonNode> entry = particlesIterator.next();
JsonNode bedrockId = entry.getValue().get("bedrockId");
JsonNode bedrockIdNumeric = entry.getValue().get("bedrockNumericId");
JsonNode eventType = entry.getValue().get("eventType");
if (bedrockIdNumeric != null) {
PARTICLE_TO_ID.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockIdNumeric.asInt());
}
if (bedrockId != null) {
PARTICLE_TO_STRING.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockId.asText());
}
Expand Down Expand Up @@ -164,11 +154,19 @@ public static void init() {
}

/**
* Used for area effect clouds.
*
* @param type the Java particle to search for
* @return the Bedrock integer ID of the particle, or -1 if it does not exist
*/
public static int getParticleId(@NonNull ParticleType type) {
return PARTICLE_TO_ID.getOrDefault(type, -1);
public static int getParticleId(GeyserSession session, @NonNull ParticleType type) {
LevelEventType levelEventType = getParticleLevelEventType(type);
if (levelEventType == null) {
return -1;
}

// Remove the legacy bit applied to particles for LevelEventType serialization
return session.getUpstream().getSession().getPacketCodec().getHelper().getLevelEventId(levelEventType) & ~0x4000;
}

/**
Expand Down