Crafting through the cauldron

Started by Yuranga0 on Sat, 10/12/2019 - 14:37

Topic category: Help with MCreator modding

Last seen on 09:30, 14. Nov 2019
Joined Oct 2017
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Crafting through the cauldron
Sat, 10/12/2019 - 14:37

I need to when using the item on the cauldron, this item turns into another object, with a portion of the water in the boiler should be spent, as when you wash off the dye from leather armor.
How can this be implemented?​​​​​​​

Last seen on 19:28, 13. Nov 2019
Joined May 2019
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Don´t think you can do this…
Sat, 10/19/2019 - 23:02

Don´t think you can do this on MCreator yet but here´s the code that removes color from the armor.

 

if (i > 0 && item instanceof ItemArmor)
                {
                    ItemArmor itemarmor = (ItemArmor)item;

                    if (itemarmor.getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER && itemarmor.hasColor(itemstack) && !worldIn.isRemote)
                    {
                        itemarmor.removeColor(itemstack);
                        this.setWaterLevel(worldIn, pos, state, i - 1);
                        playerIn.addStat(StatList.ARMOR_CLEANED);
                        return true;
                    }
                }

Last seen on 20:44, 13. Nov 2019
Joined Nov 2017
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Yep, not doable without…
Sun, 10/20/2019 - 01:50

Yep, not doable without custom code. Cauldrons use a "level" block state which determines how much water is inside it (a number between 0 and 3). However, MCreator doesn't really support block states (yet), so you can't use procedure blocks alone. What you'd need to do is:

  1. Check if the block you right clicked is a cauldron
  2. If so, check that the "level" is greater than 0
  3. Change the item and reduce the cauldron "level" by 1
Last seen on 09:30, 14. Nov 2019
Joined Oct 2017
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
How?
Thu, 10/24/2019 - 17:42

How?

Last seen on 20:44, 13. Nov 2019
Joined Nov 2017
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
It should be doable with…
Thu, 10/24/2019 - 21:02

It should be doable with procedures ("On item right-click on block") if you use custom code blocks. Tomorrow I'll try to see how it can be implemented. A sample code could be:

// Make sure to check that the block at x, y, z is a cauldron first!!

/*
 * Declare a "IBlockState" variable: the block at x, y, z with its block state
 * We know it's a cauldron because we checked for it beforehand
 */
IBlockState blockState = world.getBlockState(new BlockPos(x, y, z));

// This variable "stores" the water level of the cauldron
int waterLevel = blockState.getValue(BlockCauldron.LEVEL);

// Check if the water level of the cauldron is greater than 0
if (blockState.getValue(BlockCauldron.LEVEL) > 0)
{
    // Procedure stuff to change the item

    // Place a cauldron at x, y, z, but with less water
    world.setBlockState(new BlockPos(x, y, z), Blocks.CAULDRON.getDefaultState().withProperty(LEVEL, waterLevel - 1); 
}

(keep in mind I can't test or recompile this right now, so it might not work!)

Last seen on 20:44, 13. Nov 2019
Joined Nov 2017
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
 (small mistake on my side,…
Thu, 10/24/2019 - 21:08

 (small mistake on my side, but it shouldn't affect the code at all). You can replace the line

if (blockState.getValue(BlockCauldron.LEVEL) > 0)

with this one, which is shorter and cleaner:

if (waterLevel > 0)

 

Last seen on 20:44, 13. Nov 2019
Joined Nov 2017
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Thanks for linking the…
Tue, 10/29/2019 - 22:52

Thanks for linking the tutorial! I made it specifically to answer this post, but forgot to link it here