2020-07-26 16:14:51 +00:00
|
|
|
package com.thebrokenrail.energonrelics.block;
|
|
|
|
|
|
|
|
import com.thebrokenrail.energonrelics.block.entity.HolographicSkyBlockEntity;
|
2020-07-26 23:05:59 +00:00
|
|
|
import com.thebrokenrail.energonrelics.block.util.energy.EnergyBlock;
|
2020-07-26 16:14:51 +00:00
|
|
|
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;
|
2020-07-31 22:53:51 +00:00
|
|
|
import net.minecraft.util.math.Direction;
|
2020-07-26 16:14:51 +00:00
|
|
|
import net.minecraft.world.BlockView;
|
|
|
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
2020-07-26 23:05:59 +00:00
|
|
|
public class HolographicSkyBlock extends EnergyBlock {
|
2020-07-26 16:14:51 +00:00
|
|
|
public static final BooleanProperty POWERED = Properties.POWERED;
|
|
|
|
public static final IntProperty LIGHT_LEVEL = IntProperty.of("light_level", 0, 15);
|
|
|
|
|
|
|
|
public HolographicSkyBlock() {
|
2020-07-31 22:53:51 +00:00
|
|
|
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)));
|
2020-07-26 16:14:51 +00:00
|
|
|
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) {
|
2020-07-31 22:53:51 +00:00
|
|
|
return state.get(POWERED);
|
2020-07-26 16:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-31 22:53:51 +00:00
|
|
|
public BlockRenderType getRenderType(BlockState state) {
|
|
|
|
return state.get(POWERED) ? BlockRenderType.ENTITYBLOCK_ANIMATED : BlockRenderType.MODEL;
|
2020-07-26 16:14:51 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 22:53:51 +00:00
|
|
|
@Environment(EnvType.CLIENT)
|
2020-07-26 16:14:51 +00:00
|
|
|
@Override
|
2020-07-31 22:53:51 +00:00
|
|
|
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);
|
2020-07-26 16:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
|
|
|
|
return HolographicSkyBlockEntity::new;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
|
|
protected Function<BlockEntityRenderDispatcher, BlockEntityRenderer<BlockEntity>> getRenderer() {
|
|
|
|
return HolographicSkyBlockEntityRenderer::new;
|
|
|
|
}
|
|
|
|
}
|