use of net.minecraft.block.BlockState 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.block.BlockState in project BluePower by Qmunity.
the class MultipartUtils method getClosestState.
/**
* Returns the closest Multipart state to the Vec3 in in a given position.
* @param world
* @param start
* @param end
* @param pos
*/
@Nullable
public static BlockState getClosestState(World world, Vector3d start, Vector3d end, BlockPos pos) {
TileEntity te = world.getBlockEntity(pos);
BlockState state = null;
double distance = Double.POSITIVE_INFINITY;
if (te instanceof TileBPMultipart) {
for (BlockState part : ((TileBPMultipart) te).getStates()) {
RayTraceResult res = part.getVisualShape(world, pos, ISelectionContext.empty()).clip(start, end, pos);
if (res != null) {
double partDistance = start.distanceToSqr(res.getLocation());
if (distance > partDistance) {
distance = partDistance;
state = part;
}
}
}
}
return state;
}
use of net.minecraft.block.BlockState in project Overloaded by CJ-MC-Mods.
the class TileItemInterface method updateClient.
private void updateClient() {
BlockState state = getLevel().getBlockState(getBlockPos());
getLevel().sendBlockUpdated(this.getBlockPos(), state, state, 3);
}
use of net.minecraft.block.BlockState in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method breakAndUseEnergy.
/**
* @return True if the break was successful, false otherwise
*/
@Nonnull
private static BlockBreakResult breakAndUseEnergy(@Nonnull ServerWorld worldIn, @Nonnull BlockPos blockPos, @Nonnull IEnergyStorage energy, @Nonnull ServerPlayerEntity player, int efficiency, int unbreaking) {
BlockState state = worldIn.getBlockState(blockPos);
if (!player.abilities.instabuild) {
float hardness = state.getDestroySpeed(worldIn, blockPos);
if (hardness < 0) {
return BlockBreakResult.FAIL_UNBREAKABLE;
}
float floatBreakCost = getBreakCost(hardness, efficiency, unbreaking, getDistance(player, blockPos));
if (Float.isInfinite(floatBreakCost) || Float.isNaN(floatBreakCost))
return BlockBreakResult.FAIL_ENERGY;
int breakCost = Math.round(floatBreakCost);
if (breakCost < 0 || energy.getEnergyStored() < breakCost) {
return BlockBreakResult.FAIL_ENERGY;
}
}
if (player.distanceToSqr(blockPos.getX(), blockPos.getY(), blockPos.getZ()) > OverloadedConfig.INSTANCE.multiToolConfig.reach * OverloadedConfig.INSTANCE.multiToolConfig.reach) {
return BlockBreakResult.FAIL_RANGE;
}
if (!state.getBlock().canEntityDestroy(state, worldIn, blockPos, player)) {
return BlockBreakResult.FAIL_REMOVE;
}
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(worldIn, blockPos, state, player);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled()) {
return BlockBreakResult.FAIL_REMOVE;
}
boolean result = PlayerInteractionUtil.tryHarvestBlock(player, worldIn, blockPos);
return result ? BlockBreakResult.SUCCESS : BlockBreakResult.FAIL_REMOVE;
}
use of net.minecraft.block.BlockState in project NetherEx by LogicTechCorp.
the class ElderMushroomBlock method isValidPosition.
@Override
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
BlockPos posDown = pos.down();
BlockState stateDown = world.getBlockState(posDown);
Block blockDown = stateDown.getBlock();
if (blockDown != Blocks.MYCELIUM && blockDown != Blocks.PODZOL) {
return stateDown.canSustainPlant(world, posDown, Direction.UP, this);
} else {
return true;
}
}
Aggregations