コード例 #1
0
  // 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);
  }
コード例 #2
0
 public ItemStack tryPlaceContainedLiquid(
     World world, ItemStack bucket, int x, int y, int z, int side) {
   if (world.isRemote) return bucket;
   CarbonContainer item = (CarbonContainer) bucket.getItem();
   int id = bucket.getItemDamage();
   if (id != 0) {
     if (!item.canPlaceInWorld) return bucket;
     FluidStack liquid = LiquidRegistry.getLiquid(id);
     if (world.setBlock(x, y, z, liquid.getFluid().getBlock(), 0, 3))
       return item.getContainerItem(bucket);
     return bucket;
   }
   if (!item.canBeFilledFromWorld) return bucket;
   Block block = world.getBlock(x, y, z);
   if (block instanceof IFluidBlock) {
     FluidStack liquid = ((IFluidBlock) block).drain(world, x, y, z, false);
     if (liquid != null && FluidRegistry.isFluidRegistered(liquid.getFluid())) {
       ItemStack r = FluidContainerRegistry.fillFluidContainer(liquid, bucket);
       if (r != null && FluidContainerRegistry.isFilledContainer(r)) {
         ((IFluidBlock) block).drain(world, x, y, z, true);
         return r;
       }
     }
   }
   return bucket;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
ファイル: TEBarrel.java プロジェクト: Kittychanley/TFCraft
 public ItemStack addLiquid(ItemStack is) {
   if (is == null) return is;
   if (FluidContainerRegistry.isFilledContainer(is)) {
     FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(is);
     if (addLiquid(fs)) {
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
       return is.getItem().getContainerItem(is);
     }
   }
   return is;
 }
コード例 #5
0
  @Override
  public boolean isItemValidForSlot(int slotID, ItemStack itemstack) {
    if (slotID == 1) {
      return false;
    } else if (slotID == 0) {
      return FluidContainerRegistry.isFilledContainer(itemstack);
    } else if (slotID == 2) {
      return ChargeUtils.canBeDischarged(itemstack);
    }

    return false;
  }
コード例 #6
0
ファイル: JarOHoney.java プロジェクト: Adaptivity/TheErebus
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (world.isRemote) return true;
    TileEntityJarOHoney tile = Utils.getTileEntity(world, x, y, z, TileEntityJarOHoney.class);
    if (tile == null) return false;

    ItemStack stack = player.getCurrentEquippedItem();
    if (FluidContainerRegistry.isFilledContainer(stack)) {
      FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
      if (fluidStack.isFluidEqual(tile.getHoney()))
        if (fluidStack.amount + tile.getHoney().amount > TileEntityJarOHoney.HONEY_MAX_AMOUNT)
          return true;
        else {
          tile.addHoney(fluidStack.amount);
          ItemStack container = stack.getItem().getContainerItem(stack);
          stack.stackSize--;
          if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, container);
          else if (!player.inventory.addItemStackToInventory(container))
            Utils.dropStack(world, x, y, z, container);

          return true;
        }
    } else if (FluidContainerRegistry.isEmptyContainer(stack)) {
      ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(tile.getHoney(), stack);
      if (filledContainer != null) {
        stack.stackSize--;
        if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, filledContainer);
        else if (!player.inventory.addItemStackToInventory(filledContainer))
          Utils.dropStack(world, x, y, z, filledContainer);

        tile.drainHoney(FluidContainerRegistry.getFluidForFilledItem(filledContainer).amount);
        return true;
      }
    } else {
      player.getFoodStats().addStats(1, 0.8F);
      player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 100, 1));
      tile.drainHoney(100);
    }
    return false;
  }
コード例 #7
0
  @Override
  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    // we allow to insert buckets into the smeltery
    TileEntity te = worldIn.getTileEntity(pos);
    if (!(te instanceof IFluidHandler)) {
      return false;
    }
    IFluidHandler tank = (IFluidHandler) te;
    side = side.getOpposite();

    ItemStack stack = player.getHeldItem();
    if (stack == null) {
      return false;
    }

    // regular bucket
    ItemStack result = FluidUtil.tryEmptyBucket(stack, tank, side);
    if (result != null) {
      if (!player.capabilities.isCreativeMode) {
        player.inventory.decrStackSize(player.inventory.currentItem, 1);
        PlayerHelper.spawnItemAtPlayer(player, result);
      }
      return true;
    }

    // universal bucket
    ItemStack copy = stack.copy();
    if (FluidUtil.tryEmptyFluidContainerItem(stack, tank, side, player)) {
      if (player.capabilities.isCreativeMode) {
        // reset the stack that got modified
        player.inventory.setInventorySlotContents(player.inventory.currentItem, copy);
      }
      return true;
    }

    // prevent interaction of the item if it's a fluidcontainer. Prevents placing liquids when
    // interacting with the tank
    return FluidContainerRegistry.isFilledContainer(stack)
        || stack.getItem() instanceof IFluidContainerItem;
  }
