use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileBattery method tick.
@Override
public void tick() {
if (!level.isClientSide) {
storage.resetCurrent();
// 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()).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
}
double energy = storage.getEnergy();
int batteryLevel = (int) ((energy / MAX_ENERGY) * 6);
BlockState state = getBlockState();
if (state.getValue(BlockBattery.LEVEL) != batteryLevel) {
this.level.setBlockAndUpdate(worldPosition, state.setValue(BlockBattery.LEVEL, batteryLevel));
markForRenderUpdate();
setChanged();
}
}
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileBlulectricCable method getCapability.
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
List<Direction> directions = new ArrayList<>(BlockBlulectricCable.FACING.getPossibleValues());
if (level != null) {
BlockState state = getBlockState();
if (state.getBlock() instanceof BlockBlulectricCable) {
// Remove upward connections
directions.remove(state.getValue(BlockBlulectricCable.FACING));
// Make sure the cable is on the same side of the block
directions.removeIf(d -> level.getBlockState(worldPosition.relative(d)).getBlock() instanceof BlockBlulectricCable && level.getBlockState(worldPosition.relative(d)).getValue(BlockBlulectricCable.FACING) != state.getValue(BlockBlulectricCable.FACING));
}
}
if (cap == CapabilityBlutricity.BLUTRICITY_CAPABILITY && (side == null || directions.contains(side))) {
if (blutricityCap == null)
blutricityCap = LazyOptional.of(() -> storage);
return blutricityCap.cast();
}
return LazyOptional.empty();
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileBlulectricCable method tick.
@Override
public void tick() {
storage.resetCurrent();
if (level != null && !level.isClientSide) {
BlockState state = getBlockState();
if (state.getBlock() instanceof BlockBlulectricCable) {
List<Direction> directions = new ArrayList<>(BlockBlulectricCable.FACING.getPossibleValues());
// Check the side has capability
directions.removeIf(d -> !getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, d).isPresent());
// Balance power of attached blulectric blocks.
for (Direction facing : directions) {
Block fBlock = level.getBlockState(worldPosition.relative(facing)).getBlock();
if (fBlock != Blocks.AIR && fBlock != Blocks.WATER) {
TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
if (tile != null)
tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
} else {
TileEntity tile = level.getBlockEntity(worldPosition.relative(facing).relative(state.getValue(BlockBlulectricCable.FACING).getOpposite()));
if (tile != null)
tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, state.getValue(BlockBlulectricCable.FACING)).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
}
}
}
}
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileFilter method pullItem.
@Override
protected void pullItem() {
Direction dir = getOutputDirection().getOpposite();
TileEntity tile = getTileCache(dir);
Direction direction = dir.getOpposite();
boolean everythingNull = true;
for (ItemStack filterStack : inventory) {
if (!filterStack.isEmpty()) {
everythingNull = false;
ItemStack extractedStack = IOHelper.extract(tile, direction, filterStack, true, false, fuzzySetting);
if (!extractedStack.isEmpty()) {
this.addItemToOutputBuffer(extractedStack, filterColor);
break;
}
}
}
if (everythingNull) {
ItemStack extractedStack = IOHelper.extract(tile, direction, false);
if (!extractedStack.isEmpty()) {
this.addItemToOutputBuffer(extractedStack, filterColor);
}
}
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileTransposer method suckEntity.
private void suckEntity() {
Direction direction = getFacingDirection();
AxisAlignedBB box = new AxisAlignedBB(worldPosition.getX() + direction.getStepX(), worldPosition.getY() + direction.getStepY(), worldPosition.getZ() + direction.getStepZ(), worldPosition.getX() + direction.getStepX() + 1, worldPosition.getY() + direction.getStepY() + 1, worldPosition.getZ() + direction.getStepZ() + 1);
for (ItemEntity entity : (List<ItemEntity>) level.getEntitiesOfClass(ItemEntity.class, box)) {
ItemStack stack = entity.getItem();
if (isItemAccepted(stack) && entity.isAlive()) {
addItemToOutputBuffer(stack, getAcceptedItemColor(stack));
entity.remove();
}
}
}
Aggregations