net.minecraft.fluid.IFluidState Java Examples

The following examples show how to use net.minecraft.fluid.IFluidState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenderBlockTileEntity.java    From MiningGadgets with MIT License 6 votes vote down vote up
private void freeze(ItemStack stack) {
    for (Direction side : Direction.values()) {
        BlockPos sidePos = pos.offset(side);
        IFluidState state = world.getFluidState(sidePos);
        int freezeCost = Config.UPGRADECOST_FREEZE.get() * -1;
        if (state.getFluid().isEquivalentTo(Fluids.LAVA) && state.getFluid().isSource(state)) {
            world.setBlockState(sidePos, Blocks.OBSIDIAN.getDefaultState());
            stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(freezeCost, false));
        } else if (state.getFluid().isEquivalentTo(Fluids.WATER) && state.getFluid().isSource(state)) {
            world.setBlockState(sidePos, Blocks.PACKED_ICE.getDefaultState());
            stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(freezeCost, false));
        } else if ((state.getFluid().isEquivalentTo(Fluids.WATER) || state.getFluid().isEquivalentTo(Fluids.LAVA)) && !state.getFluid().isSource(state)) {
            world.setBlockState(sidePos, Blocks.COBBLESTONE.getDefaultState());
            stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(freezeCost, false));
        }
    }
}
 
Example #2
Source File: MiningGadget.java    From MiningGadgets with MIT License 5 votes vote down vote up
public List<BlockPos> findSources(World world, List<BlockPos> coords) {
    List<BlockPos> sources = new ArrayList<>();
    for (BlockPos coord : coords) {
        for (Direction side : Direction.values()) {
            BlockPos sidePos = coord.offset(side);
            IFluidState state = world.getFluidState(sidePos);
            if ((state.getFluid().isEquivalentTo(Fluids.LAVA) || state.getFluid().isEquivalentTo(Fluids.WATER)))
                if (!sources.contains(sidePos))
                    sources.add(sidePos);
        }
    }
    return sources;
}
 
Example #3
Source File: CCBlockRendererDispatcher.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean renderFluid(BlockPos pos, ILightReader world, IVertexBuilder builder, IFluidState state) {
    Optional<ICCBlockRenderer> renderOpt = BlockRenderingRegistry.getBlockRenderers().stream().filter(e -> e.canHandleFluid(world, pos, state)).findFirst();
    //noinspection OptionalIsPresent
    if (renderOpt.isPresent()) {
        return renderOpt.get().renderFluid(pos, world, builder, state);
    } else {
        return super.renderFluid(pos, world, builder, state);
    }
}
 
Example #4
Source File: BlockEnderStorage.java    From EnderStorage with MIT License 4 votes vote down vote up
@Override
public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid) {
    return willHarvest || super.removedByPlayer(state, world, pos, player, willHarvest, fluid);
}
 
Example #5
Source File: ICCBlockRenderer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called to evaluate weather this ICCBlockRenderer will be called for the specified IFluidState.
 *
 * @param world      The world.
 * @param pos        The pos.
 * @param fluidState The IFluidState.
 * @return If you wish to render the IFluidState.
 */
default boolean canHandleFluid(ILightReader world, BlockPos pos, IFluidState fluidState) {
    return false;
}
 
Example #6
Source File: ICCBlockRenderer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called to render your fluid in world.
 * You MUST use the provided {@link IVertexBuilder}.
 * THE BUFFER IS ALREADY DRAWING!
 * YOU MAY BE FIRED ON THE CHUNK BATCHING THREAD!
 *
 * @param pos     Position.
 * @param world   World.
 * @param builder The {@link IVertexBuilder}.
 * @param state   The {@link IFluidState}
 * @return If any quads were added.
 */
default boolean renderFluid(BlockPos pos, ILightReader world, IVertexBuilder builder, IFluidState state) {
    return false;
}