@Override
  public void readFromNBT(NBTTagCompound nbtTags) {
    super.readFromNBT(nbtTags);

    tier = EnergyCubeTier.getFromName(nbtTags.getString("tier"));
    output = tier.OUTPUT;
  }
  @Override
  public void writeToNBT(NBTTagCompound nbtTags) {
    super.writeToNBT(nbtTags);

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

    NBTTagList recurringList = new NBTTagList();

    for (Object3D wrapper : recurringNodes) {
      NBTTagCompound tagCompound = new NBTTagCompound();
      wrapper.write(tagCompound);
      recurringList.appendTag(tagCompound);
    }

    if (recurringList.tagCount() != 0) {
      nbtTags.setTag("recurringNodes", recurringList);
    }

    NBTTagList cleaningList = new NBTTagList();

    for (Object3D obj : cleaningNodes) {
      cleaningList.appendTag(obj.write(new NBTTagCompound()));
    }

    if (cleaningList.tagCount() != 0) {
      nbtTags.setTag("cleaningNodes", cleaningList);
    }
  }
  @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 ArrayList getNetworkedData(ArrayList data) {
    super.getNetworkedData(data);

    data.add(isActive);
    data.add(controlType.ordinal());
    data.add(operatingTicks);

    if (injectTank.getGas() != null) {
      data.add(true);
      data.add(injectTank.getGas().getGas().getID());
      data.add(injectTank.getStored());
    } else {
      data.add(false);
    }

    if (outputTank.getGas() != null) {
      data.add(true);
      data.add(outputTank.getGas().getGas().getID());
      data.add(outputTank.getStored());
    } else {
      data.add(false);
    }

    return data;
  }
  @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);

    authenticated = nbtTags.getBoolean("authenticated");
    locked = nbtTags.getBoolean("locked");
    password = nbtTags.getString("password");
  }
  @Override
  public void writeToNBT(NBTTagCompound nbtTags) {
    super.writeToNBT(nbtTags);

    nbtTags.setBoolean("authenticated", authenticated);
    nbtTags.setBoolean("locked", locked);
    nbtTags.setString("password", password);
  }
  @Override
  public void handlePacketData(ByteBuf dataStream) {
    super.handlePacketData(dataStream);

    authenticated = dataStream.readBoolean();
    locked = dataStream.readBoolean();
    password = PacketHandler.readString(dataStream);
  }
  @Override
  public void writeToNBT(NBTTagCompound nbtTags) {
    super.writeToNBT(nbtTags);

    nbtTags.setBoolean("isActive", isActive);
    nbtTags.setInteger("controlType", controlType.ordinal());
    nbtTags.setInteger("operatingTicks", operatingTicks);
    nbtTags.setTag("injectTank", injectTank.write(new NBTTagCompound()));
    nbtTags.setTag("gasTank", outputTank.write(new NBTTagCompound()));
  }
  @Override
  public void readFromNBT(NBTTagCompound nbtTags) {
    super.readFromNBT(nbtTags);

    isActive = nbtTags.getBoolean("isActive");
    controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
    operatingTicks = nbtTags.getInteger("operatingTicks");
    injectTank.read(nbtTags.getCompoundTag("injectTank"));
    outputTank.read(nbtTags.getCompoundTag("gasTank"));
  }
  @Override
  public ArrayList getNetworkedData(ArrayList data) {
    super.getNetworkedData(data);

    data.add(authenticated);
    data.add(locked);
    data.add(password);

    return data;
  }
  @Override
  public void handlePacketData(ByteArrayDataInput dataStream) {
    super.handlePacketData(dataStream);

    if (dataStream.readInt() == 1) {
      fluidTank.setFluid(new FluidStack(dataStream.readInt(), dataStream.readInt()));
    } else {
      fluidTank.setFluid(null);
    }

    MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
  }
  @Override
  public ArrayList getNetworkedData(ArrayList data) {
    super.getNetworkedData(data);

    if (fluidTank.getFluid() != null) {
      data.add(1);
      data.add(fluidTank.getFluid().fluidID);
      data.add(fluidTank.getFluid().amount);
    } else {
      data.add(0);
    }

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

    prevLidAngle = lidAngle;
    float increment = 0.1F;

    if ((playersUsing.size() > 0) && (lidAngle == 0.0F)) {
      worldObj.playSoundEffect(
          xCoord + 0.5F,
          yCoord + 0.5D,
          zCoord + 0.5F,
          "random.chestopen",
          0.5F,
          (worldObj.rand.nextFloat() * 0.1F) + 0.9F);
    }

    if ((playersUsing.size() == 0 && lidAngle > 0.0F)
        || (playersUsing.size() > 0 && lidAngle < 1.0F)) {
      float angle = lidAngle;

      if (playersUsing.size() > 0) {
        lidAngle += increment;
      } else {
        lidAngle -= increment;
      }

      if (lidAngle > 1.0F) {
        lidAngle = 1.0F;
      }

      float split = 0.5F;

      if (lidAngle < split && angle >= split) {
        worldObj.playSoundEffect(
            xCoord + 0.5D,
            yCoord + 0.5D,
            zCoord + 0.5D,
            "random.chestclosed",
            0.5F,
            (worldObj.rand.nextFloat() * 0.1F) + 0.9F);
      }

      if (lidAngle < 0.0F) {
        lidAngle = 0.0F;
      }
    }

    ChargeUtils.discharge(54, this);
  }
  @Override
  public void handlePacketData(ByteBuf dataStream) {
    super.handlePacketData(dataStream);

    isActive = dataStream.readBoolean();
    controlType = RedstoneControl.values()[dataStream.readInt()];
    operatingTicks = dataStream.readInt();

    if (dataStream.readBoolean()) {
      injectTank.setGas(
          new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
    } else {
      injectTank.setGas(null);
    }

    if (dataStream.readBoolean()) {
      outputTank.setGas(
          new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
    } else {
      outputTank.setGas(null);
    }

    MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
  }
  @Override
  public void readFromNBT(NBTTagCompound nbtTags) {
    super.readFromNBT(nbtTags);

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

    if (nbtTags.hasKey("recurringNodes")) {
      NBTTagList tagList = nbtTags.getTagList("recurringNodes");

      for (int i = 0; i < tagList.tagCount(); i++) {
        recurringNodes.add(Object3D.read((NBTTagCompound) tagList.tagAt(i)));
      }
    }

    if (nbtTags.hasKey("cleaningNodes")) {
      NBTTagList tagList = nbtTags.getTagList("cleaningNodes");

      for (int i = 0; i < tagList.tagCount(); i++) {
        cleaningNodes.add(Object3D.read((NBTTagCompound) tagList.tagAt(i)));
      }
    }
  }
Esempio n. 17
0
 @Override
 public void handlePacketData(ByteArrayDataInput dataStream) {
   super.handlePacketData(dataStream);
   tier = EnergyCubeTier.getFromName(dataStream.readUTF());
 }
  @Override
  public void onUpdate() {
    ChargeUtils.discharge(2, this);

    if (inventory[0] != null) {
      if (fluidTank.getFluid() != null
          && fluidTank.getFluid().amount >= FluidContainerRegistry.BUCKET_VOLUME) {
        if (FluidContainerRegistry.isEmptyContainer(inventory[0])) {
          ItemStack tempStack =
              FluidContainerRegistry.fillFluidContainer(fluidTank.getFluid(), inventory[0]);

          if (tempStack != null) {
            if (inventory[1] == null) {
              fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);

              inventory[1] = tempStack;
              inventory[0].stackSize--;

              if (inventory[0].stackSize <= 0) {
                inventory[0] = null;
              }
            } else if (tempStack.isItemEqual(inventory[1])
                && tempStack.getMaxStackSize() > inventory[1].stackSize) {
              fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);

              inventory[1].stackSize++;
              inventory[0].stackSize--;

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

    if (!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0) {
      if (getEnergy() >= 100
          && (fluidTank.getFluid() == null
              || fluidTank.getFluid().amount + FluidContainerRegistry.BUCKET_VOLUME <= 10000)) {
        if (suck(true)) {
          PacketHandler.sendPacket(
              Transmission.CLIENTS_RANGE,
              new PacketTileEntity()
                  .setParams(Object3D.get(this), getNetworkedData(new ArrayList())),
              Object3D.get(this),
              50D);
        }

        clean(true);
      }
    }

    super.onUpdate();

    if (fluidTank.getFluid() != null) {
      for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity tileEntity = Object3D.get(this).getFromSide(orientation).getTileEntity(worldObj);

        if (tileEntity instanceof IFluidHandler) {
          FluidStack toDrain =
              new FluidStack(fluidTank.getFluid(), Math.min(100, fluidTank.getFluidAmount()));
          fluidTank.drain(
              ((IFluidHandler) tileEntity).fill(orientation.getOpposite(), toDrain, true), true);

          if (fluidTank.getFluid() == null || fluidTank.getFluid().amount <= 0) {
            break;
          }
        }
      }
    }
  }
Esempio n. 19
0
 @Override
 public ArrayList getNetworkedData(ArrayList data) {
   super.getNetworkedData(data);
   data.add(tier.name);
   return data;
 }
Esempio n. 20
0
  @Override
  public void writeToNBT(NBTTagCompound nbtTags) {
    super.writeToNBT(nbtTags);

    nbtTags.setString("tier", tier.name);
  }
Esempio n. 21
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (powerProvider != null) {
      int received =
          (int)
              (powerProvider.useEnergy(
                      0,
                      (float) ((tier.MAX_ELECTRICITY - electricityStored) * Mekanism.TO_BC),
                      true)
                  * Mekanism.FROM_BC);
      setJoules(electricityStored + received);
    }

    if (inventory[0] != null && electricityStored > 0) {
      setJoules(
          getJoules() - ElectricItemHelper.chargeItem(inventory[0], getJoules(), getVoltage()));

      if (Mekanism.hooks.IC2Loaded && inventory[0].getItem() instanceof IElectricItem) {
        double sent =
            ElectricItem.charge(
                    inventory[0], (int) (electricityStored * Mekanism.TO_IC2), 3, false, false)
                * Mekanism.FROM_IC2;
        setJoules(electricityStored - sent);
      }
    }

    if (inventory[1] != null && electricityStored < tier.MAX_ELECTRICITY) {
      setJoules(
          getJoules()
              + ElectricItemHelper.dechargeItem(
                  inventory[1], getMaxJoules() - getJoules(), getVoltage()));

      if (Mekanism.hooks.IC2Loaded && inventory[1].getItem() instanceof IElectricItem) {
        IElectricItem item = (IElectricItem) inventory[1].getItem();
        if (item.canProvideEnergy()) {
          double gain =
              ElectricItem.discharge(
                      inventory[1],
                      (int) ((tier.MAX_ELECTRICITY - electricityStored) * Mekanism.TO_IC2),
                      3,
                      false,
                      false)
                  * Mekanism.FROM_IC2;
          setJoules(electricityStored + gain);
        }
      } else if (inventory[1].itemID == Item.redstone.itemID
          && electricityStored + 1000 <= tier.MAX_ELECTRICITY) {
        setJoules(electricityStored + 1000);
        --inventory[1].stackSize;

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

    if (electricityStored > 0) {
      TileEntity tileEntity =
          VectorHelper.getTileEntityFromSide(
              worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));

      if (Mekanism.hooks.IC2Loaded) {
        if (electricityStored >= output) {
          EnergyTileSourceEvent event = new EnergyTileSourceEvent(this, output);
          MinecraftForge.EVENT_BUS.post(event);
          setJoules(electricityStored - (output - event.amount));
        }
      }

      if (tileEntity != null) {
        if (isPowerReceptor(tileEntity)) {
          IPowerReceptor receptor = (IPowerReceptor) tileEntity;
          double electricityNeeded =
              Math.min(
                      receptor.powerRequest(),
                      receptor.getPowerProvider().getMaxEnergyStored()
                          - receptor.getPowerProvider().getEnergyStored())
                  * Mekanism.FROM_BC;
          float transferEnergy =
              (float) Math.min(electricityStored, Math.min(electricityNeeded, output));
          receptor
              .getPowerProvider()
              .receiveEnergy(
                  (float) (transferEnergy * Mekanism.TO_BC),
                  ForgeDirection.getOrientation(facing).getOpposite());
          setJoules(electricityStored - transferEnergy);
        }
      }
    }

    if (!worldObj.isRemote) {
      ForgeDirection outputDirection = ForgeDirection.getOrientation(facing);
      ArrayList<IElectricityNetwork> inputNetworks = new ArrayList<IElectricityNetwork>();

      for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        if (direction != outputDirection) {
          IElectricityNetwork network =
              ElectricityNetworkHelper.getNetworkFromTileEntity(
                  VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), direction),
                  direction);
          if (network != null) {
            inputNetworks.add(network);
          }
        }
      }

      TileEntity outputTile =
          VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), outputDirection);

      IElectricityNetwork outputNetwork =
          ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);

      if (outputNetwork != null && !inputNetworks.contains(outputNetwork)) {
        double outputWatts =
            Math.min(outputNetwork.getRequest().getWatts(), Math.min(getJoules(), 10000));

        if (getJoules() > 0 && outputWatts > 0 && getJoules() - outputWatts >= 0) {
          outputNetwork.startProducing(
              this, Math.min(outputWatts, getJoules()) / getVoltage(), getVoltage());
          setJoules(electricityStored - outputWatts);
        } else {
          outputNetwork.stopProducing(this);
        }
      }
    }
  }