Posted April 30, 20205 yr I am struggling on how to add XP after harvesting my custom ore. Any ideas? Here is my ore class: package com.pixxibunny.minecraftmod.blocks; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraftforge.common.ToolType; import java.util.Random; public class RoseOre extends Block { public RoseOre() { super(Properties.create(Material.ROCK) .hardnessAndResistance(3.0f,3.0f) .sound(SoundType.STONE) .harvestLevel(2) .harvestTool(ToolType.PICKAXE)); } }
April 30, 20205 yr Author I'm pretty new to this stuff, so how would I go about overriding the experience? package com.pixxibunny.minecraftmod.blocks; import net.minecraft.block.OreBlock; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraftforge.common.ToolType; public class RoseOre extends OreBlock { public RoseOre() { super(Properties.create(Material.ROCK) .hardnessAndResistance(3.0f,3.0f) .sound(SoundType.STONE) .harvestLevel(2) .harvestTool(ToolType.PICKAXE)); } }
April 30, 20205 yr @Override public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) { dropXpOnBlockBreak(worldIn,pos,250); super.onBlockHarvested(worldIn, pos, state, player); } That's what I generally use Edited April 30, 20205 yr by DangerousBlades
May 1, 20205 yr Author Is there any way to randomize the exp received? Like a range between 3.0-7.0 or something?
May 1, 20205 yr Well, you could create a variable and randomize it using the java. util. Random Edited May 1, 20205 yr by DangerousBlades
May 1, 20205 yr 16 minutes ago, PixxiBunny said: How would I do that exactly? You would create a new instance of java.util.Random then use random.nextInt() * (max - min) + min to get a random integer between min and max (inclusive, exclusive). Since you're new to modding and java, I strongly recommend taking a java course to learn about java.util.Random and more of the basics before you proceed. Modding Minecraft is not the best way of learning the language.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.