@Override
  public void onUpdate() {
    super.onUpdate();

    if (worldObj.isRemote && updateDelay > 0) {
      updateDelay--;

      if (updateDelay == 0 && clientActive != isActive) {
        isActive = clientActive;
        MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
      }
    }

    if (!worldObj.isRemote) {
      if (updateDelay > 0) {
        updateDelay--;

        if (updateDelay == 0 && clientActive != isActive) {
          Mekanism.packetHandler.sendToReceivers(
              new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())),
              new Range4D(Coord4D.get(this)));
        }
      }
    }
  }
Beispiel #2
0
  public Coord4D getClosestCoords(Coord4D coord) {
    Coord4D closest = null;

    for (Coord4D iterCoord : activeCoords) {
      if (iterCoord.equals(coord)) {
        continue;
      }

      if (closest == null) {
        closest = iterCoord;
        continue;
      }

      if (coord.dimensionId != closest.dimensionId && coord.dimensionId == iterCoord.dimensionId) {
        closest = iterCoord;
        continue;
      } else if (coord.dimensionId == closest.dimensionId
          && coord.dimensionId != iterCoord.dimensionId) {
        continue;
      } else {
        if (coord.distanceTo(closest) > coord.distanceTo(iterCoord)) {
          closest = iterCoord;
          continue;
        } else {
          continue;
        }
      }
    }

    return closest;
  }
  @Override
  public TMultiPart newPart(
      ItemStack stack,
      EntityPlayer player,
      World world,
      BlockCoord coord,
      int face,
      Vector3 vecHit) {
    TransmitterType type = TransmitterType.values()[stack.getItemDamage()];

    if (type.getTransmission() != TransmissionType.ITEM) {
      Coord4D obj = new Coord4D(coord.x, coord.y, coord.z, world.provider.dimensionId);

      List<ITransmitterNetwork<?, ?>> networks = new ArrayList<ITransmitterNetwork<?, ?>>();

      for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity tile = obj.getFromSide(side).getTileEntity(world);

        if (tile instanceof IGridTransmitter
            && TransmissionType.checkTransmissionType(tile, type.getTransmission())) {
          networks.add(((IGridTransmitter) tile).getTransmitterNetwork());
        }
      }

      if (networks.size() > 0) {
        if (!networks.iterator().next().canMerge(networks)) {
          return null;
        }
      }
    }

    return PartTransmitter.getPartType(TransmitterType.values()[getDamage(stack)]);
  }
  @Override
  public void writeToNBT(NBTTagCompound nbtTags) {
    super.writeToNBT(nbtTags);

    nbtTags.setBoolean("finishedCalc", finishedCalc);

    if (fluidTank.getFluid() != null) {
      nbtTags.setTag("fluidTank", fluidTank.writeToNBT(new NBTTagCompound()));
    }

    NBTTagList activeList = new NBTTagList();

    for (Coord4D wrapper : activeNodes) {
      NBTTagCompound tagCompound = new NBTTagCompound();
      wrapper.write(tagCompound);
      activeList.appendTag(tagCompound);
    }

    if (activeList.tagCount() != 0) {
      nbtTags.setTag("activeNodes", activeList);
    }

    NBTTagList usedList = new NBTTagList();

    for (Coord4D obj : usedNodes) {
      activeList.appendTag(obj.write(new NBTTagCompound()));
    }

    if (activeList.tagCount() != 0) {
      nbtTags.setTag("usedNodes", usedList);
    }
  }
  @Override
  public void readFromNBT(NBTTagCompound nbtTags) {
    super.readFromNBT(nbtTags);

    finishedCalc = nbtTags.getBoolean("finishedCalc");

    if (nbtTags.hasKey("fluidTank")) {
      fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank"));
    }

    if (nbtTags.hasKey("activeNodes")) {
      NBTTagList tagList = nbtTags.getTagList("activeNodes", NBT.TAG_COMPOUND);

      for (int i = 0; i < tagList.tagCount(); i++) {
        activeNodes.add(Coord4D.read((NBTTagCompound) tagList.getCompoundTagAt(i)));
      }
    }

    if (nbtTags.hasKey("usedNodes")) {
      NBTTagList tagList = nbtTags.getTagList("usedNodes", NBT.TAG_COMPOUND);

      for (int i = 0; i < tagList.tagCount(); i++) {
        usedNodes.add(Coord4D.read((NBTTagCompound) tagList.getCompoundTagAt(i)));
      }
    }
  }
 @Override
 public int hashCode() {
   int code = 1;
   code = 31 * code + startTransporter.hashCode();
   code = 31 * code + end.hashCode();
   code = 31 * code + endSide.hashCode();
   return code;
 }
