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/portal/EnergizedObsidianBlock.java

68 lines
2.3 KiB
Java

package com.thebrokenrail.energonrelics.block.portal;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.api.block.SimpleBlock;
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.Blocks.ENERGY_BEAM || state.getBlock() == EnergonRelics.Blocks.ENERGY_PROJECTOR) && 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();
}
}
}