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;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
    ItemStack stack = null;
    Slot slot = (Slot) inventorySlots.get(slotNumber);

    if ((slot != null) && (slot.getHasStack())) {
      ItemStack stack1 = slot.getStack();
      stack = stack1.copy();
      EntityEquipmentSlot desiredSlot = EntityLiving.getSlotForItemStack(stack);

      if (slotNumber == 0) // CraftingResult
      {
        if (!mergeItemStack(stack1, 13, 49, true)) return ItemStack.field_190927_a;

        slot.onSlotChange(stack1, stack);
      } else if ((slotNumber >= 1) && (slotNumber < 5)) // CraftingGrid
      {
        if (!mergeItemStack(stack1, 13, 49, false)) return ItemStack.field_190927_a;
      } else if ((slotNumber >= 5) && (slotNumber < 13)) // NormalArmor & CosmeticArmor
      {
        if (!mergeItemStack(stack1, 13, 49, false)) return ItemStack.field_190927_a;
      } else if (desiredSlot.getSlotType() == EntityEquipmentSlot.Type.ARMOR
          && !inventorySlots
              .get(8 - desiredSlot.getIndex())
              .getHasStack()) // ItemArmor - check NormalArmor slots
      {
        int j = 8 - desiredSlot.getIndex();

        if (!mergeItemStack(stack1, j, j + 1, false)) return ItemStack.field_190927_a;
      } else if (desiredSlot.getSlotType() == EntityEquipmentSlot.Type.ARMOR
          && !inventorySlots
              .get(12 - desiredSlot.getIndex())
              .getHasStack()) // ItemArmor - check CosmeticArmor slots
      {
        int j = 12 - desiredSlot.getIndex();

        if (!mergeItemStack(stack1, j, j + 1, false)) return ItemStack.field_190927_a;
      } else if ((slotNumber >= 13) && (slotNumber < 40)) // PlayerInventory
      {
        if (!mergeItemStack(stack1, 40, 49, false)) return ItemStack.field_190927_a;
      } else if ((slotNumber >= 40) && (slotNumber < 49)) // PlayerHotBar
      {
        if (!mergeItemStack(stack1, 13, 40, false)) return ItemStack.field_190927_a;
      } else if (!mergeItemStack(stack1, 13, 49, false)) {
        return ItemStack.field_190927_a;
      }

      if (stack1.func_190916_E() == 0) slot.putStack(ItemStack.field_190927_a);
      else slot.onSlotChanged();

      if (stack1.func_190916_E() == stack.func_190916_E()) return ItemStack.field_190927_a;

      slot.func_190901_a(player, stack1);

      if (slotNumber == 0) player.dropItem(stack1, false);
    }

    return stack;
  }
 @Override
 public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) {
   if (player.experienceLevel > 0 && player.inventory.hasItem(Item.bucketEmpty.itemID)) {
     player.experienceLevel--;
     player.inventory.consumeInventoryItem(Item.bucketEmpty.itemID);
     if (!player.inventory.addItemStackToInventory(
         new ItemStack(MineFactoryReloadedCore.mobEssenceBucketItem))) {
       player.dropItem(MineFactoryReloadedCore.mobEssenceBucketItem.itemID, 1);
     }
   }
   return stack;
 }
  @Override
  public void onContainerClosed(EntityPlayer player) {
    super.onContainerClosed(player);

    for (int i = 0; i < 4; i++) {
      ItemStack stack = craftMatrix.removeStackFromSlot(i);

      if (stack != null) player.dropItem(stack, false);
    }

    craftResult.setInventorySlotContents(0, ItemStack.field_190927_a);
  }
Beispiel #5
0
  public boolean onBlockActivated(
      World par1World,
      int par2,
      int par3,
      int par4,
      EntityPlayer par5EntityPlayer,
      int par6,
      float par7,
      float par8,
      float par9) {
    ItemStack itemstack = par5EntityPlayer.inventory.getCurrentItem();

    if (itemstack == null) {
      return false;
    } else if (!par1World.isRemote && itemstack.getItem() == PennyArcade.goldCoin) {
      if (!par5EntityPlayer.capabilities.isCreativeMode) itemstack.stackSize--;
      this.go1 = go.nextInt(2000);
      par5EntityPlayer.addChatComponentMessage(
          new ChatComponentText(
              EnumChatFormatting.RED
                  + "[Pinball Machine] You scored "
                  + this.go1
                  + " points on your first go!"));
      this.go2 = go.nextInt(2000);
      par5EntityPlayer.addChatComponentMessage(
          new ChatComponentText(
              EnumChatFormatting.RED
                  + "[Pinball Machine] You scored "
                  + this.go2
                  + " points on your second go!"));
      this.go3 = go.nextInt(2000);
      par5EntityPlayer.addChatComponentMessage(
          new ChatComponentText(
              EnumChatFormatting.RED
                  + "[Pinball Machine] You scored "
                  + this.go3
                  + " points on your third go!"));
      this.total = (this.go1 + this.go2 + this.go3);
      par5EntityPlayer.addChatComponentMessage(
          new ChatComponentText(
              EnumChatFormatting.RED
                  + "[Pinball Machine] You scored a total of "
                  + this.total
                  + " points!"));

      if (total < 3000) {
        par5EntityPlayer.addChatComponentMessage(
            new ChatComponentText(EnumChatFormatting.RED + "Unlucky! You don't win anything!"));
      } else if (total >= 3000 && total < 4500) {
        Random coins = new Random();
        int y = (coins.nextInt(3) + 1);
        EntityItem item = par5EntityPlayer.dropItem(PennyArcade.goldCoin, y);
        item.delayBeforeCanPickup = 0;
        par5EntityPlayer.addChatComponentMessage(
            new ChatComponentText(
                EnumChatFormatting.RED + "Congratulations! You won " + y + " gold coin!"));
      } else if (total >= 4500 && total < 5000) {
        EntityItem item = par5EntityPlayer.dropItem(PennyArcade.emeraldToken, 1);
        item.delayBeforeCanPickup = 0;
        par5EntityPlayer.addChatComponentMessage(
            new ChatComponentText(
                EnumChatFormatting.RED + "Congratulations! You won an emerald token!"));
      } else if (total >= 5000 && total < 5500) {
        EntityItem item = par5EntityPlayer.dropItem(Items.emerald, 1);
        item.delayBeforeCanPickup = 0;
        par5EntityPlayer.addChatComponentMessage(
            new ChatComponentText(EnumChatFormatting.RED + "Congratulations! You won an emerald!"));
      } else if (total >= 5500 && total < 6000) {
        EntityItem item = par5EntityPlayer.dropItem(Items.diamond, 1);
        item.delayBeforeCanPickup = 0;
        par5EntityPlayer.addChatComponentMessage(
            new ChatComponentText(EnumChatFormatting.RED + "Congratulations! You won a diamond!"));
      } else if (total == 6000) {
        EntityItem item = par5EntityPlayer.dropItem(Item.getItemFromBlock(Blocks.diamond_block), 1);
        item.delayBeforeCanPickup = 0;
        par5EntityPlayer.addChatComponentMessage(
            new ChatComponentText(EnumChatFormatting.RED + "Max Score! Diamond Block!"));
      }
    } else {
      return false;
    }
    return true;
  }