Area cloud fixes (#684)

* Fix NotNull error with particles, replace incorrect string meta with int meta.

* Add back newline

* Remove debug line

* Update Protocol and prepare for merge

Co-authored-by: DoctorMacc <toy.fighter1@gmail.com>
This commit is contained in:
Arktisfox 2020-10-08 18:33:36 -04:00 committed by GitHub
parent 172a5a6db8
commit 16eb2a491a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 28 deletions

View file

@ -33,7 +33,7 @@
<dependency>
<groupId>com.github.CloudburstMC.Protocol</groupId>
<artifactId>bedrock-v408</artifactId>
<version>250beb2a94</version>
<version>02f46a8700</version>
<scope>compile</scope>
<exclusions>
<exclusion>

View file

@ -50,11 +50,12 @@ public class AreaEffectCloudEntity extends Entity {
if (entityMetadata.getId() == 7) {
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, entityMetadata.getValue());
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 2.0f * (float) entityMetadata.getValue());
} else if (entityMetadata.getId() == 10) {
Particle particle = (Particle) entityMetadata.getValue();
metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, EffectRegistry.getParticleString(particle.getType()));
} else if (entityMetadata.getId() == 8) {
metadata.put(EntityData.POTION_AUX_VALUE, entityMetadata.getValue());
} else if (entityMetadata.getId() == 10) {
Particle particle = (Particle) entityMetadata.getValue();
int particleId = EffectRegistry.getParticleId(particle.getType());
metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, particleId);
}
super.updateBedrockMetadata(entityMetadata, session);
}

View file

@ -117,7 +117,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
case HAVE_ALL_PACKS:
ResourcePackStackPacket stackPacket = new ResourcePackStackPacket();
stackPacket.setExperimental(false);
stackPacket.setExperimentsPreviouslyToggled(false);
stackPacket.setForcedToAccept(false); // Leaving this as false allows the player to choose to download or not
stackPacket.setGameVersion(session.getClientData().getGameVersion());

View file

@ -32,10 +32,11 @@ import com.nukkitx.protocol.bedrock.data.LevelEventType;
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.utils.FileUtils;
import org.geysermc.connector.utils.LanguageUtils;
import java.io.InputStream;
import java.util.HashMap;
@ -50,8 +51,19 @@ public class EffectRegistry {
public static final Map<SoundEffect, Effect> SOUND_EFFECTS = new HashMap<>();
public static final Int2ObjectMap<SoundEvent> RECORDS = new Int2ObjectOpenHashMap<>();
private static Map<ParticleType, LevelEventType> particleTypeMap = new HashMap<>();
private static Map<ParticleType, String> particleStringMap = new HashMap<>();
/**
* 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
*/
private static final Map<ParticleType, LevelEventType> PARTICLE_TO_LEVEL_EVENT = new HashMap<>();
/**
* Java particle type to Bedrock namespaced string ID
*/
private static final Map<ParticleType, String> PARTICLE_TO_STRING = new HashMap<>();
public static void init() {
// no-op
@ -68,22 +80,24 @@ public class EffectRegistry {
}
Iterator<Map.Entry<String, JsonNode>> particlesIterator = particleEntries.fields();
while (particlesIterator.hasNext()) {
Map.Entry<String, JsonNode> entry = particlesIterator.next();
try {
particleTypeMap.put(ParticleType.valueOf(entry.getKey().toUpperCase()), LevelEventType.valueOf(entry.getValue().asText().toUpperCase()));
} catch (IllegalArgumentException e1) {
try {
particleStringMap.put(ParticleType.valueOf(entry.getKey().toUpperCase()), entry.getValue().asText());
GeyserConnector.getInstance().getLogger().debug("Force to map particle "
+ entry.getKey()
+ "=>"
+ entry.getValue().asText()
+ ", it will take effect.");
} catch (IllegalArgumentException e2){
GeyserConnector.getInstance().getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.particle.failed_map", entry.getKey(), entry.getValue().asText()));
try {
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());
}
if (eventType != null) {
PARTICLE_TO_LEVEL_EVENT.put(ParticleType.valueOf(entry.getKey().toUpperCase()), LevelEventType.valueOf(eventType.asText().toUpperCase()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
/* Load effects */
@ -149,11 +163,27 @@ public class EffectRegistry {
}
}
public static LevelEventType getParticleLevelEventType(@NonNull ParticleType type) {
return particleTypeMap.getOrDefault(type, null);
/**
* @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 String getParticleString(@NonNull ParticleType type){
return particleStringMap.getOrDefault(type, null);
/**
* @param type the Java particle to search for
* @return the level event equivalent Bedrock particle
*/
public static LevelEventType getParticleLevelEventType(@NonNull ParticleType type) {
return PARTICLE_TO_LEVEL_EVENT.getOrDefault(type, null);
}
/**
* @param type the Java particle to search for
* @return the namespaced ID equivalent for Bedrock
*/
public static String getParticleString(@NonNull ParticleType type) {
return PARTICLE_TO_STRING.getOrDefault(type, null);
}
}

@ -1 +1 @@
Subproject commit 93b2caed3c4ecd94b3c77a87f1b2304a7bf4f062
Subproject commit 5f21792264a364e32425014e0be79db93593da1e

@ -1 +1 @@
Subproject commit 28a22d2baad680f511bffc36d90d06bf626f0527
Subproject commit 0fae8d3f0de6210a10435a36128db14cb7650ae6