How do I make an event after crafting an item?

Started by vanya1642 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I make an event after crafting an item?

How do I make an event after crafting an item? I need to have a 20% chance of an explosion in the 4-block workbench area after crafting an item. Please describe in detail how I can do this. I will be very grateful. Also, so that the explosion demolishes 2 hearts.

Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'd be glad to help you…
Sat, 03/09/2024 - 19:33

I'd be glad to help you create a procedure in MCreator that triggers a 20% chance of an explosion upon crafting an item, damaging the surrounding workbench area by 2 hearts. Here's a detailed breakdown:

1. Create a New Procedure:

  • In MCreator, navigate to the "Procedures" tab.
  • Click the "+" button to create a new procedure.
  • Name it descriptively, like "CraftExplosionChance."

2. Add the Crafting Trigger:

  • In the procedure editor, search for the trigger "Item is crafted."
  • Drag and drop this trigger onto the workspace.

3. Implement the Random Chance:

  • Search for the "Math" category and locate the "Random Integer" function.
  • Drag and drop it next to the "Item is crafted" trigger.
  • Double-click the "Random Integer" function and set the following parameters:
    • Minimum value: 1 (inclusive)
    • Maximum value: 5 (inclusive) - This creates a 20% chance (1 out of 5) of triggering an explosion.

4. Check for Explosion Condition:

  • Connect the output of the "Random Integer" function to a "Decision" block.
  • In the "Decision" block, set the condition to check if the output is equal to 1 (representing the 20% chance).

5. Create the Explosion (if triggered):

  • If the "Decision" block outputs "True" (explosion triggered):
    • Search for the "World" category and find the "Play Explosion" function.
    • Drag and drop it next to the "True" output of the "Decision" block.
    • Double-click the "Play Explosion" function and configure the following:
      • Power: 2 (equivalent to 2 hearts of damage)
      • Position: Use the "Get Player Looking At" function (optional, to target the block the player is looking at) or define specific coordinates (if targeting a specific location).
      • Sound: Choose the desired explosion sound effect (optional).
      • Smokescale: Set the smoke scale for the explosion (optional).
      • Fire: Decide whether to create fire after the explosion (optional).

6. Optional: Remove Crafted Item (if desired):

  • If you want to remove the crafted item from the player's inventory upon a successful explosion, you can use the "Player" category's "Remove Item From Inventory" function. However, this behavior might not be ideal for your mod, so consider it carefully.

7. (Optional) Handle Non-Explosion Scenario:

  • If the "Decision" block outputs "False" (no explosion triggered):
    • You can add functionality here, such as displaying a message to the player informing them they were lucky or adding a visual effect.

8. Connect and Finalize:

  • Connect the "False" output of the "Decision" block to the end (represented by a diamond shape) of the procedure.
  • Save your procedure.

Additional Considerations:

  • You can adjust the explosion power to match your desired damage level.
  • Test your procedure thoroughly to ensure it functions as intended.
  • Consider refining the explosion placement logic (using "Get Player Looking At") if you want more control over where the explosion occurs.