// result
  private void getRecipeFood(
      World world, int x, int y, int z, EntityPlayer player, ItemStack input, ItemStack result) {
    if (input == null || input.getItem() == null) return;
    ItemStack container = null;
    if (FluidContainerRegistry.isFilledContainer(input)) {
      container = FluidContainerRegistry.drainFluidContainer(input);
    } else {
      container = input.getItem().getContainerItem(input);
    }

    if (!player.capabilities.isCreativeMode && --input.stackSize <= 0) {
      player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack) null);
    }

    if (!world.isRemote) {
      EntityItem entity = new EntityItem(world, player.posX, player.posY, player.posZ, result);
      world.spawnEntityInWorld(entity);
    }

    if (container != null) {
      if (!world.isRemote) {
        EntityItem entity = new EntityItem(world, player.posX, player.posY, player.posZ, container);
        world.spawnEntityInWorld(entity);
      }
    }

    world.playSoundAtEntity(player, "random.pop", 0.4F, 1.8F);
  }
 public static ItemStack drainFluidContainer(FluidTank tank, ItemStack containerIn) {
   if (FluidContainerRegistry.isFilledContainer(containerIn)) {
     FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(containerIn);
     if (fs != null && tank.getFluidAmount() + fs.amount <= tank.getCapacity()) {
       ItemStack emptyContainer = FluidContainerRegistry.drainFluidContainer(containerIn);
       if (emptyContainer != null && tank.fill(fs, true) == fs.amount) return emptyContainer;
     }
   }
   return null;
 }
Exemplo n.º 3
0
  private ItemStack getContainer(ItemStack stack) {
    if (stack.getItem() == ModItems.waterBowl) return new ItemStack(Items.bowl);

    if (stack.getItem().hasContainerItem(stack)) return stack.getItem().getContainerItem(stack);
    else if (stack.getItem() instanceof IFluidContainerItem) {
      ((IFluidContainerItem) stack.getItem())
          .drain(stack, FluidContainerRegistry.BUCKET_VOLUME, true);
      return stack;
    }
    return FluidContainerRegistry.drainFluidContainer(stack);
  }
  public static boolean fillFluidHandlerWithPlayerItem(
      World world, IFluidHandler handler, EntityPlayer player, ItemStack equipped) {
    if (equipped == null) return false;

    FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(equipped);
    if (fluid != null) {
      if (handler.fill(null, fluid, false) == fluid.amount || player.capabilities.isCreativeMode) {
        if (world.isRemote) return true;

        ItemStack filledStack = FluidContainerRegistry.drainFluidContainer(equipped);
        if (!player.capabilities.isCreativeMode) {
          if (equipped.stackSize == 1) {
            player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
            player.inventory.addItemStackToInventory(filledStack);
          } else {
            equipped.stackSize -= 1;
            if (filledStack != null && !player.inventory.addItemStackToInventory(filledStack))
              player.dropItem(filledStack, false, true);
          }
          player.openContainer.detectAndSendChanges();
          if (player instanceof EntityPlayerMP)
            ((EntityPlayerMP) player)
                .updateCraftingInventory(player.openContainer, player.openContainer.getInventory());
        }
        handler.fill(null, fluid, true);
        return true;
      }
    } else if (equipped.getItem() instanceof IFluidContainerItem) {
      IFluidContainerItem container = (IFluidContainerItem) equipped.getItem();
      fluid = container.getFluid(equipped);
      if (handler.fill(null, fluid, false) > 0) {
        if (world.isRemote) return true;

        int fill = handler.fill(null, fluid, true);
        if (equipped.stackSize > 1) {
          ItemStack emptied = ItemStackUtils.copyStackWithAmount(equipped, 1);
          equipped.stackSize -= 1;
          container.drain(emptied, fill, true);
          if (!player.inventory.addItemStackToInventory(emptied))
            player.dropItem(emptied, false, true);
        } else container.drain(equipped, fill, true);
        player.openContainer.detectAndSendChanges();
        if (player instanceof EntityPlayerMP)
          ((EntityPlayerMP) player)
              .updateCraftingInventory(player.openContainer, player.openContainer.getInventory());
        return true;
      }
    }
    return false;
  }
Exemplo n.º 5
0
 public ItemStack addLiquid(ItemStack is) {
   if (is == null || is.stackSize > 1) return is;
   if (FluidContainerRegistry.isFilledContainer(is)) {
     FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(is);
     if (addLiquid(fs)) {
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
       return FluidContainerRegistry.drainFluidContainer(is);
     }
   } else if (is.getItem() instanceof IFluidContainerItem) {
     FluidStack isfs = ((IFluidContainerItem) is.getItem()).getFluid(is);
     if (isfs != null && addLiquid(isfs)) {
       ((IFluidContainerItem) is.getItem()).drain(is, is.getMaxDamage(), true);
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     }
   }
   return is;
 }