Beispiel #7
0
  private boolean smeltBlock(Coord4D block) {
    ItemStack stack = block.getStack(worldObj);

    if (stack == null) {
      return false;
    }

    ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(block.getStack(worldObj));

    if (result != null) {
      if (!worldObj.isRemote) {
        Block b = block.getBlock(worldObj);
        int meta = block.getMetadata(worldObj);

        if (Block.getBlockFromItem(result.getItem()) != Blocks.air) {
          worldObj.setBlock(
              block.xCoord,
              block.yCoord,
              block.zCoord,
              Block.getBlockFromItem(result.getItem()),
              result.getItemDamage(),
              3);
        } else {
          worldObj.setBlockToAir(block.xCoord, block.yCoord, block.zCoord);

          EntityItem item =
              new EntityItem(
                  worldObj,
                  block.xCoord + 0.5,
                  block.yCoord + 0.5,
                  block.zCoord + 0.5,
                  result.copy());
          item.motionX = 0;
          item.motionY = 0;
          item.motionZ = 0;
          worldObj.spawnEntityInWorld(item);
        }

        worldObj.playAuxSFXAtEntity(
            null,
            2001,
            block.xCoord,
            block.yCoord,
            block.zCoord,
            Block.getIdFromBlock(b) + (meta << 12));
      }

      spawnParticlesAt(new Pos3D(block).translate(0.5, 0.5, 0.5));

      return true;
    }

    return false;
  }
  private void updatePower() {
    boolean power = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);

    if (redstone != power) {
      redstone = power;
      Mekanism.packetHandler.sendToReceivers(
          new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())),
          new Range4D(Coord4D.get(this)));

      onPowerChange();
    }
  }
  @Override
  public void setActive(boolean active) {
    isActive = active;

    if (clientActive != active && updateDelay == 0) {
      Mekanism.packetHandler.sendToReceivers(
          new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList<Object>())),
          new Range4D(Coord4D.get(this)));

      updateDelay = 10;
      clientActive = active;
    }
  }
  @Override
  public void setFacing(short direction) {
    if (canSetFacing(direction)) {
      facing = direction;
    }

    if (!(facing == clientFacing || worldObj.isRemote)) {
      Mekanism.packetHandler.sendToReceivers(
          new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())),
          new Range4D(Coord4D.get(this)));
      markDirty();
      clientFacing = facing;
    }
  }
  public void loop(TileEntity tileEntity) {
    iteratedNodes.add(Coord4D.get(tileEntity));

    for (EnumFacing side : EnumFacing.VALUES) {
      Coord4D coord = Coord4D.get(tileEntity).offset(side);

      if (coord.exists(pointer.getWorld())) {
        TileEntity tile = coord.getTileEntity(pointer.getWorld());

        if (tile != null && isNode(tile) && !iteratedNodes.contains(coord)) {
          loop(tile);
        }
      }
    }
  }
