コード例 #1
0
  public int getProgress() {
    ItemStack stack = inventory.getStackInSlot(0);
    if (stack == null) return 0;
    Item item = stack.getItem();
    FluidStack fluidstack = null;
    int capacity = 0;
    if (item instanceof IFluidContainerItem) {
      IFluidContainerItem iFluidContainerItem = (IFluidContainerItem) stack.getItem();
      fluidstack = iFluidContainerItem.getFluid(stack);
      capacity = iFluidContainerItem.getCapacity(stack);
    } else if (FluidContainerRegistry.isContainer(stack)) {
      fluidstack = FluidContainerRegistry.getFluidForFilledItem(stack);
      capacity =
          FluidContainerRegistry.getContainerCapacity(fill ? tank.getFluid() : fluidstack, stack);
    }

    if (fluidstack == null || capacity <= 0) {
      if (fill) return 0;
      return 16;
    }
    if (fill) return (int) ((fluidstack.amount * 16D) / capacity);
    return (int) (((capacity - fluidstack.amount) * 16D) / capacity);
  }
コード例 #2
0
  @Override
  public void updateEntity() {
    super.updateEntity();
    if (worldObj.isRemote) return;
    ItemStack stack = inventory.getStackInSlot(0);
    if (stack != null) {
      Item stackItem = stack.getItem();
      if (stackItem instanceof IFluidContainerItem) {
        IFluidContainerItem iFluidContainerItem = (IFluidContainerItem) stackItem;
        if (fill) {
          if (!tank.isEmpty()) {
            int amount = 128;
            if (tank.getFluidAmount() < amount) amount = tank.getFluidAmount();
            if (energy >= amount) {
              drain(
                  ForgeDirection.UNKNOWN,
                  iFluidContainerItem.fill(stack, new FluidStack(tank.getFluid(), amount), true),
                  true);
              energy -= amount;
            }
          }
        } else {
          FluidStack contained = iFluidContainerItem.getFluid(stack);
          if (!fill && !tank.isFull() && contained != null && contained.amount > 0) {
            int amount = 64;
            if (tank.getFreeSpace() < amount) amount = tank.getFreeSpace();
            if (amount > contained.amount) amount = contained.amount;
            iFluidContainerItem.drain(
                stack, fill(ForgeDirection.UNKNOWN, new FluidStack(contained, amount), true), true);
          }
        }
      } else if (FluidContainerRegistry.isContainer(stack)) {
        if (fill) {
          if (!tank.isEmpty()) {
            int amount = FluidContainerRegistry.getContainerCapacity(tank.getFluid(), stack);
            if (amount > 0 && energy >= amount && tank.getFluidAmount() >= amount) {
              ItemStack filledContainer =
                  FluidContainerRegistry.fillFluidContainer(
                      new FluidStack(tank.getFluid(), amount), stack);
              if (filledContainer != null
                  && filledContainer.getItem() != null
                  && filledContainer.stackSize > 0) {
                energy -= amount;
                drain(ForgeDirection.UNKNOWN, amount, true);
                inventory.setInventorySlotContents(0, filledContainer.copy());
              }
            }
          }
        } else {
          FluidStack contained = FluidContainerRegistry.getFluidForFilledItem(stack);
          if (contained != null
              && contained.amount > 0
              && tank.getFreeSpace() >= contained.amount) {
            if (fill(ForgeDirection.UNKNOWN, contained, false) == contained.amount) {
              fill(ForgeDirection.UNKNOWN, contained, true);
              ItemStack drainedContainer = FluidContainerRegistry.drainFluidContainer(stack);
              if (drainedContainer != null
                  && drainedContainer.getItem() != null
                  && drainedContainer.stackSize > 0)
                inventory.setInventorySlotContents(0, drainedContainer.copy());
            }
          }
        }
      }

      if (getProgress() >= 16) {
        stack = getStackInSlot(0);
        if (stack != null) {
          ItemStack outputStack = getStackInSlot(1);
          if (outputStack == null || outputStack.getItem() == null || outputStack.stackSize <= 0) {
            ItemStack copyStack = stack.copy();
            copyStack.stackSize = 1;
            inventory.setInventorySlotContents(1, copyStack);
            inventory.decrStackSize(0, 1);
          }
        }
      }
    }
  }
コード例 #3
0
  private void loadItems() {
    registerVariantNames();
    int size = 0;
    ImmutableList<Item> items = ImmutableList.copyOf(GameData.getItemRegistry().typeSafeIterable());
    for (Item item : items) {
      size += getVariantNames(item).size();
    }
    itemBar = ProgressManager.push("ModelLoader: items", size);
    for (Item item : items) {
      // default loading
      for (String s : (List<String>) getVariantNames(item)) {
        ResourceLocation file = getItemLocation(s);
        ModelResourceLocation memory = getInventoryVariant(s);
        itemBar.step(memory.toString());
        IModel model = null;
        try {
          model = getModel(file);
        } catch (IOException e) {
          // Handled by our finally block.
        } finally {
          if (model == null || model == getMissingModel()) {
            FMLLog.fine(
                "Item json isn't found for '"
                    + memory
                    + "', trying to load the variant from the blockstate json");
            try {
              registerVariant(getModelBlockDefinition(memory), memory);
            } catch (Exception exception) {
              FMLLog.getLogger().warn("Unable to load definition " + memory, exception);
            }
          } else stateModels.put(memory, model);
        }
      }
    }
    ProgressManager.pop(itemBar);

    // replace vanilla bucket models if desired. done afterwards for performance reasons
    if (ForgeModContainer.replaceVanillaBucketModel) {
      // ensure the bucket model is loaded
      if (!stateModels.containsKey(ModelDynBucket.LOCATION)) {
        // load forges blockstate json for it
        ModelResourceLocation memory = getInventoryVariant("forge:dynbucket");
        registerVariant(getModelBlockDefinition(memory), memory);
      }

      // empty bucket
      for (String s : getVariantNames(Items.bucket)) {
        ModelResourceLocation memory = getInventoryVariant(s);
        try {
          IModel model = getModel(new ResourceLocation("forge", "item/bucket"));
          // only on successful load, otherwise continue using the old model
          stateModels.put(memory, model);
        } catch (IOException e) {
          // use the original vanilla model
        }
      }

      setBucketModel(Items.water_bucket);
      setBucketModel(Items.lava_bucket);
      // milk bucket only replaced if some mod adds milk
      if (FluidRegistry.isFluidRegistered("milk")) {
        // can the milk be put into a bucket?
        Fluid milk = FluidRegistry.getFluid("milk");
        FluidStack milkStack = new FluidStack(milk, FluidContainerRegistry.BUCKET_VOLUME);
        if (FluidContainerRegistry.getContainerCapacity(milkStack, new ItemStack(Items.bucket))
            == FluidContainerRegistry.BUCKET_VOLUME) {
          setBucketModel(Items.milk_bucket);
        }
      } else {
        // milk bucket if no milk fluid is present
        for (String s : getVariantNames(Items.milk_bucket)) {
          ModelResourceLocation memory = getInventoryVariant(s);
          try {
            IModel model = getModel(new ResourceLocation("forge", "item/bucket_milk"));
            // only on successful load, otherwise continue using the old model
            stateModels.put(memory, model);
          } catch (IOException e) {
            // use the original vanilla model
          }
        }
      }
    }
  }