Jump to content

[Solved] [1.15.2] Custom Arrow Texture


lisilew

Recommended Posts

I want CompoundBowItem to be able to shoot only CompoundArrowEntity.

Everything works but CompoundArrowEntity does not have custom texture.

public class CompoundArrowItem extends ArrowItem {
    public CompoundArrowItem(Properties builder) {
        super(builder);
    }

    @Override
    public AbstractArrowEntity createArrow(World worldIn, ItemStack stack, LivingEntity shooter) {
        return new CompoundArrowEntity(worldIn, shooter);
    }
}
public class CompoundBowItem extends BowItem {
    public CompoundBowItem(Properties builder) {
        super(builder);
    }

    @Override
    public Predicate<ItemStack> getInventoryAmmoPredicate() {
        return getAmmoPredicate();
    }

    @Override
    public Predicate<ItemStack> getAmmoPredicate() {
        return itemStack -> itemStack.getItem() instanceof CompoundArrowItem;
    }
}
public class CompoundArrowEntity extends ArrowEntity {
    public CompoundArrowEntity(EntityType<? extends CompoundArrowEntity> p_i50172_1_, World p_i50172_2_) {
        super(p_i50172_1_, p_i50172_2_);
    }

    public CompoundArrowEntity(World worldIn, double x, double y, double z) {
        super(worldIn, x, y, z);
    }

    public CompoundArrowEntity(World worldIn, LivingEntity shooter) {
        super(worldIn, shooter);
    }

    @Override
    protected ItemStack getArrowStack() {
        return new ItemStack(Items.COMPOUND_ARROW.get());
    }
}
public class CompoundArrowRenderer extends ArrowRenderer<CompoundArrowEntity> {
    private static final ResourceLocation COMPOUND_ARROW_TEXTURE = new ResourceLocation(ExampleMod.ID, "textures/entity/projectiles/compound_arrow.png");

    public CompoundArrowRenderer(EntityRendererManager renderManagerIn) {
        super(renderManagerIn);
    }

    @Override
    public ResourceLocation getEntityTexture(CompoundArrowEntity entity) {
        return COMPOUND_ARROW_TEXTURE;
    }
}

textures/entity/projectiles/compound_arrow.png is just recolored version of minecraft/textures/entity/projectiles/arrow.png yet it has minecraft arrow texture.

Edited by lisilew
Link to comment
Share on other sites

1 hour ago, imacatlolol said:

Did you maybe forget to use RenderingRegistry.registerEntityRenderingHandler?

This is how I registered the renderer and I think I do not have any issues with it.

private void doClientStuff(final FMLClientSetupEvent event) {
    // do something that can only be done on the client
    LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
    RenderingRegistry.registerEntityRenderingHandler(EntityTypes.COMPOUND_ARROW.get(), CompoundArrowRenderer::new);
}

 

Edited by lisilew
Link to comment
Share on other sites

6 hours ago, lisilew said:

This is how I registered the renderer and I think I do not have any issues with it.

You need to override Entity::createSpawnPacket and return NetworkHooks.getEntitySpawningPacket

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, Animefan8888 said:

You need to override Entity::createSpawnPacket and return NetworkHooks.getEntitySpawningPacket

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

I did override it but it still uses vanilla arrow texture.

Nothing related to CompoundArrowEntity was logged so I assume the issue is not about invalid resources.

Do I need anything else other than PNG file under textures/entity/projectiles for EntityRenderer?

Link to comment
Share on other sites

1 minute ago, lisilew said:

I did override it but it still uses vanilla arrow texture.

Step through your render code in the debugger does your getEntityTexture method ever get called and does that texture ever get bound?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

7 hours ago, Animefan8888 said:

Step through your render code in the debugger does your getEntityTexture method ever get called and does that texture ever get bound?

I have set breakpoint on getEntityTexture and also put System.out.println but it seems like method is never called.

Link to comment
Share on other sites

22 minutes ago, lisilew said:

I have set breakpoint on getEntityTexture and also put System.out.println but it seems like method is never called.

Does your CompoundArrowRenderer's constructor ever get called?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

