From ed91e2aa7bdb73ddd1d88385aa28b7b58af386d6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 24 Aug 2020 22:19:28 +0200 Subject: [PATCH] Fix "#entity follow " under Forge One of the Forge patches removes EntityList.REGISTRY and provides the getClass method as a replacement. The fix is based on a similar one I found in WorldDownloader Closes #1376 (and duplicates: #1777 and #1815) --- .../api/command/datatypes/EntityClassById.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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;