Exemplo n.º 6
0
 public static boolean fillFluidHandlerWithPlayerItem(
     World world, IFluidHandler handler, EntityPlayer player) {
   ItemStack equipped = player.getCurrentEquippedItem();
   if (equipped == null) return false;
   FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(equipped);
   if (fluid != null) {
     if (handler.fill(ForgeDirection.UNKNOWN, fluid, false) == fluid.amount
         || player.capabilities.isCreativeMode) {
       ItemStack filledStack = FluidContainerRegistry.drainFluidContainer(equipped);
       if (!player.capabilities.isCreativeMode) {
         if (equipped.stackSize == 1) {
           player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
           player.inventory.addItemStackToInventory(filledStack);
         } else {
           equipped.stackSize -= 1;
           if (filledStack != null && !player.inventory.addItemStackToInventory(filledStack))
             player.func_146097_a(filledStack, false, true);
         }
         player.openContainer.detectAndSendChanges();
         ((EntityPlayerMP) player)
             .sendContainerAndContentsToPlayer(
                 player.openContainer, player.openContainer.getInventory());
       }
       handler.fill(ForgeDirection.UNKNOWN, fluid, true);
       return true;
     }
   } else if (equipped.getItem() instanceof IFluidContainerItem) {
     IFluidContainerItem container = (IFluidContainerItem) equipped.getItem();
     fluid = container.getFluid(equipped);
     if (handler.fill(ForgeDirection.UNKNOWN, fluid, false) > 0) {
       int fill = handler.fill(ForgeDirection.UNKNOWN, fluid, true);
       container.drain(equipped, fill, true);
       player.openContainer.detectAndSendChanges();
       ((EntityPlayerMP) player)
           .sendContainerAndContentsToPlayer(
               player.openContainer, player.openContainer.getInventory());
       return true;
     }
   }
   return false;
 }
  // change soup type
  @Override
  public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (world.isRemote || !this.onFurnace(world, x, y, z) || entity == null) return;
    TileEntity tile = world.getTileEntity(x, y, z);
    if (tile == null || !(tile instanceof TileFilledSoupPan)) return;

    TileFilledSoupPan pan = (TileFilledSoupPan) tile;
    boolean flag = false;
    if (entity instanceof EntityItem) {
      ItemStack input = ((EntityItem) entity).getEntityItem();
      IFondueSource recipe = RecipeRegisterManager.fondueRecipe.getType(input);

      if (recipe != null && recipe.beforeType() == pan.getType() && recipe.matches(input)) {
        this.setSoupType(world, x, y, z, pan, recipe.afterType());
        world.playSoundAtEntity(entity, "random.pop", 0.4F, 1.8F);

        ItemStack container = null;
        if (FluidContainerRegistry.isFilledContainer(input)) {
          container = FluidContainerRegistry.drainFluidContainer(input);
        } else {
          container = input.getItem().getContainerItem(input);
        }

        if (container != null) {
          EntityItem cont = new EntityItem(world, x, y + 1.0D, z, container);
          world.spawnEntityInWorld(cont);
        }

        if (input.stackSize > 1) {
          ((EntityItem) entity).getEntityItem().stackSize--;
        } else {
          entity.setDead();
        }
      }
    }
  }
  @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);
          }
        }
      }
    }
  }
