Jump to content

Recommended Posts

Posted (edited)

Is there a way to "override" an entity's texture to something else without creating a "dummy" item when using ThrownItemRenderer? I tried creating a Renderer that extends it with a ResourceLocation override but this does not change the entity's 2D texture. Any help would be appreciated.

Render class:

public class BulletEntityRenderer extends ThrownItemRenderer {

    private static final ResourceLocation TEXTURE = new ResourceLocation(ExampleMod.MOD_ID, "textures/entity/bullet.png");

    public BulletEntityRenderer(EntityRendererProvider.Context context) {
        super(context);
    }

    @Override
    public ResourceLocation getTextureLocation(Entity entity) {
        return TEXTURE;
    }
}

Render registry:

public class ModRender {

    public static void registerRender() {
        EntityRenderers.register(ExampleMod.BULLET, BulletEntityRenderer::new);
    }
}

Entity class:

public class BulletEntity extends ThrowableItemProjectile {

    private float damage = 12.0F;
    private int pierceLevel = 0;
    private int ticksAlive = 0;
    private final int lifespan = 60;

    public BulletEntity(EntityType<BulletEntity> type, Level world) {
        super(type, world);
    }

    public BulletEntity(Player player, Level world, float damage, int pierceLevel) {
        super(ExampleMod.BULLET, player, world);
        this.damage = damage;
        this.pierceLevel = pierceLevel;
        this.setNoGravity(true);
    }

    public DamageSource causeBulletDamage(BulletEntity bullet, Entity attacker) {
        return (new IndirectEntityDamageSource("bullet", bullet, attacker)).setProjectile();
    }

    public void tick() {
        super.tick();

        Vec3 vec3d = this.getDeltaMovement();
        double d1 = vec3d.x;
        double d2 = vec3d.y;
        double d0 = vec3d.z;

        if (this.isInWater()) {
            this.level.addParticle(ParticleTypes.BUBBLE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0);
        } else {
            this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0);
        }

        if (ticksAlive > lifespan) {
            this.discard();
        }
        ticksAlive++;
    }

    @Override
    protected void onHitEntity(EntityHitResult hitResult) {
        LivingEntity target = (LivingEntity) hitResult.getEntity();
        Entity shooter = getOwner();
        double armor = target.getArmorValue() * (1 - (0.2 * pierceLevel));
        double toughness = target.getAttribute(Attributes.ARMOR_TOUGHNESS).getValue();
        float finalDamage = (float) (damage * (1 - (Math.min(20, Math.max((armor / 5), armor - ((4 * damage) / (toughness + 8))))) / 25));
        target.hurt(causeBulletDamage(this, shooter).bypassArmor(), finalDamage);
    }
    
    @Override
    public Item getDefaultItem() {
        return ModItems.BULLET;
    }
}
Edited by CrackedScreen
Marked as solved.
Posted
6 hours ago, Luis_ST said:

which Entity? a vanilla Entity?

The entity I created uses the 2D item texture of itself when it spawns since it extends ThrowableItemProjectile, what I want to do is override/change this texture to something else in the renderer if this is possible.

6 hours ago, diesieben07 said:

Custom entities must override getAddEntityPacket and call NetworkHooks.getEntitySpawningPackets.

Entity renderers must be registered using EntityRenderersEvent.RegisterRenderers.

Did the following, but didn't have an effect on the texture (unless it isn't supposed to or I am still doing something incorrectly):

BulletEntity:

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

Main mod class:

@SubscribeEvent
public static void registerRenders(EntityRenderersEvent.RegisterRenderers event) {
	event.registerEntityRenderer(ExampleMod.BULLET, BulletEntityRenderer::new);
}

 

Posted (edited)

Init:

public static EntityType<BulletEntity> BULLET = EntityType.Builder.<BulletEntity>of(BulletEntity::new, MobCategory.MISC)
            .sized(0.5F, 0.5F)
            .setTrackingRange(4)
            .setUpdateInterval(20)
            .setShouldReceiveVelocityUpdates(true)
            .build(MOD_ID + ":bullet");

Entity spawn:
 

    @Override
    public void createProjectile(Player player, Level level, ItemStack stack) {
        int pierceLevel = EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.FIREPOWER, stack);
        if (!level.isClientSide) {
            BulletEntity bullet = new BulletEntity(player, level, getDamage(), pierceLevel);
            bullet.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F);
            level.addFreshEntity(bullet);
        }
    }
