use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileThermopile method tick.
@Override
public void tick() {
if (!level.isClientSide) {
storage.resetCurrent();
if (level.getBlockState(worldPosition.relative(Direction.DOWN)).getBlock() == Blocks.LAVA && storage.getEnergy() < MAX_VOLTAGE)
storage.addEnergy(0.1, false);
// Balance power of attached blulectric blocks.
for (Direction facing : Direction.values()) {
TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
if (tile != null && tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).isPresent()) {
IPowerBase exStorage = tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).orElse(null);
EnergyHelper.balancePower(exStorage, storage);
}
}
}
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class WorldGenVolcano method generateLootChamber.
private void generateLootChamber(IWorld world, int middleX, int startY, int middleZ, Random rand) {
int roomSize = 9;
int roomHeight = 5;
int startX = middleX - roomSize / 2;
int startZ = middleZ - roomSize / 2;
for (int x = startX; x < startX + roomSize; x++) {
for (int y = startY; y < startY + roomHeight; y++) {
for (int z = startZ; z < startZ + roomSize; z++) {
int xOffset = Math.abs(x - middleX);
int zOffset = Math.abs(z - middleZ);
if (xOffset != 0 || zOffset != 0) {
boolean spawnGlass = xOffset <= 1 && zOffset <= 1;
setBlock(world, new BlockPos(x, y, z), spawnGlass ? BPBlocks.reinforced_sapphire_glass.defaultBlockState() : Blocks.AIR.defaultBlockState());
}
}
}
}
for (Direction d : Direction.values()) {
if (d != Direction.UP && d != Direction.DOWN) {
if (rand.nextInt(2) == 0) {
generateAltar(world, middleX + d.getStepX() * roomSize / 2, startY - 1, middleZ + d.getStepZ() * roomSize / 2, rand, d);
}
}
}
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class BlockBPCableBase method getStateForPos.
private BlockState getStateForPos(World world, BlockPos pos, BlockState state, Direction face) {
List<Direction> directions = new ArrayList<>(FACING.getPossibleValues());
List<Direction> internal = null;
boolean connected_left = false;
boolean connected_right = false;
boolean connected_front = false;
boolean connected_back = false;
boolean join_left = false;
boolean join_right = false;
boolean join_front = false;
boolean join_back = false;
// Make sure the side we are trying to connect on isn't blocked.
TileEntity ownTile = world.getBlockEntity(pos);
if (ownTile instanceof TileBPMultipart) {
directions.removeIf(d -> ((TileBPMultipart) ownTile).isSideBlocked(getCapability(), d));
internal = ((TileBPMultipart) ownTile).getStates().stream().filter(s -> s.getBlock() == this).map(s -> s.getValue(FACING)).collect(Collectors.toList());
}
// Make sure the cable is on the same side of the block
directions.removeIf(d -> {
TileEntity t = world.getBlockEntity(pos.relative(d));
return (world.getBlockState(pos.relative(d)).getBlock() == this && world.getBlockState(pos.relative(d)).getValue(FACING) != face) || (t instanceof TileBPMultipart && ((TileBPMultipart) t).getStates().stream().noneMatch(s -> s.getValue(FACING) == face));
});
// Populate all directions
for (Direction d : directions) {
TileEntity tileEntity = world.getBlockEntity(pos.relative(d));
BlockState dirState = world.getBlockState(pos.relative(d));
BlockPos dirPos = pos.relative(d);
boolean join = false;
// If Air look for a change in Direction
if (world.getBlockState(pos.relative(d)).getBlock() == Blocks.AIR) {
dirState = world.getBlockState(pos.relative(d).relative(face.getOpposite()));
dirPos = pos.relative(d).relative(face.getOpposite());
if (dirState.getBlock() == this && dirState.getValue(FACING) == d) {
tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
join = true;
} else if (dirState.getBlock() instanceof BlockBPMultipart) {
tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
if (tileEntity instanceof TileBPMultipart && ((TileBPMultipart) tileEntity).getStates().stream().filter(s -> s.getBlock() == this).anyMatch(s -> s.getValue(FACING) == d)) {
join = true;
} else {
tileEntity = null;
}
}
}
// Check Capability for Direction
switch(state.getValue(FACING)) {
case UP:
case DOWN:
switch(d) {
case EAST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case WEST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case NORTH:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case SOUTH:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case NORTH:
switch(d) {
case WEST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case EAST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case SOUTH:
switch(d) {
case EAST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case WEST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case EAST:
switch(d) {
case NORTH:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case SOUTH:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case WEST:
switch(d) {
case SOUTH:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case NORTH:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
}
}
if (internal != null)
for (Direction d : internal) {
switch(state.getValue(FACING)) {
case UP:
case DOWN:
switch(d) {
case EAST:
connected_left = true;
break;
case WEST:
connected_right = true;
break;
case NORTH:
connected_back = true;
break;
case SOUTH:
connected_front = true;
break;
}
break;
case NORTH:
switch(d) {
case WEST:
connected_left = true;
break;
case EAST:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case SOUTH:
switch(d) {
case EAST:
connected_left = true;
break;
case WEST:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case EAST:
switch(d) {
case NORTH:
connected_left = true;
break;
case SOUTH:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case WEST:
switch(d) {
case SOUTH:
connected_left = true;
break;
case NORTH:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
}
}
FluidState fluidstate = world.getFluidState(pos);
return state.setValue(CONNECTED_LEFT, connected_left).setValue(CONNECTED_RIGHT, connected_right).setValue(CONNECTED_FRONT, connected_front).setValue(CONNECTED_BACK, connected_back).setValue(JOIN_LEFT, join_left).setValue(JOIN_RIGHT, join_right).setValue(JOIN_FRONT, join_front).setValue(JOIN_BACK, join_back).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
}
use of net.minecraft.util.Direction in project Ceramics by KnightMiner.
the class ChannelBlock method getStateForPlacement.
@Override
@Nullable
public BlockState getStateForPlacement(BlockItemUseContext context) {
World world = context.getWorld();
BlockPos pos = context.getPos();
BlockState state = this.getDefaultState().with(POWERED, world.isBlockPowered(pos));
Direction side = context.getFace();
// we cannot connect upwards, so done here
if (side == Direction.DOWN) {
return state;
}
// if placed on the top face, try to connect down
if (side == Direction.UP) {
return state.with(DOWN, canConnect(world, pos, Direction.DOWN));
}
// if placed on a fluid handler, connect to that
ChannelConnection connection = ChannelConnection.NONE;
BlockPos placedOn = pos.offset(side.getOpposite());
// on another channel means in or out
if (world.getBlockState(placedOn).isIn(this)) {
PlayerEntity player = context.getPlayer();
connection = player != null && player.isSneaking() ? ChannelConnection.IN : ChannelConnection.OUT;
} else if (isFluidHandler(world, side, placedOn)) {
connection = ChannelConnection.OUT;
}
return state.with(DIRECTION_MAP.get(side.getOpposite()), connection);
}
use of net.minecraft.util.Direction in project Ceramics by KnightMiner.
the class CisternBlock method isConnected.
/**
* Check if the given block is something the barrel should connect to
* @param facing Side to check
* @param facingState Block on side
* @return True if connected, false otherwise
*/
protected boolean isConnected(Direction facing, BlockState facingState) {
// must be in tag
if (!facingState.isIn(CeramicsTags.Blocks.CISTERN_CONNECTIONS)) {
return false;
}
// if the block has a side property, use that
Direction opposite = facing.getOpposite();
BooleanProperty sideProp = CONNECTIONS.get(opposite);
if (facingState.hasProperty(sideProp)) {
return facingState.get(sideProp);
}
// channel connections
EnumProperty<ChannelConnection> channelProp = ChannelBlock.DIRECTION_MAP.get(opposite);
if (facingState.hasProperty(channelProp)) {
return facingState.get(channelProp) == ChannelConnection.OUT;
}
// if there is a face property and it is not wall, not connected
if (facingState.hasProperty(BlockStateProperties.FACE) && facingState.get(BlockStateProperties.FACE) != AttachFace.WALL) {
return false;
}
// try relevant facing properties, if any are present must be facing this
return facingConnected(facing, facingState, BlockStateProperties.HORIZONTAL_FACING) && facingConnected(facing, facingState, BlockStateProperties.FACING) && facingConnected(facing, facingState, BlockStateProperties.FACING_EXCEPT_UP);
}
Aggregations