forked from GeyserMC/Geyser
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:
parent
172a5a6db8
commit
16eb2a491a
6 changed files with 59 additions and 28 deletions
|
@ -33,7 +33,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.CloudburstMC.Protocol</groupId>
|
<groupId>com.github.CloudburstMC.Protocol</groupId>
|
||||||
<artifactId>bedrock-v408</artifactId>
|
<artifactId>bedrock-v408</artifactId>
|
||||||
<version>250beb2a94</version>
|
<version>02f46a8700</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
|
|
@ -50,11 +50,12 @@ public class AreaEffectCloudEntity extends Entity {
|
||||||
if (entityMetadata.getId() == 7) {
|
if (entityMetadata.getId() == 7) {
|
||||||
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, entityMetadata.getValue());
|
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, entityMetadata.getValue());
|
||||||
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 2.0f * (float) 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) {
|
} else if (entityMetadata.getId() == 8) {
|
||||||
metadata.put(EntityData.POTION_AUX_VALUE, entityMetadata.getValue());
|
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);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
||||||
|
|
||||||
case HAVE_ALL_PACKS:
|
case HAVE_ALL_PACKS:
|
||||||
ResourcePackStackPacket stackPacket = new ResourcePackStackPacket();
|
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.setForcedToAccept(false); // Leaving this as false allows the player to choose to download or not
|
||||||
stackPacket.setGameVersion(session.getClientData().getGameVersion());
|
stackPacket.setGameVersion(session.getClientData().getGameVersion());
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,11 @@ import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
||||||
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
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 lombok.NonNull;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.utils.FileUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
import org.geysermc.connector.utils.LanguageUtils;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -50,8 +51,19 @@ public class EffectRegistry {
|
||||||
public static final Map<SoundEffect, Effect> SOUND_EFFECTS = new HashMap<>();
|
public static final Map<SoundEffect, Effect> SOUND_EFFECTS = new HashMap<>();
|
||||||
public static final Int2ObjectMap<SoundEvent> RECORDS = new Int2ObjectOpenHashMap<>();
|
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() {
|
public static void init() {
|
||||||
// no-op
|
// no-op
|
||||||
|
@ -68,22 +80,24 @@ public class EffectRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<Map.Entry<String, JsonNode>> particlesIterator = particleEntries.fields();
|
Iterator<Map.Entry<String, JsonNode>> particlesIterator = particleEntries.fields();
|
||||||
|
try {
|
||||||
while (particlesIterator.hasNext()) {
|
while (particlesIterator.hasNext()) {
|
||||||
Map.Entry<String, JsonNode> entry = particlesIterator.next();
|
Map.Entry<String, JsonNode> entry = particlesIterator.next();
|
||||||
try {
|
JsonNode bedrockId = entry.getValue().get("bedrockId");
|
||||||
particleTypeMap.put(ParticleType.valueOf(entry.getKey().toUpperCase()), LevelEventType.valueOf(entry.getValue().asText().toUpperCase()));
|
JsonNode bedrockIdNumeric = entry.getValue().get("bedrockNumericId");
|
||||||
} catch (IllegalArgumentException e1) {
|
JsonNode eventType = entry.getValue().get("eventType");
|
||||||
try {
|
if (bedrockIdNumeric != null) {
|
||||||
particleStringMap.put(ParticleType.valueOf(entry.getKey().toUpperCase()), entry.getValue().asText());
|
PARTICLE_TO_ID.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockIdNumeric.asInt());
|
||||||
GeyserConnector.getInstance().getLogger().debug("Force to map particle "
|
}
|
||||||
+ entry.getKey()
|
if (bedrockId != null) {
|
||||||
+ "=>"
|
PARTICLE_TO_STRING.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockId.asText());
|
||||||
+ entry.getValue().asText()
|
}
|
||||||
+ ", it will take effect.");
|
if (eventType != null) {
|
||||||
} catch (IllegalArgumentException e2){
|
PARTICLE_TO_LEVEL_EVENT.put(ParticleType.valueOf(entry.getKey().toUpperCase()), LevelEventType.valueOf(eventType.asText().toUpperCase()));
|
||||||
GeyserConnector.getInstance().getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.particle.failed_map", entry.getKey(), entry.getValue().asText()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load effects */
|
/* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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) {
|
public static String getParticleString(@NonNull ParticleType type) {
|
||||||
return particleStringMap.getOrDefault(type, null);
|
return PARTICLE_TO_STRING.getOrDefault(type, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 93b2caed3c4ecd94b3c77a87f1b2304a7bf4f062
|
Subproject commit 5f21792264a364e32425014e0be79db93593da1e
|
|
@ -1 +1 @@
|
||||||
Subproject commit 28a22d2baad680f511bffc36d90d06bf626f0527
|
Subproject commit 0fae8d3f0de6210a10435a36128db14cb7650ae6
|
Loading…
Reference in a new issue