Edited by CrackedScreen
Posted

Swapped the entity to a RegistryObject, but now getting a constructor error in my Entity Class:
 

Cannot resolve constructor 'BulletEntity'

Registry:

public static final RegistryObject<EntityType<? extends BulletEntity>> BULLET = ENTITIES.register("bullet", () -> EntityType.Builder.of(BulletEntity::new, MobCategory.MISC)
            .sized(0.5F, 0.5F)
            .setShouldReceiveVelocityUpdates(true)
            .setTrackingRange(4)
            .setUpdateInterval(20)
            .build("bullet"));

Class constructors:

    public BulletEntity(EntityType<? extends BulletEntity> type, Level level) {
        super(type, level);
    }

    public BulletEntity(Level level, float damage, int pierceLevel) {
        super(ExampleMod.BULLET.get(), level);
        this.damage = damage;
        this.pierceLevel = pierceLevel;
        this.setNoGravity(true);
    }

The second constructor is used elsewhere to create the projectile in the world, yet the IDE will not stop throwing an error until it is removed or commented out.

I ask again if it is possible to change a 2D item texture from a projectile extending ThrowableProjectileEntity using a custom render (extending from ThrownItemRenderer), as that was my original question.

Posted

Bumping topic again, as I have gotten the projectile to register properly and even print out the amount of ticks it is alive, yet doesn't "spawn" in the world when it should be.

Spawning code:

    @Override
    public void createProjectile(Player player, Level level, ItemStack stack) {
        int pierceLevel = EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.FIREPOWER, stack);
        if (!level.isClientSide) {
            BulletEntity bullet = new BulletEntity(level, getDamage(), pierceLevel);
            bullet.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F);
            level.addFreshEntity(bullet);
        }
    }

BulletEntity:
 

public class BulletEntity extends ThrowableItemProjectile {

    private float damage = 12.0F;
    private int pierceLevel = 0;
    private int ticksAlive = 0;
    private final int lifespan = 60;

    public BulletEntity(EntityType<? extends BulletEntity> type, Level level) {
        super(type, level);
    }

    public BulletEntity(Level level, float damage, int pierceLevel) {
        super(ExampleMod.BULLET.get(), level);
        this.damage = damage;
        this.pierceLevel = pierceLevel;
        this.setNoGravity(true);
    }

    public DamageSource causeBulletDamage(BulletEntity bullet, Entity attacker) {
        return (new IndirectEntityDamageSource("bullet", bullet, attacker)).setProjectile();
    }

    public void tick() {
        super.tick();

        Vec3 vec3d = this.getDeltaMovement();
        double d1 = vec3d.x;
        double d2 = vec3d.y;
        double d0 = vec3d.z;

        if (this.isInWater()) {
            this.level.addParticle(ParticleTypes.BUBBLE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0);
        } else {
            this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0);
        }

        if (ticksAlive > lifespan) {
            this.discard();
        }
        ticksAlive++;
    }

    @Override
    protected void onHitEntity(EntityHitResult hitResult) {
        LivingEntity target = (LivingEntity) hitResult.getEntity();
        Entity shooter = getOwner();
        double armor = target.getArmorValue() * (1 - (0.2 * pierceLevel));
        double toughness = target.getAttribute(Attributes.ARMOR_TOUGHNESS).getValue();
        float finalDamage = (float) (damage * (1 - (Math.min(20, Math.max((armor / 5), armor - ((4 * damage) / (toughness + 8))))) / 25));
        target.hurt(causeBulletDamage(this, shooter).bypassArmor(), finalDamage);
    }

    @Override
    public Item getDefaultItem() {
        return ModItems.BULLET;
    }

    public Packet<?> getAddEntityPacket() {
        return NetworkHooks.getEntitySpawningPacket(this);
    }
}

Registry:

public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, MOD_ID);

public static final RegistryObject<EntityType<BulletEntity>> BULLET = ENTITIES.register("bullet", () -> EntityType.Builder.<BulletEntity>of(BulletEntity::new, MobCategory.MISC)
            .sized(0.5F, 0.5F)
            .setShouldReceiveVelocityUpdates(true)
            .setTrackingRange(4)
            .setUpdateInterval(20)
            .build("bullet"));
  
public ExampleMod() {
	ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
	MinecraftForge.EVENT_BUS.register(this);
}

 

