コード例 #1
0
  @Override
  public void writeToNBT(NBTTagCompound data) {
    super.writeToNBT(data);

    NBTTagList itemList = new NBTTagList();
    NBTTagList sideItemList = new NBTTagList();
    NBTTagCompound configData;

    data.setBoolean("shareRS", isRSShared);

    for (int i = 0; i < 3; i++) {

      if (inventory.getStackInSlot(i) != null) {
        NBTTagCompound itemCompound = new NBTTagCompound();
        itemCompound.setInteger("slot", i);
        inventory.getStackInSlot(i).writeToNBT(itemCompound);
        itemList.appendTag(itemCompound);
      }

      if (tanks[i].getFluid() != null) {
        data.setInteger("tankCap" + i, tanks[i].getCapacity());
        data.setTag("Fluid" + i, tanks[i].getFluid().writeToNBT(new NBTTagCompound()));
      }

      data.setBoolean("rsControl" + i, rsControl[i]);
      data.setBoolean("rsLatch" + i, rsLatch[i]);
    }

    data.setTag("items", itemList);

    for (int i = 0; i < 6; i++) {
      data.setInteger("side" + i, sides[i]);
      configData = new NBTTagCompound();
      configs[i].writeToNBT(configData);
      data.setCompoundTag("config" + i, configData);
      data.setBoolean("rs" + i, sideRS[i]);
      data.setBoolean("lock" + i, sideLocked[i]);
      data.setInteger("facID" + i, facID[i]);
      data.setInteger("facMeta" + i, facMeta[i]);

      if (sideInventory.getStackInSlot(i) != null) {
        NBTTagCompound itemCompound = new NBTTagCompound();
        itemCompound.setInteger("slot", i);
        sideInventory.getStackInSlot(i).writeToNBT(itemCompound);
        sideItemList.appendTag(itemCompound);
      }
    }

    data.setTag("sideItems", sideItemList);

    if (capacitor != null) {
      data.setInteger("realPower", capacitor.getEnergyStored());
      capacitor.writeToNBT(data);
      data.setInteger("powerCap2", capacitor.getMaxEnergyStored());
    }
  }
コード例 #2
0
 public static void compactStacks(ItemStack[] stacks, int start, int max) {
   InventoryBasic inv = new InventoryBasic("temp", true, max);
   for (int i = 0; i < max; i++) {
     ItemStack stack = stacks[i + start];
     if (stack != null) {
       mergeItemStack(inv, stack, 0, max, null);
     }
   }
   for (int i = 0; i < max; i++) {
     ItemStack stack = inv.getStackInSlot(i);
     if (stack != null && stack.stackSize == 0) {
       stack = null;
     }
     stacks[i + start] = stack;
   }
 }
コード例 #3
0
  public int addItemInternal(ItemStack stack, boolean doAdd, int inv) {
    int amntAdded;
    int temp;

    if (inv > -1 && inv < 3) {
      ItemStack currStack = inventory.getStackInSlot(inv);

      if (currStack == null) {
        if (doAdd) {
          inventory.setInventorySlotContents(inv, stack.copy());
          for (int i = 0; i < 6; i++) {
            SocketModule m = getSide(ForgeDirection.getOrientation(i));
            m.onInventoryChange(configs[i], inv, this, ForgeDirection.getOrientation(i), true);
          }
        }

        return stack.stackSize;
      } else if (currStack.isItemEqual(stack)) {
        temp =
            Math.min(
                currStack.stackSize + stack.stackSize, currStack.getItem().getItemStackLimit());
        if (temp == (currStack.stackSize + stack.stackSize)) {
          amntAdded = stack.stackSize;
        } else {
          amntAdded = currStack.getItem().getItemStackLimit() - currStack.stackSize;
        }

        if (doAdd && amntAdded > 0) {
          currStack.stackSize += amntAdded;
          for (int i = 0; i < 6; i++) {
            SocketModule m = getSide(ForgeDirection.getOrientation(i));
            m.onInventoryChange(configs[i], inv, this, ForgeDirection.getOrientation(i), true);
          }
        }

        return amntAdded;
      }
    }

    return 0;
  }
コード例 #4
0
  public ItemStack extractItemInternal(boolean doRemove, int inv, int maxItemCount) {
    ItemStack newStack;

    if (inv > -1 && inv < 3) {
      ItemStack currStack = inventory.getStackInSlot(inv);

      if (currStack != null) {
        newStack = currStack.copy();
        newStack.stackSize = Math.min(currStack.stackSize, maxItemCount);
        if (doRemove) {
          currStack.stackSize -= newStack.stackSize;
          if (currStack.stackSize <= 0) inventory.setInventorySlotContents(inv, null);
          for (int i = 0; i < 6; i++) {
            SocketModule m = getSide(ForgeDirection.getOrientation(i));
            m.onInventoryChange(configs[i], inv, this, ForgeDirection.getOrientation(i), false);
          }
        }

        return newStack;
      }
    }

    return null;
  }
