Search in sources :

Example 6 with IFluidBlock

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

the class BlastSonic method doPreExplode.

@Override
public void doPreExplode() {
    if (!this.world().isRemote) {
        if (this.hasShockWave) {
            for (int x = (int) (-this.getRadius() * 2); x < this.getRadius() * 2; ++x) {
                for (int y = (int) (-this.getRadius() * 2); y < this.getRadius() * 2; ++y) {
                    for (int z = (int) (-this.getRadius() * 2); z < this.getRadius() * 2; ++z) {
                        Location targetPosition = position.add(new Pos(x, y, z));
                        Block blockID = world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                        if (blockID != Blocks.air) {
                            Material material = blockID.getMaterial();
                            if (blockID != Blocks.bedrock && !(material.isLiquid()) && (blockID.getExplosionResistance(this.exploder, world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi()) > this.nengLiang || material == Material.glass)) {
                                targetPosition.setBlock(world(), Blocks.air);
                            }
                        }
                    }
                }
            }
        }
        this.thread = new ThreadLargeExplosion(this.position, (int) this.getRadius(), this.nengLiang, this.exploder, new IThreadCallBack() {

            @Override
            public float getResistance(World world, IPos3D explosionPosition, IPos3D targetPosition, Entity source, Block block) {
                float resistance = 0;
                if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
                    resistance = 1f;
                } else {
                    resistance = block.getExplosionResistance(source, world, (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z(), explosionPosition.x(), explosionPosition.y(), explosionPosition.z());
                }
                return resistance;
            }
        });
        this.thread.start();
    }
    if (this.hasShockWave) {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "hypersonic", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    } else {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "sonicwave", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IThreadCallBack(icbm.classic.content.explosive.thread.ThreadLargeExplosion.IThreadCallBack) Material(net.minecraft.block.material.Material) World(net.minecraft.world.World) ThreadLargeExplosion(icbm.classic.content.explosive.thread.ThreadLargeExplosion) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) BlockLiquid(net.minecraft.block.BlockLiquid) Pos(com.builtbroken.mc.imp.transform.vector.Pos) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 7 with IFluidBlock

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

the class BlastRedmatter method doDestroyBlocks.

protected void doDestroyBlocks() {
    // Try to find and grab some blocks to orbit
    int blocksDestroyed = 0;
    for (int currentRadius = 1; currentRadius < getRadius(); currentRadius++) {
        for (int xr = -currentRadius; xr < currentRadius; xr++) {
            for (int yr = -currentRadius; yr < currentRadius; yr++) {
                for (int zr = -currentRadius; zr < currentRadius; zr++) {
                    final Location currentPos = position.add(xr, yr, zr);
                    final double dist = position.distance(currentPos);
                    //We are looping in a shell orbit around the center
                    if (dist < currentRadius && dist > currentRadius - 2) {
                        final Block block = currentPos.getBlock();
                        //Null if call was made on an unloaded chunk
                        if (block != null) {
                            int meta = currentPos.getBlockMetadata();
                            //Ignore air blocks and unbreakable blocks
                            if (!block.isAir(world(), currentPos.xi(), currentPos.yi(), currentPos.zi()) && block.getBlockHardness(this.world(), currentPos.xi(), currentPos.yi(), currentPos.zi()) >= 0) {
                                //TODO handle multi-blocks
                                final boolean isFluid = block instanceof BlockLiquid || block instanceof IFluidBlock;
                                currentPos.setBlock(Blocks.air, 0, isFluid ? 0 : 3);
                                //TODO: render fluid streams moving into hole
                                if (!isFluid && doFlyingBlocks) {
                                    //Convert a random amount of destroyed blocks into flying blocks for visuals
                                    if (this.world().rand.nextFloat() > 0.8) {
                                        EntityFlyingBlock entity = new EntityFlyingBlock(this.world(), currentPos.add(0.5D), block, meta);
                                        entity.yawChange = 50 * this.world().rand.nextFloat();
                                        entity.pitchChange = 50 * this.world().rand.nextFloat();
                                        this.world().spawnEntityInWorld(entity);
                                    }
                                }
                                //Keep track of blocks removed to keep from lagging the game
                                blocksDestroyed++;
                                if (blocksDestroyed > this.MAX_BLOCKS_REMOVED_PER_TICK) {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : BlockLiquid(net.minecraft.block.BlockLiquid) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 8 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 == null) {
                iterator.remove();
                markDirty();
                if (!ejectionScheduled)
                    break;
            } else if (returnedStack.stackSize != tubeStack.stack.stackSize) {
                markDirty();
                if (!ejectionScheduled)
                    break;
            } else {
                break;
            }
        } else if (spawnItemsInWorld) {
            ForgeDirection direction = getFacingDirection().getOpposite();
            if ((worldObj.getBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ).getBlocksMovement(worldObj, xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ)) || (worldObj.getBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ) instanceof BlockLiquid) || (worldObj.getBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ) instanceof IFluidBlock)) {
                ejectItemInWorld(tubeStack.stack, direction);
                iterator.remove();
                markDirty();
            } else {
                break;
            }
        }
    }
}
Also used : BlockLiquid(net.minecraft.block.BlockLiquid) TubeStack(com.bluepowermod.part.tube.TubeStack) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack)

Example 9 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project NetherEx by LogicTechCorp.

the class NetherExModels method registerModel.

private static void registerModel(IFluidBlock block) {
    Item item = Item.getItemFromBlock((Block) block);
    ModelBakery.registerItemVariants(item);
    ModelResourceLocation modelLocation = new ModelResourceLocation(NetherEx.MOD_ID + ":fluid", block.getFluid().getName());
    ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> modelLocation));
    ModelLoader.setCustomStateMapper((Block) block, new StateMapperBase() {

        @Override
        protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
            return modelLocation;
        }
    });
}
Also used : nex.block(nex.block) NetherExItems(nex.init.NetherExItems) Item(net.minecraft.item.Item) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) ModelBakery(net.minecraft.client.renderer.block.model.ModelBakery) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) Mod(net.minecraftforge.fml.common.Mod) ModelLoader(net.minecraftforge.client.model.ModelLoader) NetherExBlocks(nex.init.NetherExBlocks) BlockWall(net.minecraft.block.BlockWall) ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) EnumFacing(net.minecraft.util.EnumFacing) BlockSlab(net.minecraft.block.BlockSlab) NetherEx(nex.NetherEx) BlockFenceGate(net.minecraft.block.BlockFenceGate) IBlockState(net.minecraft.block.state.IBlockState) StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Logger(org.apache.logging.log4j.Logger) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ItemSalamanderHide(nex.item.ItemSalamanderHide) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) LogManager(org.apache.logging.log4j.LogManager) StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 10 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project NewHorizonsCoreMod by GTNewHorizons.

