This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/block/BlockBreakerBlock.java

51 lines
2.0 KiB
Java
Raw Normal View History

2020-07-22 18:07:29 +00:00
package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.BlockBreakerBlockEntity;
import com.thebrokenrail.energonrelics.block.util.energy.FacingEnergyProviderBlock;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.WorldAccess;
import java.util.function.Function;
public class BlockBreakerBlock extends FacingEnergyProviderBlock {
public static final BooleanProperty POWERED = Properties.POWERED;
public BlockBreakerBlock() {
2020-07-22 20:01:10 +00:00
super(FabricBlockSettings.copy(Blocks.BLACKSTONE).strength(2.0F, 6.0F).nonOpaque().lightLevel(state -> state.get(POWERED) ? 7 : 0));
2020-07-22 18:07:29 +00:00
setDefaultState(getDefaultState().with(POWERED, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(POWERED);
}
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
if (state.get(FACING) == direction) {
BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof BlockBreakerBlockEntity) {
((BlockBreakerBlockEntity) entity).resetProgress();
}
}
return super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
}
@Override
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return BlockBreakerBlockEntity::new;
}
}