Search in sources :

Example 36 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock 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()]);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BlockPos(net.minecraft.util.math.BlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 37 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project ICBM-Classic by BuiltBrokenModding.

the class BlastAntiGravitational method doExplode.

@Override
public // TODO rewrite entire method
boolean doExplode(// TODO rewrite entire method
int callCount) {
    int r = this.callCount;
    if (world() != null && !this.world().isRemote) {
        try {
            if (// TODO replace thread check with callback triggered by thread and delayed into main thread
            this.thread != null) {
                if (this.thread.isComplete) {
                    // Copy as concurrent list is not fast to sort
                    List<BlockPos> results = new ArrayList();
                    results.addAll(getThreadResults());
                    if (r == 0) {
                        Collections.sort(results, new PosDistanceSorter(location, true));
                    }
                    int blocksToTake = 20;
                    for (BlockPos targetPosition : results) {
                        final IBlockState blockState = world.getBlockState(targetPosition);
                        if (// don't pick up air
                        !blockState.getBlock().isAir(blockState, world, targetPosition) && // don't pick up replacable blocks like fire, grass, or snow (this does not include crops)
                        !blockState.getBlock().isReplaceable(world, targetPosition) && !(blockState.getBlock() instanceof IFluidBlock) && // don't pick up liquids
                        !(blockState.getBlock() instanceof BlockLiquid)) {
                            float hardness = blockState.getBlockHardness(world, targetPosition);
                            if (hardness >= 0 && hardness < 1000) {
                                if (world().rand.nextInt(3) > 0) {
                                    // Remove block
                                    world.setBlockToAir(targetPosition);
                                    // Mark blocks taken
                                    blocksToTake--;
                                    if (blocksToTake <= 0) {
                                        break;
                                    }
                                    // Create flying block
                                    EntityFlyingBlock entity = new EntityFlyingBlock(world(), targetPosition, blockState, 0);
                                    entity.yawChange = 50 * world().rand.nextFloat();
                                    entity.pitchChange = 100 * world().rand.nextFloat();
                                    entity.motionY += Math.max(0.15 * world().rand.nextFloat(), 0.1);
                                    entity.noClip = true;
                                    world().spawnEntity(entity);
                                    // Track flying block
                                    flyingBlocks.add(entity);
                                }
                            }
                        }
                    }
                }
            } else {
                String msg = String.format("BlastAntiGravitational#doPostExplode() -> Failed to run due to null thread" + "\nWorld = %s " + "\nThread = %s" + "\nSize = %s" + "\nPos = ", world, thread, size, location);
                ICBMClassic.logger().error(msg);
            }
        } catch (Exception e) {
            String msg = String.format("BlastAntiGravitational#doPostExplode() ->  Unexpected error while running post detonation code " + "\nWorld = %s " + "\nThread = %s" + "\nSize = %s" + "\nPos = ", world, thread, size, location);
            ICBMClassic.logger().error(msg, e);
        }
    }
    int radius = (int) this.getBlastRadius();
    AxisAlignedBB bounds = new AxisAlignedBB(location.x() - radius, location.y() - radius, location.z() - radius, location.y() + radius, 100, location.z() + radius);
    List<Entity> allEntities = world().getEntitiesWithinAABB(Entity.class, bounds);
    for (Entity entity : allEntities) {
        if (!(entity instanceof EntityFlyingBlock) && entity.posY < 100 + location.y()) {
            if (entity.motionY < 0.4) {
                entity.motionY += 0.15;
            }
        }
    }
    return this.callCount > 20 * 120;
}
Also used : PosDistanceSorter(icbm.classic.lib.transform.PosDistanceSorter) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) BlockLiquid(net.minecraft.block.BlockLiquid) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 38 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project BluePower by Qmunity.

the class TileMachineBase method ejectItems.