11 minutes ago, Animefan8888 said:

Does your CompoundArrowRenderer's constructor ever get called?

Added breakpoints to all three constructors and it seems like it is not called.

12 minutes ago, diesieben07 said:

All your entity constructors must call a super constructor that specifies the EntityType. Otherwise your entity will be constructed with the wrong type, causing it to save to disk as the wrong type and be sent to the client as the wrong type.

Then I am guessing that my arrow should extend AbstractArrowEntity as I cannot override two constructors from ArrowEntity with my arrow type.

Link to comment
Share on other sites

16 minutes ago, diesieben07 said:

ArrowEntity provides a constructor that takes an EntityType. Use this constructor.

public class EntityTypes {
    private static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, ExampleMod.ID);
    public static final RegistryObject<EntityType<CompoundArrowEntity>> COMPOUND_ARROW = register("compound_arrow", EntityType.Builder.<CompoundArrowEntity>create((p_create_1_, p_create_2_) -> new CompoundArrowEntity(p_create_2_), EntityClassification.MISC).size((float) 0.5, (float) 0.5));

    private static <T extends Entity> RegistryObject<EntityType<T>> register(String name, EntityType.Builder<T> builder) {
        return ENTITY_TYPES.register(name, () -> builder.build(new ResourceLocation(ExampleMod.ID, name).toString()));
    }

    public static void register(IEventBus bus) {
        ENTITY_TYPES.register(bus);
    }
}
public class CompoundBowItem extends BowItem {
    public CompoundBowItem(Properties builder) {
        super(builder);
    }

    @Override
    public Predicate<ItemStack> getInventoryAmmoPredicate() {
        return getAmmoPredicate();
    }

    @Override
    public Predicate<ItemStack> getAmmoPredicate() {
        return itemStack -> itemStack.getItem() instanceof CompoundArrowItem;
    }

    @Override
    public AbstractArrowEntity customeArrow(AbstractArrowEntity arrow) {
        return new CompoundArrowEntity(arrow.world);
    }
}
public class CompoundArrowItem extends ArrowItem {
    public CompoundArrowItem(Properties builder) {
        super(builder);
    }

    @Override
    public AbstractArrowEntity createArrow(World worldIn, ItemStack stack, LivingEntity shooter) {
        return new CompoundArrowEntity(worldIn);
    }
}
public class CompoundArrowEntity extends ArrowEntity {
    public CompoundArrowEntity(World world) {
        super(EntityTypes.COMPOUND_ARROW.get(), world);
    }

    @Override
    protected ItemStack getArrowStack() {
        return new ItemStack(Items.COMPOUND_ARROW.get());
    }

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

I have updated classes like above.

I added customeArrow in CompoundBowItem and now debugger says constructor of CompoundArrowEntity is called.

However, now it does not even have vanilla texture and only shooting sound is played.

Link to comment
Share on other sites

8 minutes ago, diesieben07 said:

You'll have to make sure the code in your arrow and bow items actually functions properly.

What is the purpose of customeArrow?

BowItem uses createArrow on ArrowItem to create AbstractArrowEntity.

Then, it calls customeArrow(abstractArrowEntity).

If I override that, arrow loses texture.

If I do not, arrow uses vanilla texture.

I assume that I am not correctly understanding what customeArrow is supposed to do.

Link to comment
Share on other sites

28 minutes ago, diesieben07 said:

Is createArrow called?

createArrow is called when I have CompoundArrowItem in my inventory whether I am in survival or creative mode.

From enabling hitbox, I noticed that the entity is actually not spawned even though createArrow is called.

Other mechanics like finding ammo from inventory and consuming ammo work.

Link to comment
Share on other sites

15 minutes ago, diesieben07 said:

Since you are now using the ArrowEntity(EntityType, World) constructor, you need to replicate the actions done by the ArrowEntity(World, LivingEntity) constructor, which is normally used in createArrow.

Thanks. This solved the issue.

I might as well just extend AbstractArrowEntity to remove code duplication.

Anyway, once again, thank you iamacatlolol, Animefan8888 and diesieben07 for taking your time and helping me out.

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.