Posted

Fixed the spawn location problem, though the Item texture override I specified in my BulletRenderer isn't being used. Is it possible to override entity textures when extending from ThrownItemRenderer, or will I have to create an entirely new renderer from scratch?

  • CrackedScreen changed the title to [Solved][1.18] ThrownItemRenderer texture override

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

    • New users at Temu receive a $100 discount on orders over $100 Use the code [aci789589] during checkout to get Temu Coupon Code $100 off For New Users. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. Temu 100% Off coupon code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. You can get a$100 bonus plus 30% off any purchase at Temu with the$100 Coupon Bundle at Temu if you sign up with the referral code [aci789589] and make a first purchase of$50 or more. The Temu $100 Off coupon code (aci789589) will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes Temu offers $100 Off Coupon Code “aci789589” for First Time Users. Yes, Temu offers $100 off coupon code {aci789589} for first-time users. You can get a $100 bonus plus 100% off any purchase at Temu with the $100 Coupon Bundle if you sign up with the referral code [aci789589] and make a first purchase of $100 or more. If you are who wish to join Temu, then you should use this exclusive Temu coupon code $100 off (aci789589) and get $100 off on your purchase with Temu. You can get a $100 discount with Temu coupon code {aci789589}. This exclusive offer is for existing customers and can be used for a $100 reduction on your total purchase. Enter coupon code {aci789589} at checkout to avail of the discount. You can use the code {aci789589} to get a $100 off Temu coupon as a new customer. Apply this Temu coupon code $100 off (aci789589) to get a $100 discount on your shopping with Temu. If you’re a first-time user and looking for a Temu coupon code $100 first time user(aci789589) then using this code will give you a flat $100 Off and a 90% discount on your Temu shopping. Temu $100% Off Coupon Code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Temu coupon code$100off-{aci789589} Temu coupon code -{aci789589} Temu coupon code$50 off-{aci789589} Temu Coupon code [aci789589] for existing users can get up to 50% discount on product during checkout. Temu Coupon Codes for Existing Customers-aci789589 Temu values its loyal customers and offers various promo codes, including the Legit Temu Coupon Code (aci789589]) or (aci789589), which existing users can use. This ensures that repeat shoppers can also benefit from significant discounts on their purchases. Keep an eye out for special promotions and offers that are periodically available to enhance your shopping experience.
    • New users at Temu receive a $100 discount on orders over $100 Use the code [aci789589] during checkout to get Temu Coupon Code $100 off For New Users. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. Temu 100% Off coupon code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. You can get a$100 bonus plus 30% off any purchase at Temu with the$100 Coupon Bundle at Temu if you sign up with the referral code [aci789589] and make a first purchase of$50 or more. The Temu $100 Off coupon code (aci789589) will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes Temu offers $100 Off Coupon Code “aci789589” for First Time Users. Yes, Temu offers $100 off coupon code {aci789589} for first-time users. You can get a $100 bonus plus 100% off any purchase at Temu with the $100 Coupon Bundle if you sign up with the referral code [aci789589] and make a first purchase of $100 or more. If you are who wish to join Temu, then you should use this exclusive Temu coupon code $100 off (aci789589) and get $100 off on your purchase with Temu. You can get a $100 discount with Temu coupon code {aci789589}. This exclusive offer is for existing customers and can be used for a $100 reduction on your total purchase. Enter coupon code {aci789589} at checkout to avail of the discount. You can use the code {aci789589} to get a $100 off Temu coupon as a new customer. Apply this Temu coupon code $100 off (aci789589) to get a $100 discount on your shopping with Temu. If you’re a first-time user and looking for a Temu coupon code $100 first time user(aci789589) then using this code will give you a flat $100 Off and a 90% discount on your Temu shopping. Temu $100% Off Coupon Code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Temu coupon code$100off-{aci789589} Temu coupon code -{aci789589} Temu coupon code$50 off-{aci789589} Temu Coupon code [aci789589] for existing users can get up to 50% discount on product during checkout. Temu Coupon Codes for Existing Customers-aci789589 Temu values its loyal customers and offers various promo codes, including the Legit Temu Coupon Code (aci789589]) or (aci789589), which existing users can use. This ensures that repeat shoppers can also benefit from significant discounts on their purchases. Keep an eye out for special promotions and offers that are periodically available to enhance your shopping experience.
    • Try other builds: https://www.curseforge.com/minecraft/mc-mods/geckolib/files/all?page=1&pageSize=20&version=1.16.5&gameVersionTypeId=1 Currently, you are using build 96 - the latest one that I linked is build 106 So try 97 to 105  
    • New users at Temu receive a $100 discount on orders over $100 Use the code [aci789589] during checkout to get Temu Coupon Code $100 off For New Users. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. Temu 100% Off coupon code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. You can get a$100 bonus plus 30% off any purchase at Temu with the$100 Coupon Bundle at Temu if you sign up with the referral code [aci789589] and make a first purchase of$50 or more. The Temu $100 Off coupon code (aci789589) will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes Temu offers $100 Off Coupon Code “aci789589” for First Time Users. Yes, Temu offers $100 off coupon code {aci789589} for first-time users. You can get a $100 bonus plus 100% off any purchase at Temu with the $100 Coupon Bundle if you sign up with the referral code [aci789589] and make a first purchase of $100 or more. If you are who wish to join Temu, then you should use this exclusive Temu coupon code $100 off (aci789589) and get $100 off on your purchase with Temu. You can get a $100 discount with Temu coupon code {aci789589}. This exclusive offer is for existing customers and can be used for a $100 reduction on your total purchase. Enter coupon code {aci789589} at checkout to avail of the discount. You can use the code {aci789589} to get a $100 off Temu coupon as a new customer. Apply this Temu coupon code $100 off (aci789589) to get a $100 discount on your shopping with Temu. If you’re a first-time user and looking for a Temu coupon code $100 first time user(aci789589) then using this code will give you a flat $100 Off and a 90% discount on your Temu shopping. Temu $100% Off Coupon Code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Temu coupon code$100off-{aci789589} Temu coupon code -{aci789589} Temu coupon code$50 off-{aci789589} Temu Coupon code [aci789589] for existing users can get up to 50% discount on product during checkout. Temu Coupon Codes for Existing Customers-aci789589 Temu values its loyal customers and offers various promo codes, including the Legit Temu Coupon Code (aci789589]) or (aci789589), which existing users can use. This ensures that repeat shoppers can also benefit from significant discounts on their purchases. Keep an eye out for special promotions and offers that are periodically available to enhance your shopping experience.
    • New users at Temu receive a $100 discount on orders over $100 Use the code [aci789589] during checkout to get Temu Coupon Code $100 off For New Users. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. Temu 100% Off coupon code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. You can get a$100 bonus plus 30% off any purchase at Temu with the$100 Coupon Bundle at Temu if you sign up with the referral code [aci789589] and make a first purchase of$50 or more. The Temu $100 Off coupon code (aci789589) will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes Temu offers $100 Off Coupon Code “aci789589” for First Time Users. Yes, Temu offers $100 off coupon code {aci789589} for first-time users. You can get a $100 bonus plus 100% off any purchase at Temu with the $100 Coupon Bundle if you sign up with the referral code [aci789589] and make a first purchase of $100 or more. If you are who wish to join Temu, then you should use this exclusive Temu coupon code $100 off (aci789589) and get $100 off on your purchase with Temu. You can get a $100 discount with Temu coupon code {aci789589}. This exclusive offer is for existing customers and can be used for a $100 reduction on your total purchase. Enter coupon code {aci789589} at checkout to avail of the discount. You can use the code {aci789589} to get a $100 off Temu coupon as a new customer. Apply this Temu coupon code $100 off (aci789589) to get a $100 discount on your shopping with Temu. If you’re a first-time user and looking for a Temu coupon code $100 first time user(aci789589) then using this code will give you a flat $100 Off and a 90% discount on your Temu shopping. Temu $100% Off Coupon Code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Temu coupon code$100off-{aci789589} Temu coupon code -{aci789589} Temu coupon code$50 off-{aci789589} Temu Coupon code [aci789589] for existing users can get up to 50% discount on product during checkout. Temu Coupon Codes for Existing Customers-aci789589 Temu values its loyal customers and offers various promo codes, including the Legit Temu Coupon Code (aci789589]) or (aci789589), which existing users can use. This ensures that repeat shoppers can also benefit from significant discounts on their purchases. Keep an eye out for special promotions and offers that are periodically available to enhance your shopping experience.
  • Topics

×
×
  • Create New...

Important Information

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