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

    if (getRunning()) run();
    else postRun();

    if (Config.useFuel && !worldObj.isRemote) {
      if (inventory.getStackInSlot(0) != null
          && TileEntityFurnace.isItemFuel(inventory.getStackInSlot(0))
          && (fuel.get() + TileEntityFurnace.getItemBurnTime(inventory.getStackInSlot(0)))
              <= Config.maxFuelLevel)
        if (inventory.getStackInSlot(0).getItem().equals(Items.lava_bucket)) {
          fuel.modify(TileEntityFurnace.getItemBurnTime(inventory.decrStackSize(0, 1)));
          inventory.setInventorySlotContents(0, new ItemStack(Items.bucket));
        } else {
          fuel.modify(TileEntityFurnace.getItemBurnTime(inventory.decrStackSize(0, 1)));
        }

      if (fuel.isDirty()) sync();
    }

    lastTickPosX = posX;
    lastTickPosY = posY;
    lastTickPosZ = posZ;

    posX += motionX;
    posY += motionY;
    posZ += motionZ;

    setPosition(posX, posY, posZ);

    if (getTimeSinceHit() > 0) setTimeSinceHit(getTimeSinceHit() - 1);
    if (getDamageTaken() > 0) setDamageTaken(getDamageTaken() - 1);
  }
コード例 #2
0
ファイル: RMFurnaceTile.java プロジェクト: Roblomal/ProjectE
  @Override
  public boolean isItemValidForSlot(int slot, ItemStack stack) {
    if (stack == null) {
      return false;
    }

    if (slot == 0) {
      return TileEntityFurnace.isItemFuel(stack) || stack.getItem() == ObjHandler.kleinStars;
    } else if (slot >= 1 && slot <= 13) {
      return FurnaceRecipes.smelting().getSmeltingResult(stack) != null;
    }

    return false;
  }
コード例 #3
0
  /** Called to transfer a stack from one inventory to the other eg. when shift clicking. */
  @Override
  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) {
    ItemStack var2 = null;
    final Slot var3 = (Slot) inventorySlots.get(par1);

    if (var3 != null && var3.getHasStack()) {
      final ItemStack var4 = var3.getStack();
      var2 = var4.copy();

      if (par1 == 1) {
        if (!mergeItemStack(var4, 2, 38, true)) {
          return null;
        }

        var3.onSlotChange(var4, var2);
      } else if (par1 != 1 && par1 != 0) {
        if (FurnaceRecipes.smelting().getSmeltingResult(var4) != null) {
          if (!mergeItemStack(var4, 0, 1, false)) {
            return null;
          }
        } else if (TileEntityFurnace.isItemFuel(var4)) {
          if (!mergeItemStack(var4, 0, 1, false)) {
            return null;
          }
        } else if (par1 >= 2 && par1 < 29) {
          if (!mergeItemStack(var4, 29, 38, false)) {
            return null;
          }
        } else if (par1 >= 29 && par1 < 38 && !mergeItemStack(var4, 2, 29, false)) {
          return null;
        }
      } else if (!mergeItemStack(var4, 2, 38, false)) {
        return null;
      }

      if (var4.stackSize == 0) {
        var3.putStack((ItemStack) null);
      } else {
        var3.onSlotChanged();
      }

      if (var4.stackSize == var2.stackSize) {
        return null;
      }

      var3.onPickupFromSlot(par1EntityPlayer, var4);
    }

    return var2;
  }
コード例 #4
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 (slotID == 2) {
        if (!mergeItemStack(slotStack, 3, 39, true)) {
          return null;
        }
      } else if (slotID != 1 && slotID != 0) {
        if (FurnaceRecipes.smelting().getSmeltingResult(slotStack) != null) {
          if (!mergeItemStack(slotStack, 0, 1, false)) {
            return null;
          }
        } else if (TileEntityFurnace.isItemFuel(slotStack)) {
          if (!mergeItemStack(slotStack, 1, 2, false)) {
            return null;
          }
        } else if (slotID >= 3 && slotID < 30) {
          if (!mergeItemStack(slotStack, 30, 39, false)) {
            return null;
          }
        } else if (slotID >= 30 && slotID < 39 && !mergeItemStack(slotStack, 3, 30, false)) {
          return null;
        }
      } else if (!mergeItemStack(slotStack, 3, 39, false)) {
        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;
  }
コード例 #5
0
  private boolean getFuelFromInventory() {
    for (int i = 0; i < owner.getInventory().getSizeInventory(); i++) {
      ItemStack stack = owner.getInventory().getStackInSlot(i);

      if (stack != null) {
        try {
          final boolean isFuel = TileEntityFurnace.isItemFuel(stack);
          int fuelValue =
              TileEntityFurnace.getItemBurnTime(stack) == 0
                  ? GameRegistry.getFuelValue(stack)
                  : TileEntityFurnace.getItemBurnTime(stack);
          fuelValue = fuelValue / Time.SECOND / 10;

          if (fuelValue == 0 && isFuel) {
            fuelValue = 1;
          }

          if (fuelValue > 0) {
            hasFuel = true;
            fuelUsesRemaining = fuelValue;

            owner
                .getInventory()
                .decrStackSize(owner.getInventory().getFirstSlotContainingItem(stack.getItem()), 1);
          }
        } catch (
            ClassCastException
                e) // Known problem with earlier versions of MCA, not sure why this happened.
        {
          continue;
        }
      }
    }

    return hasFuel;
  }
コード例 #6
0
 public static boolean canItemBurn(ItemStack stack) {
   if (TileEntityFurnace.isItemFuel(stack)) return true;
   return contains(burnItem, stack);
 }
