Skip to content

Magic Consumption Items

Deadlydiamond98 edited this page Aug 3, 2024 · 7 revisions

There are currently 2 consumption items in here that can be used as a base for new items: MagicItem and TransformationItem.


Magic Item

The Constructor of the Magic Item takes in manaCost, which is the cost of mana needed to use the item

doManaAction(PlayerEntity user)

Do Mana Action is called when the item is used, and will consume mana. If the manaCost is greater than the user's Max Mana, it won't run

Here's an example that consumes mana to give you diamonds:

@Override
protected void doManaAction(PlayerEntity user, World world) {
    super.doManaAction(user);
    user.giveItemStack(Items.DIAMOND.getDefaultStack());     
}

doNoManaEvent(PlayerEntity user, World world)

This method is called if Mana isn't able to be consumed by the item

getManaCost()

This getter is set to be the manaCost, and is used to add Magic Costs as an item tooltip

@Override
    public int getManaCost() {
        return 10;
    }

Transformation Item

The Transformation Item allows you to convert blocks, living entities, and item entities into different forms.

The constructor takes in the Following Variables

  • manaCost: The amount of Mana consumed when transforming something
  • consumed: If the item is removed from the player after use
  • cooldown: How long of a cool down the item has after use (with 0 or below giving no cooldown)
  • hasDefault: if this is true, it will convert any entities that aren't given a transformation into defaultEntity
  • defaultEntity: EntityType to transform into

getManaCost is present here and works the same as it did before, but there are also three classes: initializeBlockConversions, initializeEntityConversions, and initializeItemConversions. These 3 methods utilize the variables blockConversionMap, entityConversionMap, and itemConversionMap respectivly.

You can add conversions with these 3 methods like so:

This Converts Grass to Myceilium on Right-Click (takes in Block)

private void initializeBlockConversions() {
    blockConversionMap.put(Blocks.GRASS_BLOCK, Blocks.MYCELIUM);
}

This Converts Zoglins to Hoglins on Right-Click (takes in EntityType)

private void initializeEntityConversions() {
    entityConversionMap.put(EntityType.ZOGLIN, EntityType.HOGLIN);
}

This Converts Iron Ingots to Gold Ingots on Right-Click (takes in Item)

  • Note this is converting item entities, and there is no limit to the amount that is converted on the right click
private void initializeItemConversions() {
    itemConversionMap.put(Items.IRON_INGOT, Items.GOLD_INGOT);
}

Magic Item Data

If you want to make an item such as a custom sword have a magic consumption tooltip, you can implement the interface MagicItemData to do so. Just make sure you define the magic Consumption!

Example:

public class SwordTest extends SwordItem implements MagicItemData {
    public SwordTest(ToolMaterial toolMaterial, int attackDamage, float attackSpeed, Settings settings) {
        super(toolMaterial, attackDamage, attackSpeed, settings);
    }

    @Override
    public int getManaCost() {
        return 3;
    }
}

Clone this wiki locally