英文:
Minecraft Block Harvest Level Restriction
问题
我正在编写一个Minecraft模组,尝试让我的方块只在用等级为2或更高的工具(铁或更高级别的工具)挖掘时掉落战利品。我将挖掘等级设置为2,但仍然可以用拳头挖掘。这是我的方块的代码:
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.ToolType;
public class RubyBlock extends Block {
public RubyBlock() {
super(Properties.create(Material.IRON)
.hardnessAndResistance(5.0f, 6.0f)
.sound(SoundType.METAL)
.harvestLevel(2)
.harvestTool(ToolType.PICKAXE)
);
}
}
您的代码看起来正确,根据设置应该需要等级为2或更高的镐来挖掘它。如果您仍然能够用拳头挖掘,可能需要确保您没有在游戏中使用其他修改或插件,这些可能会影响挖掘行为。此外,确保您已重新加载或重新启动了游戏以使代码生效。
英文:
I am coding a minecraft mod, and I am trying to make my block drop loot only when mined with a harvest level of 2 or more(iron or above). I set my harvest level to 2 but still can mine it with my fist. Why is this? Here is my code for the block.
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.ToolType;
public class RubyBlock extends Block {
public RubyBlock(){
super(Properties.create(Material.IRON)
.hardnessAndResistance(5.0f,6.0f)
.sound(SoundType.METAL)
.harvestLevel(2)
.harvestTool(ToolType.PICKAXE)
);
}
}
答案1
得分: 1
我遇到了和你一样的问题,在简短的谷歌搜索之后,我在 Forge 论坛上找到了这篇帖子:https://forums.minecraftforge.net/topic/87845-solved-bug-fixed-harvest-level-just-straight-up-not-working/
显然,在设置采收等级和工具后,你需要添加 .func_235861_h_()
来重新加载新的信息。
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.ToolType;
public class RubyBlock extends Block {
public RubyBlock(){
super(Properties.create(Material.IRON)
.hardnessAndResistance(5.0f,6.0f)
.sound(SoundType.METAL)
.harvestLevel(2)
.harvestTool(ToolType.PICKAXE)
.func_235861_h_()
);
}
}
英文:
I had the same problem as you and after a brief google search, I found this post on the forge forms https://forums.minecraftforge.net/topic/87845-solved-bug-fixed-harvest-level-just-straight-up-not-working/
Apparently you need to add .func_235861_h_()
after setting the harvest level and tool to reload with the new information.
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.ToolType;
public class RubyBlock extends Block {
public RubyBlock(){
super(Properties.create(Material.IRON)
.hardnessAndResistance(5.0f,6.0f)
.sound(SoundType.METAL)
.harvestLevel(2)
.harvestTool(ToolType.PICKAXE)
.func_235861_h_()
);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论