Search in sources :

Example 11 with TileEntityScreen

use of micdoodle8.mods.galacticraft.core.tile.TileEntityScreen 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 12 with TileEntityScreen

use of micdoodle8.mods.galacticraft.core.tile.TileEntityScreen 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 13 with TileEntityScreen

use of micdoodle8.mods.galacticraft.core.tile.TileEntityScreen 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)

Aggregations

BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)13 TileEntity (net.minecraft.tileentity.TileEntity)12 EnumFacing (net.minecraft.util.EnumFacing)5 IBlockState (net.minecraft.block.state.IBlockState)2 MinecraftProfileTexture (com.mojang.authlib.minecraft.MinecraftProfileTexture)1 Type (com.mojang.authlib.minecraft.MinecraftProfileTexture.Type)1 ArrayList (java.util.ArrayList)1 IDetectableResource (micdoodle8.mods.galacticraft.api.block.IDetectableResource)1 IEntityNoisy (micdoodle8.mods.galacticraft.api.entity.IEntityNoisy)1 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 GuiCelestialSelection (micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection)1 DrawGameScreen (micdoodle8.mods.galacticraft.core.client.screen.DrawGameScreen)1 WorldProviderMoon (micdoodle8.mods.galacticraft.core.dimension.WorldProviderMoon)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)1 ItemSensorGlasses (micdoodle8.mods.galacticraft.core.items.ItemSensorGlasses)1 GalacticraftPacketHandler (micdoodle8.mods.galacticraft.core.network.GalacticraftPacketHandler)1 PacketRotateRocket (micdoodle8.mods.galacticraft.core.network.PacketRotateRocket)1 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)1