@Override
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer player,
      World world,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    IBlockState iblockstate = world.getBlockState(pos);
    Block localBlock = iblockstate.getBlock();
    BlockPos posThere = pos;
    BlockPos posOffset = pos.offset(side);

    if (localBlock == Blocks.snow_layer && localBlock.isReplaceable(world, pos))
      side = EnumFacing.UP;
    else if (!localBlock.isReplaceable(world, pos)) pos = pos.offset(side);

    TileEntityIESlab stackSlab = null;
    if (side.getAxis().isVertical()
        && this.block.equals(world.getBlockState(posThere).getBlock())
        && world.getBlockState(posThere).getBlock().getMetaFromState(world.getBlockState(posThere))
            == stack.getItemDamage()) {
      TileEntity te = world.getTileEntity(posThere);
      if (te instanceof TileEntityIESlab && ((TileEntityIESlab) te).slabType + side.ordinal() == 1)
        stackSlab = ((TileEntityIESlab) te);
    } else if (this.block.equals(world.getBlockState(posOffset).getBlock())
        && world
                .getBlockState(posOffset)
                .getBlock()
                .getMetaFromState(world.getBlockState(posOffset))
            == stack.getItemDamage()) {
      TileEntity te = world.getTileEntity(posOffset);
      if (te instanceof TileEntityIESlab) {
        int type = ((TileEntityIESlab) te).slabType;
        if ((type == 0 && (side == EnumFacing.DOWN || hitY >= .5))
            || (type == 1 && (side == EnumFacing.UP || hitY <= .5)))
          stackSlab = ((TileEntityIESlab) te);
      }
    } else return super.onItemUse(stack, player, world, pos, side, hitX, hitY, hitZ);
    if (stackSlab != null) {
      stackSlab.slabType = 2;
      world.markBlockForUpdate(stackSlab.getPos());
      world.playSoundEffect(
          stackSlab.getPos().getX() + .5,
          stackSlab.getPos().getY() + .5,
          stackSlab.getPos().getZ() + .5,
          this.block.stepSound.getPlaceSound(),
          (this.block.stepSound.getVolume() + 1.0F) / 2.0F,
          this.block.stepSound.getFrequency() * 0.8F);
      --stack.stackSize;
      return true;
    } else return super.onItemUse(stack, player, world, pos, side, hitX, hitY, hitZ);
  }
예제 #2
0
  /** Called when a Block is right-clicked with this Item */
  public boolean onItemUse(
      ItemStack stack,
      Player playerIn,
      World worldIn,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (side != EnumFacing.UP) {
      return false;
    } else {
      IBlockState iblockstate = worldIn.getBlockState(pos);
      Block block = iblockstate.getBlock();

      if (!block.isReplaceable(worldIn, pos)) {
        pos = pos.offset(side);
      }

      if (!playerIn.canPlayerEdit(pos, side, stack)) {
        return false;
      } else if (!this.block.canPlaceBlockAt(worldIn, pos)) {
        return false;
      } else {
        placeDoor(worldIn, pos, EnumFacing.fromAngle((double) playerIn.rotationYaw), this.block);
        --stack.stackSize;
        return true;
      }
    }
  }
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float xOffset,
      float yOffset,
      float zOffset) {

    ItemStack ci = player.inventory.mainInventory[player.inventory.currentItem];
    if (ci != null && Block.getBlockFromItem(ci.getItem()).equals(this)) {
      for (int i = y + 1, e = world.getActualHeight(); i < e; ++i) {
        Block block = world.getBlock(x, i, z);
        if (block.isAir(world, x, i, z) || block.isReplaceable(world, x, i, z)) {
          if (!world.isRemote && world.setBlock(x, i, z, this, 0, 3)) {
            world.playAuxSFXAtEntity(null, 2001, x, i, z, Block.getIdFromBlock(this));
            if (!player.capabilities.isCreativeMode) {
              ci.stackSize--;
              if (ci.stackSize == 0) {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
              }
            }
          }
          return true;
        } else if (!block.equals(this)) {
          return false;
        }
      }
    }
    return false;
  }