Beispiel #12
0
  /**
   * Gets the adjacent connections to a TileEntity, from a subset of its sides.
   *
   * @param tileEntity - center TileEntity
   * @param sides - set of sides to check
   * @return boolean[] of adjacent connections
   */
  public static boolean[] getConnections(TileEntity tileEntity, Set<ForgeDirection> sides) {
    boolean[] connectable = new boolean[] {false, false, false, false, false, false};
    Coord4D coord = Coord4D.get(tileEntity);

    for (ForgeDirection side : sides) {
      TileEntity tile = coord.getFromSide(side).getTileEntity(tileEntity.getWorldObj());

      connectable[side.ordinal()] |=
          isEnergyAcceptor(tile) && isConnectable(tileEntity, tile, side);
      connectable[side.ordinal()] |= isCable(tile);
      connectable[side.ordinal()] |= isOutputter(tile, side);
    }

    return connectable;
  }
  @Override
  public void setMultiblock(String id) {
    if (id == null && multiblockUUID != null) {
      SynchronizedTurbineData.clientRotationMap.remove(multiblockUUID);
    }

    super.setMultiblock(id);

    Coord4D coord = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);
    TileEntity tile = coord.getTileEntity(worldObj);

    if (tile instanceof TileEntityTurbineRotor) {
      ((TileEntityTurbineRotor) tile).updateRotors();
    }
  }
    public static void openServerGui(
        MinerGuiPacket t, int guiType, World world, EntityPlayerMP playerMP, Coord4D obj, int i) {
      Container container = null;

      playerMP.closeContainer();

      if (guiType == 0) {
        container =
            new ContainerNull(playerMP, (TileEntityContainerBlock) obj.getTileEntity(world));
      } else if (guiType == 4) {
        container =
            new ContainerDigitalMiner(
                playerMP.inventory, (TileEntityDigitalMiner) obj.getTileEntity(world));
      } else if (guiType == 5) {
        container =
            new ContainerNull(playerMP, (TileEntityContainerBlock) obj.getTileEntity(world));
      } else if (guiType == 1 || guiType == 2 || guiType == 3 || guiType == 6) {
        container =
            new ContainerFilter(
                playerMP.inventory, (TileEntityContainerBlock) obj.getTileEntity(world));
      }

      playerMP.getNextWindowId();
      int window = playerMP.currentWindowId;

      if (t == MinerGuiPacket.SERVER) {
        Mekanism.packetHandler.sendTo(
            new DigitalMinerGuiMessage(MinerGuiPacket.CLIENT, obj, guiType, window, 0), playerMP);
      } else if (t == MinerGuiPacket.SERVER_INDEX) {
        Mekanism.packetHandler.sendTo(
            new DigitalMinerGuiMessage(MinerGuiPacket.CLIENT_INDEX, obj, guiType, window, i),
            playerMP);
      }

      playerMP.openContainer = container;
      playerMP.openContainer.windowId = window;
      playerMP.openContainer.addCraftingToCrafters(playerMP);

      if (guiType == 0) {
        TileEntityDigitalMiner tile = (TileEntityDigitalMiner) obj.getTileEntity(world);

        for (EntityPlayer player : tile.playersUsing) {
          Mekanism.packetHandler.sendTo(
              new TileEntityMessage(obj, tile.getFilterPacket(new ArrayList())),
              (EntityPlayerMP) player);
        }
      }
    }
Beispiel #15
0
  @Override
  public void mouseClicked(int xAxis, int yAxis, int button) {
    if (xAxis >= xLocation + 1
        && xAxis <= xLocation + width - 1
        && yAxis >= yLocation + 1
        && yAxis <= yLocation + height - 1) {
      ItemStack stack = mc.thePlayer.inventory.getItemStack();

      if (guiObj instanceof GuiMekanism
          && stack != null
          && stack.getItem() instanceof ItemGaugeDropper) {
        TileEntity tile = ((GuiMekanism) guiObj).getTileEntity();

        if (tile instanceof ITankManager) {
          int index =
              Arrays.asList(((ITankManager) tile).getTanks()).indexOf(infoHandler.getTank());

          if (index != -1) {
            if (button == 0 && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
              button = 2;
            }

            Mekanism.packetHandler.sendToServer(
                new DropperUseMessage(Coord4D.get(tile), button, index));
          }
        }
      }
    }
  }
