Search in sources :

Example 96 with BlockVec3

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

the class TileEntityScreen method checkScreenSize.

public void checkScreenSize() {
    this.log("Checking screen size");
    int up = 0;
    int down = 0;
    int left = 0;
    int right = 0;
    int meta = this.getBlockMetadata() & 7;
    BlockVec3 vec = new BlockVec3(this);
    TileEntityScreen tile = this;
    while (up < 8) {
        if (tile.connectedUp) {
            up++;
            TileEntity newTile = vec.getTileEntityOnSide(this.worldObj, 1);
            if (newTile instanceof TileEntityScreen) {
                tile = (TileEntityScreen) newTile;
                vec.translate(0, 1, 0);
            } else {
                System.out.println("Debug - connected up to a non-screen tile");
                // tile.connectedUp = false;
                this.setConnectedUp(false);
                tile.markDirty();
                up--;
                break;
            }
        } else {
            break;
        }
    }
    vec = new BlockVec3(this);
    tile = this;
    while (down < 8 - up) {
        if (tile.connectedDown) {
            down++;
            TileEntity newTile = vec.getTileEntityOnSide(this.worldObj, 0);
            if (newTile instanceof TileEntityScreen) {
                tile = (TileEntityScreen) newTile;
                vec.translate(0, -1, 0);
            } else {
                System.out.println("Debug - connected down to a non-screen tile");
                // tile.connectedDown = false;
                this.setConnectedDown(false);
                tile.markDirty();
                down--;
                break;
            }
        } else {
            break;
        }
    }
    vec = new BlockVec3(this);
    tile = this;
    int leftside = this.getLeft(meta);
    while (left < ((up + down == 0) ? 1 : 8)) {
        if (tile.connectedLeft) {
            left++;
            TileEntity newTile = vec.getTileEntityOnSide(this.worldObj, leftside);
            if (newTile instanceof TileEntityScreen) {
                tile = (TileEntityScreen) newTile;
                vec = vec.newVecSide(leftside);
            } else {
                System.out.println("Debug - connected left to a non-screen tile");
                // tile.connectedLeft = false;
                this.setConnectedLeft(false);
                tile.markDirty();
                left--;
                break;
            }
        } else {
            break;
        }
    }
    vec = new BlockVec3(this);
    tile = this;
    int rightside = this.getRight(meta);
    while (right < ((up + down == 0) ? 1 : 8) - left) {
        if (tile.connectedRight) {
            right++;
            TileEntity newTile = vec.getTileEntityOnSide(this.worldObj, rightside);
            if (newTile instanceof TileEntityScreen) {
                tile = (TileEntityScreen) newTile;
                vec = vec.newVecSide(rightside);
            } else {
                System.out.println("Debug - connected right to a non-screen tile");
                // tile.connectedRight = false;
                this.setConnectedRight(false);
                tile.markDirty();
                right--;
                break;
            }
        } else {
            break;
        }
    }
    this.log("Screen size check midpoint " + up + " " + down + " " + left + " " + right + " ");
    vec = new BlockVec3(this);
    TileEntity newtile = vec.getTileEntityOnSide(this.worldObj, 1);
    TileEntityScreen tileUp = (newtile instanceof TileEntityScreen) ? (TileEntityScreen) newtile : null;
    newtile = vec.getTileEntityOnSide(this.worldObj, 0);
    TileEntityScreen tileDown = (newtile instanceof TileEntityScreen) ? (TileEntityScreen) newtile : null;
    newtile = vec.getTileEntityOnSide(this.worldObj, leftside);
    TileEntityScreen tileLeft = (newtile instanceof TileEntityScreen) ? (TileEntityScreen) newtile : null;
    newtile = vec.getTileEntityOnSide(this.worldObj, rightside);
    TileEntityScreen tileRight = (newtile instanceof TileEntityScreen) ? (TileEntityScreen) newtile : null;
    // Prevent 3 x 1 and longer
    if (left + right == 0 && up + down >= 1) {
        if (// No need for null check if up > 0
        up > 0 && !tileUp.connectedUp) {
            up = 1;
            down = 0;
        } else {
            up = 0;
            if (tileDown != null && !tileDown.connectedDown) {
                down = 1;
            } else {
                down = 0;
            }
        }
    }
    if (up + down == 0 && left + right >= 1) {
        if (// No need for null check if right > 0
        left > 0 && !tileLeft.connectedLeft) {
            if (right == 0 || tileRight == null || tileRight.connectionsLeft == 0) {
                left = 1;
                right = 0;
            } else {
                left = 0;
                right = 1;
            }
        } else {
            left = 0;
            if (tileRight != null && !tileRight.connectedRight) {
                right = 1;
            } else {
                right = 0;
            }
        }
    }
    if (up == 0) {
        this.setConnectedUp(false);
        if (tileUp != null) {
            tileUp.setConnectedDown(false);
        }
    // this.connectedUp = false;
    // if (tileUp != null) tileUp.connectedDown = false;
    }
    if (down == 0) {
        this.setConnectedDown(false);
        if (tileUp != null) {
            tileUp.setConnectedUp(false);
        }
    // this.connectedDown = false;
    // if (tileDown != null) tileDown.connectedUp = false;
    }
    if (left == 0) {
        this.setConnectedLeft(false);
        if (tileUp != null) {
            tileUp.setConnectedRight(false);
        }
    // this.connectedLeft = false;
    // if (tileLeft != null) tileLeft.connectedRight = false;
    }
    if (right == 0) {
        this.setConnectedRight(false);
        if (tileUp != null) {
            tileUp.setConnectedLeft(false);
        }
    // this.connectedRight = false;
    // if (tileRight != null) tileRight.connectedLeft = false;
    }
    this.log("Finished screen size check");
    this.checkWholeScreen(up, down, left, right);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 97 with BlockVec3

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

the class TileEntityScreen method joinRight.

private void joinRight() {
    int meta = this.getBlockMetadata();
    int side = this.getRight(meta);
    BlockVec3 vec = new BlockVec3(this);
    for (int z = -this.connectionsUp; z <= this.connectionsDown; z++) {
        TileEntity tile;
        BlockVec3 newVec = vec.clone().modifyPositionFromSide(EnumFacing.DOWN, z);
        if (z == 0) {
            tile = this;
        } else {
            tile = newVec.getTileEntity(this.worldObj);
        }
        if (tile instanceof TileEntityScreen && tile.getBlockMetadata() == meta && !tile.isInvalid()) {
            TileEntityScreen screenTile = (TileEntityScreen) tile;
            // screenTile.connectedRight = true;
            screenTile.setConnectedRight(true);
            TileEntity te2 = newVec.getTileEntityOnSide(this.worldObj, side);
            if (te2 instanceof TileEntityScreen && te2.getBlockMetadata() == meta && !te2.isInvalid()) {
                screenTile.tryConnectRight((TileEntityScreen) te2);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 98 with BlockVec3

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

the class TileEntityScreen method refreshConnections.

/**
 * Check whether the screen can sustain 'multi-screen' connections on each of its 4 sides
 * (note: this can be called recursively from inside itself)
 *
 * @param doScreen If true, build a new multi-screen if connections are found
 */
public void refreshConnections(boolean doScreen) {
    this.log("Starting connection check");
    IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
    EnumFacing facing = iblockstate.getValue(BlockScreen.FACING);
    int meta = this.getBlockMetadata() & 7;
    if (meta < 2) {
        // TODO System.out.println("Up/down oriented screens cannot be multiscreen");
        this.resetToSingle();
        return;
    }
    TileEntity tileUp = null;
    TileEntity tileDown = null;
    TileEntity tileLeft = null;
    TileEntity tileRight = null;
    BlockVec3 vec = new BlockVec3(this);
    // First, basic check that a neighbour is there and in the same orientation
    if (this.connectedUp) {
        tileUp = vec.getTileEntityOnSide(this.worldObj, 1);
        // this.connectedUp = tileUp instanceof TileEntityScreen && tileUp.getBlockMetadata() == meta && !tileUp.isInvalid();
        this.setConnectedUp(tileUp instanceof TileEntityScreen && tileUp.getBlockMetadata() == meta && !tileUp.isInvalid());
    }
    if (this.connectedDown) {
        tileDown = vec.getTileEntityOnSide(this.worldObj, 0);
        // this.connectedDown = tileDown instanceof TileEntityScreen && tileDown.getBlockMetadata() == meta && !tileDown.isInvalid();
        this.setConnectedDown(tileDown instanceof TileEntityScreen && tileDown.getBlockMetadata() == meta && !tileDown.isInvalid());
    }
    if (this.connectedLeft) {
        int side = this.getLeft(meta);
        tileLeft = vec.getTileEntityOnSide(this.worldObj, side);
        // this.connectedLeft = tileLeft instanceof TileEntityScreen && tileLeft.getBlockMetadata() == meta && !tileLeft.isInvalid();
        this.setConnectedLeft(tileLeft instanceof TileEntityScreen && tileLeft.getBlockMetadata() == meta && !tileLeft.isInvalid());
    }
    if (this.connectedRight) {
        int side = this.getRight(meta);
        tileRight = vec.getTileEntityOnSide(this.worldObj, side);
        // this.connectedRight = tileRight instanceof TileEntityScreen && tileRight.getBlockMetadata() == meta && !tileRight.isInvalid();
        this.setConnectedRight(tileRight instanceof TileEntityScreen && tileRight.getBlockMetadata() == meta && !tileRight.isInvalid());
    }
    // Now test whether a connection can be sustained with that other tile
    if (this.connectedUp) {
        // this.connectedUp = this.tryConnectUp((TileEntityScreen)tileUp);
        this.setConnectedUp(this.tryConnectUp((TileEntityScreen) tileUp));
    }
    if (this.connectedDown) {
        // this.connectedDown = this.tryConnectDown((TileEntityScreen)tileDown);
        this.setConnectedDown(this.tryConnectDown((TileEntityScreen) tileDown));
    }
    if (this.connectedLeft) {
        // this.connectedLeft = this.tryConnectLeft((TileEntityScreen)tileLeft);
        this.setConnectedLeft(this.tryConnectLeft((TileEntityScreen) tileLeft));
    }
    if (this.connectedRight) {
        // this.connectedRight = this.tryConnectRight((TileEntityScreen)tileRight);
        this.setConnectedRight(this.tryConnectRight((TileEntityScreen) tileRight));
    }
    this.log("Ending connection check");
    if (doScreen) {
        this.checkScreenSize();
        this.markDirty();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 99 with BlockVec3

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

the class AsteroidsTickHandlerServer method removeChunkData.

public static void removeChunkData(GCPlayerStats stats, EntityAstroMiner entityToRemove) {
    int index = 0;
    for (EntityAstroMiner miner : activeMiners) {
        if (// Found it in the list here
        miner == entityToRemove) {
            List<BlockVec3> list = stats.getActiveAstroMinerChunks();
            Iterator<BlockVec3> it = list.iterator();
            while (it.hasNext()) {
                BlockVec3 data = it.next();
                if (// Found it in the player's stats
                data.sideDoneBits == index) {
                    it.remove();
                    return;
                }
            }
            return;
        }
        index++;
    }
}
Also used : EntityAstroMiner(micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 100 with BlockVec3

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

the class TileEntityBeamOutput method onMachineActivated.

public boolean onMachineActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (this.nodeList.size() > 1) {
        int index = -1;
        if (this.getTarget() != null) {
            for (int i = 0; i < this.nodeList.size(); i++) {
                if (new BlockVec3(this.nodeList.get(i).getTile()).equals(new BlockVec3(this.getTarget().getTile()))) {
                    index = i;
                    break;
                }
            }
        }
        if (index == -1) {
            // This shouldn't happen, but just in case...
            this.initiateReflector();
        } else {
            index++;
            index %= this.nodeList.size();
            this.setTarget(this.nodeList.get(index));
            return true;
        }
    }
    return false;
}
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