Jump to content

[SOLVED] [1.16.2] Unknown Problems With Creating Basic Entity


BlueMond

Recommended Posts

I've been working on my first implementation of a basic Entity. I pulled from a few different sources on trying to make sure I register and implement everything properly, but on my first attempt using it in the client, I get a crash, once mcforge actually completes loading the client, that has inexplicable origins to me. In the debug client, I can also see a bunch of errors popping up before the crash happens, which also seem to have nothing to do with my mod, and yet never happened until I tried to create a basic entity. My model class was mostly made by Blockbench. I will include code snippets pertinent to the entity. *Please note you may see items related to "Mana and Artifice", this is just a dependency of my mod, since it's being developed as an addon.

 

Sorry for all the code, but I really don't know where this could be coming from. It's not my workspace either because I've tried rebuilding my workspace and also attempting to run an actual client using the built jar. It may also seem like it's coming from Mana and Artifice, but I assure you, it's not. Here is a link to the crash report if that may also help: https://pastebin.com/hifFKCQu

 

Let me know if I may have left something out that is needed to see where the problem might be.

 

Entity class (just basic implementation, not fully finished)

 


public class EmpowermentEntity extends Entity {

    private static final String KEY_POTIONSTACK = "itemstack";
    private static final String KEY_EFFECT = "effect";

    private ItemStack potionStack;
    private Effect effect;

    public EmpowermentEntity(EntityType<? extends EmpowermentEntity> entityTypeIn, World worldIn) {
        super(entityTypeIn, worldIn);
    }

    @Override
    protected void registerData() {

    }

    @Override
    protected void readAdditional(CompoundNBT compound) {

    }

    @Override
    protected void writeAdditional(CompoundNBT compound) {

    }

    @Override
    public IPacket<?> createSpawnPacket() {
        return NetworkHooks.getEntitySpawningPacket(this);
    }

    @Override
    public boolean canBeCollidedWith(){
        return false;
    }

    @Override
    protected boolean canBeRidden(Entity entityIn){
        return false;
    }

    @Override
    public boolean canBeAttackedWithItem(){
        return false;
    }

}

 

 

 

Mod class constructor

 

public BlueMagic() {
    // Register ourselves for server and other game events we are interested in
    IEventBus eventBus = MinecraftForge.EVENT_BUS;

    EntityInit.ENTITY_TYPES.register(eventBus);

    eventBus.register(this);
}

 

 

 

EntityInit class (includes deferred register)

 


public class EntityInit {
    public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, BlueMagic.MOD_ID);

    public static final RegistryObject<EntityType<EmpowermentEntity>> EMPOWERMENT_ENTITY =
            ENTITY_TYPES
                    .register("empowerment_entity",
                            () -> EntityType.Builder.create(EmpowermentEntity::new, EntityClassification.MISC)
                                    .setShouldReceiveVelocityUpdates(false)
                                    .disableSummoning()
                                    .build(new ResourceLocation(BlueMagic.MOD_ID, "empowerment_entity").toString()));
    
}

 

 

 

ClientEventBusSubscriber class

 

@Mod.EventBusSubscriber(modid = BlueMagic.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientEventBusSubscriber {

    @SubscribeEvent
    public static void clientSetupEvent(FMLClientSetupEvent event){
        RenderingRegistry.registerEntityRenderingHandler(EntityInit.EMPOWERMENT_ENTITY.get(), EmpowermentEntityRenderer::new);

    }
}

 

 

 

Renderer class

 

public class EmpowermentEntityRenderer extends EntityRenderer<EmpowermentEntity> {

    protected static final ResourceLocation TEXTURE = new ResourceLocation(BlueMagic.MOD_ID, "textures/entity/empowerment_entity.png");

    public EmpowermentEntityRenderer(EntityRendererManager renderManager) {
        super(renderManager);
    }

    @Override
    public ResourceLocation getEntityTexture(EmpowermentEntity entity){
        return TEXTURE;
    }
}

 

 

 

 

Model class

 

public class EmpowermentEntityModel<T extends EmpowermentEntity> extends EntityModel<T> {
    private final ModelRenderer Body;
    private final ModelRenderer Torso;
    private final ModelRenderer Legs;
    private final ModelRenderer Leg1;
    private final ModelRenderer Leg2;
    private final ModelRenderer Leg3;
    private final ModelRenderer Leg4;

    public EmpowermentEntityModel() {
        textureWidth = 32;
        textureHeight = 32;

        Body = new ModelRenderer(this);
        Body.setRotationPoint(0.0F, 24.0F, 0.0F);


        Torso = new ModelRenderer(this);
        Torso.setRotationPoint(0.0F, 0.0F, 0.0F);
        Body.addChild(Torso);
        Torso.setTextureOffset(0, 0).addBox(-3.0F, -11.0F, -3.0F, 6.0F, 6.0F, 6.0F, 0.0F, false);

        Legs = new ModelRenderer(this);
        Legs.setRotationPoint(0.0F, 0.0F, 0.0F);
        Body.addChild(Legs);


        Leg1 = new ModelRenderer(this);
        Leg1.setRotationPoint(0.0F, 0.0F, 0.0F);
        Legs.addChild(Leg1);


        Leg2 = new ModelRenderer(this);
        Leg2.setRotationPoint(0.0F, 0.0F, 0.0F);
        Legs.addChild(Leg2);


        Leg3 = new ModelRenderer(this);
        Leg3.setRotationPoint(0.0F, 0.0F, 0.0F);
        Legs.addChild(Leg3);


        Leg4 = new ModelRenderer(this);
        Leg4.setRotationPoint(0.0F, 0.0F, 0.0F);
        Legs.addChild(Leg4);

    }

    @Override
    public void setRotationAngles(T entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {

    }


    @Override
    public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
        Body.render(matrixStack, buffer, packedLight, packedOverlay);
    }

    public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
        modelRenderer.rotateAngleX = x;
        modelRenderer.rotateAngleY = y;
        modelRenderer.rotateAngleZ = z;
    }
}
Edited by BlueMond
Link to comment
Share on other sites

What vemerion said will work because deferred registers need to be registered on the Mod bus...while with this code:

IEventBus eventBus = MinecraftForge.EVENT_BUS;
EntityInit.ENTITY_TYPES.register(eventBus);

you are registering your deferred register to the Forge event bus, which is where in-game events are posted. Registry events (for items, blocks, entities etc....) happen during the loading of the game and are posted on the mod bus (which is different from the forge bus), which can be retrieved with:

FMLJavaModLoadingContext.get().getModEventBus()

 

  • Like 1

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

Ah okay, I see what youre saying. I'll make that change and give it a try. Thanks vemerion and beethoven.

 

EDIT: Oh boy, it still seems to be having the same exact issue. So I guess it wasnt coming from my entity as expected. I found a typo in one of my registries I was sending to the dependency mod that also had to do with the new entity, but not directly. Fixing that seems to allow it to load properly. Oops

 

Thanks for that though because that would have probably been my next problem regardless of this issue

 

Edited by BlueMond
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



×
×
  • Create New...

Important Information

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