예제 #4
0
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    IBlockState var9 = worldIn.getBlockState(pos);
    Block var10 = var9.getBlock();
    if (var10 == Blocks.snow_layer
        && ((Integer) var9.getValue(BlockSnow.LAYERS_PROP)).intValue() < 1) {
      side = EnumFacing.UP;
    } else if (!var10.isReplaceable(worldIn, pos)) {
      pos = pos.offset(side);
    }

    if (stack.stackSize == 0) {
      return false;
    } else if (!playerIn.func_175151_a(pos, side, stack)) {
      return false;
    } else if (pos.getY() == 255 && this.block.getMaterial().isSolid()) {
      return false;
    } else if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity) null, stack)) {
      int var11 = this.getMetadata(stack.getMetadata());
      IBlockState var12 =
          this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, var11, playerIn);
      if (worldIn.setBlockState(pos, var12, 3)) {
        var12 = worldIn.getBlockState(pos);
        if (var12.getBlock() == this.block) {
          setTileEntityNBT(worldIn, pos, stack);
          this.block.onBlockPlacedBy(worldIn, pos, var12, playerIn, stack);
        }

        worldIn.playSoundEffect(
            (double) ((float) pos.getX() + 0.5F),
            (double) ((float) pos.getY() + 0.5F),
            (double) ((float) pos.getZ() + 0.5F),
            this.block.stepSound.getPlaceSound(),
            (this.block.stepSound.getVolume() + 1.0F) / 2.0F,
            this.block.stepSound.getFrequency() * 0.8F);
        --stack.stackSize;
      }

      return true;
    } else {
      return false;
    }
  }
예제 #5
0
  public static int getSurfaceBlockY(World world, int x, int z) {

    int y = world.getChunkFromBlockCoords(x, z).getTopFilledSegment() + 16;

    Block block;
    do {
      if (--y < 0) {
        break;
      }
      block = world.getBlock(x, y, z);
    } while (block.isAir(world, x, y, z)
        || block.isReplaceable(world, x, y, z)
        || block.isLeaves(world, x, y, z)
        || block.isFoliage(world, x, y, z)
        || block.canBeReplacedByLeaves(world, x, y, z));
    return y;
  }
  @Override
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer player,
      World world,
      int x,
      int y,
      int z,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    Block block = world.getBlock(x, y, z);

    SkinPointer skinPointer = EquipmentNBTHelper.getSkinPointerFromStack(stack);

    if (skinPointer != null && skinPointer.getSkinType() == SkinTypeRegistry.skinBlock) {
      ForgeDirection dir = ForgeDirection.getOrientation(side);
      Block replaceBlock = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
      if (replaceBlock.isReplaceable(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ)) {
        if (!world.isRemote) {
          int l =
              MathHelper.floor_double((double) (player.rotationYaw * 16.0F / 360.0F) + 0.5D) & 15;
          world.setBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, ModBlocks.skinnable);
          world.setBlockMetadataWithNotify(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, l, 2);
          world.setTileEntity(
              x + dir.offsetX,
              y + dir.offsetY,
              z + dir.offsetZ,
              ((ITileEntityProvider) ModBlocks.skinnable).createNewTileEntity(world, 0));
          TileEntitySkinnable te =
              (TileEntitySkinnable)
                  world.getTileEntity(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
          te.setSkinPointer(skinPointer);
          stack.stackSize--;
        }
        return true;
      }
    }

    return false;
  }
