Search in sources :

Example 61 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class TileEntityArclamp method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);
    nbt.setInteger("Facing", this.facing);
    NBTTagList airBlocks = new NBTTagList();
    for (BlockVec3 vec : this.airToRestore) {
        NBTTagCompound tag = new NBTTagCompound();
        vec.writeToNBT(tag);
        airBlocks.appendTag(tag);
    }
    nbt.setTag("AirBlocks", airBlocks);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 62 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class TileEntityArclamp method decodePacketdata.

@Override
public void decodePacketdata(ByteBuf buffer) {
    while (buffer.readableBytes() >= 12) {
        int x = buffer.readInt();
        int y = buffer.readInt();
        int z = buffer.readInt();
        this.airToRestore.add(new BlockVec3(x, y, z));
    }
}
Also used : BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 63 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class WorldProviderAsteroids method getClosestAsteroidXZ.

public BlockVec3 getClosestAsteroidXZ(int x, int y, int z, boolean mark) {
    if (!this.checkHasAsteroids()) {
        return null;
    }
    BlockVec3 result = null;
    AsteroidData resultRoid = null;
    int lowestDistance = Integer.MAX_VALUE;
    for (AsteroidData test : this.asteroids) {
        if (mark && (test.sizeAndLandedFlag & 128) > 0) {
            continue;
        }
        int dx = x - test.centre.x;
        int dz = z - test.centre.z;
        int a = dx * dx + dz * dz;
        if (a < lowestDistance) {
            lowestDistance = a;
            result = test.centre;
            resultRoid = test;
        }
    }
    if (result == null) {
        return null;
    }
    if (mark) {
        resultRoid.sizeAndLandedFlag |= 128;
        this.writeToNBT(this.datafile.datacompound);
    }
    result = result.clone();
    result.sideDoneBits = resultRoid.sizeAndLandedFlag & 127;
    return result;
}
Also used : BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 64 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class TeleportTypeAsteroids method getPlayerSpawnLocation.

@Override
public Vector3 getPlayerSpawnLocation(WorldServer world, EntityPlayerMP player) {
    if (player != null) {
        GCPlayerStats stats = GCPlayerStats.get(player);
        int x = MathHelper.floor_double(stats.getCoordsTeleportedFromX());
        int z = MathHelper.floor_double(stats.getCoordsTeleportedFromZ());
        int limit = ConfigManagerCore.otherPlanetWorldBorders - 2;
        if (limit > 20) {
            if (x > limit) {
                z *= limit / x;
                x = limit;
            } else if (x < -limit) {
                z *= -limit / x;
                x = -limit;
            }
            if (z > limit) {
                x *= limit / z;
                z = limit;
            } else if (z < -limit) {
                x *= -limit / z;
                z = -limit;
            }
        }
        int attemptCount = 0;
        // Small pre-generate with a chunk loading radius of 3, to make sure some asteroids get generated
        // (if the world is already generated here, this will be very quick)
        this.preGenChunks(world, x >> 4, z >> 4);
        do {
            BlockVec3 bv3 = null;
            if (world.provider instanceof WorldProviderAsteroids) {
                bv3 = ((WorldProviderAsteroids) world.provider).getClosestAsteroidXZ(x, 0, z, true);
            }
            if (bv3 != null) {
                // Check whether the returned asteroid is too far from the desired entry location in which case, give up
                if (bv3.distanceSquared(new BlockVec3(x, 128, z)) > 25600) {
                    break;
                }
                if (ConfigManagerCore.enableDebug) {
                    GCLog.info("Testing asteroid at x" + (bv3.x) + " y" + (bv3.y) + " z" + bv3.z);
                }
                this.loadChunksAround(bv3.x, bv3.z, 2, world.theChunkProviderServer);
                this.loadChunksAround(bv3.x, bv3.z, -3, world.theChunkProviderServer);
                if (goodAsteroidEntry(world, bv3.x, bv3.y, bv3.z)) {
                    return new Vector3(bv3.x, 310, bv3.z);
                }
                if (goodAsteroidEntry(world, bv3.x + 2, bv3.y, bv3.z + 2)) {
                    return new Vector3(bv3.x + 2, 310, bv3.z + 2);
                }
                if (goodAsteroidEntry(world, bv3.x + 2, bv3.y, bv3.z - 2)) {
                    return new Vector3(bv3.x + 2, 310, bv3.z - 2);
                }
                if (goodAsteroidEntry(world, bv3.x - 2, bv3.y, bv3.z - 2)) {
                    return new Vector3(bv3.x - 2, 310, bv3.z - 2);
                }
                if (goodAsteroidEntry(world, bv3.x - 2, bv3.y, bv3.z + 2)) {
                    return new Vector3(bv3.x - 2, 310, bv3.z + 2);
                }
                // Failed to find an asteroid even though there should be one there
                if (ConfigManagerCore.enableDebug) {
                    GCLog.info("Removing drilled out asteroid at x" + (bv3.x) + " z" + (bv3.z));
                }
                ((WorldProviderAsteroids) world.provider).removeAsteroid(bv3.x, bv3.y, bv3.z);
            }
            attemptCount++;
        } while (attemptCount < 5);
        FMLLog.info("Failed to find good large asteroid landing spot! Falling back to making a small one.");
        this.makeSmallLandingSpot(world, x, z);
        return new Vector3(x, 310, z);
    }
    FMLLog.severe("Null player when teleporting to Asteroids!");
    return new Vector3(0, 310, 0);
}
Also used : GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 65 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class EntityAstroMiner method prepareMoveClient.

