Skip to content

Commit 8f5160c

Browse files
Add polished sandstone and simplify registering
1 parent bbb5cb1 commit 8f5160c

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

parallelworlds/src/main/java/parallelmc/parallelworlds/ParallelWorldsBootstrapper.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66
import net.minecraft.core.*;
77
import net.minecraft.core.registries.Registries;
88
import net.minecraft.network.chat.Component;
9+
import net.minecraft.network.chat.Style;
910
import net.minecraft.resources.Identifier;
1011
import net.minecraft.resources.ResourceKey;
1112
import net.minecraft.world.level.block.Block;
1213
import net.minecraft.world.level.block.Blocks;
1314
import net.minecraft.world.level.block.NoteBlock;
1415
import net.minecraft.world.level.block.SoundType;
1516
import net.minecraft.world.level.block.state.BlockBehaviour;
17+
import net.minecraft.world.level.block.state.BlockState;
1618
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
1719
import net.minecraft.world.level.material.MapColor;
1820
import org.bukkit.plugin.java.JavaPlugin;
1921
import parallelmc.parallelworlds.blocks.QuicksandBlock;
2022
import parallelmc.parallelworlds.blocks.TestBlock;
2123
import parallelmc.parallelworlds.registry.ParallelBlockRegistry;
2224

25+
import java.util.function.Function;
26+
2327

2428
public class ParallelWorldsBootstrapper implements PluginBootstrap {
2529

@@ -28,11 +32,17 @@ public void bootstrap(BootstrapContext context) {
2832

2933
ParallelBlockRegistry registry = ParallelBlockRegistry.getInstance();
3034

31-
ResourceKey<Block> quicksandKey = ResourceKey.create(Registries.BLOCK, Identifier.fromNamespaceAndPath("parallelutils", "quicksand"));
32-
Block quicksandBlock = new QuicksandBlock(BlockBehaviour.Properties.of().mapColor(MapColor.SAND).strength(0.25F).sound(SoundType.SAND)
33-
.dynamicShape().noOcclusion().isRedstoneConductor((blockState, blockGetter, blockPos) -> false).setId(quicksandKey));
34-
registry.registerBlock(quicksandKey, quicksandBlock,
35-
Blocks.NOTE_BLOCK.getStateDefinition().any().setValue(NoteBlock.INSTRUMENT, NoteBlockInstrument.BANJO).setValue(NoteBlock.NOTE, 1), Component.literal("Quicksand"));
35+
if (registry == null) throw new RuntimeException("ParallelBlockRegistry is null!");
36+
37+
register(registry, "polished_sandstone", Block::new,
38+
BlockBehaviour.Properties.of().mapColor(MapColor.SAND).requiresCorrectToolForDrops().strength(0.8F).sound(SoundType.STONE),
39+
Blocks.NOTE_BLOCK.getStateDefinition().any().setValue(NoteBlock.INSTRUMENT, NoteBlockInstrument.BANJO).setValue(NoteBlock.NOTE, 0),
40+
Component.literal("Polished Sandstone").setStyle(Style.EMPTY));
41+
42+
register(registry, "quicksand", QuicksandBlock::new,
43+
BlockBehaviour.Properties.of().mapColor(MapColor.SAND).strength(0.25F).sound(SoundType.SAND).dynamicShape().noOcclusion().isRedstoneConductor((blockState, blockGetter, blockPos) -> false),
44+
Blocks.NOTE_BLOCK.getStateDefinition().any().setValue(NoteBlock.INSTRUMENT, NoteBlockInstrument.BANJO).setValue(NoteBlock.NOTE, 1),
45+
Component.literal("Quicksand").setStyle(Style.EMPTY));
3646

3747
registry.freeze();
3848
}
@@ -42,6 +52,11 @@ public JavaPlugin createPlugin(PluginProviderContext context) {
4252
return PluginBootstrap.super.createPlugin(context);
4353
}
4454

55+
private static void register(ParallelBlockRegistry registry, String name, Function<BlockBehaviour.Properties, Block> factory, BlockBehaviour.Properties properties, BlockState targetBlockstate, Component itemName) {
56+
ResourceKey<Block> blockKey = ResourceKey.create(Registries.BLOCK, Identifier.fromNamespaceAndPath("parallelutils", name));
57+
Block block = factory.apply(properties.setId(blockKey));
58+
registry.registerBlock(blockKey, block, targetBlockstate, itemName);
59+
}
4560

4661

4762
}

parallelworlds/src/main/java/parallelmc/parallelworlds/events/BlockBreakPlaceListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.minecraft.world.item.ItemStack;
66
import net.minecraft.world.level.block.Block;
77
import net.minecraft.world.level.block.state.BlockState;
8+
import org.bukkit.GameMode;
89
import org.bukkit.block.data.BlockData;
910
import org.bukkit.craftbukkit.block.CraftBlock;
1011
import org.bukkit.craftbukkit.inventory.CraftItemStack;
@@ -27,6 +28,7 @@ public BlockBreakPlaceListener() {
2728

2829
@EventHandler(priority = EventPriority.HIGHEST)
2930
public void handleBlockBreak(BlockBreakEvent event) {
31+
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) return;
3032
CraftBlock cb = (CraftBlock)event.getBlock();
3133

3234
BlockState blockState = cb.getNMS();

parallelworlds/src/main/java/parallelmc/parallelworlds/registry/ParallelBlockRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private ParallelBlockRegistry() throws RuntimeException, NoSuchMethodException {
6262
// TODO: Fill available states
6363
addFullBlock(Blocks.NOTE_BLOCK);
6464
addFullBlock(Blocks.SCULK_SENSOR);
65+
addFullBlock(Blocks.CALIBRATED_SCULK_SENSOR);
6566

6667
}
6768

0 commit comments

Comments
 (0)