Use dyecolor and byte, remove old method

This commit is contained in:
Tofaa2 2025-03-31 21:27:58 +04:00
parent e181b979a0
commit 7298de0bb7
3 changed files with 42 additions and 5 deletions

View file

@ -1,10 +1,12 @@
package me.tofaa.entitylib.meta.mobs.golem;
import com.github.retrooper.packetevents.protocol.color.DyeColor;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.world.Direction;
import com.github.retrooper.packetevents.util.Vector3i;
import me.tofaa.entitylib.meta.Metadata;
import me.tofaa.entitylib.meta.types.MobMeta;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Optional;
@ -13,6 +15,8 @@ public class ShulkerMeta extends MobMeta {
public static final byte OFFSET = MobMeta.MAX_OFFSET;
public static final byte MAX_OFFSET = OFFSET + 1;
private static final DyeColor[] DYE_COLORS = DyeColor.values();
public ShulkerMeta(int entityId, Metadata metadata) {
super(entityId, metadata);
@ -35,20 +39,27 @@ public class ShulkerMeta extends MobMeta {
}
public byte getShieldHeight() {
return super.metadata.getIndex(offset(OFFSET, 2), (byte) 0);
return super.metadata.getIndex(offset(OFFSET, 1), (byte) 0);
}
public void setShieldHeight(byte value) {
super.metadata.setIndex(offset(OFFSET, 2), EntityDataTypes.BYTE, value);
super.metadata.setIndex(offset(OFFSET, 1), EntityDataTypes.BYTE, value);
}
public byte getColor() {
return super.metadata.getIndex(offset(OFFSET, 3), (byte) 10);
return super.metadata.getIndex(offset(OFFSET, 2), (byte) 16);
}
public DyeColor getColorEnum() {
return DYE_COLORS[getColor()];
}
public void setColor(byte value) {
super.metadata.setIndex(offset(OFFSET, 3), EntityDataTypes.BYTE, value);
super.metadata.setIndex(offset(OFFSET, 2), EntityDataTypes.BYTE, value);
}
public void setColor(DyeColor color) {
setColor((byte)color.ordinal());
}
}

View file

@ -40,7 +40,8 @@ abstract class ELVersionTask : DefaultTask() {
* This file is generated by the auto-version task. Modifying it will have no effect.
*/
package $packageName;
import java.text.DateFormat;
import com.github.retrooper.packetevents.util.PEVersion;
public final class ELVersions {
@ -52,6 +53,29 @@ abstract class ELVersionTask : DefaultTask() {
private ELVersions() {
throw new IllegalStateException();
}
public static class Version {
private final long timestamp;
public Version(long timestamp) {
this.timestamp = timestamp;
}
public long getTimestamp() {
return timestamp;
}
public String getTimestampFormatted() {
return DateFormat.getDateTimeInstance().format(new java.util.Date(timestamp));
}
public boolean isOlderThan(Version version) {
return this.timestamp < version.timestamp;
}
}
}
""".trimIndent())
}

View file

@ -9,11 +9,13 @@ import org.bukkit.command.CommandMap;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.InvocationTargetException;
import java.text.DateFormat;
public class TestEntityLibPlugin extends JavaPlugin {
@Override
public void onEnable() {
DateFormat.getDateTimeInstance().format(new java.util.Date(timestamp));
SpigotEntityLibPlatform platform = new SpigotEntityLibPlatform(this);
APIConfig settings = new APIConfig(PacketEvents.getAPI())