Search in sources :

Example 16 with BlockLiquid

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

the class FreefallHandler method testFreefall.

public boolean testFreefall(EntityPlayer player) {
    ZeroGravityEvent zeroGEvent = new ZeroGravityEvent.InFreefall(player);
    MinecraftForge.EVENT_BUS.post(zeroGEvent);
    if (zeroGEvent.isCanceled()) {
        return false;
    }
    // Test whether feet are on a block, also stops the login glitch
    int playerFeetOnY = (int) (player.getEntityBoundingBox().minY - 0.01D);
    int xx = MathHelper.floor_double(player.posX);
    int zz = MathHelper.floor_double(player.posZ);
    BlockPos pos = new BlockPos(xx, playerFeetOnY, zz);
    IBlockState state = player.worldObj.getBlockState(pos);
    Block b = state.getBlock();
    if (b.getMaterial() != Material.air && !(b instanceof BlockLiquid)) {
        double blockYmax;
        if (b == GCBlocks.platform)
            blockYmax = playerFeetOnY + 1.0D;
        else
            blockYmax = playerFeetOnY + b.getBlockBoundsMaxY();
        if (player.getEntityBoundingBox().minY - blockYmax < 0.01D && player.getEntityBoundingBox().minY - blockYmax > -0.5D) {
            player.onGround = true;
            if (player.getEntityBoundingBox().minY - blockYmax > 0D) {
                player.posY -= player.getEntityBoundingBox().minY - blockYmax;
                player.setEntityBoundingBox(player.getEntityBoundingBox().offset(0, blockYmax - player.getEntityBoundingBox().minY, 0));
            } else if (b.canCollideCheck(player.worldObj.getBlockState(new BlockPos(xx, playerFeetOnY, zz)), false)) {
                AxisAlignedBB collisionBox = b.getCollisionBoundingBox(player.worldObj, new BlockPos(xx, playerFeetOnY, zz), state);
                if (collisionBox != null && collisionBox.intersectsWith(player.getEntityBoundingBox())) {
                    player.posY -= player.getEntityBoundingBox().minY - blockYmax;
                    player.setEntityBoundingBox(player.getEntityBoundingBox().offset(0, blockYmax - player.getEntityBoundingBox().minY, 0));
                }
            }
            return false;
        }
    }
    return true;
}
Also used : ZeroGravityEvent(micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.BlockPos)

Example 17 with BlockLiquid

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

the class EntityAstroMiner method tryMineBlock.

private boolean tryMineBlock(BlockPos pos) {
    // Check things to avoid in front of it (see static list for list) including base type things
    // Can move through liquids including flowing lava
    IBlockState state = this.worldObj.getBlockState(pos);
    Block b = state.getBlock();
    if (b.getMaterial() == Material.air) {
        return false;
    }
    if (noMineList.contains(b)) {
        blockingBlock.block = b;
        blockingBlock.meta = b.getMetaFromState(state);
        return true;
    }
    if (b instanceof BlockLiquid) {
        return (this.AIstate != AISTATE_RETURNING && (b == Blocks.lava || b == Blocks.flowing_lava) && state.getValue(BlockLiquid.LEVEL).intValue() == 0);
    }
    if (b instanceof IFluidBlock) {
        return false;
    }
    boolean gtFlag = false;
    if (b != GCBlocks.fallenMeteor) {
        if (b instanceof IPlantable && b != Blocks.tallgrass && b != Blocks.deadbush && b != Blocks.double_plant && b != Blocks.waterlily && !(b instanceof BlockFlower)) {
            blockingBlock.block = b;
            blockingBlock.meta = b.getMetaFromState(state);
            return true;
        }
        int meta = b.getMetaFromState(state);
        if (b.getBlockHardness(this.worldObj, pos) < 0) {
            blockingBlock.block = b;
            blockingBlock.meta = meta;
            return true;
        }
        if (b.hasTileEntity(state)) {
            if (CompatibilityManager.isGTLoaded() && gregTechCheck(b)) {
                gtFlag = true;
            } else {
                blockingBlock.block = b;
                blockingBlock.meta = meta;
                return true;
            }
        }
    }
    if (this.tryBlockLimit == 0) {
        return false;
    }
    int result = ForgeHooks.onBlockBreakEvent(this.worldObj, this.playerMP.theItemInWorldManager.getGameType(), this.playerMP, pos);
    if (result < 0) {
        return true;
    }
    this.tryBlockLimit--;
    // Collect the mined block - unless it's a plant or leaves in which case just break it
    if (!(b instanceof IPlantable || b instanceof BlockLeaves)) {
        ItemStack drops = gtFlag ? getGTDrops(this.worldObj, pos, b) : getPickBlock(this.worldObj, pos, b);
        if (drops != null && !this.addToInventory(drops)) {
            // drop itemstack if AstroMiner can't hold it
            dropStack(pos, drops);
        }
    }
    this.worldObj.setBlockState(pos, Blocks.air.getDefaultState(), 3);
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockLeaves(net.minecraft.block.BlockLeaves) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) ItemStack(net.minecraft.item.ItemStack) BlockFlower(net.minecraft.block.BlockFlower)

