Skip to content

API for non-player entities to use Tinker tools (primarily projectile weapons) #5350

Description

@lcy0x1

Minecraft Version

1.20.1

Forge Version

47.1.3+

Mantle Version

1.11.36

Tinkers' Construct Version

3.9.1.19

Problem description

Currently, ModifiableBowItem and ModifiableCrossbowItem are both restricted to player use only, while the underlying logic actually allow non-player to trigger most of the mechanics.

The current vanilla stack trace for mobs using projectile weapon is quite obscure and inflexible:
RangedAttackMob::performRangedAttack

  • ProjectileUtil::getMobArrow
    • ArrowItem::createArrow
    • AbstractArrow::setEnchantmentEffectsFromEntity
  • BowItem::customArrow

Since TConstruct does not follow the vanilla logic for arrow entity creation, could there be an interface for mobs to use TConstruct bows and crossbows?

I have already implemented mob using TConstruct bows and crossbows, but in a way that copied and modified a large chunk of respective TConstruct code. It's not clean and could break in the future if TConstruct modified this part of the code. Is it possible to extract an API for this, so that I can keep minimal repetition of TConstruct code?

This is my implementation: https://github.com/Minecraft-LightLand/ModularGolems/tree/lcy0x1/1.20/src/main/java/dev/xkmc/modulargolems/compat/materials/tinker/behavior

Suggested solution

Here is something I would propose:

class ModifiableBowItem {void shootArrows(LivingEntity user, ItemStack bow, ProjectileStrategy strategy)}

interface ProjectileStrategy {void shootArrow(Projectile arrowEntity, float arrowVelocity, float arrowGravity, float angleInDegree, float inaccuracy);}

Where ProjectileStrategy is an interface that allows mobs to control the initial velocity of the arrow.

This implementation would be very similar to respective Bow / Crossbow code, where there could b a ProjectileStrategy for player. It's the easiest fix

Alternatives considered

The alternative would be to follow the vanilla logic, where the major logic and hook moves to customArrow, and call that part in item usage.

Additional context

No response

Searched for existing enhancement?

Used the search bar, Checked the FAQ, Checked the in game books

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.20Issue affects 1.20EnhancementIssue or pull request addresses a change to an existing functional feature

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions