2020-08-01 20:22:32 +00:00
|
|
|
package com.thebrokenrail.energonrelics.block.portal;
|
|
|
|
|
|
|
|
import com.thebrokenrail.energonrelics.EnergonRelics;
|
2020-08-04 17:06:11 +00:00
|
|
|
import com.thebrokenrail.energonrelics.api.block.SimpleBlock;
|
2020-08-01 20:22:32 +00:00
|
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.block.Blocks;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.Items;
|
|
|
|
import net.minecraft.state.property.Properties;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.Direction;
|
|
|
|
import net.minecraft.world.BlockView;
|
|
|
|
import net.minecraft.world.WorldAccess;
|
|
|
|
|
|
|
|
public class EnergizedObsidianBlock extends SimpleBlock {
|
|
|
|
public EnergizedObsidianBlock() {
|
|
|
|
super(FabricBlockSettings.copy(Blocks.OBSIDIAN).emissiveLighting((state, world, pos) -> true).nonOpaque().lightLevel(state -> 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean registerItem() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Item asItem() {
|
|
|
|
return Items.OBSIDIAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean faces(WorldAccess world, BlockPos targetPos, BlockPos pos) {
|
|
|
|
BlockState state = world.getBlockState(targetPos);
|
|
|
|
if ((state.getBlock() == EnergonRelics.ENERGY_BEAM_BLOCK || state.getBlock() == EnergonRelics.ENERGY_PROJECTOR_BLOCK) && state.contains(Properties.FACING)) {
|
|
|
|
Direction facing = state.get(Properties.FACING);
|
|
|
|
for (Direction side : Direction.values()) {
|
|
|
|
if (targetPos.offset(side).equals(pos)) {
|
|
|
|
return facing == side;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
@Override
|
|
|
|
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
|
|
|
|
boolean valid = false;
|
|
|
|
|
|
|
|
for (Direction dir : Direction.values()) {
|
|
|
|
if (faces(world, pos.offset(dir), pos)) {
|
|
|
|
valid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
return super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
|
|
|
|
} else {
|
|
|
|
return Blocks.OBSIDIAN.getDefaultState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|