packetevents icon indicating copy to clipboard operation
packetevents copied to clipboard

EntityData Wrappers

Open CubBossa opened this issue 2 years ago • 2 comments

People told me on the discord that EntityData Wrappers had already been a thing. I am working on a project where I want to work with metadata a lot but it should not be version bound. This was fine until now but from 1.20.1 to 1.20.2, display entities have a new meta field and all indices are one off. I started to make wrappers for the different EntityData fields, but thought it was something many people could profit of. There are only little changes in between different versions, but it is a lot of work to initially set it up. I can do this for some basic fields and maybe other people will contribute too until we could have a branch with wrappers for all the meta fields.

I had something like this in mind (in reality with a baseclass EntityDataWrapper that holds the server version and inherits from EntityData): Also the following example would require one change in the EntityMeta Packet Wrapper, which is to filter all EntityData objects whose index is < 0.

public class RemainingAirEntityDataWrapper extends EntityData {

    private final ServerVersion serverVersion;

    public RemainingAirEntityDataWrapper(int ticks) {
        super(-1, EntityDataTypes.INT, ticks);
        setIndex(versionedIndex());
        this.serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
    }

    @Override
    public Integer getValue() {
        return (Integer) super.getValue();
    }

    /**
     * @return -1 if this field (not the index) does not exist on the current version. Otherwise, the index of the field
     * will be returned according to the current server version.
     */
    private int versionedIndex() {
        return 1; // in this case never changed from 1.8 to 1.20.2
    }
}

The only reason to add it is to make client side entities that are mostly not bound to a specific version.

CubBossa avatar Oct 20 '23 13:10 CubBossa

https://github.com/CubBossa/ClientEntities/blob/main/src/main/java/de/cubbossa/cliententities/entitydata/EntityDataWrapper.java I did a start here so that my plugin does work with 1.20.2. If you're interested in copying it over just ask

CubBossa avatar Oct 21 '23 09:10 CubBossa

I would definitely support your project if you made this entity data abstraction a seperate project. It could then be seen as a packetevents addon, if its fully functional i would advocate for it.

retrooper avatar Nov 25 '23 12:11 retrooper