use of net.minecraft.block.BlockLiquid in project BloodMagic by WayofTime.
the class RitualPump method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
TileEntity tileEntity = world.getTileEntity(masterRitualStone.getBlockPos().up());
if (currentEssence < getRefreshCost()) {
masterRitualStone.getOwnerNetwork().causeNausea();
return;
}
if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN);
IBlockState tankState = world.getBlockState(masterRitualStone.getBlockPos().up());
int maxDrain = fluidHandler.getTankProperties()[0].getCapacity();
if (fluidHandler.getTankProperties()[0].getContents() != null && fluidHandler.getTankProperties()[0].getContents().amount >= maxDrain)
return;
for (BlockPos pos : getBlockRange(PUMP_RANGE).getContainedPositions(masterRitualStone.getBlockPos())) {
IBlockState state = world.getBlockState(pos);
IFluidHandler blockHandler = null;
if (state.getBlock() instanceof BlockLiquid)
blockHandler = new BlockLiquidWrapper((BlockLiquid) state.getBlock(), world, pos);
else if (state.getBlock() instanceof IFluidHandler)
blockHandler = new FluidBlockWrapper((IFluidBlock) state.getBlock(), world, pos);
if (blockHandler != null) {
FluidStack blockDrain = blockHandler.drain(maxDrain, false);
if (blockDrain != null && fluidHandler.fill(blockDrain, false) == blockDrain.amount) {
Pair<BlockPos, FluidStack> posInfo = Pair.of(pos, blockHandler.drain(maxDrain, false));
if (!liquidsCache.contains(posInfo))
liquidsCache.add(posInfo);
}
}
}
blockPosIterator = liquidsCache.iterator();
if (blockPosIterator.hasNext()) {
Pair<BlockPos, FluidStack> posInfo = blockPosIterator.next();
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
fluidHandler.fill(posInfo.getRight(), true);
world.setBlockState(posInfo.getLeft(), Blocks.STONE.getDefaultState());
world.notifyBlockUpdate(posInfo.getLeft(), tankState, tankState, 3);
blockPosIterator.remove();
}
}
}
use of net.minecraft.block.BlockLiquid in project GregTech by GregTechCE.
the class MetaTileEntityPump method checkFluidBlockAt.
private void checkFluidBlockAt(BlockPos pumpHeadPos, BlockPos checkPos) {
IBlockState blockHere = getWorld().getBlockState(checkPos);
boolean shouldCheckNeighbours = isStraightInPumpRange(checkPos);
if (blockHere.getBlock() instanceof BlockLiquid || blockHere.getBlock() instanceof IFluidBlock) {
IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), checkPos, null);
FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
if (drainStack != null && drainStack.amount > 0) {
this.fluidSourceBlocks.add(checkPos);
}
shouldCheckNeighbours = true;
}
if (shouldCheckNeighbours) {
int maxPumpRange = getMaxPumpRange();
for (EnumFacing facing : EnumFacing.VALUES) {
BlockPos offsetPos = checkPos.offset(facing);
if (offsetPos.distanceSq(pumpHeadPos) > maxPumpRange * maxPumpRange)
// do not add blocks outside bounds
continue;
if (!fluidSourceBlocks.contains(offsetPos) && !blocksToCheck.contains(offsetPos)) {
this.blocksToCheck.add(offsetPos);
}
}
}
}
use of net.minecraft.block.BlockLiquid in project GregTech by GregTechCE.
the class MetaTileEntityPump method tryPumpFirstBlock.
private void tryPumpFirstBlock() {
BlockPos fluidBlockPos = fluidSourceBlocks.poll();
if (fluidBlockPos == null)
return;
IBlockState blockHere = getWorld().getBlockState(fluidBlockPos);
if (blockHere.getBlock() instanceof BlockLiquid || blockHere.getBlock() instanceof IFluidBlock) {
IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), fluidBlockPos, null);
FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
if (drainStack != null && exportFluids.fill(drainStack, false) == drainStack.amount) {
exportFluids.fill(drainStack, true);
fluidHandler.drain(drainStack.amount, true);
this.fluidSourceBlocks.remove(fluidBlockPos);
energyContainer.changeEnergy(-GTValues.V[getTier()]);
}
}
}
use of net.minecraft.block.BlockLiquid in project Tale-of-Kingdoms by Ivasik78.
the class ItemSpawnEgg method onItemRightClick.
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (world.isRemote) {
return stack;
} else {
MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer(world, player, true);
if (movingobjectposition == null) {
return stack;
} else {
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
int x = movingobjectposition.blockX;
int y = movingobjectposition.blockY;
int z = movingobjectposition.blockZ;
if (!world.canMineBlock(player, x, y, z))
return stack;
if (!player.canPlayerEdit(x, y, z, movingobjectposition.sideHit, stack))
return stack;
if (world.getBlock(x, y, z) instanceof BlockLiquid) {
Entity entity = spawnEntity(stack, world, x, y, z);
if (entity != null) {
if (entity instanceof EntityLivingBase && stack.hasDisplayName())
((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());
if (!player.capabilities.isCreativeMode)
--stack.stackSize;
}
}
}
return stack;
}
}
}
use of net.minecraft.block.BlockLiquid in project harvestcraft by MatrexsVigil.
the class TileEntityWaterTrap method getRunTime.
private int getRunTime() {
final int radius = 2;
// final World world = world;
final int varX = pos.getX();
final int varY = pos.getY();
final int varZ = pos.getZ();
int speed = 3500;
for (int offsetX = -radius; offsetX <= radius; ++offsetX) {
for (int offsetZ = -radius; offsetZ <= radius; ++offsetZ) {
if (offsetX * offsetX + offsetZ * offsetZ > radius * radius || offsetX == -radius - 1 && offsetZ == -radius - 1 || offsetX == radius - 1 && offsetZ == radius - 1 || offsetX == radius - 1 && offsetZ == -radius - 1 || offsetX == -radius - 1 && offsetZ == radius - 1)
continue;
final BlockPos pos = new BlockPos(varX + offsetX, varY, varZ + offsetZ);
if (!world.isBlockLoaded(pos))
continue;
final Block blockAtCoords = world.getBlockState(pos).getBlock();
if (blockAtCoords instanceof BlockLiquid) {
speed = (int) (speed * 0.95);
}
if (blockAtCoords != BlockRegistry.watertrap)
continue;
speed = (int) (speed / 0.85);
}
}
return speed;
}
Aggregations