Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi!
I want to render an entity with a json file, but when i spawn the entity it is like invisible.

The Main File: https://pastebin.com/Asa5Tymq

The Renderer Classes: https://pastebin.com/Vag0YmDZhttps://pastebin.com/iD14HzvHhttps://pastebin.com/beV8gxCc

Where i spawn The Entity:

@Override
    public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
        if (world instanceof ServerWorld) {
            int ammo = this.getAmmo(player);
            if (ammo > 0) {
                //this.removeAmmo(player);
                BulletEntity bullet = new BulletEntity(world, player);
                bullet.setBaseDamage(this.getDamage());
                bullet.setOwner(player);
                bullet.setPos(player.getX(), player.getY(), player.getZ());
                bullet.setDeltaMovement(1, 1, 1);
                world.addFreshEntity(bullet);
                return ActionResult.consume(player.inventory.getSelected());
            }
        }
        return super.use(world, player, hand);
    }

The Item associated with the entity (the bullet) has no particular code, and the model shows fine.

Edited by Yurim64

  • Author

Ok so, after a couple of hours of debugging, i found out that the IBakedModel of the Bullet is null.

This is what i do for adding the model:

@SubscribeEvent
    public static void onModelRegister(ModelRegistryEvent event) {
        System.out.println("Register model");
        ModelLoader.addSpecialModel(new ResourceLocation(GunMod.MODID, "item/bullet"));
    }

The method is called correctly, and there is no error when i add the Special Model. but then it shows to be null.
Anyone can help me?

 

I also changed the Registry Type of my item in this way:
 

private void setupClient(FMLClientSetupEvent event) {
        RenderingRegistry.registerEntityRenderingHandler(ModEntities.BULLET.get(), manager -> new SpriteRenderer<>(manager, Minecraft.getInstance().getItemRenderer()));
    }

I don't know if this is the correct way

Edited by Yurim64

So, why are you trying to make the bullet json separate from the item itself? You seem to be under the assumption that #addSpecialModel attaches the model to your item. It just attaches the model to general ModelManager. However, this seems completely unnecessary as you could just specify this as the item model.

  • Author

The bullet is like an Arrow.
I have a BulletEntity and a BulletItem
The Bullet item shows perfectly, and has no problem to load the model from the json.
But the BulletEntity is invisible, I don't know how to associate the item model with the entity.

I tried to use the SpriteRenderer, but the Entity is still insisible as it has no model.

What can i do?

32 minutes ago, Yurim64 said:

But the BulletEntity is invisible, I don't know how to associate the item model with the entity.

I just told you there is no association. The item model manager has no concept of any models that are not part of an item. If you want to add a special model, you have to pull it directly from the ModelManager and not from the ItemModelMesher.

33 minutes ago, Yurim64 said:

The bullet is like an Arrow.

This doesn't explain why it can't be part of the item. You could just use the gui model for the gui transform type and specify the other json mdoel as the first person right/left hand using the perspective model json. The notion of having a completely separate model from the item being thrown imo is outdated and should be respectively attached to the item render itself.

  • Author

Ok, so how can i do that?
There is some tutorial that explain how to render an Entity ad an Item?

  • Author

The only thing I can tell you is that I don't understand why if I do this:

private void setupClient(FMLClientSetupEvent event) {
        RenderingRegistry.registerEntityRenderingHandler(ModEntities.BULLET.get(), manager -> new BulletRender<>(manager));
    }

And then I generate my entity, It does not call the render method inside the BulletRenderer class which extends EntityRenderer.
Why? Is there another way? What I miss??

Otherwise the entity works.
I can use it, I can kill the mobs as I have programmed it, but it is as if it did not have a registered renderer. I don't really understand ...

Edited by Yurim64

1 hour ago, Yurim64 said:

Ok, so how can i do that?

Look at a reference of the perspectives test.

58 minutes ago, Yurim64 said:

And then I generate my entity, It does not call the render method inside the BulletRenderer class which extends EntityRenderer.
Why? Is there another way? What I miss??

If that's the case, you're probably not overriding the render method. Put an override annotation on the method. If it fails, find the correct method signature and adjust.

  • Author

This is the Renderer Class:

public class BulletRender<T extends BulletEntity> extends EntityRenderer<T> {

