Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityData Wrappers #615

Open
CubBossa opened this issue Oct 20, 2023 · 2 comments
Open

EntityData Wrappers #615

CubBossa opened this issue Oct 20, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@CubBossa
Copy link

CubBossa commented Oct 20, 2023

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 CubBossa added the enhancement New feature or request label Oct 20, 2023
@CubBossa
Copy link
Author

CubBossa commented Oct 21, 2023

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

@retrooper
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants