Add NetheriteOnlyBlock and update block properties and tags

This commit is contained in:
IM23a-spirgif
2025-05-12 22:18:49 +02:00
parent bd18873afa
commit a6d9e81f53
3 changed files with 37 additions and 5 deletions
@@ -18,13 +18,13 @@ public class ModBlocks {
DeferredRegister.createBlocks(Stalinium.MODID); DeferredRegister.createBlocks(Stalinium.MODID);
public static final DeferredBlock<Block> COMPRESSED_BEDROCK = registerBlock("compressed_bedrock", public static final DeferredBlock<Block> COMPRESSED_BEDROCK = registerBlock("compressed_bedrock",
() -> new Block(BlockBehaviour.Properties.of() () -> new NetheriteOnlyBlock(BlockBehaviour.Properties.of()
.strength(50f, 1200f) .strength(50f, 1200f)
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.sound(SoundType.STONE))); .sound(SoundType.STONE)));
public static final DeferredBlock<Block> STALINIUM_ORE = registerBlock("stalinium_ore", public static final DeferredBlock<Block> STALINIUM_ORE = registerBlock("stalinium_ore",
() -> new Block(BlockBehaviour.Properties.of() () -> new NetheriteOnlyBlock(BlockBehaviour.Properties.of()
.strength(5f, 6f) .strength(5f, 6f)
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.sound(SoundType.NETHER_ORE))); .sound(SoundType.NETHER_ORE)));
@@ -35,6 +35,8 @@ public class ModBlocks {
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.sound(SoundType.NETHERITE_BLOCK))); .sound(SoundType.NETHERITE_BLOCK)));
private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) { private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) {
DeferredBlock<T> toReturn = BLOCKS.register(name, block); DeferredBlock<T> toReturn = BLOCKS.register(name, block);
registerBlockItem(name, toReturn); registerBlockItem(name, toReturn);
@@ -0,0 +1,26 @@
package net.krituximon.stalinium.block;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;
public class NetheriteOnlyBlock extends Block {
public NetheriteOnlyBlock(BlockBehaviour.Properties props) {
super(props);
}
@Override
public boolean canHarvestBlock(BlockState state, BlockGetter world, BlockPos pos, Player player) {
ItemStack stack = player.getMainHandItem();
if (!(stack.getItem() instanceof PickaxeItem)) {
return false;
}
return ((PickaxeItem) stack.getItem()).getTier() == Tiers.NETHERITE;
}
}
@@ -22,9 +22,13 @@ public class ModBlockTagProvider extends BlockTagsProvider {
protected void addTags(HolderLookup.Provider provider) { protected void addTags(HolderLookup.Provider provider) {
tag(Tags.Blocks.STORAGE_BLOCKS) tag(Tags.Blocks.STORAGE_BLOCKS)
.add(ModBlocks.STALINIUM_BLOCK.get()); .add(ModBlocks.STALINIUM_BLOCK.get());
tag(BlockTags.NEEDS_DIAMOND_TOOL)
tag(BlockTags.MINEABLE_WITH_PICKAXE)
.add(ModBlocks.STALINIUM_BLOCK.get()); .add(ModBlocks.STALINIUM_BLOCK.get());
tag(BlockTags.MINEABLE_WITH_PICKAXE)
.add(
ModBlocks.STALINIUM_BLOCK.get(),
ModBlocks.STALINIUM_ORE.get(),
ModBlocks.COMPRESSED_BEDROCK.get()
);
} }
} }