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/HolographicSkyBlock.java

72 lines
3.1 KiB
Java

package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.HolographicSkyBlockEntity;
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
import com.thebrokenrail.energonrelics.client.block.entity.render.DefensiveLaserBlockEntityRenderer;
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.ShapeContext;
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.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import java.util.function.Function;
@SuppressWarnings("deprecation")
public class HolographicSkyBlock extends EnergyProviderBlock {
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(POWERED) ? 7 : 0).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 true;
}
@Override
public VoxelShape getVisualShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return VoxelShapes.empty();
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return state.get(POWERED) ? BlockRenderType.ENTITYBLOCK_ANIMATED : BlockRenderType.MODEL;
}
@Override
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return HolographicSkyBlockEntity::new;
}
@Override
@Environment(EnvType.CLIENT)
protected Function<BlockEntityRenderDispatcher, BlockEntityRenderer<BlockEntity>> getRenderer() {
return HolographicSkyBlockEntityRenderer::new;
}
}