Example 18 with BlockLiquid

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

the class EntityAstroMiner method tryBlockClient.

private boolean tryBlockClient(BlockPos pos) {
    BlockVec3 bv = new BlockVec3(pos.getX(), pos.getY(), pos.getZ());
    if (this.laserBlocks.contains(bv)) {
        return false;
    }
    // Add minable blocks to the laser fx list
    IBlockState state = this.worldObj.getBlockState(pos);
    Block b = state.getBlock();
    if (b.getMaterial() == Material.air) {
        return false;
    }
    if (noMineList.contains(b)) {
        return true;
    }
    if (b instanceof BlockLiquid) {
        return false;
    }
    if (b instanceof IFluidBlock) {
        return false;
    }
    if (b instanceof IPlantable) {
        return true;
    }
    int meta = b.getMetaFromState(state);
    if (b.hasTileEntity(state) || b.getBlockHardness(this.worldObj, pos) < 0) {
        return true;
    }
    if (this.tryBlockLimit == 0) {
        return false;
    }
    this.tryBlockLimit--;
    this.laserBlocks.add(bv);
    this.laserTimes.add(this.ticksExisted);
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 19 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project BuildCraft by BuildCraft.

the class BuildCraftCore method postInit.

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
    BCLog.logger.info("BuildCraft's fake player: UUID = " + gameProfile.getId().toString() + ", name = '" + gameProfile.getName() + "'!");
    BCRegistry.INSTANCE.save();
    for (Object o : Block.blockRegistry) {
        Block block = (Block) o;
        if (block instanceof BlockFluidBase || block instanceof BlockLiquid || block instanceof IPlantable) {
            BuildCraftAPI.softBlocks.add(block);
        }
    }
    BuildCraftAPI.softBlocks.add(Blocks.snow);
    BuildCraftAPI.softBlocks.add(Blocks.vine);
    BuildCraftAPI.softBlocks.add(Blocks.fire);
    CropManager.setDefaultHandler(new CropHandlerPlantable());
    CropManager.registerHandler(new CropHandlerReeds());
    BuildCraftAPI.registerWorldProperty("replaceable", new WorldPropertyIsReplaceable());
    BuildCraftAPI.registerWorldProperty("soft", new WorldPropertyIsSoft());
    BuildCraftAPI.registerWorldProperty("wood", new WorldPropertyIsWood());
    BuildCraftAPI.registerWorldProperty("leaves", new WorldPropertyIsLeaf());
    for (int i = 0; i < 4; i++) {
        BuildCraftAPI.registerWorldProperty("ore@hardness=" + i, new WorldPropertyIsOre(i));
    }
    BuildCraftAPI.registerWorldProperty("harvestable", new WorldPropertyIsHarvestable());
    BuildCraftAPI.registerWorldProperty("farmland", new WorldPropertyIsFarmland());
    BuildCraftAPI.registerWorldProperty("shoveled", new WorldPropertyIsShoveled());
    BuildCraftAPI.registerWorldProperty("dirt", new WorldPropertyIsDirt());
    BuildCraftAPI.registerWorldProperty("fluidSource", new WorldPropertyIsFluidSource());
    BuildCraftAPI.registerWorldProperty("freepath", new WorldPropertyIsFreePath());
    // Landmarks are often caught incorrectly, making building them counter-productive.
    SchematicRegistry.INSTANCE.registerSchematicBlock(markerBlock, SchematicIgnore.class);
    SchematicRegistry.INSTANCE.registerSchematicBlock(pathMarkerBlock, SchematicIgnore.class);
    ColorUtils.initialize();
    actionControl = new IActionExternal[IControllable.Mode.values().length];
    for (IControllable.Mode mode : IControllable.Mode.values()) {
        if (mode != IControllable.Mode.Unknown && mode != IControllable.Mode.Mode) {
            actionControl[mode.ordinal()] = new ActionMachineControl(mode);
        }
    }
    MinecraftForge.EVENT_BUS.register(ListOreDictionaryCache.INSTANCE);
    for (String s : OreDictionary.getOreNames()) {
        ListOreDictionaryCache.INSTANCE.registerName(s);
    }
    ListRegistry.registerHandler(new ListMatchHandlerOreDictionary());
}
Also used : IPlantable(net.minecraftforge.common.IPlantable) IControllable(buildcraft.api.tiles.IControllable) CropHandlerReeds(buildcraft.core.crops.CropHandlerReeds) BlockLiquid(net.minecraft.block.BlockLiquid) BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) Block(net.minecraft.block.Block) CropHandlerPlantable(buildcraft.core.crops.CropHandlerPlantable)

