Skip to content

Commit

Permalink
Optimize if else in updateEntityMetaData()
Browse files Browse the repository at this point in the history
  • Loading branch information
Axionize committed Nov 17, 2024
1 parent 2496510 commit 2bc467a
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ public void updateEntityMetadata(int entityID, List<EntityData> watchableObjects
player.compensatedWorld.openShulkerBoxes.add(data);
}
}
}

if (entity instanceof PacketEntityRideable) {
} else if (entity instanceof PacketEntityRideable) {
int offset = 0;
if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThanOrEquals(ServerVersion.V_1_8_8)) {
if (entity.getType() == EntityTypes.PIG) {
Expand Down Expand Up @@ -350,9 +348,7 @@ public void updateEntityMetadata(int entityID, List<EntityData> watchableObjects
((PacketEntityRideable) entity).hasSaddle = (boolean) striderSaddle.getValue();
}
}
}

if (entity instanceof PacketEntityHorse) {
} else if (entity instanceof PacketEntityHorse) {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9_4)) {
int offset = 0;

Expand Down Expand Up @@ -397,23 +393,7 @@ public void updateEntityMetadata(int entityID, List<EntityData> watchableObjects
((PacketEntityHorse) entity).isRearing = (info & 0x40) != 0;
}
}
}

if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9_4)) {
EntityData gravity = WatchableIndexUtil.getIndex(watchableObjects, 5);

if (gravity != null) {
Object gravityObject = gravity.getValue();

if (gravityObject instanceof Boolean) {
// Vanilla uses hasNoGravity, which is a bad name IMO
// hasGravity > hasNoGravity
entity.hasGravity = !((Boolean) gravityObject);
}
}
}

if (entity.getType() == EntityTypes.FIREWORK_ROCKET) {
} else if (entity.getType() == EntityTypes.FIREWORK_ROCKET) {
int offset = 0;
if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThanOrEquals(ServerVersion.V_1_12_2)) {
offset = 2;
Expand All @@ -436,9 +416,7 @@ public void updateEntityMetadata(int entityID, List<EntityData> watchableObjects
player.compensatedFireworks.addNewFirework(entityID);
}
}
}

if (entity instanceof PacketEntityHook) {
} else if (entity instanceof PacketEntityHook) {
int index;
if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThanOrEquals(ServerVersion.V_1_9_4)) {
index = 5;
Expand All @@ -456,5 +434,19 @@ public void updateEntityMetadata(int entityID, List<EntityData> watchableObjects
Integer attachedEntityID = (Integer) hookWatchableObject.getValue();
((PacketEntityHook) entity).attached = attachedEntityID - 1; // the server adds 1 to the ID
}

if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9_4)) {
EntityData gravity = WatchableIndexUtil.getIndex(watchableObjects, 5);

if (gravity != null) {
Object gravityObject = gravity.getValue();

if (gravityObject instanceof Boolean) {
// Vanilla uses hasNoGravity, which is a bad name IMO
// hasGravity > hasNoGravity
entity.hasGravity = !((Boolean) gravityObject);
}
}
}
}
}

0 comments on commit 2bc467a

Please sign in to comment.