コード例 #5
0
 public ItemStack getStackInInventorySlot(int inv) {
   return inventory.getStackInSlot(inv);
 }
コード例 #6
0
 @Override
 public ItemStack getStackInSlotOnClosing(int slot) {
   return inventory.getStackInSlot(slot);
 }
コード例 #7
0
 @Override
 public boolean interact(EntityPlayer player) {
   ItemStack itemstack = player.inventory.getCurrentItem();
   if (!this.worldObj.isRemote) {
     // Allow taming in creative mode without items
     if (!this.isTamed() && player.capabilities.isCreativeMode) {
       this.func_152115_b(player.getUniqueID().toString()); // Set owner UUID
       this.setTamed(true);
     }
     // If tamed
     if (this.isTamed()) {
       // If player has item
       if (itemstack != null) {
         // If armour, equip it
         if (itemstack.getItem() instanceof ItemArmor && !player.isSneaking()) {
           int i = EntityLiving.getArmorPosition(itemstack) - 1;
           if (this.getEquipmentInSlot(i + 1) == null) {
             this.setCurrentItemOrArmor(i + 1, itemstack.copy());
             if (!player.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
               player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
           } else {
             EntityItem entityItem =
                 new EntityItem(
                     this.worldObj,
                     this.posX,
                     this.posY,
                     this.posZ,
                     this.getEquipmentInSlot(i + 1));
             this.worldObj.spawnEntityInWorld(entityItem);
             this.setCurrentItemOrArmor(i + 1, null);
           }
           return true;
         }
         // If lead and mounted, unmount
         else if (itemstack.getItem() == Items.lead && this.isRiding() && !player.isSneaking())
           this.mountEntity(null);
         // If entity is holding something and player is holding a stick, drop current item
         else if (itemstack.getItem() == Items.stick && this.getHeldItem() != null) {
           EntityItem entityItem =
               new EntityItem(
                   player.worldObj, this.posX, this.posY, this.posZ, this.getHeldItem().copy());
           player.worldObj.spawnEntityInWorld(entityItem);
           this.setCarrying(null);
           // Drop chest contents
           for (int i = 0; i < inventory.getSizeInventory(); i++) {
             ItemStack itemStackToDrop = inventory.getStackInSlot(i);
             if (itemStackToDrop != null) {
               entityItem =
                   new EntityItem(
                       player.worldObj, this.posX, this.posY, this.posZ, itemStackToDrop);
               player.worldObj.spawnEntityInWorld(entityItem);
             }
             inventory.setInventorySlotContents(i, null);
           }
         } else if (this.getHeldItem() == null) {
           ItemStack newItemStack = itemstack.copy();
           newItemStack.stackSize = 1;
           this.setCarrying(newItemStack);
           player.playSound(
               "mob.chickenplop",
               1.0F,
               (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
           if (!player.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
             player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
         }
       }
       // If entity is holding something and player isn't, open GUI
       if (this.getHeldItem() != null && !player.isSneaking()) {
         if (Block.getBlockFromItem(this.getHeldItem().getItem()) == Blocks.chest)
           player.openGui(MiniCreatures.instance, 0, player.worldObj, this.getEntityId(), 0, 0);
         else if (Block.getBlockFromItem(this.getHeldItem().getItem()) == Blocks.anvil)
           player.openGui(
               MiniCreatures.instance,
               1,
               player.worldObj,
               (int) this.posX,
               (int) this.posY,
               (int) this.posZ);
       } else if (player.isEntityEqual(this.getOwner()) && !this.worldObj.isRemote) {
         if (this.isRiding()) {
           EntityTameable ridingEntity = (EntityTameable) this.ridingEntity;
           ridingEntity.func_70907_r().setSitting(!ridingEntity.isSitting());
           ridingEntity.setSitting(!ridingEntity.isSitting());
           ridingEntity.setJumping(false);
           ridingEntity.setPathToEntity(null);
           ridingEntity.setTarget(null);
           ridingEntity.setAttackTarget(null);
         } else {
           this.aiSit.setSitting(!this.isSitting());
           this.setSitting(!this.isSitting());
           this.isJumping = false;
           this.setPathToEntity(null);
           this.setTarget(null);
           this.setAttackTarget(null);
         }
       }
     }
   }
   return super.interact(player);
 }