Beispiel #16
0
  private static double emit_do(
      TileEntityElectricBlock emitter,
      List<ForgeDirection> outputtingSides,
      double totalToSend,
      boolean tryAgain) {
    double remains = totalToSend % outputtingSides.size();
    double splitSend = (totalToSend - remains) / outputtingSides.size();
    double sent = 0;

    List<ForgeDirection> toRemove = new ArrayList<ForgeDirection>();

    for (ForgeDirection side : outputtingSides) {
      TileEntity tileEntity =
          Coord4D.get(emitter).getFromSide(side).getTileEntity(emitter.getWorldObj());
      double toSend = splitSend + remains;
      remains = 0;

      double prev = sent;
      sent += emit_do_do(emitter, tileEntity, side, toSend, tryAgain);

      if (sent - prev == 0) {
        toRemove.add(side);
      }
    }

    for (ForgeDirection side : toRemove) {
      outputtingSides.remove(side);
    }

    return sent;
  }
  @Override
  public boolean isInteriorValid(SynchronizedMatrixData structure) {
    for (Coord4D coord : innerNodes) {
      TileEntity tile = coord.getTileEntity(pointer.getWorldObj());

      if (tile instanceof TileEntityInductionCell) {
        structure.cells.add(coord);
        structure.storageCap += ((TileEntityInductionCell) tile).tier.maxEnergy;
      } else if (tile instanceof TileEntityInductionProvider) {
        structure.providers.add(coord);
        structure.transferCap += ((TileEntityInductionProvider) tile).tier.output;
      }
    }

    return true;
  }
  @Override
  public boolean upgrade(BaseTier upgradeTier) {
    if (upgradeTier.ordinal() != tier.ordinal() + 1) {
      return false;
    }

    tier = FluidTankTier.values()[upgradeTier.ordinal()];
    fluidTank.setCapacity(tier.storage);

    Mekanism.packetHandler.sendToReceivers(
        new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())),
        new Range4D(Coord4D.get(this)));
    markDirty();

    return true;
  }
  public boolean canReplace(Coord4D coord, boolean checkNodes, boolean isPathfinding) {
    if (checkNodes && usedNodes.contains(coord)) {
      return false;
    }

    if (coord.isAirBlock(worldObj) || MekanismUtils.isDeadFluid(worldObj, coord)) {
      return true;
    }

    if (MekanismUtils.isFluid(worldObj, coord)) {
      return isPathfinding;
    }

    return coord
        .getBlock(worldObj)
        .isReplaceable(worldObj, coord.xCoord, coord.yCoord, coord.zCoord);
  }
  public int pushUp(FluidStack fluid, boolean doFill) {
    Coord4D up = Coord4D.get(this).offset(EnumFacing.UP);

    if (up.getTileEntity(worldObj) instanceof TileEntityFluidTank) {
      IFluidHandler handler =
          CapabilityUtils.getCapability(
              up.getTileEntity(worldObj),
              CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
              EnumFacing.DOWN);

      if (PipeUtils.canFill(handler, fluid)) {
        return handler.fill(fluid, doFill);
      }
    }

    return 0;
  }
  @Override
  public void validate() {
    super.validate();

    if (worldObj.isRemote) {
      Mekanism.packetHandler.sendToServer(new DataRequestMessage(Coord4D.get(this)));
    }
  }
 @Override
 public int hashCode() {
   int code = 1;
   code = 31 * code + super.hashCode();
   code = 31 * code + side.ordinal();
   code = 31 * code + valveLocation.hashCode();
   return code;
 }
