Exemplo n.º 1
0
  public void setData(int i) {
    // CraftBukkit start - Filter out data for items that shouldn't have it
    // The crafting system uses this value for a special purpose so we have to allow it
    if (i == 32767) {
      this.damage = i;
      return;
    }

    // Is this a block?
    if (CraftMagicNumbers.getBlock(CraftMagicNumbers.getId(this.getItem())) != Blocks.AIR) {
      // If vanilla doesn't use data on it don't allow any
      if (!(this.usesData() || this.getItem().usesDurability())) {
        i = 0;
      }
    }

    // Filter invalid plant data
    if (CraftMagicNumbers.getBlock(CraftMagicNumbers.getId(this.getItem())) == Blocks.DOUBLE_PLANT
        && (i > 5 || i < 0)) {
      i = 0;
    }
    // CraftBukkit end

    this.damage = i;
    if (this.damage < -1) { // CraftBukkit
      this.damage = 0;
    }
  }
Exemplo n.º 2
0
 @Override
 public void setPlaying(Material record) {
   if (record == null || CraftMagicNumbers.getItem(record) == null) {
     record = Material.AIR;
     jukebox.setRecord(null);
   } else {
     jukebox.setRecord(new ItemStack(CraftMagicNumbers.getItem(record), 1));
   }
   jukebox.update();
   if (record == Material.AIR) {
     world.getHandle().setData(getX(), getY(), getZ(), 0, 3);
   } else {
     world.getHandle().setData(getX(), getY(), getZ(), 1, 3);
   }
   world.playEffect(getLocation(), Effect.RECORD_PLAY, record.getId());
 }
Exemplo n.º 3
0
 @Override
 public Material getPlaying() {
   ItemStack record = jukebox.getRecord();
   if (record == null) {
     return Material.AIR;
   }
   return CraftMagicNumbers.getMaterial(record.getItem());
 }
Exemplo n.º 4
0
 // CraftBukkit start
 public org.bukkit.inventory.ShapedRecipe toBukkitRecipe() {
   CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
   CraftShapedRecipe recipe = new CraftShapedRecipe(result, this);
   switch (this.height) {
     case 1:
       switch (this.width) {
         case 1:
           recipe.shape("a");
           break;
         case 2:
           recipe.shape("ab");
           break;
         case 3:
           recipe.shape("abc");
           break;
       }
       break;
     case 2:
       switch (this.width) {
         case 1:
           recipe.shape("a", "b");
           break;
         case 2:
           recipe.shape("ab", "cd");
           break;
         case 3:
           recipe.shape("abc", "def");
           break;
       }
       break;
     case 3:
       switch (this.width) {
         case 1:
           recipe.shape("a", "b", "c");
           break;
         case 2:
           recipe.shape("ab", "cd", "ef");
           break;
         case 3:
           recipe.shape("abc", "def", "ghi");
           break;
       }
       break;
   }
   char c = 'a';
   for (ItemStack stack : this.items) {
     if (stack != null) {
       recipe.setIngredient(
           c,
           org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(stack.getItem()),
           stack.getData());
     }
     c++;
   }
   return recipe;
 }
Exemplo n.º 5
0
  public boolean placeItem(
      EntityHuman entityhuman,
      World world,
      BlockPosition blockposition,
      EnumDirection enumdirection,
      float f,
      float f1,
      float f2) {
    // CraftBukkit start - handle all block place event logic here
    int data = this.getData();
    int count = this.count;

    if (!(this.getItem() instanceof ItemBucket)) { // if not bucket
      world.captureBlockStates = true;
      // special case bonemeal
      if (this.getItem() instanceof ItemDye && this.getData() == 15) {
        Block block = world.getType(blockposition).getBlock();
        if (block == Blocks.SAPLING || block instanceof BlockMushroom) {
          world.captureTreeGeneration = true;
        }
      }
    }
    boolean flag =
        this.getItem()
            .interactWith(this, entityhuman, world, blockposition, enumdirection, f, f1, f2);
    int newData = this.getData();
    int newCount = this.count;
    this.count = count;
    this.setData(data);
    world.captureBlockStates = false;
    if (flag && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) {
      world.captureTreeGeneration = false;
      Location location =
          new Location(
              world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
      TreeType treeType = BlockSapling.treeType;
      BlockSapling.treeType = null;
      List<BlockState> blocks = (List<BlockState>) world.capturedBlockStates.clone();
      world.capturedBlockStates.clear();
      StructureGrowEvent event = null;
      if (treeType != null) {
        event =
            new StructureGrowEvent(
                location, treeType, false, (Player) entityhuman.getBukkitEntity(), blocks);
        org.bukkit.Bukkit.getPluginManager().callEvent(event);
      }
      if (event == null || !event.isCancelled()) {
        // Change the stack to its new contents if it hasn't been tampered with.
        if (this.count == count && this.getData() == data) {
          this.setData(newData);
          this.count = newCount;
        }
        for (BlockState blockstate : blocks) {
          blockstate.update(true);
        }
      }

      return flag;
    }
    world.captureTreeGeneration = false;

    if (flag) {
      org.bukkit.event.block.BlockPlaceEvent placeEvent = null;
      List<BlockState> blocks = (List<BlockState>) world.capturedBlockStates.clone();
      world.capturedBlockStates.clear();
      if (blocks.size() > 1) {
        placeEvent =
            org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(
                world,
                entityhuman,
                blocks,
                blockposition.getX(),
                blockposition.getY(),
                blockposition.getZ());
      } else if (blocks.size() == 1) {
        placeEvent =
            org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(
                world,
                entityhuman,
                blocks.get(0),
                blockposition.getX(),
                blockposition.getY(),
                blockposition.getZ());
      }

      if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) {
        flag = false; // cancel placement
        // revert back all captured blocks
        for (BlockState blockstate : blocks) {
          blockstate.update(true, false);
        }
      } else {
        // Change the stack to its new contents if it hasn't been tampered with.
        if (this.count == count && this.getData() == data) {
          this.setData(newData);
          this.count = newCount;
        }
        for (BlockState blockstate : blocks) {
          int x = blockstate.getX();
          int y = blockstate.getY();
          int z = blockstate.getZ();
          int updateFlag = ((CraftBlockState) blockstate).getFlag();
          org.bukkit.Material mat = blockstate.getType();
          Block oldBlock = CraftMagicNumbers.getBlock(mat);
          BlockPosition newblockposition = new BlockPosition(x, y, z);
          IBlockData block = world.getType(newblockposition);

          if (!(block instanceof BlockContainer)) { // Containers get placed automatically
            block.getBlock().onPlace(world, newblockposition, block);
          }

          world.notifyAndUpdatePhysics(
              newblockposition,
              null,
              oldBlock,
              block.getBlock(),
              updateFlag); // send null chunk as chunk.k() returns false by this point
        }
        entityhuman.b(StatisticList.USE_ITEM_COUNT[Item.getId(this.item)]);
      }
    }
    world.capturedBlockStates.clear();
    // CraftBukkit end

    return flag;
  }