Skip to content

Commit

Permalink
Fix potion effect display (#2194)
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name authored Aug 26, 2024
1 parent 4344117 commit 95a67b9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/cn/nukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public abstract class Entity extends Location implements Metadatable {
public static final int DATA_PLAYER_LAST_DEATH_POS = 127;
public static final int DATA_PLAYER_LAST_DEATH_DIMENSION = 128;
public static final int DATA_PLAYER_HAS_DIED = 129;
public static final int DATA_COLLISION_BOX = 130; //vector3f
public static final int DATA_VISIBLE_MOB_EFFECTS = 131; //long

// Flags
public static final int DATA_FLAG_ONFIRE = 0;
Expand Down Expand Up @@ -845,6 +847,8 @@ protected void recalculateEffectColor() {
int[] color = new int[3];
int count = 0;
boolean ambient = true;
long effectsData = 0;
int packedEffectsCount = 0;
for (Effect effect : this.effects.values()) {
if (effect.isVisible()) {
int[] c = effect.getColor();
Expand All @@ -855,6 +859,10 @@ protected void recalculateEffectColor() {
if (!effect.isAmbient()) {
ambient = false;
}
if (packedEffectsCount < 8) {
effectsData = effectsData << 7 | ((effect.getId() & 0x3f) << 1) | (effect.isAmbient() ? 1 : 0);
packedEffectsCount++;
}
}
}

Expand All @@ -869,6 +877,7 @@ protected void recalculateEffectColor() {
this.setDataProperty(new IntEntityData(Entity.DATA_POTION_COLOR, 0));
this.setDataProperty(new ByteEntityData(Entity.DATA_POTION_AMBIENT, 0));
}
this.setDataProperty(new LongEntityData(Entity.DATA_VISIBLE_MOB_EFFECTS, effectsData));
}

public static Entity createEntity(String name, Position pos, Object... args) {
Expand Down

0 comments on commit 95a67b9

Please sign in to comment.