private boolean onPlayerPlaceBlock(
     PlayerControllerMP controller,
     EntityPlayer player,
     ItemStack offhand,
     BlockPos pos,
     EnumFacing l,
     Vec3 hitVec) {
   final World worldObj = player.worldObj;
   if (!worldObj.getWorldBorder().contains(pos)) {
     return false;
   }
   float f = (float) hitVec.xCoord - (float) pos.getX();
   float f1 = (float) hitVec.yCoord - (float) pos.getY();
   float f2 = (float) hitVec.zCoord - (float) pos.getZ();
   boolean flag = false;
   if (!controller.isSpectatorMode()) {
     if (offhand.getItem().onItemUseFirst(offhand, player, worldObj, pos, l, f, f1, f2)) {
       return true;
     }
     if (!player.isSneaking()
         || player.getCurrentEquippedItem() == null
         || player.getCurrentEquippedItem().getItem().doesSneakBypassUse(worldObj, pos, player)) {
       IBlockState b = worldObj.getBlockState(pos);
       if (!b.getBlock().isAir(worldObj, pos)
           && b.getBlock().onBlockActivated(worldObj, pos, b, player, l, f, f1, f2)) {
         flag = true;
       }
     }
     if (!flag && offhand.getItem() instanceof ItemBlock) {
       ItemBlock itemblock = (ItemBlock) offhand.getItem();
       if (!itemblock.canPlaceBlockOnSide(worldObj, pos, l, player, offhand)) {
         return false;
       }
     }
   }
   Battlegear.packetHandler.sendPacketToServer(
       new OffhandPlaceBlockPacket(pos, l, offhand, f, f1, f2).generatePacket());
   if (flag || controller.isSpectatorMode()) {
     return true;
   } else if (offhand == null) {
     return false;
   } else {
     if (controller.isInCreativeMode()) {
       int i1 = offhand.getMetadata();
       int j1 = offhand.stackSize;
       boolean flag1 = offhand.onItemUse(player, worldObj, pos, l, f, f1, f2);
       offhand.setItemDamage(i1);
       offhand.stackSize = j1;
       return flag1;
     } else {
       if (!offhand.onItemUse(player, worldObj, pos, l, f, f1, f2)) {
         return false;
       }
       if (offhand.stackSize <= 0) {
         ForgeEventFactory.onPlayerDestroyItem(player, offhand);
       }
       return true;
     }
   }
 }
 /*
  * This messy function is a work in progress.  It is a temporary setup for
  * placing a custom block from my mod over the door of the given npch.
  *
  * Returns the location of where the sign should be placed.
  *
  * Needs to be rewritten badly.
  */
 public static BlockPos placeBlockOverDoor(
     ItemStack stack,
     EntityPlayer playerIn,
     World worldIn,
     NPCHouse npch,
     String block_name,
     float hitX,
     float hitY,
     float hitZ) {
   String placeMe = ("bh_housing:" + block_name);
   BlockPos door = BlockHelper.findDoor(worldIn, npch);
   if (!door.equals(npch.getCorner(0))) {
     int north = npch.getCorner(0).getZ();
     int south = npch.getCorner(2).getZ();
     int west = npch.getCorner(0).getX();
     int east = npch.getCorner(1).getX();
     BlockPos placeHere = door;
     boolean shouldUse = false;
     EnumFacing direction = EnumFacing.NORTH;
     if (worldIn.getBlockState(placeHere).getBlock() instanceof NPCHouse_Block) {
       return placeHere;
     } else if (door.getX() == west) {
       placeHere = door.up().west();
       direction = EnumFacing.WEST;
     } else if (door.getX() == east) {
       placeHere = door.up().east();
       direction = EnumFacing.EAST;
     } else if (door.getZ() == north) {
       placeHere = door.up().north();
       direction = EnumFacing.NORTH;
     } else if (door.getZ() == south) {
       placeHere = door.up().south();
       direction = EnumFacing.SOUTH;
     }
     shouldUse =
         worldIn.setBlockState(
             placeHere,
             NPCHouse_Block.getBlockFromName(placeMe)
                 .getDefaultState()
                 .withProperty(NPCHouse_Block.FACING, direction),
             3);
     if (shouldUse) {
       --stack.stackSize;
       if (stack.stackSize == 0) {
         playerIn.destroyCurrentEquippedItem();
       }
       if (block_name == "npch_block") {
         NPCHouse_Block npchblock = (NPCHouse_Block) worldIn.getBlockState(placeHere).getBlock();
         npchblock.setNPCHouse(npch);
       }
       IBlockState temp = worldIn.getBlockState(placeHere);
       if (temp.getBlock().getRegistryName() == "npch_block") {
         ItemBlock.setTileEntityNBT(
             worldIn, playerIn, placeHere, new ItemStack(Block.getBlockFromName("npch_block"), 1));
       }
     }
     return placeHere;
   }
   return null;
 }
