https://github.com/squiddev/forgelint
Static analysis for Forge mods
https://github.com/squiddev/forgelint
Last synced: about 1 year ago
JSON representation
Static analysis for Forge mods
- Host: GitHub
- URL: https://github.com/squiddev/forgelint
- Owner: SquidDev
- License: bsd-3-clause
- Created: 2017-09-11T13:57:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-24T10:07:31.000Z (about 8 years ago)
- Last Synced: 2025-02-12T06:21:20.165Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 67.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# forgelint
Primitive static analysis for Forge mods
## Features
- Warn when using client-/server-only functionality, when not annotated with `@SideOnly`.
## Example
```java
public class ExampleItem extends Item {
@SideOnly(Side.CLIENT)
private RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
// ^
// warning: Using a CLIENT class, but this could be either server or client
@Nonnull
@Override
public String getUnlocalizedName(ItemStack stack) {
if (hasEffect(stack)) {
// ^
// warning: Using a CLIENT method, but this could be either server or client
return "item." + getUnlocalizedName() + ".effect";
} else {
return "item." + getUnlocalizedName() + ".no_effect";
}
}
@Nonnull
@Override
public ActionResult onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
if (world.isRemote) {
world.spawnParticle(EnumParticleTypes.CRIT_MAGIC, false, player.posX, player.posY, player.posZ, 0, 0, 0);
// No warning: world.isRemote acts as a guard
}
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
@Override
public boolean shouldRotateAroundWhenRendering() {
// ^
// Note: Overriding a CLIENT method, but no @SideOnly annotation
return true;
}
}
```
## Usage
Add this to your `build.gradle`:
```groovy
repositories { maven { url 'https://dl.bintray.com/squiddev/maven' } }
dependencies { provided "org.squiddev:forgelint:0.1.0" }
compileJava { options.compilerArgs += ["-Xplugin:ForgeLint"] }
```
## Planned features
- Detect non-server-thread manipulation of the world.
- Smarter control flow handling, meaning we don't require `@SideOnly` on private methods.
## See also
The [MinecraftDev](https://github.com/minecraft-dev/MinecraftDev) plugin also provides a sidedness checker. The plugin
is slightly more lenient than ForgeLint in some of its warnings, but is integrated into the editor which provides a
nicer experience.