Skip to content

Commit

Permalink
add dev warning if provider class is used as target
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Nov 24, 2023
1 parent bba4c1a commit 73de725
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/mcp/mobius/waila/registry/Registrar.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public <T> void addIcon(IBlockComponentProvider provider, Class<T> clazz, int pr
if (Waila.CLIENT_SIDE) {
assertLock();
assertPriority(priority);
warnTargetClass(provider, clazz);
blockIcon.add(clazz, provider, priority);
}
}
Expand All @@ -192,6 +193,7 @@ public <T> void addComponent(IBlockComponentProvider provider, TooltipPosition p
if (Waila.CLIENT_SIDE) {
assertLock();
assertPriority(priority);
warnTargetClass(provider, clazz);
blockComponent.get(position).add(clazz, provider, priority);
}
}
Expand All @@ -201,6 +203,7 @@ public <T> void addComponent(IBlockComponentProvider provider, TooltipPosition p
public <T, BE extends BlockEntity> void addBlockData(IDataProvider<BE> provider, Class<T> clazz, int priority) {
assertLock();
assertPriority(priority);
warnTargetClass(provider, clazz);
blockData.add(clazz, (IDataProvider<BlockEntity>) provider, priority);
}

Expand All @@ -214,6 +217,7 @@ public <T> void addOverride(IEntityComponentProvider provider, Class<T> clazz, i
if (Waila.CLIENT_SIDE) {
assertLock();
assertPriority(priority);
warnTargetClass(provider, clazz);
entityOverride.add(clazz, provider, priority);
}
}
Expand All @@ -223,6 +227,7 @@ public <T> void addIcon(IEntityComponentProvider provider, Class<T> clazz, int p
if (Waila.CLIENT_SIDE) {
assertLock();
assertPriority(priority);
warnTargetClass(provider, clazz);
entityIcon.add(clazz, provider, priority);
}
}
Expand All @@ -232,6 +237,7 @@ public <T> void addComponent(IEntityComponentProvider provider, TooltipPosition
if (Waila.CLIENT_SIDE) {
assertLock();
assertPriority(priority);
warnTargetClass(provider, clazz);
entityComponent.get(position).add(clazz, provider, priority);
}
}
Expand All @@ -241,6 +247,7 @@ public <T> void addComponent(IEntityComponentProvider provider, TooltipPosition
public <T, E extends Entity> void addEntityData(IDataProvider<E> provider, Class<T> clazz, int priority) {
assertLock();
assertPriority(priority);
warnTargetClass(provider, clazz);
entityData.add(clazz, (IDataProvider<Entity>) provider, priority);
}

Expand Down Expand Up @@ -314,4 +321,10 @@ private void assertPriority(int priority) {
"Priority must be equals or more than 0");
}

private void warnTargetClass(Object object, Class<?> clazz) {
if (Waila.DEV && clazz.isInstance(object)) {
LOG.warn("The target class {} is the same as the provider class, this is probably an error", clazz.getSimpleName());
}
}

}

0 comments on commit 73de725

Please sign in to comment.