diff --git a/src/main/java/de/jottyfan/minecraft/block/ChristmasTree.java b/src/main/java/de/jottyfan/minecraft/block/ChristmasTree.java index cb77df3..90c5171 100644 --- a/src/main/java/de/jottyfan/minecraft/block/ChristmasTree.java +++ b/src/main/java/de/jottyfan/minecraft/block/ChristmasTree.java @@ -6,6 +6,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.SweetBerryBushBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +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; @@ -14,9 +16,17 @@ import net.minecraft.world.WorldView; import net.minecraft.world.event.GameEvent; public class ChristmasTree extends SweetBerryBushBlock { + public static final BooleanProperty ACTIVATED = BooleanProperty.of("activated"); public ChristmasTree(Settings settings) { - super(settings); + super(settings.ticksRandomly().noCollision().luminance(state -> state.get(ACTIVATED) ? 15 : 0)); + setDefaultState(getDefaultState().with(ACTIVATED, false)); + } + + @Override + protected void appendProperties(Builder builder) { + builder.add(ACTIVATED); + super.appendProperties(builder); } @Override @@ -26,14 +36,14 @@ public class ChristmasTree extends SweetBerryBushBlock { @Override protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { - if (state.get(AGE) > 1) { + if (state.get(AGE) > 1 && state.get(ACTIVATED)) { dropStack(world, pos, new ItemStack(ModItems.GINGERBREAD)); - BlockState blockState = state.with(AGE, 1); + BlockState blockState = state.with(AGE, 0).cycle(ACTIVATED); world.setBlockState(pos, blockState, Block.NOTIFY_LISTENERS); world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState)); - return ActionResult.SUCCESS; - } else { - return super.onUse(state, world, pos, player, hit); + } else if (state.get(AGE) <= 1) { + world.setBlockState(pos, state.cycle(ACTIVATED)); } + return ActionResult.SUCCESS; } } diff --git a/src/main/java/de/jottyfan/minecraft/block/ModBlocks.java b/src/main/java/de/jottyfan/minecraft/block/ModBlocks.java index 0d9d640..321ebd5 100644 --- a/src/main/java/de/jottyfan/minecraft/block/ModBlocks.java +++ b/src/main/java/de/jottyfan/minecraft/block/ModBlocks.java @@ -14,43 +14,37 @@ import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; -import net.minecraft.sound.BlockSoundGroup; import net.minecraft.util.Identifier; public class ModBlocks { - public static final Block RUBY_BLOCK = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_block"), - AbstractBlock.Settings.create().strength(4f).requiresTool().sounds(BlockSoundGroup.AMETHYST_BLOCK)); - public static final Block RUBY_ORE = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_ore"), - AbstractBlock.Settings.create().strength(4f).requiresTool()); - public static final Block CHRISTMASTREE = registerSpecialBlock(Identifier.of(Gtamfmd.MOD_ID, "christmastree"), - AbstractBlock.Settings.create().ticksRandomly().noCollision().luminance(state -> 15), - x -> new ChristmasTree(x)); + public static final Block RUBY_BLOCK = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_block"), x -> new Block(x)); + public static final Block RUBY_ORE = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_ore"), + x -> new Block(x.strength(4).requiresTool())); + public static final Block CHRISTMASTREE = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "christmastree"), + x -> new ChristmasTree(x)); - // functional interface - private static Block registerSpecialBlock(Identifier identifier, Settings settings, Function function) { - Block block = function.apply(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, Function function) { + return registerBlock(identifier, AbstractBlock.Settings.create(), function); + } - 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()); - return Registry.register(Registries.BLOCK, identifier, block); - } + // functional interface + private static Block registerBlock(Identifier identifier, Settings settings, Function function) { + Block block = function.apply(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier))); + registerBlockItem(identifier, block, new Item.Settings()); + return Registry.register(Registries.BLOCK, identifier, block); + } - private static void registerBlockItem(Identifier identifier, Block block, Item.Settings settings) { - Registry.register(Registries.ITEM, identifier, new BlockItem(block, - settings.useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)))); - } + private static void registerBlockItem(Identifier identifier, Block block, Item.Settings settings) { + Registry.register(Registries.ITEM, identifier, new BlockItem(block, + settings.useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)))); + } - public static void registerModBlocks() { - Gtamfmd.LOGGER.info("Registering Mod Blocks for {}", Gtamfmd.MOD_ID); - ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS) - .register(entries -> { - entries.add(RUBY_BLOCK); - entries.add(RUBY_ORE); - }); - } + public static void registerModBlocks() { + Gtamfmd.LOGGER.info("Registering Mod Blocks for {}", Gtamfmd.MOD_ID); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(entries -> { + entries.add(RUBY_BLOCK); + entries.add(RUBY_ORE); + }); + } }