Example 20 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EventsCommon method onExplosionStart.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onExplosionStart(ExplosionEvent.Start event) {
    // Only run on server side
    if (!event.getWorld().isRemote) {
        Explosion explosion = event.getExplosion();
        Vector3dc center = new Vector3d(explosion.x, explosion.y, explosion.z);
        Optional<PhysicsObject> optionalPhysicsObject = ValkyrienUtils.getPhysoManagingBlock(event.getWorld(), new BlockPos(event.getExplosion().getPosition()));
        if (optionalPhysicsObject.isPresent()) {
            return;
        }
        // Explosion radius
        float radius = explosion.size;
        AxisAlignedBB toCheck = new AxisAlignedBB(center.x() - radius, center.y() - radius, center.z() - radius, center.x() + radius, center.y() + radius, center.z() + radius);
        // Find nearby ships, we will check if the explosion effects them
        List<PhysicsObject> shipsNear = ((IHasShipManager) event.getWorld()).getManager().getPhysObjectsInAABB(toCheck);
        // Process the explosion on the nearby ships
        for (PhysicsObject ship : shipsNear) {
            Vector3d inLocal = new Vector3d(center);
            inLocal.mulPosition(ship.getShipTransform().getGlobalToSubspace());
            Explosion expl = new Explosion(event.getWorld(), explosion.exploder, inLocal.x, inLocal.y, inLocal.z, radius, explosion.causesFire, explosion.damagesTerrain);
            double waterRange = .6D;
            for (int x = (int) Math.floor(expl.x - waterRange); x <= Math.ceil(expl.x + waterRange); x++) {
                for (int y = (int) Math.floor(expl.y - waterRange); y <= Math.ceil(expl.y + waterRange); y++) {
                    for (int z = (int) Math.floor(expl.z - waterRange); z <= Math.ceil(expl.z + waterRange); z++) {
                        IBlockState state = event.getWorld().getBlockState(new BlockPos(x, y, z));
                        if (state.getBlock() instanceof BlockLiquid) {
                            return;
                        }
                    }
                }
            }
            expl.doExplosionA();
            event.getExplosion().affectedBlockPositions.addAll(expl.affectedBlockPositions);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Explosion(net.minecraft.world.Explosion) IBlockState(net.minecraft.block.state.IBlockState) Vector3dc(org.joml.Vector3dc) BlockLiquid(net.minecraft.block.BlockLiquid) Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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