Beispiel #23
0
  /**
   * Whether or not a cable can connect to a specific acceptor.
   *
   * @param side - side to check
   * @param tile - cable TileEntity
   * @return whether or not the cable can connect to the specific side
   */
  public static boolean canConnectToAcceptor(ForgeDirection side, TileEntity tile) {
    if (tile == null) {
      return false;
    }

    TileEntity tileEntity = Coord4D.get(tile).getFromSide(side).getTileEntity(tile.getWorldObj());

    return isConnectable(tile, tileEntity, side);
  }
 @Override
 public int hashCode() {
   int code = 1;
   code = 31 * code + location.hashCode();
   code = 31 * code + height;
   code = 31 * code + length;
   code = 31 * code + width;
   return code;
 }
  public int getCurrentNeeded() {
    int needed = fluidTank.getCapacity() - fluidTank.getFluidAmount();

    Coord4D top = Coord4D.get(this).offset(EnumFacing.UP);
    TileEntity topTile = top.getTileEntity(worldObj);

    if (topTile instanceof TileEntityFluidTank) {
      TileEntityFluidTank topTank = (TileEntityFluidTank) topTile;

      if (fluidTank.getFluid() != null && topTank.fluidTank.getFluid() != null) {
        if (fluidTank.getFluid().getFluid() != topTank.fluidTank.getFluid().getFluid()) {
          return needed;
        }
      }

      needed += topTank.getCurrentNeeded();
    }

    return needed;
  }
    @Override
    public void toBytes(ByteBuf dataStream) {
      dataStream.writeInt(packetType.ordinal());

      if (packetType == SecurityPacketType.BLOCK) {
        coord4D.write(dataStream);
      } else {
        dataStream.writeInt(currentHand.ordinal());
      }

      dataStream.writeInt(value.ordinal());
    }
    @Override
    public void fromBytes(ByteBuf dataStream) {
      packetType = SecurityPacketType.values()[dataStream.readInt()];

      if (packetType == SecurityPacketType.BLOCK) {
        coord4D = Coord4D.read(dataStream);
      } else {
        currentHand = EnumHand.values()[dataStream.readInt()];
      }

      value = SecurityMode.values()[dataStream.readInt()];
    }
  @Override
  public IHeatTransfer getAdjacent(ForgeDirection side) {
    if (canConnectHeat(side)) {
      TileEntity adj = Coord4D.get(this).getFromSide(side).getTileEntity(worldObj);

      if (adj instanceof IHeatTransfer) {
        return (IHeatTransfer) adj;
      }
    }

    return null;
  }
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (worldObj.isRemote) {
      updateSound();
    }

    if (isFormed()) {
      getReactor().simulate();

      if (!worldObj.isRemote
          && (getReactor().isBurning() != clientBurning
              || Math.abs(getReactor().getPlasmaTemp() - clientTemp) > 1000000)) {
        Mekanism.packetHandler.sendToAllAround(
            new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())),
            Coord4D.get(this).getTargetPoint(50D));
        clientBurning = getReactor().isBurning();
        clientTemp = getReactor().getPlasmaTemp();
      }
    }
  }
  private void doPlenish() {
    if (usedNodes.size() >= MAX_NODES) {
      finishedCalc = true;
      return;
    }

    if (activeNodes.isEmpty()) {
      if (usedNodes.isEmpty()) {
        Coord4D below = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);

        if (!canReplace(below, true, true)) {
          finishedCalc = true;
          return;
        }

        activeNodes.add(below);
      } else {
        finishedCalc = true;
        return;
      }
    }

    Set<Coord4D> toRemove = new HashSet<Coord4D>();

    for (Coord4D coord : activeNodes) {
      if (coord.exists(worldObj)) {
        if (canReplace(coord, true, false)) {
          worldObj.setBlock(
              coord.xCoord,
              coord.yCoord,
              coord.zCoord,
              MekanismUtils.getFlowingBlock(fluidTank.getFluid().getFluid()),
              0,
              3);

          setEnergy(getEnergy() - usage.fluidicPlenisherUsage);
          fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
        }

        for (ForgeDirection dir : dirs) {
          Coord4D sideCoord = coord.getFromSide(dir);

          if (sideCoord.exists(worldObj) && canReplace(sideCoord, true, true)) {
            activeNodes.add(sideCoord);
          }
        }

        toRemove.add(coord);
        break;
      } else {
        toRemove.add(coord);
      }
    }

    for (Coord4D coord : toRemove) {
      activeNodes.remove(coord);
      usedNodes.add(coord);
    }
  }