added block state property
This commit is contained in:
@ -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());
|
||||
|
39
src/main/java/de/jottyfan/gta/gdp/block/RubyBlock.java
Normal file
39
src/main/java/de/jottyfan/gta/gdp/block/RubyBlock.java
Normal file
@ -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<Block, BlockState> 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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user