diff --git a/src/api/java/baritone/api/command/datatypes/EntityClassById.java b/src/api/java/baritone/api/command/datatypes/EntityClassById.java index aed7cdf41..becc649c1 100644 --- a/src/api/java/baritone/api/command/datatypes/EntityClassById.java +++ b/src/api/java/baritone/api/command/datatypes/EntityClassById.java @@ -32,7 +32,19 @@ public enum EntityClassById implements IDatatypeFor> { public Class get(IDatatypeContext ctx) throws CommandException { ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString()); Class entity; - if ((entity = EntityList.REGISTRY.getObject(id)) == null) { + try { + entity = EntityList.REGISTRY.getObject(id); + } catch(NoSuchFieldError e) { + // Forge removes EntityList.REGISTRY field and provides the getClass method as a replacement + // See https://github.com/MinecraftForge/MinecraftForge/blob/1.12.x/patches/minecraft/net/minecraft/entity/EntityList.java.patch + try { + entity = (Class) EntityList.class.getMethod("getClass", ResourceLocation.class).invoke(null, id); + } catch (Exception ex) { + throw new RuntimeException("EntityList.REGISTRY does not exist and failed to call the Forge-replacement method", ex); + } + } + + if (entity == null) { throw new IllegalArgumentException("no entity found by that id"); } return entity;