the class OilGeneratorFix method getTopBlock.

private int getTopBlock(World pWorld, int pLocX, int pLocZ) {
    Chunk tChunk = pWorld.getChunkFromBlockCoords(pLocX, pLocZ);
    int y = tChunk.getTopFilledSegment() + 15;
    int trimmedX = pLocX & 0xF;
    int trimmedZ = pLocZ & 0xF;
    for (; y > 0; y--) {
        Block tBlock = tChunk.getBlock(trimmedX, y, trimmedZ);
        if (!tBlock.isAir(pWorld, pLocX, y, pLocZ)) {
            if ((tBlock instanceof BlockStaticLiquid)) {
                return y;
            }
            if ((tBlock instanceof BlockFluidBase)) {
                return y;
            }
            if ((tBlock instanceof IFluidBlock)) {
                return y;
            }
            if (tBlock.getMaterial().blocksMovement()) {
                if (!(tBlock instanceof BlockFlower)) {
                    return y - 1;
                }
            }
        }
    }
    return -1;
}
Also used : BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) BlockStaticLiquid(net.minecraft.block.BlockStaticLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Chunk(net.minecraft.world.chunk.Chunk) BlockFlower(net.minecraft.block.BlockFlower)

Aggregations

IFluidBlock (net.minecraftforge.fluids.IFluidBlock)12 Block (net.minecraft.block.Block)10 BlockLiquid (net.minecraft.block.BlockLiquid)5 IBlockState (net.minecraft.block.state.IBlockState)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 Location (com.builtbroken.mc.imp.transform.vector.Location)2 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)2 BlockStaticLiquid (net.minecraft.block.BlockStaticLiquid)2 Item (net.minecraft.item.Item)2 ItemBlock (net.minecraft.item.ItemBlock)2 ItemStack (net.minecraft.item.ItemStack)2 EnumFacing (net.minecraft.util.EnumFacing)2 Fluid (net.minecraftforge.fluids.Fluid)2 TubeStack (com.bluepowermod.part.tube.TubeStack)1 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)1 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 BlockMod (com.witchworks.common.block.BlockMod)1 BlockSaltBarrier (com.witchworks.common.block.magic.BlockSaltBarrier)1 BlockBeehive (com.witchworks.common.block.natural.BlockBeehive)1 ItemMod (com.witchworks.common.item.ItemMod)1