Fix apparently a long standing issue where getNewEntityId wasn't working in 1.14+ as per #786

This commit is contained in:
libraryaddict 2024-11-30 11:00:35 +13:00
parent 6278d3a993
commit ebf66ce1b0
14 changed files with 33 additions and 12 deletions

View File

@ -92,7 +92,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return atomicInteger.incrementAndGet(); return atomicInteger.incrementAndGet();
} else { } else {
return atomicInteger.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return atomicInteger.get() + 1;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -92,7 +92,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return atomicInteger.incrementAndGet(); return atomicInteger.incrementAndGet();
} else { } else {
return atomicInteger.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return atomicInteger.get() + 1;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -94,7 +94,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return atomicInteger.incrementAndGet(); return atomicInteger.incrementAndGet();
} else { } else {
return atomicInteger.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return atomicInteger.get() + 1;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -93,7 +93,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return atomicInteger.incrementAndGet(); return atomicInteger.incrementAndGet();
} else { } else {
return atomicInteger.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return atomicInteger.get() + 1;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -108,7 +108,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return atomicInteger.incrementAndGet(); return atomicInteger.incrementAndGet();
} else { } else {
return atomicInteger.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return atomicInteger.get() + 1;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -107,7 +107,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return atomicInteger.incrementAndGet(); return atomicInteger.incrementAndGet();
} else { } else {
return atomicInteger.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return atomicInteger.get() + 1;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -107,7 +107,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return atomicInteger.incrementAndGet(); return atomicInteger.incrementAndGet();
} else { } else {
return atomicInteger.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return atomicInteger.get() + 1;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -130,7 +130,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return entityCounter.incrementAndGet(); return entityCounter.incrementAndGet();
} else { } else {
return entityCounter.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return entityCounter.get() + 1;
} }
} }

View File

@ -130,7 +130,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return entityCounter.incrementAndGet(); return entityCounter.incrementAndGet();
} else { } else {
return entityCounter.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return entityCounter.get() + 1;
} }
} }

View File

@ -133,7 +133,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return entityCounter.incrementAndGet(); return entityCounter.incrementAndGet();
} else { } else {
return entityCounter.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return entityCounter.get() + 1;
} }
} }

View File

@ -138,7 +138,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return entityCounter.incrementAndGet(); return entityCounter.incrementAndGet();
} else { } else {
return entityCounter.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return entityCounter.get() + 1;
} }
} }

View File

@ -140,7 +140,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
if (increment) { if (increment) {
return entityCounter.incrementAndGet(); return entityCounter.incrementAndGet();
} else { } else {
return entityCounter.get(); // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used
return entityCounter.get() + 1;
} }
} }

View File

@ -269,6 +269,7 @@ public class DisguiseAPI {
} }
int id = ReflectionManager.getNewEntityId(false); int id = ReflectionManager.getNewEntityId(false);
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise); DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
return id; return id;

View File

@ -604,6 +604,10 @@ public class ReflectionManager {
} }
public static int getNewEntityId(boolean increment) { public static int getNewEntityId(boolean increment) {
// From earlier versions up to 1.13, entityId = entityCounter++
// From 1.14 and onwards, entityId = entityCounter.incrementAndGet()
// Obviously, they are very different.
if (nmsReflection != null) { if (nmsReflection != null) {
return nmsReflection.getNewEntityId(increment); return nmsReflection.getNewEntityId(increment);
} }
@ -623,6 +627,10 @@ public class ReflectionManager {
} }
} }
if (NmsVersion.v1_14.isSupported()) {
return entityCount.intValue() + 1;
}
return entityCount.intValue(); return entityCount.intValue();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();