예제 #7
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (supertile.getWorld().isRemote || redstoneSignal > 0) return;

    if (ticksExisted % 10 == 0) {
      IBlockState filter = getUnderlyingBlock();

      boolean scanned = false;
      List<BlockPos> validPositions = new ArrayList<>();

      int rangePlace = getRange();
      int rangePlaceY = getRangeY();

      BlockPos pos = supertile.getPos();

      List<EntityItem> items =
          supertile
              .getWorld()
              .getEntitiesWithinAABB(
                  EntityItem.class,
                  new AxisAlignedBB(
                      supertile.getPos().add(-RANGE, -RANGE_Y, -RANGE),
                      supertile.getPos().add(RANGE + 1, RANGE_Y + 1, RANGE + 1)));
      int slowdown = getSlowdownFactor();
      for (EntityItem item : items) {
        int age;
        try {
          age = (int) MethodHandles.itemAge_getter.invokeExact(item);
        } catch (Throwable t) {
          continue;
        }

        if (age < (60 + slowdown) || item.isDead) continue;

        ItemStack stack = item.getEntityItem();
        Item stackItem = stack.getItem();
        if (stackItem instanceof ItemBlock
            || stackItem instanceof ItemBlockSpecial
            || stackItem instanceof ItemRedstone
            || stackItem instanceof IFlowerPlaceable) {
          if (!scanned) {
            for (BlockPos pos_ :
                BlockPos.getAllInBox(
                    pos.add(-rangePlace, -rangePlaceY, -rangePlace),
                    pos.add(rangePlace, rangePlaceY, rangePlace))) {
              IBlockState stateAbove = supertile.getWorld().getBlockState(pos_.up());
              Block blockAbove = stateAbove.getBlock();
              BlockPos up = pos_.up();
              if (filter == supertile.getWorld().getBlockState(pos_)
                  && (blockAbove.isAir(stateAbove, supertile.getWorld(), up)
                      || blockAbove.isReplaceable(supertile.getWorld(), up)))
                validPositions.add(up);
            }

            scanned = true;
          }

          if (!validPositions.isEmpty()) {
            BlockPos coords =
                validPositions.get(supertile.getWorld().rand.nextInt(validPositions.size()));

            IBlockState stateToPlace = null;
            if (stackItem instanceof IFlowerPlaceable)
              stateToPlace =
                  ((IFlowerPlaceable) stackItem).getBlockToPlaceByFlower(stack, this, coords);
            if (stackItem instanceof ItemBlock)
              stateToPlace =
                  ((ItemBlock) stackItem)
                      .block.getStateFromMeta(stackItem.getMetadata(stack.getItemDamage()));
            else if (stackItem instanceof ItemBlockSpecial)
              stateToPlace =
                  ((Block)
                          ReflectionHelper.getPrivateValue(
                              ItemBlockSpecial.class,
                              (ItemBlockSpecial) stackItem,
                              LibObfuscation.REED_ITEM))
                      .getDefaultState();
            else if (stackItem instanceof ItemRedstone)
              stateToPlace = Blocks.REDSTONE_WIRE.getDefaultState();

            if (stateToPlace != null) {
              if (stateToPlace.getBlock().canPlaceBlockAt(supertile.getWorld(), coords)) {
                supertile.getWorld().setBlockState(coords, stateToPlace, 1 | 2);
                if (ConfigHandler.blockBreakParticles)
                  supertile.getWorld().playEvent(2001, coords, Block.getStateId(stateToPlace));
                validPositions.remove(coords);

                TileEntity tile = supertile.getWorld().getTileEntity(coords);
                if (tile != null && tile instanceof ISubTileContainer) {
                  ISubTileContainer container = (ISubTileContainer) tile;
                  String subtileName = ItemBlockSpecialFlower.getType(stack);
                  container.setSubTile(subtileName);
                  SubTileEntity subtile = container.getSubTile();
                  subtile.onBlockPlacedBy(
                      supertile.getWorld(),
                      coords,
                      supertile.getWorld().getBlockState(coords),
                      null,
                      stack);
                }

                if (stackItem instanceof IFlowerPlaceable)
                  ((IFlowerPlaceable) stackItem).onBlockPlacedByFlower(stack, this, coords);

                stack.stackSize--;
                if (stack.stackSize <= 0) item.setDead();

                if (mana > 1) mana--;
                return;
              }
            }
          }
        }
      }
    }
  }