Exemplo n.º 9
0
  @Override
  public void updateEntity() {
    if (!worldObj.isRemote) {
      ItemStack itemstack = storage[INPUT_SLOT];
      BarrelPreservativeRecipe preservative =
          BarrelManager.getInstance()
              .findMatchingPreservativeRepice(this, itemstack, fluid, sealed);
      if (itemstack != null && fluid != null && fluid.getFluid() == TFCFluids.FRESHWATER) {
        if (TFC_ItemHeat.hasTemp(itemstack)) {
          float temp = TFC_ItemHeat.getTemp(itemstack);
          if (fluid.amount >= 1 && temp > 1) {
            temp -= 50;
            fluid.amount -= 1;
            TFC_ItemHeat.setTemp(itemstack, temp);
            TFC_ItemHeat.handleItemHeat(itemstack);
          }
        }
      }
      if (fluid != null && itemstack != null && itemstack.getItem() instanceof IFood) {
        float w = ((IFood) itemstack.getItem()).getFoodWeight(itemstack);
        if (fluid.getFluid() == TFCFluids.VINEGAR) {
          // If the food is brined then we attempt to pickle it
          if (Food.isBrined(itemstack)
              && !Food.isPickled(itemstack)
              && w / fluid.amount <= Global.FOOD_MAX_WEIGHT / this.getMaxLiquid()
              && this.getSealed()
              && sealtime != 0
              && TFC_Time.getTotalHours() - sealtime >= 4) {
            fluid.amount -= 1 * w;
            Food.setPickled(itemstack, true);
          }
        }
      }

      if (preservative == null) {
        // No preservative was matched - decay normally
        TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord);
      } else {
        float env = preservative.getEnvironmentalDecayFactor();
        float base = preservative.getBaseDecayModifier();
        if (Float.isNaN(env) || env < 0.0) {
          TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord);
        } else if (Float.isNaN(base) || base < 0.0) {
          TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord, env);
        } else {
          TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord, env, base);
        }
      }

      // If lightning can strike here then it means that the barrel can see the sky, so rain can hit
      // it. If true then we fill
      // the barrel when its raining.
      if (!this.getSealed() && worldObj.canLightningStrikeAt(xCoord, yCoord + 1, zCoord)) {
        int count = getInvCount();
        if (count == 0 || count == 1 && this.getInputStack() != null) {
          if (this.fluid == null) fluid = new FluidStack(TFCFluids.FRESHWATER, 1);
          else if (this.fluid != null && fluid.getFluid() == TFCFluids.FRESHWATER)
            fluid.amount = Math.min(fluid.amount + 1, getMaxLiquid());
        }
      }

      // We only want to bother ticking food once per 5 seconds to keep overhead low.
      processTimer++;
      if (processTimer > 100) {
        processItems();
        processTimer = 0;
      }

      // Here we handle item stacks that are too big for MC to handle such as when making mortar.
      // If the stack is > its own max stack size then we split it and add it to the invisible solid
      // storage area or
      // spawn the item in the world if there is no room left.
      if (this.getFluidLevel() > 0 && getInputStack() != null) {
        int count = 1;
        while (this.getInputStack().stackSize > getInputStack().getMaxStackSize()) {
          ItemStack is = getInputStack().splitStack(getInputStack().getMaxStackSize());
          if (count < this.storage.length && this.getStackInSlot(count) == null) {
            this.setInventorySlotContents(count, is);
          } else {
            worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord, yCoord, zCoord, is));
          }
          count++;
        }
      }

      // Move any items in the solid storage slots to the main slot if they exist and the barrel has
      // liquid.
      else if (this.getFluidLevel() > 0 && getInputStack() == null && this.getInvCount() > 0) {
        for (int i = 0; i < storage.length; i++) {
          if (storage[i] != null) {
            storage[INPUT_SLOT] = storage[i].copy();
            storage[i] = null;
            break;
          }
        }
      }

      // Reset our fluid if all of the liquid is gone.
      if (fluid != null && fluid.amount == 0) fluid = null;

      // Handle adding fluids to the barrel if the barrel is currently in input mode.
      if (mode == MODE_IN) {
        ItemStack container = getInputStack();
        FluidStack inLiquid = FluidContainerRegistry.getFluidForFilledItem(container);

        if (container != null && container.getItem() instanceof IFluidContainerItem) {
          FluidStack isfs = ((IFluidContainerItem) container.getItem()).getFluid(container);
          if (isfs != null && addLiquid(isfs)) {
            ((IFluidContainerItem) container.getItem())
                .drain(
                    container,
                    ((IFluidContainerItem) container.getItem()).getCapacity(container),
                    true);
          }
        } else if (inLiquid != null && container != null && container.stackSize == 1) {
          if (addLiquid(inLiquid)) {
            this.setInventorySlotContents(0, FluidContainerRegistry.drainFluidContainer(container));
          }
        }
      }
      // Drain liquid from the barrel to a container if the barrel is in output mode.
      else if (mode == MODE_OUT) {
        ItemStack container = getInputStack();

        if (container != null
            && fluid != null
            && container.getItem() instanceof IFluidContainerItem) {
          FluidStack isfs = ((IFluidContainerItem) container.getItem()).getFluid(container);
          if (isfs == null || fluid.isFluidEqual(isfs)) {
            fluid.amount -=
                ((IFluidContainerItem) container.getItem()).fill(container, fluid, true);
            if (fluid.amount == 0) fluid = null;
          }
        } else if (FluidContainerRegistry.isEmptyContainer(container)) {
          this.setInventorySlotContents(0, this.removeLiquid(getInputStack()));
        }
      }
    }
  }