private void ejectItems() {
    for (Iterator<TubeStack> iterator = internalItemStackBuffer.iterator(); iterator.hasNext(); ) {
        TubeStack tubeStack = iterator.next();
        if (IOHelper.canInterfaceWith(getTileCache(getOutputDirection()), getFacingDirection())) {
            ItemStack returnedStack = IOHelper.insert(getTileCache(getOutputDirection()), tubeStack.stack, getFacingDirection(), tubeStack.color, false);
            if (returnedStack.isEmpty()) {
                iterator.remove();
                setChanged();
                if (!ejectionScheduled)
                    break;
            } else if (returnedStack.getCount() != tubeStack.stack.getCount()) {
                setChanged();
                if (!ejectionScheduled)
                    break;
            } else {
                break;
            }
        } else if (spawnItemsInWorld) {
            Direction direction = getFacingDirection().getOpposite();
            Block block = level.getBlockState(worldPosition.relative(direction)).getBlock();
            if (!level.getBlockState(worldPosition.relative(direction)).canOcclude() || block instanceof IFluidBlock) {
                ejectItemInWorld(tubeStack.stack, direction);
                iterator.remove();
                setChanged();
            } else {
                break;
            }
        }
    }
}
Also used : TubeStack(com.bluepowermod.container.stack.TubeStack) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 39 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project Railcraft by Railcraft.

the class BlockTrackOutfitted method clearBlock.

@Override
public boolean clearBlock(IBlockState state, World world, BlockPos pos, @Nullable EntityPlayer player) {
    TrackType trackType = getTrackType(world, pos);
    IBlockState newState = TrackToolsAPI.makeTrackState(trackType.getBaseBlock(), TrackTools.getTrackDirectionRaw(state));
    Charge.distribution.network(world).removeNode(pos);
    boolean b = WorldPlugin.setBlockState(world, pos, newState);
    world.notifyNeighborsOfStateChange(pos, this, true);
    // Below is ugly workaround for fluids!
    if (Arrays.stream(EnumFacing.VALUES).map(face -> WorldPlugin.getBlock(world, pos.offset(face))).anyMatch(block -> block instanceof IFluidBlock || block instanceof BlockLiquid)) {
        newState.getBlock().dropBlockAsItem(world, pos, newState, 0);
    }
    return b;
}
Also used : Explosion(net.minecraft.world.Explosion) EnumHand(net.minecraft.util.EnumHand) Charge(mods.railcraft.api.charge.Charge) TrackShapeHelper(mods.railcraft.common.blocks.tracks.TrackShapeHelper) Level(org.apache.logging.log4j.Level) BlockStateContainer(net.minecraft.block.state.BlockStateContainer) TrackTools(mods.railcraft.common.blocks.tracks.TrackTools) BlockLiquid(net.minecraft.block.BlockLiquid) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) NonNullList(net.minecraft.util.NonNullList) IChargeBlock(mods.railcraft.api.charge.IChargeBlock) UnlistedProperty(mods.railcraft.common.blocks.UnlistedProperty) PropertyBool(net.minecraft.block.properties.PropertyBool) EntityMinecart(net.minecraft.entity.item.EntityMinecart) RailcraftBlocks(mods.railcraft.common.blocks.RailcraftBlocks) PropertyEnum(net.minecraft.block.properties.PropertyEnum) Nullable(org.jetbrains.annotations.Nullable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) mods.railcraft.api.tracks(mods.railcraft.api.tracks) java.util(java.util) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) mods.railcraft.common.plugins.forge(mods.railcraft.common.plugins.forge) IPostConnection(mods.railcraft.api.core.IPostConnection) BlockMeta(mods.railcraft.common.blocks.BlockMeta) ExtendedBlockState(net.minecraftforge.common.property.ExtendedBlockState) TrackTypes(mods.railcraft.common.blocks.tracks.behaivor.TrackTypes) Railcraft(mods.railcraft.common.core.Railcraft) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRailBase(net.minecraft.block.BlockRailBase) IUnlistedProperty(net.minecraftforge.common.property.IUnlistedProperty) CreativeTabs(net.minecraft.creativetab.CreativeTabs) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IBlockAccess(net.minecraft.world.IBlockAccess) InvTools(mods.railcraft.common.util.inventory.InvTools) Entity(net.minecraft.entity.Entity) Properties(net.minecraftforge.common.property.Properties) World(net.minecraft.world.World) PropertyInteger(net.minecraft.block.properties.PropertyInteger) EnumFacing(net.minecraft.util.EnumFacing) Tuple(net.minecraft.util.Tuple) Game(mods.railcraft.common.util.misc.Game) BlockPos(net.minecraft.util.math.BlockPos) BlockTrackTile(mods.railcraft.common.blocks.tracks.BlockTrackTile) IBlockState(net.minecraft.block.state.IBlockState) StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IVariantEnum(mods.railcraft.api.core.IVariantEnum) TileEntity(net.minecraft.tileentity.TileEntity) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock)

