Start implementing timelines
This commit is contained in:
5 files changed
+135
-6
No files matched your search
@@ -18,6 +18,7 @@
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.nbt;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtCodecException;
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtDecoder;
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtEncoder;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
@@ -62,10 +63,10 @@ public class NBTCompound extends NBT {
|
||||
return tags.size();
|
||||
}
|
||||
|
||||
public NBT getTagOrThrow(String key) {
|
||||
public NBT getTagOrThrow(String key) throws NbtCodecException {
|
||||
NBT tag = getTagOrNull(key);
|
||||
if (tag == null) {
|
||||
throw new IllegalStateException(MessageFormat.format("NBT {0} does not exist", key));
|
||||
throw new NbtCodecException("Tag " + key + " doesn't exist");
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
@@ -75,12 +76,12 @@ public class NBTCompound extends NBT {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends NBT> T getTagOfTypeOrThrow(String key, Class<T> type) {
|
||||
public <T extends NBT> T getTagOfTypeOrThrow(String key, Class<T> type) throws NbtCodecException {
|
||||
NBT tag = getTagOrThrow(key);
|
||||
if (type.isInstance(tag)) {
|
||||
return (T) tag;
|
||||
} else {
|
||||
throw new IllegalStateException(MessageFormat.format("NBT {0} has unexpected type, expected {1}, but got {2}", key, type, tag.getClass()));
|
||||
throw new NbtCodecException(MessageFormat.format("NBT {0} has unexpected type, expected {1}, but got {2}", key, type, tag.getClass()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,10 +95,10 @@ public class NBTCompound extends NBT {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends NBT> NBTList<T> getTagListOfTypeOrThrow(String key, Class<T> type) {
|
||||
public <T extends NBT> NBTList<T> getTagListOfTypeOrThrow(String key, Class<T> type) throws NbtCodecException {
|
||||
NBTList<? extends NBT> list = getTagOfTypeOrThrow(key, NBTList.class);
|
||||
if (!type.isAssignableFrom(list.getTagsType().getNBTClass())) {
|
||||
throw new IllegalStateException(MessageFormat.format("NBTList {0} tags type has unexpected type, expected {1}, but got {2}", key, type, list.getTagsType().getNBTClass()));
|
||||
throw new NbtCodecException(MessageFormat.format("NBTList {0} tags type has unexpected type, expected {1}, but got {2}", key, type, list.getTagsType().getNBTClass()));
|
||||
}
|
||||
return (NBTList<T>) list;
|
||||
}
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.github.retrooper.packetevents.protocol.world.attributes;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTInt;
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtCodec;
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtCodecException;
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtMapCodec;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* @versions 1.21.11+
|
||||
*/
|
||||
@NullMarked
|
||||
public class Keyframe<T> {
|
||||
|
||||
private final int ticks;
|
||||
private final T value;
|
||||
|
||||
public Keyframe(int ticks, T value) {
|
||||
this.ticks = ticks;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static <T> NbtCodec<Keyframe<T>> codec(NbtCodec<T> codec) {
|
||||
return new NbtMapCodec<Keyframe<T>>() {
|
||||
@Override
|
||||
public Keyframe<T> decode(NBTCompound compound, PacketWrapper<?> wrapper) throws NbtCodecException {
|
||||
int ticks = compound.getNumberTagOrThrow("ticks").getAsInt();
|
||||
T value = compound.getOrThrow("value", codec, wrapper);
|
||||
return new Keyframe<>(ticks, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(NBTCompound compound, PacketWrapper<?> wrapper, Keyframe<T> value) throws NbtCodecException {
|
||||
compound.setTag("ticks", new NBTInt(value.ticks));
|
||||
compound.set("value", value.value, codec, wrapper);
|
||||
}
|
||||
}.codec();
|
||||
}
|
||||
|
||||
public int getTicks() {
|
||||
return this.ticks;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.github.retrooper.packetevents.protocol.world.attributes;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @versions 1.21.11+
|
||||
*/
|
||||
@NullMarked
|
||||
public class KeyframeTrack<T> {
|
||||
|
||||
private final List<Keyframe<T>> keyframes;
|
||||
private final EasingType easingType;
|
||||
|
||||
public KeyframeTrack(List<Keyframe<T>> keyframes, EasingType easingType) {
|
||||
this.keyframes = keyframes;
|
||||
this.easingType = easingType;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
public List<Keyframe<T>> getKeyframes() {
|
||||
return this.keyframes;
|
||||
}
|
||||
|
||||
public EasingType getEasingType() {
|
||||
return this.easingType;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.github.retrooper.packetevents.protocol.world.attributes;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.CopyableEntity;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.DeepComparableEntity;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @versions 1.21.11+
|
||||
*/
|
||||
@NullMarked
|
||||
public interface Timeline extends MappedEntity, CopyableEntity<Timeline>, DeepComparableEntity {
|
||||
|
||||
int getPeriodTicks();
|
||||
|
||||
Map<EnvironmentAttribute<?>, TimelineTrack<?, ?>> getTracks();
|
||||
|
||||
// TODO
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.github.retrooper.packetevents.protocol.world.attributes;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* @versions 1.21.11+
|
||||
*/
|
||||
@NullMarked
|
||||
public class TimelineTrack<T, A> {
|
||||
|
||||
private final AttributeModifier<T, A> modifier;
|
||||
private final KeyframeTrack<A> argumentTrack;
|
||||
|
||||
public TimelineTrack(AttributeModifier<T, A> modifier, KeyframeTrack<A> argumentTrack) {
|
||||
this.modifier = modifier;
|
||||
this.argumentTrack = argumentTrack;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
public AttributeModifier<T, A> getModifier() {
|
||||
return this.modifier;
|
||||
}
|
||||
|
||||
public KeyframeTrack<A> getArgumentTrack() {
|
||||
return this.argumentTrack;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user