예제 #8
0
  @Override
  public void handleCommand(ICommandSender sender, String[] args) {

    if (args.length < 7) {
      sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
      throw new WrongUsageException("info.cofh.command." + getCommandName() + ".syntax");
    }
    World world = sender.getEntityWorld();
    if (world.isRemote) {
      return;
    }

    ChunkCoordinates center = null;
    int i = 1;
    int xS, xL;
    if ("@".equals(args[i])) {
      center = sender.getPlayerCoordinates();
      ++i;
      xS = CommandBase.parseInt(sender, args[i++]);
    } else {
      try {
        xS = CommandBase.parseInt(sender, args[i++]);
      } catch (Throwable t) {
        center = CommandBase.getPlayer(sender, args[i - 1]).getPlayerCoordinates();
        xS = CommandBase.parseInt(sender, args[i++]);
      }
    }
    int yS = CommandBase.parseInt(sender, args[i++]), yL;
    int zS = CommandBase.parseInt(sender, args[i++]), zL;
    int t = i + 1;

    try {
      xL = CommandBase.parseInt(sender, args[i++]);
      yL = CommandBase.parseInt(sender, args[i++]);
      zL = CommandBase.parseInt(sender, args[i++]);
    } catch (Throwable e) {
      if (i > t || center == null) {
        throw Throwables.propagate(e);
      }
      --i;
      xL = xS;
      yL = yS;
      zL = zS;
    }

    if (center != null) {
      xS = center.posX - xS;
      yS = center.posY - yS;
      zS = center.posZ - zS;

      xL = center.posX + xL;
      yL = center.posY + yL;
      zL = center.posZ + zL;
    }

    yS &= ~yS >> 31; // max(yS, 0)
    yL &= ~yL >> 31; // max(yL, 0)

    if (xL < xS) {
      t = xS;
      xS = xL;
      xL = t;
    }
    if (yL < yS) {
      t = yS;
      yS = yL;
      yL = t;
    }
    if (zL < zS) {
      t = zS;
      zS = zL;
      zL = t;
    }

    if (yS > 255) {
      sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
      sender.addChatMessage(
          new ChatComponentTranslation("info.cofh.command." + getCommandName() + ".syntax"));
      return;
    } else if (yL > 255) {
      yL = 255;
    }

    Block replBlock;
    int replMeta;
    String blockReplRaw;
    {
      int meta = 0;
      String blockRaw = args[i];
      blockReplRaw = blockRaw;
      t = blockRaw.indexOf('#');
      if (t > 0) {
        meta = CommandBase.parseInt(sender, blockRaw.substring(t + 1));
        blockRaw = blockRaw.substring(0, t);
      }
      Block block = Block.getBlockFromName(blockRaw);
      if (block == Blocks.air || meta > 15 || meta < 0) {
        sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
        sender.addChatMessage(
            new ChatComponentTranslation("info.cofh.command." + getCommandName() + ".syntax"));
        // TODO: more descriptive error
        return;
      }
      replBlock = block;
      replMeta = meta;
    }

    long blockCounter = ((long) xL - xS) * ((long) yL - yS) * ((long) zL - zS);
    CommandHandler.logAdminCommand(
        sender,
        this,
        "info.cofh.command.replaceblocks.start",
        blockCounter,
        xS,
        yS,
        zS,
        xL,
        yL,
        zL,
        blockReplRaw);

    THashSet<Chunk> set = new THashSet<Chunk>();

    blockCounter = 0;
    for (int e = args.length; i < e; ++i) {
      String blockRaw = args[i];
      if (blockRaw.charAt(0) == '*') {
        if (blockRaw.equals("*fluid")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial().isLiquid()) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*tree")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isWood(world, x, y, z) || block.isLeaves(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.startsWith("*repl")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isReplaceable(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*stone")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isReplaceableOreGen(world, x, y, z, Blocks.stone)
                    || block.isReplaceableOreGen(world, x, y, z, Blocks.netherrack)
                    || block.isReplaceableOreGen(world, x, y, z, Blocks.end_stone)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*rock")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial() == Material.rock) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*sand")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial() == Material.sand) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*dirt")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.grass
                    || m == Material.ground
                    || m == Material.clay
                    || m == Material.snow
                    || m == Material.craftedSnow
                    || m == Material.ice
                    || m == Material.packedIce) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.startsWith("*plant")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.plants
                    || m == Material.vine
                    || m == Material.cactus
                    || m == Material.leaves) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*fire")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.fire || m == Material.lava || block.isBurning(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        }
        continue;
      }
      int meta = -1;
      t = blockRaw.indexOf('#');
      if (t > 0) {
        meta = CommandBase.parseInt(sender, blockRaw.substring(t + 1));
        blockRaw = blockRaw.substring(0, t);
      }
      Block block = Block.getBlockFromName(blockRaw);
      if (block == Blocks.air) {
        continue;
      }

      for (int x = xS; x <= xL; ++x) {
        for (int z = zS; z <= zL; ++z) {
          Chunk chunk = world.getChunkFromBlockCoords(x, z);
          int cX = x & 15, cZ = z & 15;
          for (int y = yS; y <= yL; ++y) {
            boolean v = meta == -1 || chunk.getBlockMetadata(cX, y, cZ) == meta;
            if (v && chunk.getBlock(cX, y, cZ) == block) {
              if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                ++blockCounter;
                set.add(chunk);
              }
            }
          }
        }
      }
    }
    if (!set.isEmpty()) {
      CommandHandler.logAdminCommand(
          sender,
          this,
          "info.cofh.command.replaceblocks.success",
          blockCounter,
          xS,
          yS,
          zS,
          xL,
          yL,
          zL,
          blockReplRaw);
    } else {
      CommandHandler.logAdminCommand(sender, this, "info.cofh.command.replaceblocks.failure");
    }

    if (world instanceof WorldServer) {
      TObjectHashIterator<Chunk> c = set.iterator();
      for (int k = 0, e = set.size(); k < e; ++k) {
        Chunk chunk = c.next();
        PlayerManager manager = ((WorldServer) world).getPlayerManager();
        if (manager == null) {
          return;
        }
        PlayerInstance watcher =
            manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, false);
        if (watcher != null) {
          watcher.sendToAllPlayersWatchingChunk(new S21PacketChunkData(chunk, false, -1));
        }
      }
    }
  }