    public BulletRender(EntityRendererManager manager) {
        super(manager);
    }

    @Override
    public void render(T entity, float f1, float f2, MatrixStack matrix, IRenderTypeBuffer buffer, int light) {
        super.render(entity, f1, f2, matrix, buffer, light);
        System.out.println("Render");
        RenderUtil.renderColoredModel(SpecialModels.BULLET.getModel(), ItemCameraTransforms.TransformType.NONE, false, matrix, buffer, light, OverlayTexture.NO_OVERLAY);
    }

    @Override
    public boolean shouldRender(T p_225626_1_, ClippingHelper p_225626_2_, double p_225626_3_, double p_225626_5_, double p_225626_7_) {
        return true;
    }

    @Override
    public ResourceLocation getTextureLocation(T p_110775_1_) {
        return null;
    }
}

The print is not shown on the console, as if the method is never invoked.

 

Now i try with the perspective, thanks

  • Author

Ok so, i tried to use the perspctive, but it works only for the item bullet.

Again, the BulletEntity is not rendered, And I don't know what to do or how to do it anymore.

  • Author

The Item:

public class Bullet extends Item {

    public Bullet() {
        super(new Item.Properties().tab(ItemGroup.TAB_COMBAT));
    }

}

The Entity:

public class BulletEntity extends DamagingProjectileEntity implements IRendersAsItem {

    private static final ItemStack STACK = new ItemStack(ModItems.BULLET.get());

    private int damage;

    public BulletEntity(World world) {
        super(ModEntities.BULLET.get(), world);
    }

    @Override
    public ItemStack getItem() {
        return STACK;
    }

    @Override
    public void setOwner(@Nullable Entity owner) {
        super.setOwner(owner);
    }

    @Override
    protected void onHitBlock(BlockRayTraceResult p_230299_1_) {
        super.onHitBlock(p_230299_1_);
        if (!this.level.isClientSide) {
            this.remove();
        }
    }

    @Override
    protected void onHitEntity(EntityRayTraceResult entityRayTraceResult) {
        super.onHitEntity(entityRayTraceResult);
        if (!this.level.isClientSide) {
            Entity entity = entityRayTraceResult.getEntity();
            DamageSource source = new DamageSource("bullet");
            source = source.setProjectile();
            entity.hurt(source, this.damage);
            this.remove();
        }
    }

    @Override
    public void tick() {
        super.tick();
    }

    @Override
    public void addAdditionalSaveData(CompoundNBT nbt) {
        super.addAdditionalSaveData(nbt);
        nbt.putInt("bulletDamage", this.damage);
    }

    @Override
    public void readAdditionalSaveData(CompoundNBT nbt) {
        super.readAdditionalSaveData(nbt);
        if (nbt.contains("bulletDamage")) {
            this.damage = nbt.getInt("bulletDamage");
        }
    }

    public void setDamage(int damage) {
        this.damage = damage;
    }

    @Override
    public IPacket<?> getAddEntityPacket() {
        return super.getAddEntityPacket();
    }
}

The Entity Renderer:

public class BulletRender<T extends BulletEntity> extends EntityRenderer<T> {

    public BulletRender(EntityRendererManager manager) {
        super(manager);
    }

    @Override
    public void render(T entity, float f1, float f2, MatrixStack matrix, IRenderTypeBuffer buffer, int light) {
        super.render(entity, f1, f2, matrix, buffer, light);
        System.out.println("Render");
        RenderUtil.renderColoredModel(SpecialModels.BULLET.getModel(), ItemCameraTransforms.TransformType.NONE, false, matrix, buffer, light, OverlayTexture.NO_OVERLAY);
    }

    @Override
    public boolean shouldRender(T p_225626_1_, ClippingHelper p_225626_2_, double p_225626_3_, double p_225626_5_, double p_225626_7_) {
        return true;
    }

    @Override
    public ResourceLocation getTextureLocation(T p_110775_1_) {
        return null;
    }
}

Tell me if you need something else.

1 hour ago, Yurim64 said:

@Override public IPacket<?> getAddEntityPacket() { return super.getAddEntityPacket(); }

Aha, this need to return NetworkHooks#getEntitySpawningPacket. Vanilla has hardcoded entries for non living entity types. As such, you need to set it to the custom packet so that the entity will spawn on the client and be rendered.

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.