コード例 #8
0
ファイル: TEBarrel.java プロジェクト: rjdunlap/TFCraft
 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;
 }
コード例 #9
0
  // 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();
        }
      }
    }
  }
コード例 #10
0
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
    ItemStack stack = null;
    Slot currentSlot = (Slot) inventorySlots.get(slotID);

    if (currentSlot != null && currentSlot.getHasStack()) {
      ItemStack slotStack = currentSlot.getStack();
      stack = slotStack.copy();

      if (ChargeUtils.canBeDischarged(slotStack)) {
        if (slotID != 4) {
          if (!mergeItemStack(slotStack, 4, 5, false)) {
            return null;
          }
        } else {
          if (!mergeItemStack(slotStack, 5, inventorySlots.size(), true)) {
            return null;
          }
        }
      } else if (FluidContainerRegistry.isEmptyContainer(slotStack)
          || FluidContainerRegistry.isFilledContainer(slotStack)) {
        if (slotID != 2 && slotID != 3) {
          if (!mergeItemStack(slotStack, 2, 3, false)) {
            return null;
          }
        } else {
          if (!mergeItemStack(slotStack, 5, inventorySlots.size(), true)) {
            return null;
          }
        }
      } else if (slotStack.getItem() instanceof IGasItem) {
        if (slotID != 0 && slotID != 1) {
          if (((IGasItem) slotStack.getItem())
              .canProvideGas(
                  slotStack,
                  tileEntity.gasTank.getGas() != null
                      ? tileEntity.gasTank.getGas().getGas()
                      : null)) {
            if (!mergeItemStack(slotStack, 0, 1, false)) {
              return null;
            }
          } else if (((IGasItem) slotStack.getItem())
              .canReceiveGas(
                  slotStack,
                  tileEntity.gasTank.getGas() != null
                      ? tileEntity.gasTank.getGas().getGas()
                      : null)) {
            if (!mergeItemStack(slotStack, 1, 2, false)) {
              return null;
            }
          }
        } else {
          if (!mergeItemStack(slotStack, 5, inventorySlots.size(), true)) {
            return null;
          }
        }
      } else {
        if (slotID >= 5 && slotID <= 31) {
          if (!mergeItemStack(slotStack, 32, inventorySlots.size(), false)) {
            return null;
          }
        } else if (slotID > 31) {
          if (!mergeItemStack(slotStack, 5, 31, false)) {
            return null;
          }
        } else {
          if (!mergeItemStack(slotStack, 5, inventorySlots.size(), true)) {
            return null;
          }
        }
      }

      if (slotStack.stackSize == 0) {
        currentSlot.putStack((ItemStack) null);
      } else {
        currentSlot.onSlotChanged();
      }

      if (slotStack.stackSize == stack.stackSize) {
        return null;
      }

      currentSlot.onPickupFromSlot(player, slotStack);
    }

    return stack;
  }
コード例 #11
0
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
    ItemStack stack = null;
    Slot currentSlot = (Slot) inventorySlots.get(slotID);

    if (currentSlot != null && currentSlot.getHasStack()) {
      ItemStack slotStack = currentSlot.getStack();
      stack = slotStack.copy();

      if (ChargeUtils.canBeDischarged(slotStack)) {
        if (slotID != 2) {
          if (!mergeItemStack(slotStack, 2, 3, false)) {
            return null;
          }
        } else {
          if (!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) {
            return null;
          }
        }
      } else if (FluidContainerRegistry.isFilledContainer(slotStack)) {
        if (slotID != 0) {
          if (!mergeItemStack(slotStack, 0, 1, false)) {
            return null;
          }
        } else if (slotID == 0) {
          if (!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) {
            return null;
          }
        }
      } else if (slotID == 1) {
        if (!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) {
          return null;
        }
      } else {
        if (slotID >= 3 && slotID <= 29) {
          if (!mergeItemStack(slotStack, 30, inventorySlots.size(), false)) {
            return null;
          }
        } else if (slotID > 29) {
          if (!mergeItemStack(slotStack, 3, 29, false)) {
            return null;
          }
        } else {
          if (!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) {
            return null;
          }
        }
      }

      if (slotStack.stackSize == 0) {
        currentSlot.putStack((ItemStack) null);
      } else {
        currentSlot.onSlotChanged();
      }

      if (slotStack.stackSize == stack.stackSize) {
        return null;
      }

      currentSlot.onPickupFromSlot(player, slotStack);
    }

    return stack;
  }
コード例 #12
0
  @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);
              }
            }
          }
        }
      }
    }
  }