コード例 #7
0
ファイル: RMFurnaceTile.java プロジェクト: Roblomal/ProjectE
  private void pullFromInventories() {
    TileEntity tile = this.worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);

    if (tile instanceof ISidedInventory) {
      final int side = 0;
      ISidedInventory inv = (ISidedInventory) tile;

      int[] slots = inv.getAccessibleSlotsFromSide(side);

      if (slots.length > 0) {
        for (int i : slots) {
          ItemStack stack = inv.getStackInSlot(i);

          if (stack == null) {
            continue;
          }

          if (inv.canExtractItem(i, stack, side)) {
            if (TileEntityFurnace.isItemFuel(stack) || stack.getItem() == ObjHandler.kleinStars) {
              if (inventory[0] == null) {
                inventory[0] = stack;
                inv.setInventorySlotContents(i, null);
              } else if (Utils.areItemStacksEqual(stack, inventory[0])) {
                int remain = inventory[0].getMaxStackSize() - inventory[0].stackSize;

                if (stack.stackSize <= remain) {
                  inventory[0].stackSize += stack.stackSize;
                  inv.setInventorySlotContents(i, null);
                } else {
                  inventory[0].stackSize += remain;
                  stack.stackSize -= remain;
                }
              }

              continue;
            }

            for (int j = inputStorage[0]; j < inputStorage[1]; j++) {
              ItemStack otherStack = inventory[j];

              if (otherStack == null) {
                inventory[j] = stack;
                inv.setInventorySlotContents(i, null);
                break;
              } else if (Utils.areItemStacksEqual(stack, otherStack)) {
                int remain = otherStack.getMaxStackSize() - otherStack.stackSize;

                if (stack.stackSize <= remain) {
                  inventory[j].stackSize += stack.stackSize;
                  inv.setInventorySlotContents(i, null);
                  break;
                } else {
                  inventory[j].stackSize += remain;
                  stack.stackSize -= remain;
                }
              }
            }
          }
        }
      }
    } else if (tile instanceof IInventory) {
      IInventory inv = (IInventory) tile;

      for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);

        if (stack == null) {
          continue;
        }

        if (TileEntityFurnace.isItemFuel(stack) || stack.getItem() == ObjHandler.kleinStars) {
          ItemStack fuel = inventory[0];

          if (fuel == null) {
            inventory[0] = stack;
            inv.setInventorySlotContents(i, null);
          } else {
            int remain = fuel.getMaxStackSize() - fuel.stackSize;

            if (stack.stackSize <= remain) {
              inventory[0].stackSize += stack.stackSize;
              inv.setInventorySlotContents(i, null);
            } else {
              inventory[0].stackSize += remain;
              stack.stackSize -= remain;
            }
          }

          continue;
        } else if (FurnaceRecipes.smelting().getSmeltingResult(stack) == null) {
          continue;
        }

        for (int j = inputStorage[0]; j < inputStorage[1]; j++) {
          ItemStack otherStack = inventory[j];

          if (otherStack == null) {
            inventory[j] = stack;
            inv.setInventorySlotContents(i, null);
            break;
          } else if (Utils.areItemStacksEqual(stack, otherStack)) {
            int remain = otherStack.getMaxStackSize() - otherStack.stackSize;

            if (stack.stackSize <= remain) {
              inventory[j].stackSize += stack.stackSize;
              inv.setInventorySlotContents(i, null);
              break;
            } else {
              inventory[j].stackSize += remain;
              stack.stackSize -= remain;
            }
          }
        }
      }
    }
  }
コード例 #8
0
  /**
   * Called when a player shift-clicks on a slot. You must override this or you will crash when
   * someone does that.
   */
  @Override
  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(par2);

    if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if (par2 == 1) {
        if (!this.mergeItemStack(itemstack1, 29, 65, true)) {
          return null;
        }

        slot.onSlotChange(itemstack1, itemstack);
      } else if (par2 >= 11 && par2 <= 64) {
        if (TileEntityFurnace.isItemFuel(itemstack1)) {

          if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
            return null;
          }
          // else if (!this.mergeItemStack(itemstack1, 11, 20, false)) {

          //	return null;

          // }

          //					if (par2 <= 19) {
          //						if (!this.mergeItemStack(itemstack1, 0, 1, false))
          //						{
          //							return null;
          //						}
          //					}
          //					else if (!this.mergeItemStack(itemstack1, 11, 65, false)) {
          //						return null;
          //					}
          //					else if (!this.mergeItemStack(itemstack1, 11, 20, false))
          //					{
          //						if (!this.mergeItemStack(itemstack1, 20, 65, false))
          //						{
          //							return null;
          //						}
          //					}

        } else if (par2 >= 11 && par2 <= 28) {
          if (!this.mergeItemStack(itemstack1, 29, 65, false)) {
            return null;
          }
        } else if (par2 >= 29 && par2 <= 55) {
          if (!this.mergeItemStack(itemstack1, 11, 20, false)) {

            if (!this.mergeItemStack(itemstack1, 56, 65, false)) {
              return null;
            }
          }
        } else if (par2 >= 56 && par2 <= 64) {
          if (!this.mergeItemStack(itemstack1, 11, 20, false)) {

            if (!this.mergeItemStack(itemstack1, 29, 56, false)) {
              return null;
            }
          }
        }
      } else if (!this.mergeItemStack(itemstack1, 29, 65, false)) {
        return null;
      }

      if (itemstack1.stackSize == 0) {
        slot.putStack((ItemStack) null);
      } else {
        slot.onSlotChanged();
      }

      if (itemstack1.stackSize == itemstack.stackSize) {
        return null;
      }

      slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
    }

    return itemstack;
  }
コード例 #9
0
 @Override
 public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
   return slot > 8 && !TileEntityFurnace.isItemFuel(itemstack)
       ? false
       : (slot == 8 ? TileEntityFurnace.isItemFuel(itemstack) : true);
 }