diff --git a/src/main/java/de/jottyfan/gta/gdp/block/ModBlocks.java b/src/main/java/de/jottyfan/gta/gdp/block/ModBlocks.java index d352a52..b45f81c 100644 --- a/src/main/java/de/jottyfan/gta/gdp/block/ModBlocks.java +++ b/src/main/java/de/jottyfan/gta/gdp/block/ModBlocks.java @@ -21,11 +21,18 @@ import net.minecraft.util.Identifier; */ public class ModBlocks { - public static final Block RUBY_BLOCK = registerBlock(Identifier.of(GTAGDP.MOD_ID, "ruby_block"), - AbstractBlock.Settings.create().strength(4f).requiresTool().sounds(BlockSoundGroup.AMETHYST_BLOCK)); + public static final Block RUBY_BLOCK = registerRubyBlock(Identifier.of(GTAGDP.MOD_ID, "ruby_block"), + AbstractBlock.Settings.create().strength(4f).requiresTool().sounds(BlockSoundGroup.AMETHYST_BLOCK) + .luminance(state -> state.get(RubyBlock.ACTIVATED) ? 15 : 0)); public static final Block RUBY_ORE = registerBlock(Identifier.of(GTAGDP.MOD_ID, "ruby_ore"), AbstractBlock.Settings.create().strength(3f).requiresTool()); + private static Block registerRubyBlock(Identifier identifier, Block.Settings settings) { + Block block = new RubyBlock(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier))); + registerBlockItem(identifier, block, new Item.Settings()); + return Registry.register(Registries.BLOCK, identifier, block); + } + private static Block registerBlock(Identifier identifier, Block.Settings settings) { Block block = new Block(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier))); registerBlockItem(identifier, block, new Item.Settings()); diff --git a/src/main/java/de/jottyfan/gta/gdp/block/RubyBlock.java b/src/main/java/de/jottyfan/gta/gdp/block/RubyBlock.java new file mode 100644 index 0000000..bd7f0ba --- /dev/null +++ b/src/main/java/de/jottyfan/gta/gdp/block/RubyBlock.java @@ -0,0 +1,39 @@ +package de.jottyfan.gta.gdp.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.state.StateManager.Builder; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.util.ActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +/** + * + * @author jotty + * + */ +public class RubyBlock extends Block { + public static final BooleanProperty ACTIVATED = BooleanProperty.of("activated"); + + public RubyBlock(Settings settings) { + super(settings); + setDefaultState(getDefaultState().with(ACTIVATED, false)); + } + + @Override + protected void appendProperties(Builder builder) { + builder.add(ACTIVATED); + } + + @Override + protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + if (!world.isClient()) { + world.setBlockState(pos, state.cycle(ACTIVATED)); + } + return ActionResult.SUCCESS; + } +} +