Package net.minecraftforge.common.util

Examples of net.minecraftforge.common.util.ForgeDirection


   * @param x
   * @param y
   * @param z
   */
  protected void checkForConnections(IBlockAccess world, int x, int y, int z) {
    ForgeDirection out = getOutwardsDir();

    if(out == ForgeDirection.UNKNOWN) {
      redNetwork = null;
      redNetInput = null;
    }
View Full Code Here


        return false;
      }
    }
   
    if(BlockTurbineRotorPart.isRotorShaft(metadata)) {
      ForgeDirection majorAxis = findRotorMajorAxis(world, x, y, z, block);
     
      boolean[] hasBlades = findBlades(world, x, y, z, block, majorAxis);
     
      renderRotorShaft(block, renderer, metadata, majorAxis, hasBlades, x, y, z, false);
    }
View Full Code Here

        renderer.setRenderBounds(0D, 0D, 0D, 1D, 1D, 1D);
  }

  private void renderBladeFromWorld(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int metadata) {
    TileEntity te = world.getTileEntity(x, y, z);
    ForgeDirection rotorDir = ForgeDirection.UNKNOWN;
    if(te instanceof TileEntityTurbineRotorPart) {
      TileEntityTurbineRotorPart rotorPart = (TileEntityTurbineRotorPart)te;
      if(rotorPart.isConnected()) {
        rotorDir = rotorPart.getTurbine().getRotorDirection();
      }
    }
   
    if(rotorDir == ForgeDirection.UNKNOWN) {
      // Go walkies!
      ArrayList<ForgeDirection> bladeDirs = new ArrayList<ForgeDirection>();

      // First check, surrounding area.
      ForgeDirection[] dirsToCheck = ForgeDirection.VALID_DIRECTIONS;
      for(ForgeDirection dir : dirsToCheck) {
        Block neighborBlock = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
        if(neighborBlock == block) {
          // Blade or rotor?!
          int neighborMetadata = world.getBlockMetadata(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
          if(BlockTurbineRotorPart.isRotorShaft(neighborMetadata)) {
            // SEXY TIMES
            rotorDir = findRotorMajorAxis(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, block);
            break;
          }
          else if(BlockTurbineRotorPart.isRotorBlade(neighborMetadata)) {
            // We'll move in that direction then...
            bladeDirs.add(dir);
          }
        }
      }
     
      // Still no luck eh?
      while(rotorDir == ForgeDirection.UNKNOWN && !bladeDirs.isEmpty()) {
        ForgeDirection dir = bladeDirs.remove(bladeDirs.size() - 1); // Trim off the end to avoid shifting crap in memory
        int curX = x + dir.offsetX;
        int curY = y + dir.offsetY;
        int curZ = z + dir.offsetZ;
       
        int dist = 0;
View Full Code Here

   * @param z
   * @param block
   * @return The major axis of the rotor. This is always one of the positive directions.
   */
  private static ForgeDirection findRotorMajorAxis(IBlockAccess world, int x, int y, int z, Block block) {
    ForgeDirection retDir = ForgeDirection.UP;
   
    for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
      if(world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) == block &&
          BlockTurbineRotorPart.isRotorShaft(world.getBlockMetadata(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ))) {
        retDir = dir;
        break;
      }
    }
   
    if(retDir == ForgeDirection.DOWN || retDir == ForgeDirection.NORTH || retDir == ForgeDirection.WEST) {
      retDir = retDir.getOpposite();
    }
   
    return retDir; // Defaults to up if there's no neighbors of the same type
  }
View Full Code Here

  private static boolean[] findBlades(IBlockAccess world, int x, int y, int z, Block block, ForgeDirection majorAxis) {
    boolean[] ret = new boolean[4];
    ForgeDirection[] dirsToCheck = StaticUtils.neighborsBySide[majorAxis.ordinal()];
   
    for(int i = 0; i < dirsToCheck.length; i++) {
      ForgeDirection dir = dirsToCheck[i];
      if(world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) == block &&
          BlockTurbineRotorPart.isRotorBlade(world.getBlockMetadata(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ))) {
        ret[i] = true;
      }
      else {
View Full Code Here

 
  private static void renderRotorBladeConnection(RenderBlocks renderer, Block block, int metadata,
      ForgeDirection rotorDir, ForgeDirection bladeDir, int x, int y, int z, boolean drawOuterRectangle) {

    // This is the dimension in which the blade expands
    ForgeDirection normal = findNormal(rotorDir, bladeDir);
   
    // Used for proper calculation of the IJK coords
    int rotorDirMultiplier = rotorDir.offsetX < 0 || rotorDir.offsetY < 0 || rotorDir.offsetZ < 0 ? -1 : 1;
    int bladeDirMultiplier = bladeDir.offsetX < 0 || bladeDir.offsetY < 0 || bladeDir.offsetZ < 0 ? -1 : 1;
    int normalDirMultiplier = normal.offsetX < 0 || normal.offsetY < 0 || normal.offsetZ < 0 ? -1 : 1;
View Full Code Here

    MultiblockTurbine turbine = bearing.getTurbine();
   
    if(!turbine.isAssembled() || !turbine.getActive() || !turbine.hasGlass()) { return; }
   
    Integer displayList = bearing.getDisplayList();
    ForgeDirection rotorDir = bearing.getOutwardsDir().getOpposite();
   
    if(displayList == null) {
      RotorInfo info = bearing.getRotorInfo();
      displayList = generateRotor(info);
      bearing.setDisplayList(displayList);
View Full Code Here

  int generateRotor(RotorInfo rotorInfo) {
    int list = GLAllocation.generateDisplayLists(1);
    GL11.glNewList(list,  GL11.GL_COMPILE);

    ForgeDirection rotorDir = rotorInfo.rotorDirection;
    int rotorLen = rotorInfo.rotorLength;
    CoordTriplet currentRotorCoord = new CoordTriplet(0,0,0);

    Tessellator tessellator = Tessellator.instance;
    if(rotorDir.offsetX != 0) {
View Full Code Here

   
    // Rotor bearing must calculate outwards dir, as this is normally only calculated in onMachineAssembled().
    rotorPart.recalculateOutwardsDirection(getMinimumCoord(), getMaximumCoord());
   
    // Find out which way the rotor runs. Obv, this is inwards from the bearing.
    ForgeDirection rotorDir = rotorPart.getOutwardsDir().getOpposite();
    CoordTriplet rotorCoord = rotorPart.getWorldLocation();
   
    CoordTriplet minRotorCoord = getMinimumCoord();
    CoordTriplet maxRotorCoord = getMaximumCoord();
   
    // Constrain min/max rotor coords to where the rotor bearing is and the block opposite it
    if(rotorDir.offsetX == 0) {
      minRotorCoord.x = maxRotorCoord.x = rotorCoord.x;
    }
    if(rotorDir.offsetY == 0) {
      minRotorCoord.y = maxRotorCoord.y = rotorCoord.y;
    }
    if(rotorDir.offsetZ == 0) {
      minRotorCoord.z = maxRotorCoord.z = rotorCoord.z;
    }

    // Figure out where the rotor ends and which directions are normal to the rotor's 4 faces (this is where blades emit from)
    CoordTriplet endRotorCoord = rotorCoord.equals(minRotorCoord) ? maxRotorCoord : minRotorCoord;
    endRotorCoord.translate(rotorDir.getOpposite());

    ForgeDirection[] bladeDirections;
    if(rotorDir.offsetY != 0) {
      bladeDirections = StaticUtils.CardinalDirections;
    }
    else if(rotorDir.offsetX != 0) {
      bladeDirections = RotorXBladeDirections;
    }
    else {
      bladeDirections = RotorZBladeDirections;
    }

    Set<CoordTriplet> rotorShafts = new HashSet<CoordTriplet>(attachedRotorShafts.size());
    Set<CoordTriplet> rotorBlades = new HashSet<CoordTriplet>(attachedRotorBlades.size());
   
    for(TileEntityTurbineRotorPart part : attachedRotorShafts) {
      rotorShafts.add(part.getWorldLocation());
    }

    for(TileEntityTurbineRotorPart part : attachedRotorBlades) {
      rotorBlades.add(part.getWorldLocation());
    }
   
    // Move along the length of the rotor, 1 block at a time
    boolean encounteredCoils = false;
    while(!rotorShafts.isEmpty() && !rotorCoord.equals(endRotorCoord)) {
      rotorCoord.translate(rotorDir);
     
      // Ensure we find a rotor block along the length of the entire rotor
      if(!rotorShafts.remove(rotorCoord)) {
        throw new MultiblockValidationException(String.format("%s - This block must contain a rotor. The rotor must begin at the bearing and run the entire length of the turbine", rotorCoord));
      }
     
      // Now move out in the 4 rotor normals, looking for blades and coils
      CoordTriplet checkCoord = rotorCoord.copy();
      boolean encounteredBlades = false;
      for(ForgeDirection bladeDir : bladeDirections) {
        checkCoord.copy(rotorCoord);
        boolean foundABlade = false;
        checkCoord.translate(bladeDir);
       
        // If we find 1 blade, we can keep moving along the normal to find more blades
        while(rotorBlades.remove(checkCoord)) {
          // We found a coil already?! NOT ALLOWED.
          if(encounteredCoils) {
            throw new MultiblockValidationException(String.format("%s - Rotor blades must be placed closer to the rotor bearing than all other parts inside a turbine", checkCoord));
          }
          foundABlade = encounteredBlades = true;
          checkCoord.translate(bladeDir);
        }

        // If this block wasn't a blade, check to see if it was a coil
        if(!foundABlade) {
          if(foundCoils.remove(checkCoord)) {
            encounteredCoils = true;

            // We cannot have blades and coils intermix. This prevents intermixing, depending on eval order.
            if(encounteredBlades) {
              throw new MultiblockValidationException(String.format("%s - Metal blocks must by placed further from the rotor bearing than all rotor blades", checkCoord));
            }
           
            // Check the two coil spots in the 'corners', which are permitted if they're connected to the main rotor coil somehow
            CoordTriplet coilCheck = checkCoord.copy();
            coilCheck.translate(bladeDir.getRotation(rotorDir));
            foundCoils.remove(coilCheck);
            coilCheck.copy(checkCoord);
            coilCheck.translate(bladeDir.getRotation(rotorDir.getOpposite()));
            foundCoils.remove(coilCheck);
          }
          // Else: It must have been air.
        }
      }
View Full Code Here

  }

  @Override
    public IIcon getIcon(IBlockAccess blockAccess, int x, int y, int z, int side) {
    ForgeDirection[] dirsToCheck = StaticUtils.neighborsBySide[side];
    ForgeDirection dir;
    Block myBlock = blockAccess.getBlock(x, y, z);
    int myBlockMetadata = blockAccess.getBlockMetadata(x, y, z);
   
    // First check if we have a block in front of us of the same type - if so, just be completely transparent on this side
    ForgeDirection out = ForgeDirection.getOrientation(side);
    if(blockAccess.getBlock(x + out.offsetX, y + out.offsetY, z + out.offsetZ) == myBlock &&
        blockAccess.getBlockMetadata(x + out.offsetX, y + out.offsetY, z + out.offsetZ) == myBlockMetadata) {
      return transparentIcon;
    }
   
View Full Code Here

TOP

Related Classes of net.minecraftforge.common.util.ForgeDirection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.