private boolean prepareMoveClient(int limit, int dist) {
    BlockVec3 inFront = new BlockVec3(MathHelper.floor_double(this.posX + 0.5D), MathHelper.floor_double(this.posY + 1.5D), MathHelper.floor_double(this.posZ + 0.5D));
    if (dist == 2) {
        inFront.translate(headings2[this.facing.getIndex()]);
    } else {
        if ((this.facing.getIndex() & 1) == EnumFacing.DOWN.getIndex()) {
            dist++;
        }
        if (dist > 0) {
            inFront.translate(headings[this.facing.getIndex()].clone().scale(dist));
        }
    }
    if (inFront.equals(this.mineLast)) {
        return false;
    }
    int x = inFront.x;
    int y = inFront.y;
    int z = inFront.z;
    boolean wayBarred = false;
    this.tryBlockLimit = limit;
    // Check not obstructed by something immovable e.g. bedrock
    // Mine out the 12 blocks in front of it in direction of travel when getting close
    // There are 12 blocks around ... and 12 in front.  One block per tick?
    // (That means can move at 5/6 block per second when mining, and 1.67 bps when traveling)
    BlockPos pos = new BlockPos(x, y, z);
    switch(EnumFacing.getFront(this.facing.getIndex() & 6)) {
        case DOWN:
            if (tryBlockClient(pos)) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(1, 0, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(1, 0, -1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 0, -1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 0, -2))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-1, 0, -2))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-1, 0, -1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-2, 0, -1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-2, 0, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-1, 0, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-1, 0, 1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 0, 1))) {
                wayBarred = true;
            }
            break;
        case NORTH:
            if (tryBlockClient(pos.add(0, -2, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-1, -2, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, -1, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-1, -1, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(1, -1, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-2, -1, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(1, 0, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-2, 0, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos)) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-1, 0, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 1, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(-1, 1, 0))) {
                wayBarred = true;
            }
            break;
        case WEST:
            if (tryBlockClient(pos.add(0, -2, -1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, -1, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, -1, -1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, -1, +1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, -1, -2))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 0, 1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 0, -2))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 0, -1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, -2, 0))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 1, -1))) {
                wayBarred = true;
            }
            if (tryBlockClient(pos)) {
                wayBarred = true;
            }
            if (tryBlockClient(pos.add(0, 1, 0))) {
                wayBarred = true;
            }
            break;
    }
    // If it is obstructed, return to base, or stand still if that is impossible
    if (wayBarred) {
        this.tryBlockLimit = 0;
    }
    if (this.tryBlockLimit == limit) {
        this.mineLast = inFront;
    }
    return wayBarred;
}
Also used : BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)104 TileEntity (net.minecraft.tileentity.TileEntity)44 EnumFacing (net.minecraft.util.EnumFacing)20 IBlockState (net.minecraft.block.state.IBlockState)14 BlockPos (net.minecraft.util.BlockPos)13 World (net.minecraft.world.World)10 IPartialSealableBlock (micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock)9 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)9 Block (net.minecraft.block.Block)9 ArrayList (java.util.ArrayList)7 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)7 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)7 NBTTagList (net.minecraft.nbt.NBTTagList)7 IConductor (micdoodle8.mods.galacticraft.api.transmission.tile.IConductor)6 TileEntityOxygenSealer (micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 Entity (net.minecraft.entity.Entity)5 LinkedList (java.util.LinkedList)4 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)4 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4