Esempio n. 3
0
 public static void renameItemStack(ItemStack target, String name) {
   if (target == null) return;
   Item item = target.getItem();
   item.setUnlocalizedName(name);
   if (item instanceof ItemBlock) {
     Block.blocksList[((ItemBlock) item).getBlockID()].setUnlocalizedName(name);
   }
 }
Esempio n. 4
0
 @Override
 @SideOnly(Side.CLIENT)
 public void addInformation(
     ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
   super.addInformation(par1ItemStack, par2EntityPlayer, par3List, par4);
   if (par4) {
     par3List.add("Part ID: " + getPartTypeID(par1ItemStack));
     par3List.add("Hex: " + Integer.toHexString(getPartTypeID(par1ItemStack)));
   }
 }
 @Override
 @SideOnly(Side.CLIENT)
 // マウスオーバー時の表示情報
 public void addInformation(ItemStack item, EntityPlayer player, List list, boolean b) {
   super.addInformation(item, player, list, b);
   boolean flag = Loader.isModLoaded("NotEnoughItems") && Loader.isModLoaded("DCsNEIPluginAMT");
   if (flag) {
     list.add(EnumChatFormatting.ITALIC + "Push NEI Usage key : display recipes");
   }
 }
 @Override
 @SideOnly(Side.CLIENT)
 public void addInformation(
     ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
   list.add(
       Lang.localize("tile.enderio.blockCapacitorBank.tooltipPrefix", false)
           + " "
           + PowerDisplayUtil.formatPower(PowerHandlerUtil.getStoredEnergyForItem(itemStack))
           + " "
           + PowerDisplayUtil.abrevation());
   super.addInformation(itemStack, par2EntityPlayer, list, par4);
 }
Esempio n. 7
0
  @Nonnull
  private static List<TextureDetails> getIcons(Block block, int meta, ItemBlock itemBlock) {
    TextureDetails any = null;
    TextureDetails top = null;
    TextureDetails side = null;

    int col = itemBlock.getColorFromItemStack(new ItemStack(itemBlock, 1, meta), 0);

    TextureDetails[] icons = new TextureDetails[6];

    for (int s = 0; s < 6; s++) {
      String iconName = null;
      if (meta == OreDictionary.WILDCARD_VALUE) {
        for (int i = 0; i < 16; i++) {
          try {
            iconName = getIconName(block.getIcon(s, meta));
          } catch (Throwable err) {
            continue;
          }
          if (iconName != null) break;
        }
      } else
        try {
          iconName = getIconName(block.getIcon(s, meta));
        } catch (Throwable err) {
          continue;
        }

      if (iconName == null) continue;

      TextureDetails textureDetails = TextureDetails.createTextureDetails(iconName, col, 0);

      icons[s] = textureDetails;
      if (any == null) any = textureDetails;
      if (s < 2) {
        if (top == null) top = textureDetails;
      } else {
        if (side == null) side = textureDetails;
      }
    }

    if (any == null) return ImmutableList.of();

    for (int i = 0; i < icons.length; i++) {
      if (icons[i] != null) continue;
      if (i < 2 && top != null) icons[i] = top;
      else if (i >= 2 && side != null) icons[i] = side;
      else icons[i] = any;
    }

    return Lists.newArrayList(icons);
  }
Esempio n. 8
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 if (!worldIn.getBlockState(pos).getBlock().getMaterial().isSolid()) {
      return false;
    } else {
      pos = pos.offset(side);

      if (!playerIn.canPlayerEdit(pos, side, stack)) {
        return false;
      } else if (!Blocks.standing_sign.canPlaceBlockAt(worldIn, pos)) {
        return false;
      } else if (worldIn.isRemote) {
        return true;
      } else {
        if (side == EnumFacing.UP) {
          int i =
              MathHelper.floor_double(
                      (double) ((playerIn.rotationYaw + 180.0F) * 16.0F / 360.0F) + 0.5D)
                  & 15;
          worldIn.setBlockState(
              pos,
              Blocks.standing_sign
                  .getDefaultState()
                  .withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)),
              3);
        } else {
          worldIn.setBlockState(
              pos, Blocks.wall_sign.getDefaultState().withProperty(BlockWallSign.FACING, side), 3);
        }

        --stack.stackSize;
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntitySign
            && !ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack)) {
          playerIn.openEditSign((TileEntitySign) tileentity);
        }

        return true;
      }
    }
  }
  @Override
  public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean flag) {
    super.addInformation(itemStack, player, list, flag);

    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
      String[] tooltipLines =
          StatCollector.translateToLocal(getUnlocalizedName(itemStack) + ".tooltip").split("\\\\n");
      for (String s : tooltipLines) {
        list.add("\u00a73" + s);
      }
    } else {
      list.add("\u00a76" + StatCollector.translateToLocal(Strings.TOOLTIP_SHIFT));
    }
  }
Esempio n. 10
0
 @Override
 public void getSubItems(Item item, CreativeTabs tab, List subItems) {
   super.getSubItems(item, tab, subItems);
 }
 public Item_Block_Balloon setUnlocalizedName(String unlocal) {
   super.setUnlocalizedName(unlocal);
   return this;
 }