This commit is contained in:
@@ -6,6 +6,8 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.SweetBerryBushBlock;
|
import net.minecraft.block.SweetBerryBushBlock;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
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.ActionResult;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -14,9 +16,17 @@ import net.minecraft.world.WorldView;
|
|||||||
import net.minecraft.world.event.GameEvent;
|
import net.minecraft.world.event.GameEvent;
|
||||||
|
|
||||||
public class ChristmasTree extends SweetBerryBushBlock {
|
public class ChristmasTree extends SweetBerryBushBlock {
|
||||||
|
public static final BooleanProperty ACTIVATED = BooleanProperty.of("activated");
|
||||||
|
|
||||||
public ChristmasTree(Settings settings) {
|
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<Block, BlockState> builder) {
|
||||||
|
builder.add(ACTIVATED);
|
||||||
|
super.appendProperties(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,14 +36,14 @@ public class ChristmasTree extends SweetBerryBushBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
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));
|
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.setBlockState(pos, blockState, Block.NOTIFY_LISTENERS);
|
||||||
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState));
|
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState));
|
||||||
return ActionResult.SUCCESS;
|
} else if (state.get(AGE) <= 1) {
|
||||||
} else {
|
world.setBlockState(pos, state.cycle(ACTIVATED));
|
||||||
return super.onUse(state, world, pos, player, hit);
|
|
||||||
}
|
}
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,28 +14,23 @@ import net.minecraft.registry.Registries;
|
|||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.registry.Registry;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.sound.BlockSoundGroup;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class ModBlocks {
|
public class ModBlocks {
|
||||||
|
|
||||||
public static final Block RUBY_BLOCK = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_block"),
|
public static final Block RUBY_BLOCK = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_block"), x -> new Block(x));
|
||||||
AbstractBlock.Settings.create().strength(4f).requiresTool().sounds(BlockSoundGroup.AMETHYST_BLOCK));
|
|
||||||
public static final Block RUBY_ORE = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_ore"),
|
public static final Block RUBY_ORE = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_ore"),
|
||||||
AbstractBlock.Settings.create().strength(4f).requiresTool());
|
x -> new Block(x.strength(4).requiresTool()));
|
||||||
public static final Block CHRISTMASTREE = registerSpecialBlock(Identifier.of(Gtamfmd.MOD_ID, "christmastree"),
|
public static final Block CHRISTMASTREE = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "christmastree"),
|
||||||
AbstractBlock.Settings.create().ticksRandomly().noCollision().luminance(state -> 15),
|
|
||||||
x -> new ChristmasTree(x));
|
x -> new ChristmasTree(x));
|
||||||
|
|
||||||
// functional interface
|
private static Block registerBlock(Identifier identifier, Function<Settings, Block> function) {
|
||||||
private static Block registerSpecialBlock(Identifier identifier, Settings settings, Function<Settings, Block> function) {
|
return registerBlock(identifier, AbstractBlock.Settings.create(), 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, Block.Settings settings) {
|
// functional interface
|
||||||
Block block = new Block(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
|
private static Block registerBlock(Identifier identifier, Settings settings, Function<Settings, Block> function) {
|
||||||
|
Block block = function.apply(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
|
||||||
registerBlockItem(identifier, block, new Item.Settings());
|
registerBlockItem(identifier, block, new Item.Settings());
|
||||||
return Registry.register(Registries.BLOCK, identifier, block);
|
return Registry.register(Registries.BLOCK, identifier, block);
|
||||||
}
|
}
|
||||||
@@ -47,8 +42,7 @@ public class ModBlocks {
|
|||||||
|
|
||||||
public static void registerModBlocks() {
|
public static void registerModBlocks() {
|
||||||
Gtamfmd.LOGGER.info("Registering Mod Blocks for {}", Gtamfmd.MOD_ID);
|
Gtamfmd.LOGGER.info("Registering Mod Blocks for {}", Gtamfmd.MOD_ID);
|
||||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS)
|
ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(entries -> {
|
||||||
.register(entries -> {
|
|
||||||
entries.add(RUBY_BLOCK);
|
entries.add(RUBY_BLOCK);
|
||||||
entries.add(RUBY_ORE);
|
entries.add(RUBY_ORE);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user