EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/block/HolographicSkyBlock.java

76 lines
3.2 KiB
Java

package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.HolographicSkyBlockEntity;
import com.thebrokenrail.energonrelics.api.block.energy.EnergyBlock;
import com.thebrokenrail.energonrelics.client.block.entity.render.HolographicSkyBlockEntityRenderer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
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.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import java.util.function.Function;
@SuppressWarnings("deprecation")
public class HolographicSkyBlock extends EnergyBlock {
public static final BooleanProperty POWERED = Properties.POWERED;
public static final IntProperty LIGHT_LEVEL = IntProperty.of("light_level", 0, 15);
public HolographicSkyBlock() {
super(FabricBlockSettings.copy(Blocks.OBSIDIAN).sounds(BlockSoundGroup.GLASS).nonOpaque().allowsSpawning((state, world, pos, type) -> !state.get(POWERED)).solidBlock((state, world, pos) -> !state.get(POWERED)).suffocates((state, world, pos) -> !state.get(POWERED)).lightLevel(state -> state.get(LIGHT_LEVEL)).blockVision((state, world, pos) -> !state.get(POWERED)));
setDefaultState(getDefaultState().with(POWERED, false).with(LIGHT_LEVEL, 0));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(POWERED, LIGHT_LEVEL);
}
@Override
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
return state.get(POWERED);
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return state.get(POWERED) ? BlockRenderType.ENTITYBLOCK_ANIMATED : BlockRenderType.MODEL;
}
@Override
@Environment(EnvType.CLIENT)
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
return state == stateFrom || super.isSideInvisible(state, stateFrom, direction);
}
@Override
@Environment(EnvType.CLIENT)
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
return state.get(POWERED) ? 1f : super.getAmbientOcclusionLightLevel(state, world, pos);
}
@Override
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return HolographicSkyBlockEntity::new;
}
@Override
@Environment(EnvType.CLIENT)
protected Function<BlockEntityRenderDispatcher, BlockEntityRenderer<BlockEntity>> getRenderer() {
return HolographicSkyBlockEntityRenderer::new;
}
}