Jump to content

Help with modloader registered entities


biouxtai

Recommended Posts

I am working on a mod that when an op issues a command, I would like to get a list of all the entities that have been registered through modloader using the registerEntityId call.  Specifically, I am looking to get their classname and the string identifier that was passed to write out to a datafile.  I have been looking through the code and I am probably missing it, but I can't seem to find a function like getRegisiteredEntities that would return me a list.  I don't want to get the list out of the world as the entities that are available may not have all spawned.  I would like to be able to be mod agnostic in this so that *any* mod that registers a new entity will have it show up in this list.

 

I currently run a bukkit server with forge.  When I can my event handler and try to access the mobs names through the bukkit api they always come back as null.  I can get an unique id out of that api, but no other information.  As the modloader getUniqueId function will return different ids per server, this function is designed to map out the class names without having to resort to IDs to make config of my mod easier.

 

The ultimate goal is to get the list of names/classes so I can put them into a config file for my mod that will be used to make comparisons to entity events allowing for custom entities.

 

Thanks for any info.

 

~b

Link to comment
Share on other sites

hey OvermindDL1,

  Thanks for replying.  The Classname is exactly what I am looking for.  More specifically a usable classname.  I tried the reflection idea, but that didn't work so well to determine of the class was an instanceof EntityLiving.  I kept getting cannot convert from Class<? extends Entity> to EntityLiving.. really aggravating.  This is what I wound up doing.  It works, but probably not the cleanest.  What I was hoping for was a simple way of getting the living entities by the name they are registered with in ModLoader.

 

For example, Mo'Creatures (only mod I have that adds creatures right now) using call like this:

ModLoader.registerEntityID(MoCEntityHorse.class, "Horse", ModLoader.getUniqueEntityId());

 

I would live it if there was a function that allowed me to request the entities that are based off of EntityLiving like:

 

ModLoader.getRegisteredEntities(<baseClass>);

 

and it returns a list of strings that would be the second parameter to the register function of only the entities that are based off the class I pass in.

 

My code is below.  It works, but I am not happy with it and would like to improve it.

 

Iterator<Entry<String, Class<? extends Entity>>> iter = EntityTypes.getEntityToClassMapping().entrySet().iterator();

while (iter.hasNext()) {

Map.Entry<String, Class<? extends Entity>> mapEntry = iter.next();

eName = mapEntry.getKey();

try {

Class<?> c = mapEntry.getValue().getSuperclass();

boolean done = false;

eClass = "F";

while (!done) {

String en = c.getSimpleName();

if (en.equalsIgnoreCase("LivingEntity") ||en.equalsIgnoreCase("EntityLiving")){

eClass = "T";

done = true;

this.getLogger().info("Entity: " + eName);

} else if (en.equalsIgnoreCase("Entity") && !eName.equalsIgnoreCase("fakeBlock"))

done = true;

 

c = c.getSuperclass();

if (c.getCanonicalName().equalsIgnoreCase("java.lang.object"))

done = true;

}

} catch (Exception ex) {

this.getLogger().info("Exception! "+ex.getMessage());

}

}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Here's the link: https://mclo.gs/7L5FibL Here's the link: https://mclo.gs/7L5FibL
    • Also the mod "Connector Extras" modifies Reach-entity-attributes and can cause fatal errors when combined with ValkrienSkies mod. Disable this mod and continue to use Syntra without it.
    • Hi everyone. I was trying modify the vanilla loot of the "short_grass" block, I would like it drops seeds and vegetal fiber (new item of my mod), but I don't found any guide or tutorial on internet. Somebody can help me?
    • On 1.20.1 use ValkrienSkies mod version 2.3.0 Beta 1. I had the same issues as you and it turns out the newer beta versions have tons of unresolved incompatibilities. If you change the version you will not be required to change the versions of eureka or any other additions unless prompted at startup. This will resolve Reach-entity-attributes error sound related error and cowardly errors.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.