コード例 #1
0
  @Override
  public void onBlockPlacedBy(
      World par1World,
      int par2,
      int par3,
      int par4,
      EntityLivingBase par5EntityLivingBase,
      ItemStack par6ItemStack) {
    int playerFacing =
        MathHelper.floor_double((double) ((par5EntityLivingBase.rotationYaw * 4F) / 360F) + 0.5D)
            & 3;

    boolean facing = false;
    if (playerFacing == 0) {
      facing = false;
    }
    if (playerFacing == 1) {
      facing = true;
    }
    if (playerFacing == 2) {
      facing = false;
    }
    if (playerFacing == 3) {
      facing = true;
    }

    // ItemStackのNBT
    NBTTagCompound nbt = par6ItemStack.getTagCompound();
    ItemStack input = null;
    byte rem = 0;

    if (nbt != null && nbt.hasKey("input")) {
      input = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("input"));
      rem = nbt.getByte("remain");
    }

    TileEntity tileEntity = par1World.getTileEntity(par2, par3, par4);
    if (tileEntity != null && tileEntity instanceof TilePanG) {
      TilePanG pan = (TilePanG) tileEntity;
      pan.setDirection(facing);
      pan.setItemStack(input);
      pan.setRemainByte(rem);
      pan.markDirty();
      par1World.markBlockForUpdate(par2, par3, par4);
    }
  }
コード例 #2
0
  @Override
  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();
    TilePanG tile = (TilePanG) par1World.getTileEntity(par2, par3, par4);
    if (tile == null) return false;

    if (itemstack == null || itemstack.getItem() == Item.getItemFromBlock(this)) {
      ItemStack drop = new ItemStack(DCsAppleMilk.emptyPanGaiden, 1, 0);

      ItemStack input = tile.getItemStack();
      byte rem = tile.getRemainByte();
      String disp = tile.getDisplayName();

      if (input != null) {
        NBTTagCompound tag = new NBTTagCompound();

        tag.setByte("remain", rem);
        tag.setString("display", disp);
        tag.setTag("input", input.writeToNBT(new NBTTagCompound()));

        drop.setTagCompound(tag);
      }

      if (!par1World.isRemote) {
        EntityItem entity =
            new EntityItem(
                par1World,
                par5EntityPlayer.posX,
                par5EntityPlayer.posY,
                par5EntityPlayer.posZ,
                drop);
        par1World.spawnEntityInWorld(entity);
      }

      par1World.removeTileEntity(par2, par3, par4);
      par1World.setBlockToAir(par2, par3, par4);
      par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
      return true;
    } else if (itemstack.getItem() == Items.bowl) // 木のボウル:ノーマルのoutputを返し、remainを1減らす。
    {
      if (tile.getOutput() != null && tile.getRemainByte() > 0) {
        ItemStack ret = tile.getOutput().copy();
        int rem = tile.getRemainByte() - 1;

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

        if (!par1World.isRemote) {
          EntityItem entity =
              new EntityItem(
                  par1World,
                  par5EntityPlayer.posX,
                  par5EntityPlayer.posY,
                  par5EntityPlayer.posZ,
                  ret);
          par1World.spawnEntityInWorld(entity);
        }
        par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
        if (ret.getItem() == Item.getItemFromBlock(DCsAppleMilk.bowlBlock)) {
          par5EntityPlayer.triggerAchievement(AchievementRegister.getSoup);
        }

        tile.setRemainByte((byte) rem);
        if (rem < 1) {
          tile.setItemStack(null);
          tile.setRemainByte((byte) 0);
          tile.markDirty();
          par1World.markBlockForUpdate(par2, par3, par4);
        }
      }
      return true;
    } else if (!LoadBambooPlugin.getBasket().isEmpty()
        && LoadBambooPlugin.isBasketItem(itemstack) >= 0) // 竹のボウル:和風のoutputを返し、remainを1減らす。
    {
      if (tile.getOutput() != null && tile.getRemainByte() > 0) {
        ItemStack ret = tile.getOutputJP().copy();
        NBTTagCompound nbt = new NBTTagCompound();
        nbt.setByte("BowlNum", (byte) LoadBambooPlugin.isBasketItem(itemstack));
        ret.setTagCompound(nbt);

        int rem = tile.getRemainByte() - 1;

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

        if (!par1World.isRemote) {
          EntityItem entity =
              new EntityItem(
                  par1World,
                  par5EntityPlayer.posX,
                  par5EntityPlayer.posY,
                  par5EntityPlayer.posZ,
                  ret);
          par1World.spawnEntityInWorld(entity);
        }
        par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);

        tile.setRemainByte((byte) rem);
        if (rem < 1) {
          tile.setItemStack(null);
          tile.setRemainByte((byte) 0);
          tile.markDirty();
          par1World.markBlockForUpdate(par2, par3, par4);
        }
      }
      return true;
    } else // その他のアイテムはすべて材料判定に回す
    {
      Item ID = itemstack.getItem();
      int IDm = itemstack.getItemDamage();

      if (this.onFurnace(par1World, par2, par3 - 1, par4) && tile.getItemStack() == null) {
        ItemStack input = new ItemStack(ID, 1, IDm);

        if (ID == DCsAppleMilk.mincedFoods && IDm == 8) // チョコ鍋だけは旧仕様
        {
          par1World.removeTileEntity(par2, par3, par4);
          par1World.setBlock(par2, par3, par4, DCsAppleMilk.filledChocoPan);
          TileChocoPan tile2 = (TileChocoPan) par1World.getTileEntity(par2, par3, par4);
          tile2.setRemainByte((byte) 11);

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

          par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
          return true;
        } else {
          IPanRecipe recipe = RecipeRegisterManager.panRecipe.getRecipe(input);
          if (recipe != null) {
            tile.setItemStack(input);
            tile.setRemainByte((byte) 3);
            tile.markDirty();
            par1World.markBlockForUpdate(par2, par3, par4);

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

            par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
            par5EntityPlayer.triggerAchievement(AchievementRegister.makeRice);
            return true;
          } else {
            if (par1World.isRemote)
              par5EntityPlayer.addChatMessage(
                  new ChatComponentText(StatCollector.translateToLocal("dc.panMessage.noRecipe")));
            return true;
          }
        }
      } else {
        if (!this.onFurnace(par1World, par2, par3 - 1, par4)) {
          if (par1World.isRemote)
            par5EntityPlayer.addChatMessage(
                new ChatComponentText(
                    StatCollector.translateToLocal("dc.panMessage.noHeatSource")));
          return true;
        } else if (tile.getItemStack() != null) {
          if (par1World.isRemote)
            par5EntityPlayer.addChatMessage(
                new ChatComponentText(
                    StatCollector.translateToLocal("dc.panMessage.alreadyHasRecipe")));
          return true;
        }
        return false;
      }
    }
  }