Search in sources :

Example 36 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MorePlanets by SteveKunG.

the class ParticleLiquidDrip method onUpdate.

@Override
public void onUpdate() {
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.particleRed = this.newRed;
    this.particleGreen = this.newGreen;
    this.particleBlue = this.newBlue;
    this.particleAlpha = this.newAlpha;
    this.motionY -= this.particleGravity;
    if (this.bobTimer-- > 0) {
        this.motionX *= 0.02D;
        this.motionY *= 0.02D;
        this.motionZ *= 0.02D;
        this.setParticleTextureIndex(113);
    } else {
        this.setParticleTextureIndex(112);
    }
    this.move(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;
    if (this.particleMaxAge-- <= 0) {
        this.setExpired();
    }
    if (this.canCollide) {
        if (!this.isLavaDrip) {
            this.setExpired();
        } else {
            this.setParticleTextureIndex(114);
        }
        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }
    BlockPos pos = new BlockPos(this.posX, this.posY, this.posZ);
    IBlockState state = this.world.getBlockState(pos);
    Material material = state.getMaterial();
    if (material.isLiquid() || material.isSolid()) {
        double d0 = 0.0D;
        if (state.getBlock() instanceof BlockLiquid) {
            d0 = BlockLiquid.getLiquidHeightPercent(state.getValue(BlockLiquid.LEVEL).intValue());
        }
        double d1 = MathHelper.floor(this.posY) + 1 - d0;
        if (this.posY < d1) {
            this.setExpired();
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockPos(net.minecraft.util.math.BlockPos) Material(net.minecraft.block.material.Material)

Example 37 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MorePlanets by SteveKunG.

the class ClientEventHandler method isInsideLiquid.

private boolean isInsideLiquid(BlockPos pos) {
    IBlockState state = this.mc.player.world.getBlockState(pos);
    Block block = state.getBlock();
    double eyes = this.mc.player.posY + this.mc.player.getEyeHeight();
    double filled = 1.0f;
    if (block instanceof IFluidBlock) {
        filled = ((IFluidBlock) block).getFilledPercentage(this.mc.player.world, pos);
    } else if (block instanceof BlockLiquid) {
        filled = BlockLiquid.getLiquidHeightPercent(block.getMetaFromState(state));
    }
    if (filled < 0) {
        filled *= -1;
        return eyes > pos.getY() + 1 + (1 - filled);
    } else {
        return eyes < pos.getY() + 1 + filled;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock)

Example 38 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project Galacticraft by micdoodle8.

the class SpinManager method refresh.

/**
 * This will check all blocks which are in contact with each other to find
 * the shape of the spacestation. It also finds the centre of mass (to
 * rotate around) and the moment of inertia (how easy/hard this is to
 * rotate).
 * <p/>
 * If placingThruster is true, it will return false if the thruster (at
 * baseBlock) is not in contact with the "existing" spacestation - so the
 * player cannot place thrusters on outlying disconnected blocks and expect
 * them to have an effect.
 * <p/>
 * Note: this check will briefly load, server-side, all chunks which have
 * spacestation blocks in them or 1 block adjacent to those.
 *
 * @param baseBlock
 * @return
 */
public boolean refresh(BlockPos baseBlock, boolean placingThruster) {
    if (this.oneSSBlock == null || this.worldProvider.worldObj.getBlockState(this.oneSSBlock).getBlock().isAir(this.worldProvider.worldObj, this.oneSSBlock)) {
        if (baseBlock != null) {
            this.oneSSBlock = baseBlock;
        } else {
            this.oneSSBlock = new BlockPos(0, 64, 0);
        }
    }
    // Find contiguous blocks using an algorithm like the oxygen sealer one
    List<BlockVec3> currentLayer = new LinkedList<BlockVec3>();
    List<BlockVec3> nextLayer = new LinkedList<BlockVec3>();
    final List<BlockPos> foundThrusters = new LinkedList<BlockPos>();
    this.checked.clear();
    currentLayer.add(new BlockVec3(this.oneSSBlock));
    this.checked.add(new BlockVec3(this.oneSSBlock));
    Block bStart = this.worldProvider.worldObj.getBlockState(this.oneSSBlock).getBlock();
    if (bStart instanceof BlockSpinThruster) {
        foundThrusters.add(this.oneSSBlock);
    }
    // Mass of a thruster
    float thismass = 0.1F;
    float thismassCentreX = 0.1F * this.oneSSBlock.getX();
    float thismassCentreY = 0.1F * this.oneSSBlock.getY();
    float thismassCentreZ = 0.1F * this.oneSSBlock.getZ();
    float thismoment = 0F;
    int thisssBoundsMaxX = this.oneSSBlock.getX();
    int thisssBoundsMinX = this.oneSSBlock.getX();
    int thisssBoundsMaxY = this.oneSSBlock.getY();
    int thisssBoundsMinY = this.oneSSBlock.getY();
    int thisssBoundsMaxZ = this.oneSSBlock.getZ();
    int thisssBoundsMinZ = this.oneSSBlock.getZ();
    while (currentLayer.size() > 0) {
        int bits;
        for (BlockVec3 vec : currentLayer) {
            bits = vec.sideDoneBits;
            if (vec.x < thisssBoundsMinX) {
                thisssBoundsMinX = vec.x;
            }
            if (vec.y < thisssBoundsMinY) {
                thisssBoundsMinY = vec.y;
            }
            if (vec.z < thisssBoundsMinZ) {
                thisssBoundsMinZ = vec.z;
            }
            if (vec.x > thisssBoundsMaxX) {
                thisssBoundsMaxX = vec.x;
            }
            if (vec.y > thisssBoundsMaxY) {
                thisssBoundsMaxY = vec.y;
            }
            if (vec.z > thisssBoundsMaxZ) {
                thisssBoundsMaxZ = vec.z;
            }
            for (int side = 0; side < 6; side++) {
                if ((bits & (1 << side)) == 1) {
                    continue;
                }
                BlockVec3 sideVec = vec.newVecSide(side);
                if (sideVec != null && !this.checked.contains(sideVec)) {
                    this.checked.add(sideVec);
                    Block b = sideVec.getBlockID(this.worldProvider.worldObj);
                    if (b != null && !b.isAir(this.worldProvider.worldObj, sideVec.toBlockPos()) && !(b instanceof BlockDynamicLiquid)) {
                        nextLayer.add(sideVec);
                        if (bStart.isAir(this.worldProvider.worldObj, this.oneSSBlock)) {
                            this.oneSSBlock = sideVec.toBlockPos();
                            bStart = b;
                        }
                        float m = 1.0F;
                        // Liquids have a mass of 1, stone, metal blocks etc will be heavier
                        if (!(b instanceof BlockLiquid)) {
                            // For most blocks, hardness gives a good idea of mass
                            m = b.getBlockHardness(this.worldProvider.worldObj, sideVec.toBlockPos());
                            if (m < 0.1F) {
                                m = 0.1F;
                            } else if (m > 30F) {
                                m = 30F;
                            }
                            // Wood items have a high hardness compared with their presumed mass
                            if (b.getMaterial() == Material.wood) {
                                m /= 4;
                            }
                        // TODO: higher mass for future Galacticraft hi-density item like neutronium
                        // Maybe also check for things in other mods by name: lead, uranium blocks?
                        }
                        thismassCentreX += m * sideVec.x;
                        thismassCentreY += m * sideVec.y;
                        thismassCentreZ += m * sideVec.z;
                        thismass += m;
                        thismoment += m * (sideVec.x * sideVec.x + sideVec.z * sideVec.z);
                        if (b instanceof BlockSpinThruster && !RedstoneUtil.isBlockReceivingRedstone(this.worldProvider.worldObj, sideVec.toBlockPos())) {
                            foundThrusters.add(sideVec.toBlockPos());
                        }
                    }
                }
            }
        }
        currentLayer = nextLayer;
        nextLayer = new LinkedList<BlockVec3>();
    }
    if (placingThruster && !this.checked.contains(new BlockVec3(baseBlock))) {
        if (foundThrusters.size() > 0) {
            // The thruster was not placed on the existing contiguous space station: it must be.
            if (ConfigManagerCore.enableDebug) {
                GCLog.info("Thruster placed on wrong part of space station: base at " + this.oneSSBlock + " - baseBlock was " + baseBlock + " - found " + foundThrusters.size());
            }
            return false;
        }
        // (This first check prevents an infinite loop)
        if (!this.oneSSBlock.equals(baseBlock)) {
            this.oneSSBlock = baseBlock;
            if (this.worldProvider.worldObj.getBlockState(this.oneSSBlock).getBlock().getMaterial() != Material.air) {
                return this.refresh(baseBlock, true);
            }
        }
        return false;
    }
    // Update thruster lists based on what was found
    this.thrustersPlus.clear();
    this.thrustersMinus.clear();
    for (BlockPos thruster : foundThrusters) {
        IBlockState state = this.worldProvider.worldObj.getBlockState(thruster);
        int facing = state.getBlock().getMetaFromState(state) & 8;
        if (facing == 0) {
            this.thrustersPlus.add(thruster);
        } else {
            this.thrustersMinus.add(thruster);
        }
    }
    // Calculate centre of mass
    float mass = thismass;
    this.massCentreX = thismassCentreX / thismass + 0.5F;
    float massCentreY = thismassCentreY / thismass + 0.5F;
    this.massCentreZ = thismassCentreZ / thismass + 0.5F;
    // System.out.println("(X,Z) = "+this.massCentreX+","+this.massCentreZ);
    this.setSpinCentre(this.massCentreX, this.massCentreZ);
    // The boundary is at the outer edges of the blocks
    this.ssBoundsMaxX = thisssBoundsMaxX + 1;
    this.ssBoundsMinX = thisssBoundsMinX;
    this.ssBoundsMaxY = thisssBoundsMaxY + 1;
    this.ssBoundsMinY = thisssBoundsMinY;
    this.ssBoundsMaxZ = thisssBoundsMaxZ + 1;
    this.ssBoundsMinZ = thisssBoundsMinZ;
    // Calculate momentOfInertia
    thismoment -= this.massCentreX * this.massCentreX * mass;
    thismoment -= this.massCentreZ * this.massCentreZ * mass;
    this.momentOfInertia = thismoment;
    // TODO
    // TODO defy gravity
    // TODO break blocks which are outside SS (not in checked)
    // TODO prevent spin if there is a huge number of blocks outside SS
    GCLog.debug("MoI = " + this.momentOfInertia + " CoMx = " + this.massCentreX + " CoMz = " + this.massCentreZ);
    // Send packets to clients in this dimension
    List<Object> objList = new ArrayList<Object>();
    objList.add(Double.valueOf(this.spinCentreX));
    objList.add(Double.valueOf(this.spinCentreZ));
    GalacticraftCore.packetPipeline.sendToDimension(new PacketSimple(PacketSimple.EnumSimplePacket.C_UPDATE_STATION_DATA, GCCoreUtil.getDimensionID(this.worldProvider), objList), GCCoreUtil.getDimensionID(this.worldProvider));
    objList = new ArrayList<Object>();
    objList.add(Integer.valueOf(this.ssBoundsMinX));
    objList.add(Integer.valueOf(this.ssBoundsMaxX));
    objList.add(Integer.valueOf(this.ssBoundsMinY));
    objList.add(Integer.valueOf(this.ssBoundsMaxY));
    objList.add(Integer.valueOf(this.ssBoundsMinZ));
    objList.add(Integer.valueOf(this.ssBoundsMaxZ));
    GalacticraftCore.packetPipeline.sendToDimension(new PacketSimple(PacketSimple.EnumSimplePacket.C_UPDATE_STATION_BOX, GCCoreUtil.getDimensionID(this.worldProvider), objList), GCCoreUtil.getDimensionID(this.worldProvider));
    this.updateSpinSpeed();
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) BlockDynamicLiquid(net.minecraft.block.BlockDynamicLiquid) LinkedList(java.util.LinkedList) BlockLiquid(net.minecraft.block.BlockLiquid) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.BlockPos) BlockSpinThruster(micdoodle8.mods.galacticraft.core.blocks.BlockSpinThruster) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 39 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project Galacticraft by micdoodle8.

the class EntityFXOilDrip method onUpdate.

@Override
public void onUpdate() {
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.particleRed = 0.1F;
    this.particleGreen = 0.1F;
    this.particleBlue = 0.1F;
    this.motionY -= this.particleGravity;
    if (this.bobTimer-- > 0) {
        this.motionX *= 0.02D;
        this.motionY *= 0.02D;
        this.motionZ *= 0.02D;
        this.setParticleTextureIndex(113);
    } else {
        this.setParticleTextureIndex(112);
    }
    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;
    if (this.particleMaxAge-- <= 0) {
        this.setDead();
    }
    if (this.onGround) {
        this.setDead();
        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }
    BlockPos pos = new BlockPos(this);
    IBlockState state = this.worldObj.getBlockState(pos);
    Material material = state.getBlock().getMaterial();
    if (material.isLiquid() || material.isSolid()) {
        double d0 = 0.0D;
        if (state.getBlock() instanceof BlockLiquid) {
            d0 = BlockLiquid.getLiquidHeightPercent(((Integer) state.getValue(BlockLiquid.LEVEL)).intValue());
        }
        double d1 = MathHelper.floor_double(this.posY) + 1 - d0;
        if (this.posY < d1) {
            this.setDead();
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockPos(net.minecraft.util.BlockPos) Material(net.minecraft.block.material.Material)

Example 40 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MC-Prefab by Brian-Wuest.

the class StructureAlternateStart method CreateLadderShaft.

private static ArrayList<ItemStack> CreateLadderShaft(World world, BlockPos pos, ArrayList<ItemStack> originalStacks, EnumFacing houseFacing, ArrayList<Item> blocksToNotAdd) {
    int torchCounter = 0;
    // Keep the "west" facing.
    EnumFacing westWall = houseFacing.rotateYCCW();
    // Get the ladder state based on the house facing.
    IBlockState ladderState = Blocks.LADDER.getDefaultState().withProperty(BlockLadder.FACING, houseFacing);
    // Replace the main floor block with air since we don't want it placed in the chest at the end.
    BuildingMethods.ReplaceBlock(world, pos, Blocks.AIR);
    StructureAlternateStart.torchPositions = new ArrayList<BlockPos>();
    while (pos.getY() > 8) {
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        torchCounter++;
        // replace them with stone.
        for (int i = 0; i < 4; i++) {
            EnumFacing facing = houseFacing;
            switch(i) {
                case 1:
                    {
                        facing = houseFacing.rotateY();
                        break;
                    }
                case 2:
                    {
                        facing = houseFacing.getOpposite();
                        break;
                    }
                case 3:
                    {
                        facing = houseFacing.rotateYCCW();
                        break;
                    }
                default:
                    {
                        facing = houseFacing;
                    }
            }
            // normal processing.
            if (facing == westWall && torchCounter == 6 && pos.getY() > 14) {
                // First make sure the blocks around this block are stone, then place the torch.
                for (int j = 0; j <= 2; j++) {
                    BlockPos tempPos = null;
                    IBlockState surroundingState = null;
                    Block surroundingBlock = null;
                    if (j == 0) {
                        tempPos = pos.offset(facing, 2);
                        surroundingState = world.getBlockState(tempPos);
                        surroundingBlock = surroundingState.getBlock();
                    } else if (j == 1) {
                        tempPos = pos.offset(facing).offset(facing.rotateY());
                        surroundingState = world.getBlockState(tempPos);
                        surroundingBlock = surroundingState.getBlock();
                    } else {
                        tempPos = pos.offset(facing).offset(facing.rotateYCCW());
                        surroundingState = world.getBlockState(tempPos);
                        surroundingBlock = surroundingState.getBlock();
                    }
                    // Make sure that this is a normal solid block and not a liquid or partial block.
                    if (!(surroundingBlock instanceof BlockStone)) {
                        // This is not a stone block. Get the drops then replace it with stone.
                        originalStacks = BuildingMethods.ConsolidateDrops(surroundingBlock, world, tempPos, surroundingState, originalStacks, blocksToNotAdd);
                        BuildingMethods.ReplaceBlock(world, tempPos, Blocks.STONE);
                    }
                }
                StructureAlternateStart.torchPositions.add(pos.offset(facing));
                torchCounter = 0;
            } else {
                BlockPos tempPos = pos.offset(facing);
                IBlockState surroundingState = world.getBlockState(tempPos);
                Block surroundingBlock = surroundingState.getBlock();
                if (!surroundingBlock.isBlockNormalCube(surroundingState) || surroundingBlock instanceof BlockLiquid) {
                    // This is not a solid block. Get the drops then replace
                    // it with stone.
                    originalStacks = BuildingMethods.ConsolidateDrops(surroundingBlock, world, tempPos, surroundingState, originalStacks, blocksToNotAdd);
                    BuildingMethods.ReplaceBlock(world, tempPos, Blocks.STONE);
                }
            }
        }
        // Get the block drops then replace it with a ladder.
        originalStacks = BuildingMethods.ConsolidateDrops(block, world, pos, state, originalStacks, blocksToNotAdd);
        // Don't place a ladder at this location since it will be destroyed.
        if (pos.getY() >= 10) {
            BuildingMethods.ReplaceBlock(world, pos, ladderState);
        }
        pos = pos.down();
    }
    return originalStacks;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BuildBlock(com.wuest.prefab.StructureGen.BuildBlock) BlockPos(net.minecraft.util.math.BlockPos) BlockStone(net.minecraft.block.BlockStone)

Aggregations

BlockLiquid (net.minecraft.block.BlockLiquid)57 IBlockState (net.minecraft.block.state.IBlockState)44 Block (net.minecraft.block.Block)27 BlockPos (net.minecraft.util.math.BlockPos)22 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)20 Material (net.minecraft.block.material.Material)11 ItemStack (net.minecraft.item.ItemStack)8 EnumFacing (net.minecraft.util.EnumFacing)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 BlockPos (net.minecraft.util.BlockPos)4 BlockFluidBase (net.minecraftforge.fluids.BlockFluidBase)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)4 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 Entity (net.minecraft.entity.Entity)3 World (net.minecraft.world.World)3 IPlantable (net.minecraftforge.common.IPlantable)3 Location (com.builtbroken.mc.imp.transform.vector.Location)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2