Fix entitytype lookup for old minecraft versions

This commit is contained in:
fullwall 2024-10-27 18:51:31 +08:00
parent 172976e3d6
commit 158d4d328c
15 changed files with 17 additions and 19 deletions

View File

@ -1099,9 +1099,9 @@ public class NMSImpl implements NMSBridge {
public void registerEntityClass(Class<?> clazz, Object raw) {
if (ENTITY_REGISTRY == null)
return;
EntityTypes<?> type = (EntityTypes<?>) raw;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
MinecraftKey key = ENTITY_REGISTRY.getKey(type);
if (key == null) {
continue;

View File

@ -25,7 +25,7 @@ import net.minecraft.server.v1_14_R1.World;
public abstract class MobEntityController extends AbstractEntityController {
private final Class<?> clazz;
protected MobEntityController(Class<?> clazz) {NMS.registerEntityClass(clazz, NMSImpl.getEntityType(clazz));
protected MobEntityController(Class<?> clazz) {NMS.registerEntityClass(clazz, null);
this.clazz = clazz;
}

View File

@ -1142,9 +1142,9 @@ public class NMSImpl implements NMSBridge {
public void registerEntityClass(Class<?> clazz, Object raw) {
if (ENTITY_REGISTRY == null)
return;
EntityTypes<?> type = (EntityTypes<?>) raw;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
MinecraftKey key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null) {
continue;

View File

@ -25,7 +25,7 @@ import net.minecraft.server.v1_15_R1.World;
public abstract class MobEntityController extends AbstractEntityController {
private final Class<?> clazz;
protected MobEntityController(Class<?> clazz) {NMS.registerEntityClass(clazz, NMSImpl.getEntityType(clazz));
protected MobEntityController(Class<?> clazz) {NMS.registerEntityClass(clazz, null);
this.clazz = clazz;
}

View File

@ -1159,9 +1159,9 @@ public class NMSImpl implements NMSBridge {
public void registerEntityClass(Class<?> clazz, Object raw) {
if (ENTITY_REGISTRY == null)
return;
EntityTypes<?> type = (EntityTypes<?>) raw;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
net.minecraft.server.v1_15_R1.EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
MinecraftKey key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null) {
continue;

View File

@ -25,7 +25,7 @@ import net.minecraft.server.v1_16_R3.World;
public abstract class MobEntityController extends AbstractEntityController {
private final Class<?> clazz;
protected MobEntityController(Class<?> clazz) {NMS.registerEntityClass(clazz, NMSImpl.getEntityType(clazz));
protected MobEntityController(Class<?> clazz) {NMS.registerEntityClass(clazz, null);
this.clazz = clazz;
}

View File

@ -1182,9 +1182,9 @@ public class NMSImpl implements NMSBridge {
public void registerEntityClass(Class<?> clazz, Object raw) {
if (ENTITY_REGISTRY == null)
return;
EntityTypes<?> type = (EntityTypes<?>) raw;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
net.minecraft.server.v1_16_R3.EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
MinecraftKey key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null) {
continue;

View File

@ -25,7 +25,7 @@ public abstract class MobEntityController extends AbstractEntityController {
private final Class<?> clazz;
protected MobEntityController(Class<?> clazz) {
NMS.registerEntityClass(clazz, NMSImpl.getEntityType(clazz));
NMS.registerEntityClass(clazz, null);
this.clazz = clazz;
}

View File

@ -1188,9 +1188,9 @@ public class NMSImpl implements NMSBridge {
public void registerEntityClass(Class<?> clazz, Object raw) {
if (ENTITY_REGISTRY == null)
return;
net.minecraft.world.entity.EntityType<?> type = (net.minecraft.world.entity.EntityType) raw;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
net.minecraft.world.entity.EntityType<?> type = ENTITY_REGISTRY.findType(search);
ResourceLocation key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null) {
continue;

View File

@ -25,7 +25,7 @@ public abstract class MobEntityController extends AbstractEntityController {
private final Class<?> clazz;
protected MobEntityController(Class<?> clazz) {
NMS.registerEntityClass(clazz, NMSImpl.getEntityType(clazz));
NMS.registerEntityClass(clazz, null);
this.clazz = clazz;
}

View File

@ -1197,9 +1197,9 @@ public class NMSImpl implements NMSBridge {
public void registerEntityClass(Class<?> clazz, Object raw) {
if (ENTITY_REGISTRY == null)
return;
net.minecraft.world.entity.EntityType<?> type = (net.minecraft.world.entity.EntityType) raw;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
net.minecraft.world.entity.EntityType<?> type = ENTITY_REGISTRY.findType(search);
ResourceLocation key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null) {
continue;

View File

@ -25,7 +25,7 @@ public abstract class MobEntityController extends AbstractEntityController {
private final Class<?> clazz;
protected MobEntityController(Class<?> clazz) {
NMS.registerEntityClass(clazz, NMSImpl.getEntityType(clazz));
NMS.registerEntityClass(clazz, null);
this.clazz = clazz;
}

View File

@ -1336,9 +1336,9 @@ public class NMSImpl implements NMSBridge {
public void registerEntityClass(Class<?> clazz, Object raw) {
if (ENTITY_REGISTRY == null)
return;
net.minecraft.world.entity.EntityType<?> type = (net.minecraft.world.entity.EntityType) raw;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
net.minecraft.world.entity.EntityType<?> type = ENTITY_REGISTRY.findType(search);
ResourceLocation key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null) {
continue;

View File

@ -25,15 +25,14 @@ public abstract class MobEntityController extends AbstractEntityController {
private final Class<?> clazz;
protected MobEntityController(Class<?> clazz) {
NMS.registerEntityClass(clazz, NMSImpl.getEntityType(clazz));
NMS.registerEntityClass(clazz, null);
this.clazz = clazz;
}
@Override
protected Entity createEntity(Location at, NPC npc) {
EntityType<?> type = NMSImpl.getEntityType(clazz);
net.minecraft.world.entity.Entity entity = createEntityFromClass(type, ((CraftWorld) at.getWorld()).getHandle(),
npc);
net.minecraft.world.entity.Entity entity = createEntityFromClass(NMSImpl.getEntityType(clazz),
((CraftWorld) at.getWorld()).getHandle(), npc);
if (entity instanceof Mob) {
NMSImpl.clearGoals(npc, ((Mob) entity).goalSelector, ((Mob) entity).targetSelector);
Mob mob = (Mob) entity;

View File

@ -1001,7 +1001,6 @@ public class NMSImpl implements NMSBridge {
}
private void loadEntityTypes() {
EntityControllers.setEntityControllerForType(EntityType.ALLAY, AllayController.class);
EntityControllers.setEntityControllerForType(EntityType.AREA_EFFECT_CLOUD, AreaEffectCloudController.class);
EntityControllers.setEntityControllerForType(EntityType.ARMADILLO, ArmadilloController.class);
@ -1368,9 +1367,9 @@ public class NMSImpl implements NMSBridge {
public void registerEntityClass(Class<?> clazz, Object raw) {
if (ENTITY_REGISTRY == null)
return;
net.minecraft.world.entity.EntityType<?> type = (net.minecraft.world.entity.EntityType) raw;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
net.minecraft.world.entity.EntityType<?> type = ENTITY_REGISTRY.findType(search);
ResourceLocation key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null)
continue;