Search in sources :

Example 91 with BlockVec3

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

the class ThreadFindSeal method traceLeak.

private void traceLeak(BlockVec3 tracer) {
    ArrayList<BlockVec3> route = new ArrayList<>();
    BlockVec3 start = this.head.clone().translate(0, 1, 0);
    int count = 0;
    int x = tracer.x;
    int y = tracer.y;
    int z = tracer.z;
    while (!tracer.equals(start) && count < 90) {
        route.add(tracer);
        switch(tracer.sideDoneBits >> 6) {
            case 1:
                y--;
                break;
            case 0:
                y++;
                break;
            case 3:
                z--;
                break;
            case 2:
                z++;
                break;
            case 5:
                x--;
                break;
            case 4:
                x++;
                break;
        }
        tracer = checkedContainsTrace(x, y, z);
        if (tracer == null) {
            return;
        }
        count++;
    }
    this.leakTrace = new ArrayList<>();
    this.leakTrace.add(start);
    for (int j = route.size() - 1; j >= 0; j--) {
        this.leakTrace.add(route.get(j));
    }
}
Also used : BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 92 with BlockVec3

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

the class TileEntityScreen method canJoinRight.

private boolean canJoinRight() {
    int meta = this.getBlockMetadata();
    TileEntity te = new BlockVec3(this).getTileEntityOnSide(this.worldObj, this.getRight(meta));
    if (!(te instanceof TileEntityScreen)) {
        return false;
    }
    TileEntityScreen screenTile = (TileEntityScreen) te;
    if (screenTile.getBlockMetadata() != meta) {
        return false;
    }
    if (screenTile.connectionsUp != this.connectionsUp) {
        return false;
    }
    if (screenTile.connectionsDown != this.connectionsDown) {
        return false;
    }
    if (this.connectionsUp + this.connectionsDown > 0) {
        return true;
    }
    if (this.connectionsLeft > 0) {
        return false;
    }
    if (screenTile.connectionsRight > 0) {
        return false;
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 93 with BlockVec3

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

the class TileEntityTelemetry method getNearest.

public static TileEntityTelemetry getNearest(TileEntity te) {
    if (te == null) {
        return null;
    }
    BlockVec3 target = new BlockVec3(te);
    int distSq = 1025;
    BlockVec3Dim nearest = null;
    int dim = GCCoreUtil.getDimensionID(te.getWorld());
    for (BlockVec3Dim telemeter : loadedList) {
        if (telemeter.dim != dim) {
            continue;
        }
        int dist = telemeter.distanceSquared(target);
        if (dist < distSq) {
            distSq = dist;
            nearest = telemeter;
        }
    }
    if (nearest == null) {
        return null;
    }
    TileEntity result = te.getWorld().getTileEntity(new BlockPos(nearest.x, nearest.y, nearest.z));
    if (result instanceof TileEntityTelemetry) {
        return (TileEntityTelemetry) result;
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.BlockPos) BlockVec3Dim(micdoodle8.mods.galacticraft.api.vector.BlockVec3Dim) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 94 with BlockVec3

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

the class TileEntitySolar method update.

@Override
public void update() {
    if (!this.initialised) {
        int metadata = this.getBlockMetadata();
        if (metadata >= BlockSolar.ADVANCED_METADATA) {
            this.storage.setCapacity(30000);
            this.setTierGC(2);
        }
        this.initialised = true;
    }
    if (!this.initialisedMulti) {
        this.initialisedMulti = this.initialiseMultiTiles(this.getPos(), this.worldObj);
    }
    if (!this.worldObj.isRemote) {
        this.receiveEnergyGC(null, this.generateWatts, false);
    }
    super.update();
    if (!this.worldObj.isRemote) {
        this.recharge(this.containingItems[0]);
        if (this.disableCooldown > 0) {
            this.disableCooldown--;
        }
        if (!this.getDisabled(0) && this.ticks % 20 == 0) {
            this.solarStrength = 0;
            if (this.worldObj.isDaytime() && (this.worldObj.provider instanceof IGalacticraftWorldProvider || !this.worldObj.isRaining() && !this.worldObj.isThundering())) {
                double distance = 100.0D;
                double sinA = -Math.sin((this.currentAngle - 77.5D) / Constants.RADIANS_TO_DEGREES_D);
                double cosA = Math.abs(Math.cos((this.currentAngle - 77.5D) / Constants.RADIANS_TO_DEGREES_D));
                for (int x = -1; x <= 1; x++) {
                    for (int z = -1; z <= 1; z++) {
                        if (this.tierGC == 1) {
                            if (this.worldObj.canBlockSeeSky(this.getPos().add(x, 2, z))) {
                                boolean valid = true;
                                for (int y = this.getPos().getY() + 3; y < 256; y++) {
                                    Block block = this.worldObj.getBlockState(new BlockPos(this.getPos().getX() + x, y, this.getPos().getZ() + z)).getBlock();
                                    if (block.isOpaqueCube()) {
                                        valid = false;
                                        break;
                                    }
                                }
                                if (valid) {
                                    this.solarStrength++;
                                }
                            }
                        } else {
                            boolean valid = true;
                            BlockVec3 blockVec = new BlockVec3(this).translate(x, 3, z);
                            for (double d = 0.0D; d < distance; d++) {
                                BlockVec3 blockAt = blockVec.clone().translate((int) (d * sinA), (int) (d * cosA), 0);
                                Block block = blockAt.getBlock(this.worldObj);
                                if (block.isOpaqueCube()) {
                                    valid = false;
                                    break;
                                }
                            }
                            if (valid) {
                                this.solarStrength++;
                            }
                        }
                    }
                }
            }
        }
    }
    float angle = this.worldObj.getCelestialAngle(1.0F) - 0.7845194F < 0 ? 1.0F - 0.7845194F : -0.7845194F;
    float celestialAngle = (this.worldObj.getCelestialAngle(1.0F) + angle) * 360.0F;
    if (!(this.worldObj.provider instanceof WorldProviderSpaceStation))
        celestialAngle += 12.5F;
    if (GalacticraftCore.isPlanetsLoaded && this.worldObj.provider instanceof WorldProviderVenus)
        celestialAngle = 180F - celestialAngle;
    celestialAngle %= 360;
    boolean isDaytime = this.worldObj.isDaytime() && (celestialAngle < 180.5F || celestialAngle > 359.5F) || this.worldObj.provider instanceof WorldProviderSpaceStation;
    if (this.tierGC == 1) {
        if (!isDaytime || this.worldObj.isRaining() || this.worldObj.isThundering()) {
            this.targetAngle = 77.5F + 180.0F;
        } else {
            this.targetAngle = 77.5F;
        }
    } else {
        if (!isDaytime || this.worldObj.isRaining() || this.worldObj.isThundering()) {
            this.targetAngle = 77.5F + 180F;
        } else if (celestialAngle > 27.5F && celestialAngle < 152.5F) {
            float difference = this.targetAngle - celestialAngle + 12.5F;
            this.targetAngle -= difference / 20.0F;
        } else if (celestialAngle <= 27.5F || celestialAngle > 270F) {
            this.targetAngle = 15F;
        } else if (celestialAngle >= 152.5F) {
            this.targetAngle = 140F;
        }
    }
    float difference = this.targetAngle - this.currentAngle;
    this.currentAngle += difference / 20.0F;
    if (!this.worldObj.isRemote) {
        int generated = this.getGenerate();
        if (generated > 0) {
            this.generateWatts = Math.min(Math.max(generated, 0), TileEntitySolar.MAX_GENERATE_WATTS);
        } else {
            this.generateWatts = 0;
        }
    }
    this.produce();
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) Block(net.minecraft.block.Block) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) WorldProviderVenus(micdoodle8.mods.galacticraft.planets.venus.dimension.WorldProviderVenus)

Example 95 with BlockVec3

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

the class TileEntityScreen method breakScreen.

/**
 * Call when a screen (which maybe part of a multiscreen) is either
 * broken or rotated.
 *
 * @param state The state of the screen prior to breaking or rotation
 */
public void breakScreen(IBlockState state) {
    BlockVec3 vec = new BlockVec3(this);
    int meta = state.getBlock().getMetaFromState(state);
    TileEntity tile;
    EnumFacing facingRight = getFacing(state).rotateY();
    int left = this.connectionsLeft;
    int right = this.connectionsRight;
    int up = this.connectionsUp;
    int down = this.connectionsDown;
    boolean doUp = this.connectedUp;
    boolean doDown = this.connectedDown;
    boolean doLeft = this.connectedLeft;
    boolean doRight = this.connectedRight;
    for (int x = -left; x <= right; x++) {
        for (int z = -up; z <= down; z++) {
            if (x == 0 && z == 0) {
                this.resetToSingle();
            } else {
                BlockVec3 newVec = vec.clone().modifyPositionFromSide(facingRight, x).modifyPositionFromSide(EnumFacing.DOWN, z);
                tile = newVec.getTileEntity(this.worldObj);
                if (tile instanceof TileEntityScreen && tile.getBlockMetadata() == meta) {
                    ((TileEntityScreen) tile).resetToSingle();
                }
            }
        }
    }
    // TODO  Try to generate largest screen possible out of remaining blocks
    this.setConnectedDown(false);
    this.setConnectedUp(false);
    this.setConnectedLeft(false);
    this.setConnectedRight(false);
    if (doUp) {
        tile = vec.getTileEntityOnSide(this.worldObj, 1);
        if (tile instanceof TileEntityScreen && tile.getBlockMetadata() == meta && !tile.isInvalid()) {
            if (doLeft) {
                ((TileEntityScreen) tile).setConnectedLeft(true);
            }
            if (doRight) {
                ((TileEntityScreen) tile).setConnectedRight(true);
            }
            ((TileEntityScreen) tile).setConnectedUp(true);
            // if (doLeft) ((TileEntityScreen)tile).connectedLeft = true;
            // if (doRight) ((TileEntityScreen)tile).connectedRight = true;
            // ((TileEntityScreen)tile).connectedUp = true;
            ((TileEntityScreen) tile).refreshConnections(true);
        }
    }
    if (doDown) {
        tile = vec.getTileEntityOnSide(this.worldObj, 0);
        if (tile instanceof TileEntityScreen && tile.getBlockMetadata() == meta && !tile.isInvalid()) {
            if (doLeft) {
                ((TileEntityScreen) tile).setConnectedLeft(true);
            }
            if (doRight) {
                ((TileEntityScreen) tile).setConnectedRight(true);
            }
            ((TileEntityScreen) tile).setConnectedDown(true);
            // if (doLeft) ((TileEntityScreen)tile).connectedLeft = true;
            // if (doRight) ((TileEntityScreen)tile).connectedRight = true;
            // ((TileEntityScreen)tile).connectedDown = true;
            ((TileEntityScreen) tile).refreshConnections(true);
        }
    }
    if (doLeft) {
        tile = vec.getTileEntityOnSide(this.worldObj, this.getLeft(meta));
        if (tile instanceof TileEntityScreen && tile.getBlockMetadata() == meta && !tile.isInvalid()) {
            if (doUp) {
                ((TileEntityScreen) tile).setConnectedUp(true);
            }
            if (doDown) {
                ((TileEntityScreen) tile).setConnectedDown(true);
            }
            ((TileEntityScreen) tile).setConnectedLeft(true);
            // if (doUp) ((TileEntityScreen)tile).connectedUp = true;
            // if (doDown) ((TileEntityScreen)tile).connectedDown = true;
            // ((TileEntityScreen)tile).connectedLeft = true;
            ((TileEntityScreen) tile).refreshConnections(true);
        }
    }
    if (doRight) {
        tile = vec.getTileEntityOnSide(this.worldObj, this.getRight(meta));
        if (tile instanceof TileEntityScreen && tile.getBlockMetadata() == meta && !tile.isInvalid()) {
            if (doUp) {
                ((TileEntityScreen) tile).setConnectedUp(true);
            }
            if (doDown) {
                ((TileEntityScreen) tile).setConnectedDown(true);
            }
            ((TileEntityScreen) tile).setConnectedRight(true);
            // if (doUp) ((TileEntityScreen)tile).connectedUp = true;
            // if (doDown) ((TileEntityScreen)tile).connectedDown = true;
            // ((TileEntityScreen)tile).connectedRight = true;
            ((TileEntityScreen) tile).refreshConnections(true);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) 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