Potion effect colors

This commit is contained in:
AJ Ferguson 2024-04-28 02:10:20 -04:00
parent 6d5ac233d6
commit e97bbcc483
3 changed files with 37 additions and 3 deletions

View file

@ -454,8 +454,7 @@ public final class EntityDefinitions {
EntityDefinition<LivingEntity> livingEntityBase = EntityDefinition.inherited(LivingEntity::new, entityBase)
.addTranslator(MetadataType.BYTE, LivingEntity::setLivingEntityFlags)
.addTranslator(MetadataType.FLOAT, LivingEntity::setHealth)
.addTranslator(MetadataType.INT,
(livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityDataTypes.EFFECT_COLOR, entityMetadata.getValue()))
.addTranslator(MetadataType.PARTICLES, LivingEntity::setParticles)
.addTranslator(MetadataType.BOOLEAN,
(livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityDataTypes.EFFECT_AMBIENCE, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0)))
.addTranslator(null) // Arrow count

View file

@ -55,9 +55,13 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.EntityEffectParticleData;
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle;
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.ParticleType;
import java.util.*;
@ -152,6 +156,37 @@ public class LivingEntity extends Entity {
session.sendUpstreamPacket(attributesPacket);
}
// TODO: support all particle types
public void setParticles(ObjectEntityMetadata<List<Particle>> entityMetadata) {
List<Particle> particles = entityMetadata.getValue();
float r = 0f;
float g = 0f;
float b = 0f;
int count = 0;
for (Particle particle : particles) {
if (particle.getType() != ParticleType.ENTITY_EFFECT) {
continue;
}
int color = ((EntityEffectParticleData) particle.getData()).getColor();
r += ((color >> 16) & 0xFF) / 255f;
g += ((color >> 8) & 0xFF) / 255f;
b += ((color) & 0xFF) / 255f;
count++;
}
int result = 0;
if (count > 0) {
r = r / count * 255f;
g = g / count * 255f;
b = b / count * 255f;
result = (int) r << 16 | (int) g << 8 | (int) b;
}
dirtyMetadata.put(EntityDataTypes.EFFECT_COLOR, result);
}
public @Nullable Vector3i setBedPosition(EntityMetadata<Optional<Vector3i>, ?> entityMetadata) {
Optional<Vector3i> optionalPos = entityMetadata.getValue();
if (optionalPos.isPresent()) {

View file

@ -15,7 +15,7 @@ protocol-connection = "3.0.0.Beta1-20240411.165033-128"
raknet = "1.0.0.CR3-20240416.144209-1"
blockstateupdater="1.20.80-20240411.142413-1"
mcauthlib = "d9d773e"
mcprotocollib = "98410a1" # Revert from jitpack after release
mcprotocollib = "400f1b4" # Revert from jitpack after release
adventure = "4.14.0"
adventure-platform = "4.3.0"
junit = "5.9.2"