Polymer

Polymer

763k Downloads

Virtual passengers are removed from the backing list by value instead of index

haykam821 opened this issue ยท 1 comments

commented

According to the fastutil documentation, the IntArrayList#removeInt method uses indices instead of arrays:

public int removeInt(int index)

Removes the element at the specified position in this list (optional operation).

However, in both VirtualEntityUtils.removeVirtualPassenger methods, Polymer passes values, rather than the index of each value, to the removal method:

public static void removeVirtualPassenger(Entity entity, int passengerId) {
((EntityExt) entity).polymerVE$getVirtualRidden().removeInt(passengerId);
((EntityExt) entity).polymerVE$markVirtualRiddenDirty();
}
public static void removeVirtualPassenger(Entity entity, int... passengerId) {
for (var i : passengerId) {
((EntityExt) entity).polymerVE$getVirtualRidden().removeInt(i);
}
((EntityExt) entity).polymerVE$markVirtualRiddenDirty();
}

As a result, when attempting to remove a virtual passenger, an exception such as the following is thrown:

java.lang.IndexOutOfBoundsException: Index (1578) is greater than or equal to list size (24)
        at it.unimi.dsi.fastutil.ints.IntArrayList.removeInt(IntArrayList.java:359)
        at eu.pb4.polymer.virtualentity.api.VirtualEntityUtils.removeVirtualPassenger(VirtualEntityUtils.java:47)
commented

Fixed in 68a20c7