예제 #9
0
  /** Called when a Block is right-clicked with this Item */
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (side == EnumFacing.DOWN) {
      return false;
    } else {
      IBlockState iblockstate = worldIn.getBlockState(pos);
      Block block = iblockstate.getBlock();
      boolean flag = block.isReplaceable(worldIn, pos);

      if (!flag) {
        if (!worldIn.getBlockState(pos).getBlock().getMaterial().isSolid()) {
          return false;
        }

        pos = pos.offset(side);
      }

      if (!playerIn.canPlayerEdit(pos, side, stack)) {
        return false;
      } else if (!Blocks.skull.canPlaceBlockAt(worldIn, pos)) {
        return false;
      } else {
        if (!worldIn.isRemote) {
          worldIn.setBlockState(
              pos, Blocks.skull.getDefaultState().withProperty(BlockSkull.FACING, side), 3);
          int i = 0;

          if (side == EnumFacing.UP) {
            i =
                MathHelper.floor_double((double) (playerIn.rotationYaw * 16.0F / 360.0F) + 0.5D)
                    & 15;
          }

          TileEntity tileentity = worldIn.getTileEntity(pos);

          if (tileentity instanceof TileEntitySkull) {
            TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;

            if (stack.getMetadata() == 3) {
              GameProfile gameprofile = null;

              if (stack.hasTagCompound()) {
                NBTTagCompound nbttagcompound = stack.getTagCompound();

                if (nbttagcompound.hasKey("SkullOwner", 10)) {
                  gameprofile =
                      NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
                } else if (nbttagcompound.hasKey("SkullOwner", 8)
                    && nbttagcompound.getString("SkullOwner").length() > 0) {
                  gameprofile =
                      new GameProfile((UUID) null, nbttagcompound.getString("SkullOwner"));
                }
              }

              tileentityskull.setPlayerProfile(gameprofile);
            } else {
              tileentityskull.setType(stack.getMetadata());
            }

            tileentityskull.setSkullRotation(i);
            Blocks.skull.checkWitherSpawn(worldIn, pos, tileentityskull);
          }

          --stack.stackSize;
        }

        return true;
      }
    }
  }
예제 #10
0
  // Copied from vanila skull itemBlock. Relevant edits are indicated.
  @Nonnull
  @Override
  public EnumActionResult onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumHand hand,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ) {
    if (facing == EnumFacing.DOWN) {
      return EnumActionResult.FAIL;
    } else {
      if (worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos)) {
        facing = EnumFacing.UP;
        pos = pos.down();
      }
      IBlockState iblockstate = worldIn.getBlockState(pos);
      Block block = iblockstate.getBlock();
      boolean flag = block.isReplaceable(worldIn, pos);

      if (!flag) {
        if (!worldIn.getBlockState(pos).getMaterial().isSolid()
            && !worldIn.isSideSolid(pos, facing, true)) {
          return EnumActionResult.FAIL;
        }

        pos = pos.offset(facing);
      }

      if (playerIn.canPlayerEdit(pos, facing, stack)
          && Blocks.SKULL.canPlaceBlockAt(worldIn, pos)) {
        if (worldIn.isRemote) {
          return EnumActionResult.SUCCESS;
        } else {
          worldIn.setBlockState(
              pos,
              ModBlocks.gaiaHead.getDefaultState().withProperty(BlockSkull.FACING, facing),
              11); // Botania - skull -> gaia head
          int i = 0;

          if (facing == EnumFacing.UP) {
            i = MathHelper.floor_double(playerIn.rotationYaw * 16.0F / 360.0F + 0.5D) & 15;
          }

          TileEntity tileentity = worldIn.getTileEntity(pos);

          if (tileentity instanceof TileEntitySkull) {
            TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;

            if (stack.getMetadata() == 3) // Botania - do not retrieve skins
            {
              /*GameProfile gameprofile = null;

              if (stack.hasTagCompound())
              {
              	NBTTagCompound nbttagcompound = stack.getTagCompound();

              	if (nbttagcompound.hasKey("SkullOwner", 10))
              	{
              		gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
              	}
              	else if (nbttagcompound.hasKey("SkullOwner", 8) && !nbttagcompound.getString("SkullOwner").isEmpty())
              	{
              		gameprofile = new GameProfile((UUID)null, nbttagcompound.getString("SkullOwner"));
              	}
              }

              tileentityskull.setPlayerProfile(gameprofile);*/
            } else {
              tileentityskull.setType(3); // Botania - Force type to 3 (humanoid)
            }

            tileentityskull.setSkullRotation(i);
            Blocks.SKULL.checkWitherSpawn(worldIn, pos, tileentityskull);
          }

          --stack.stackSize;
          return EnumActionResult.SUCCESS;
        }
      } else {
        return EnumActionResult.FAIL;
      }
    }
  }