PneumaticCraft: Repressurized

PneumaticCraft: Repressurized

50M Downloads

[1.19.2] Remove 'final' access modifier at PNCUpgrade::getItem

gisellevonbingen opened this issue ยท 0 comments

commented

Describe the feature

Remove 'final' access modifier at PNCUpgrade::getItem.
Else add guide to add custom PNGUpgrade from addon mods.

Reasons why it should be considered

I'm developing mod have integration with PNC.
I would add own pneumatic armor's upgrade.

I should create own DeferredRegister to register new upgrades.
Upgrade item be register automatically like 'mymod:pneumatic_UPGRADE_NAME_upgrade' .

public static final MyDeferredRegister UPGRADES = new MyDeferredRegister(MODID);

public static final MyRegistryObject<AddonPNCUpgrade, UpgradeItem> SPACE_BREATHING = UPGRADES.register("space_breathing", MyItems::getItemProperties);
public static final MyRegistryObject<AddonPNCUpgrade, UpgradeItem> SPACE_FIRE_PROOF = UPGRADES.register("space_fire_proof", MyItems::getItemProperties);
public static final MyRegistryObject<AddonPNCUpgrade, UpgradeItem> VENUS_ACID_PROOF = UPGRADES.register("venus_acid_proof", MyItems::getItemProperties);

AddonPNCUpgrade.java

public class AddonPNCUpgrade extends PNCUpgrade
{
	public AddonPNCUpgrade()
	{
		super();
	}

	public AddonPNCUpgrade(int maxTier, String... depModIds)
	{
		super(maxTier, depModIds);
	}

}

In Charging Station, this upgrade's name show as 'Air'
image

Because item name limited to have spectific rule in getItemRegistryName.
So it return air.

/**
* Get the corresponding item for this upgrade and tier.
*
* @param tier the upgrade tier
* @return a Minecraft item, or air if no corresponding item can be found
* @throws NullPointerException if called before the upgrade is registered
*/
public final Item getItem(int tier) {
ResourceLocation rl = PneumaticRegistry.getInstance().getUpgradeRegistry().getItemRegistryName(this, tier);
return tier > maxTier || rl == null ? Items.AIR : ForgeRegistries.ITEMS.getValue(rl);
}

@Override
public ResourceLocation getItemRegistryName(PNCUpgrade upgrade, int tier) {
ResourceLocation id = ModUpgrades.UPGRADES.get().getKey(upgrade);
String registryName = Objects.requireNonNull(id) + "_upgrade";
if (upgrade.getMaxTier() > 1) registryName += "_" + tier;
return new ResourceLocation(registryName);
}

But getItem is final method.
I can't override it and return my added upgrade item.

So for addon mod, I think to need remove 'final' access modifier at 'PNCUpgrade::getItem()'.

Additional details

In 1.18.2, can instead via override 'PNCUpgrade::getItemRegistryName' method.

protected ResourceLocation getItemRegistryName(int tier) {
String registryName = Objects.requireNonNull(getRegistryName()).toString() + "_upgrade";
if (getMaxTier() > 1) registryName += "_" + tier;
return new ResourceLocation(registryName);
}