implement armor stand properties
This commit is contained in:
parent
f3d5e3f3a8
commit
c11093c392
3 changed files with 48 additions and 27 deletions
|
@ -241,11 +241,22 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
register(new DummyProperty<>("skin", SkinDescriptor.class, false));
|
||||
|
||||
register(new GlowProperty(packetFactory));
|
||||
register(new EffectsProperty("fire", 0x01));
|
||||
register(new EffectsProperty("invisible", 0x20));
|
||||
register(new SimpleBitsetProperty("fire", 0, 0x01));
|
||||
register(new SimpleBitsetProperty("invisible", 0, 0x20));
|
||||
linkProperties("glow", "fire", "invisible");
|
||||
|
||||
register(new SimpleBooleanProperty("silent", 4, false, ver.isOlderThan(ServerVersion.V_1_9)));
|
||||
|
||||
int armorStandIndex;
|
||||
if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) armorStandIndex = 15;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) armorStandIndex = 14;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) armorStandIndex = 13;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) armorStandIndex = 11;
|
||||
else armorStandIndex = 10;
|
||||
register(new SimpleBitsetProperty("small", armorStandIndex, 0x01));
|
||||
register(new SimpleBitsetProperty("arms", armorStandIndex, 0x04));
|
||||
register(new SimpleBitsetProperty("base_plate", armorStandIndex, 0x08, true));
|
||||
linkProperties("small", "arms", "base_plate");
|
||||
}
|
||||
|
||||
private void registerSerializer(PropertySerializer<?> serializer) {
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package lol.pyr.znpcsplus.entity.properties;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class EffectsProperty extends EntityPropertyImpl<Boolean> {
|
||||
private final int bitmask;
|
||||
|
||||
public EffectsProperty(String name, int bitmask) {
|
||||
super(name, false, Boolean.class);
|
||||
this.bitmask = bitmask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
||||
EntityData oldData = properties.get(0);
|
||||
byte oldValue = oldData == null ? 0 : (byte) oldData.getValue();
|
||||
properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (entity.getProperty(this) ? bitmask : 0))));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package lol.pyr.znpcsplus.entity.properties;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleBitsetProperty extends EntityPropertyImpl<Boolean> {
|
||||
private final int index;
|
||||
private final int bitmask;
|
||||
private final boolean inverted;
|
||||
|
||||
public SimpleBitsetProperty(String name, int index, int bitmask, boolean inverted) {
|
||||
super(name, !inverted, Boolean.class);
|
||||
this.index = index;
|
||||
this.bitmask = bitmask;
|
||||
this.inverted = inverted;
|
||||
}
|
||||
|
||||
public SimpleBitsetProperty(String name, int index, int bitmask) {
|
||||
this(name, index, bitmask, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
||||
EntityData oldData = properties.get(index);
|
||||
byte oldValue = oldData == null ? 0 : (byte) oldData.getValue();
|
||||
boolean enabled = entity.getProperty(this);
|
||||
if (inverted) enabled = !enabled;
|
||||
properties.put(index, newEntityData(index, EntityDataTypes.BYTE, (byte) (oldValue | (enabled ? bitmask : 0))));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue