Ejemplo n.º 1
0
  @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)));
        }
      }
    }
  }
Ejemplo n.º 2
0
  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();
    }
  }
Ejemplo n.º 3
0
  @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;
    }
  }
Ejemplo n.º 4
0
  @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;
    }
  }
Ejemplo n.º 5
0
  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);
        }
      }
    }
  }
Ejemplo n.º 6
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));
          }
        }
      }
    }
  }
Ejemplo n.º 7
0
  @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;
  }
Ejemplo n.º 8
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;
  }
  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);
    }
  }
Ejemplo n.º 10
0
  @Override
  public void validate() {
    super.validate();

    if (worldObj.isRemote) {
      Mekanism.packetHandler.sendToServer(new DataRequestMessage(Coord4D.get(this)));
    }
  }
Ejemplo n.º 11
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 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();
      }
    }
  }
Ejemplo n.º 14
0
  @Override
  public void updateEntity() {
    if (!worldObj.isRemote && general.destroyDisabledBlocks) {
      MachineType type = MachineType.get(getBlockType(), getBlockMetadata());

      if (type != null && !type.isEnabled()) {
        Mekanism.logger.info(
            "[Mekanism] Destroying machine of type '"
                + type.name
                + "' at coords "
                + Coord4D.get(this)
                + " as according to config.");
        worldObj.setBlockToAir(xCoord, yCoord, zCoord);
        return;
      }
    }

    for (ITileComponent component : components) {
      component.tick();
    }

    onUpdate();

    if (!worldObj.isRemote) {
      openedThisTick.clear();

      if (doAutoSync && playersUsing.size() > 0) {
        for (EntityPlayer player : playersUsing) {
          Mekanism.packetHandler.sendTo(
              new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())),
              (EntityPlayerMP) player);
        }
      }
    }

    ticker++;
    redstoneLastTick = redstone;
  }
Ejemplo n.º 15
0
  /**
   * Gets all the connected energy acceptors, whether IC2-based or BuildCraft-based, surrounding a
   * specific tile entity.
   *
   * @param tileEntity - center tile entity
   * @return TileEntity[] of connected acceptors
   */
  public static TileEntity[] getConnectedEnergyAcceptors(TileEntity tileEntity) {
    TileEntity[] acceptors = new TileEntity[] {null, null, null, null, null, null};

    for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) {
      TileEntity acceptor =
          Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());

      if (isEnergyAcceptor(acceptor)) {
        acceptors[orientation.ordinal()] = acceptor;
      }
    }

    return acceptors;
  }
Ejemplo n.º 16
0
  /**
   * Gets all the connected cables around a specific tile entity.
   *
   * @param tileEntity - center tile entity
   * @return TileEntity[] of connected cables
   */
  public static TileEntity[] getConnectedCables(TileEntity tileEntity) {
    TileEntity[] cables = new TileEntity[] {null, null, null, null, null, null};

    for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) {
      TileEntity cable =
          Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());

      if (isCable(cable)) {
        cables[orientation.ordinal()] = cable;
      }
    }

    return cables;
  }
Ejemplo n.º 17
0
  @Override
  public void mouseClicked(int mouseX, int mouseY, int button) throws IOException {
    super.mouseClicked(mouseX, mouseY, button);

    int xAxis = (mouseX - (width - xSize) / 2);
    int yAxis = (mouseY - (height - ySize) / 2);

    if (button == 0) {
      if (xAxis >= 6 && xAxis <= 20 && yAxis >= 6 && yAxis <= 20) {
        SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
        Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 1, 10));
      }
    }
  }
Ejemplo n.º 18
0
  /**
   * Gets all the connected cables around a specific tile entity.
   *
   * @param tileEntity - center tile entity
   * @return TileEntity[] of connected cables
   */
  public static TileEntity[] getConnectedOutputters(TileEntity tileEntity) {
    TileEntity[] outputters = new TileEntity[] {null, null, null, null, null, null};

    for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) {
      TileEntity outputter =
          Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());

      if (isOutputter(outputter, orientation)) {
        outputters[orientation.ordinal()] = outputter;
      }
    }

    return outputters;
  }
Ejemplo n.º 19
0
  @Override
  public void mouseClicked(int mouseX, int mouseY, int button) {
    super.mouseClicked(mouseX, mouseY, button);

    int xAxis = (mouseX - (width - xSize) / 2);
    int yAxis = (mouseY - (height - ySize) / 2);

    if (button == 0) {
      if (xAxis >= 6 && xAxis <= 20 && yAxis >= 6 && yAxis <= 20) {
        SoundHandler.playSound("gui.button.press");
        MekanismGenerators.packetHandler.sendToServer(
            new GeneratorsGuiMessage(Coord4D.get(tileEntity), 10));
      }
    }
  }
Ejemplo n.º 20
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();
    }
  }
Ejemplo n.º 22
0
  private void activeEmit() {
    if (fluidTank.getFluid() != null) {
      TileEntity tileEntity = Coord4D.get(this).offset(EnumFacing.DOWN).getTileEntity(worldObj);

      if (tileEntity != null
          && CapabilityUtils.hasCapability(
              tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.UP)) {
        IFluidHandler handler =
            CapabilityUtils.getCapability(
                tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.UP);
        FluidStack toDrain =
            new FluidStack(fluidTank.getFluid(), Math.min(tier.output, fluidTank.getFluidAmount()));
        fluidTank.drain(handler.fill(toDrain, true), true);
      }
    }
  }
Ejemplo n.º 23
0
  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;
  }
Ejemplo n.º 24
0
  @Override
  protected void mouseClicked(int x, int y, int button) {
    super.mouseClicked(x, y, button);

    if (button == 0) {
      int xAxis = (x - (width - xSize) / 2);
      int yAxis = (y - (height - ySize) / 2);

      if (xAxis > 45 && xAxis < 63 && yAxis > 13 && yAxis < 21) {
        ArrayList data = new ArrayList();
        data.add(0);

        Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
        SoundHandler.playSound("gui.button.press");
      }
    }
  }
  public double getBoost() {
    int lavaBoost = 0;
    double netherBoost = 0D;

    for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
      Coord4D coord = Coord4D.get(this).getFromSide(side);

      if (isLava(coord.xCoord, coord.yCoord, coord.zCoord)) {
        lavaBoost++;
      }
    }

    if (worldObj.provider.dimensionId == -1) {
      netherBoost = generators.heatGenerationNether;
    }

    return (generators.heatGenerationLava * lavaBoost) + netherBoost;
  }
Ejemplo n.º 26
0
  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;
  }
Ejemplo n.º 27
0
  @Override
  public EnumActionResult onItemUse(
      ItemStack itemstack,
      EntityPlayer entityplayer,
      World world,
      BlockPos pos,
      EnumHand hand,
      EnumFacing side,
      float posX,
      float posY,
      float posZ) {
    TileEntity tileEntity = world.getTileEntity(pos);

    if (tileEntity instanceof TileEntityChargepad) {
      TileEntityChargepad chargepad = (TileEntityChargepad) tileEntity;

      if (!chargepad.isActive) {
        if (!world.isRemote) {
          EntityRobit robit =
              new EntityRobit(world, pos.getX() + 0.5, pos.getY() + 0.1, pos.getZ() + 0.5);

          robit.setHome(Coord4D.get(chargepad));
          robit.setEnergy(getEnergy(itemstack));
          robit.setOwner(entityplayer.getName());
          robit.setInventory(getInventory(itemstack));
          robit.setCustomNameTag(getName(itemstack));

          world.spawnEntityInWorld(robit);
        }

        entityplayer.setHeldItem(hand, null);

        return EnumActionResult.SUCCESS;
      }
    }

    return EnumActionResult.PASS;
  }
  @Override
  public void onUpdate() {
    if (worldObj.isRemote) {
      Mekanism.proxy.registerSound(this);

      if (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.sendToAll(
              new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())));
        }
      }

      ChargeUtils.discharge(3, this);

      if (inventory[0] != null
          && (injectTank.getGas() == null || injectTank.getStored() < injectTank.getMaxGas())) {
        injectTank.receive(
            GasTransmission.removeGas(
                inventory[0], GasRegistry.getGas("sulfuricAcid"), injectTank.getNeeded()),
            true);
      }

      if (inventory[2] != null && outputTank.getGas() != null) {
        outputTank.draw(GasTransmission.addGas(inventory[2], outputTank.getGas()), true);
      }

      boolean changed = false;

      if (canOperate()
          && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE)
          && injectTank.getStored() >= INJECT_USAGE
          && MekanismUtils.canFunction(this)) {
        setActive(true);
        setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE));

        if (operatingTicks < MekanismUtils.getTicks(this, TICKS_REQUIRED)) {
          operatingTicks++;
          injectTank.draw(INJECT_USAGE, true);
        } else {
          GasStack stack =
              RecipeHandler.getItemToGasOutput(
                  inventory[1], true, Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get());

          outputTank.receive(stack, true);
          injectTank.draw(INJECT_USAGE, true);

          operatingTicks = 0;

          if (inventory[1].stackSize <= 0) {
            inventory[1] = null;
          }

          markDirty();
        }
      } else {
        if (prevEnergy >= getEnergy()) {
          changed = true;
          setActive(false);
        }
      }

      if (changed && !canOperate()) {
        operatingTicks = 0;
      }

      prevEnergy = getEnergy();

      if (outputTank.getGas() != null) {
        GasStack toSend =
            new GasStack(outputTank.getGas().getGas(), Math.min(outputTank.getStored(), gasOutput));

        TileEntity tileEntity =
            Coord4D.get(this).getFromSide(MekanismUtils.getRight(facing)).getTileEntity(worldObj);

        if (tileEntity instanceof IGasHandler) {
          if (((IGasHandler) tileEntity)
              .canReceiveGas(
                  MekanismUtils.getRight(facing).getOpposite(), outputTank.getGas().getGas())) {
            outputTank.draw(
                ((IGasHandler) tileEntity)
                    .receiveGas(MekanismUtils.getRight(facing).getOpposite(), toSend),
                true);
          }
        }
      }
    }
  }
  @Override
  public void onUpdate() {
    if (!worldObj.isRemote) {
      ChargeUtils.discharge(2, this);

      if (inventory[0] != null) {
        if (inventory[0].getItem() instanceof IFluidContainerItem
            && ((IFluidContainerItem) inventory[0].getItem()).getFluid(inventory[0]) != null) {
          if (((IFluidContainerItem) inventory[0].getItem())
              .getFluid(inventory[0])
              .getFluid()
              .canBePlacedInWorld()) {
            fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0]), true);

            if (((IFluidContainerItem) inventory[0].getItem()).getFluid(inventory[0]) == null
                || fluidTank.getFluidAmount() == fluidTank.getCapacity()) {
              if (inventory[1] == null) {
                inventory[1] = inventory[0].copy();
                inventory[0] = null;

                markDirty();
              }
            }
          }
        } else if (FluidContainerRegistry.isFilledContainer(inventory[0])) {
          FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);

          if ((fluidTank.getFluid() == null && itemFluid.amount <= fluidTank.getCapacity())
              || fluidTank.getFluid().amount + itemFluid.amount <= fluidTank.getCapacity()) {
            if ((fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid))
                || !itemFluid.getFluid().canBePlacedInWorld()) {
              return;
            }

            ItemStack containerItem = inventory[0].getItem().getContainerItem(inventory[0]);

            boolean filled = false;

            if (containerItem != null) {
              if (inventory[1] == null
                  || (inventory[1].isItemEqual(containerItem)
                      && inventory[1].stackSize + 1 <= containerItem.getMaxStackSize())) {
                inventory[0] = null;

                if (inventory[1] == null) {
                  inventory[1] = containerItem;
                } else {
                  inventory[1].stackSize++;
                }

                filled = true;
              }
            } else {
              inventory[0].stackSize--;

              if (inventory[0].stackSize == 0) {
                inventory[0] = null;
              }

              filled = true;
            }

            if (filled) {
              fluidTank.fill(itemFluid, true);
              markDirty();
            }
          }
        }
      }

      if (getEnergy() >= usage.fluidicPlenisherUsage
          && worldObj.getWorldTime() % 10 == 0
          && fluidTank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
        if (fluidTank.getFluid().getFluid().canBePlacedInWorld()) {
          if (!finishedCalc) {
            doPlenish();
          } else {
            Coord4D below = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);

            if (canReplace(below, false, false)
                && getEnergy() >= usage.fluidicPlenisherUsage
                && fluidTank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
              if (fluidTank.getFluid().getFluid().canBePlacedInWorld()) {
                worldObj.setBlock(
                    below.xCoord,
                    below.yCoord,
                    below.zCoord,
                    MekanismUtils.getFlowingBlock(fluidTank.getFluid().getFluid()),
                    0,
                    3);

                setEnergy(getEnergy() - usage.fluidicPlenisherUsage);
                fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
              }
            }
          }
        }
      }
    }
  }
Ejemplo n.º 30
0
  @Override
  public void onUpdate() {
    if (worldObj.isRemote) {
      if (updateDelay > 0) {
        updateDelay--;

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

      float targetScale =
          (float) (fluidTank.getFluid() != null ? fluidTank.getFluid().amount : 0)
              / fluidTank.getCapacity();

      if (Math.abs(prevScale - targetScale) > 0.01) {
        prevScale = (9 * prevScale + targetScale) / 10;
      }
    } else {
      if (updateDelay > 0) {
        updateDelay--;

        if (updateDelay == 0 && clientActive != isActive) {
          needsPacket = true;
        }
      }

      if (valve > 0) {
        valve--;

        if (valve == 0) {
          valveFluid = null;
          needsPacket = true;
        }
      }

      if (fluidTank.getFluidAmount() != prevAmount) {
        MekanismUtils.saveChunk(this);
        needsPacket = true;
      }

      prevAmount = fluidTank.getFluidAmount();

      if (inventory[0] != null) {
        manageInventory();
      }

      if (isActive) {
        activeEmit();
      }

      int newRedstoneLevel = getRedstoneLevel();

      if (newRedstoneLevel != currentRedstoneLevel) {
        markDirty();
        currentRedstoneLevel = newRedstoneLevel;
      }

      if (needsPacket) {
        Mekanism.packetHandler.sendToAllAround(
            new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())),
            Coord4D.get(this).getTargetPoint(50));
      }

      needsPacket = false;
    }
  }