Example 40 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project ForestryMC by ForestryMC.

the class ItemLiquidContainer method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
    if (!Proxies.common.isSimulating(world)) {
        return itemstack;
    }
    // / DRINKS can be drunk
    if (isDrink) {
        if (entityplayer.canEat(isAlwaysEdible)) {
            entityplayer.setItemInUse(itemstack, getMaxItemUseDuration(itemstack));
        }
        return itemstack;
    }
    // / Otherwise check empty container
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, entityplayer, true);
    if (movingobjectposition != null && movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
        int x = movingobjectposition.blockX;
        int y = movingobjectposition.blockY;
        int z = movingobjectposition.blockZ;
        Block targetedBlock = world.getBlock(x, y, z);
        FluidStack fluid = null;
        if (targetedBlock instanceof IFluidBlock) {
            fluid = ((IFluidBlock) targetedBlock).drain(world, x, y, z, false);
        } else {
            if (targetedBlock == Blocks.water || targetedBlock == Blocks.flowing_water) {
                fluid = new FluidStack(FluidRegistry.WATER, 1000);
            } else if (targetedBlock == Blocks.lava || targetedBlock == Blocks.flowing_lava) {
                fluid = new FluidStack(FluidRegistry.LAVA, 1000);
            }
        }
        if (fluid == null || fluid.amount <= 0 && this.type == EnumContainerType.BUCKET) {
            return tryPlaceLiquid(itemstack, world, entityplayer, movingobjectposition);
        }
        ItemStack filledContainer = FluidHelper.getFilledContainer(fluid.getFluid(), itemstack);
        if (filledContainer == null) {
            return itemstack;
        }
        // Search for a slot to stow a filled container in player's
        // inventory
        int slot = getMatchingSlot(entityplayer, filledContainer);
        if (slot < 0) {
            return itemstack;
        }
        if (entityplayer.inventory.getStackInSlot(slot) == null) {
            entityplayer.inventory.setInventorySlotContents(slot, filledContainer.copy());
        } else {
            entityplayer.inventory.getStackInSlot(slot).stackSize++;
        }
        // Remove consumed liquid block in world
        if (targetedBlock instanceof IFluidBlock) {
            ((IFluidBlock) targetedBlock).drain(world, x, y, z, true);
        } else {
            world.setBlockToAir(x, y, z);
        }
        // Remove consumed empty container
        itemstack.stackSize--;
        // Notify player that his inventory has changed.
        Proxies.net.inventoryChangeNotify(entityplayer);
        return itemstack;
    }
    return itemstack;
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IFluidBlock (net.minecraftforge.fluids.IFluidBlock)41 Block (net.minecraft.block.Block)28 IBlockState (net.minecraft.block.state.IBlockState)24 BlockLiquid (net.minecraft.block.BlockLiquid)18 BlockPos (net.minecraft.util.math.BlockPos)13 ItemStack (net.minecraft.item.ItemStack)11 FluidStack (net.minecraftforge.fluids.FluidStack)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 TileEntity (net.minecraft.tileentity.TileEntity)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 Fluid (net.minecraftforge.fluids.Fluid)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 Entity (net.minecraft.entity.Entity)4 World (net.minecraft.world.World)4 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 BlockStaticLiquid (net.minecraft.block.BlockStaticLiquid)3 Item (net.minecraft.item.Item)3 ItemBlock (net.minecraft.item.ItemBlock)3 EnumFacing (net.minecraft.util.EnumFacing)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3