Ejemplo n.º 1
0
  public void onBlockPlacedBy(
      World world, int x, int y, int z, EntityLivingBase entityplayer, ItemStack itemstack) {
    int l = MathHelper.floor_double((double) (entityplayer.rotationYaw * 4.0F / 360.F) + 0.5D) & 3;

    if (l == 0) {
      world.setBlockMetadataWithNotify(x, y, z, 2, 2);
    }

    if (l == 1) {
      world.setBlockMetadataWithNotify(x, y, z, 5, 2);
    }

    if (l == 2) {
      world.setBlockMetadataWithNotify(x, y, z, 3, 2);
    }

    if (l == 3) {
      world.setBlockMetadataWithNotify(x, y, z, 4, 2);
    }

    if (itemstack.hasDisplayName()) {
      ((TileEntityIBROIFurnace) world.getTileEntity(x, y, z))
          .setGuiDisplayName(itemstack.getDisplayName());
    }
  }
  @Override
  public boolean interact(EntityPlayer player) {
    ItemStack itemStack = player.inventory.getCurrentItem();

    if (itemStack != null
        && itemStack.getItem() == MPItems.spawn_egg_mp
        && itemStack.getItemDamage() == 1014) {
      if (!this.worldObj.isRemote) {
        EntityAgeable entityageable = this.createChild(this);

        if (entityageable != null) {
          entityageable.setGrowingAge(-24000);
          entityageable.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
          this.worldObj.spawnEntityInWorld(entityageable);

          if (itemStack.hasDisplayName()) {
            entityageable.setCustomNameTag(itemStack.getDisplayName());
          }
          if (!player.capabilities.isCreativeMode) {
            --itemStack.stackSize;

            if (itemStack.stackSize <= 0) {
              player.inventory.setInventorySlotContents(
                  player.inventory.currentItem, (ItemStack) null);
            }
          }
        }
      }
      return true;
    }
    return super.interact(player);
  }
Ejemplo n.º 3
0
  /** Called by ItemBlocks after a block is set in the world, to allow post-place logic */
  public void onBlockPlacedBy(
      World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    if (stack.hasDisplayName()) {
      TileEntity tileentity = worldIn.getTileEntity(pos);

      if (tileentity instanceof TileEntityBrewingStand) {
        ((TileEntityBrewingStand) tileentity).setName(stack.getDisplayName());
      }
    }
  }
Ejemplo n.º 4
0
  /** Called when the block is placed in the world. */
  @Override
  public void onBlockPlacedBy(
      World world, int x, int y, int z, EntityLivingBase entity, ItemStack is) {
    super.onBlockPlacedBy(world, x, y, z, entity, is);

    if (is.hasDisplayName()) {
      TEHopper tileentityhopper = getHopperTE(world, x, y, z);
      tileentityhopper.setCustomName(is.getDisplayName());
    }
  }
Ejemplo n.º 5
0
 @Override
 public void onBlockPlacedBy(
     World world, int x, int y, int z, EntityLivingBase entity, ItemStack item) {
   int dir = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
   TileEntityBFurnace tile = (TileEntityBFurnace) world.getBlockTileEntity(x, y, z);
   tile.direction = getFacingOnMeta(dir);
   if (item.hasDisplayName()) {
     tile.setCustomName(item.getDisplayName());
   }
 }
Ejemplo n.º 6
0
 @Override
 public void onBlockPlacedBy(
     World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
   if (world.getTileEntity(x, y, z) instanceof TileEntityFL) {
     if (itemStack.hasDisplayName()) {
       ((TileEntityFL) world.getTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName());
     }
     ((TileEntityFL) world.getTileEntity(x, y, z))
         .setOrientation(ForgeDirection.getOrientation(getFacing(entityLiving)));
     world.setBlockMetadataWithNotify(x, y, z, getFacing(entityLiving), 2);
   }
 }
Ejemplo n.º 7
0
 @Override
 public IChatComponent func_151519_b(EntityLivingBase living) {
   IChatComponent comp = (getEntity() == null ? damageSourceEntity : getEntity()).func_145748_c_();
   ItemStack item =
       getEntity() instanceof EntityLivingBase
           ? ((EntityLivingBase) getEntity()).getHeldItem()
           : null;
   String s = "death.attack.thrown.item";
   String s1 = s + ".item";
   return item != null && item.hasDisplayName() && StatCollector.canTranslate(s1)
       ? new ChatComponentTranslation(s1, living.func_145748_c_(), comp, item.func_151000_E())
       : new ChatComponentTranslation(s, living.func_145748_c_(), comp);
 }
 @Override
 public void onBlockPlacedBy(
     World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemStack) {
   int l =
       MathHelper.floor_double((double) (entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
   if (l == 0) world.setBlockMetadataWithNotify(x, y, z, 2, 2);
   if (l == 1) world.setBlockMetadataWithNotify(x, y, z, 5, 2);
   if (l == 2) world.setBlockMetadataWithNotify(x, y, z, 3, 2);
   if (l == 3) world.setBlockMetadataWithNotify(x, y, z, 4, 2);
   if (itemStack.hasDisplayName())
     ((TileEntityPlanter) world.getTileEntity(x, y, z))
         .setGuiDisplayName(itemStack.getDisplayName());
 }
Ejemplo n.º 9
0
  @Override
  public void onBlockPlacedBy(
      World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
    TileEntityTC tileEntity = (TileEntityTC) world.getTileEntity(x, y, z);

    tileEntity.setDirection(
        ForgeDirection.VALID_DIRECTIONS[
            Direction.directionToFacing[
                Direction.rotateOpposite[Math.round(player.rotationYaw / 90) & 3]]]);

    if (stack.hasDisplayName()) {
      tileEntity.setInvName(stack.getDisplayName());
    }
  }
  @Override
  public ItemStack dispenseStack(IBlockSource block, ItemStack stack) {
    EnumFacing enumfacing = BlockDispenser.func_149937_b(block.getBlockMetadata());
    double d0 = block.getX() + enumfacing.getFrontOffsetX();
    double d1 = block.getYInt() + 0.2F;
    double d2 = block.getZ() + enumfacing.getFrontOffsetZ();
    Entity entity = ItemEntityEgg.spawnEntity(block.getWorld(), stack.getItemDamage(), d0, d1, d2);

    if (entity instanceof EntityLivingBase && stack.hasDisplayName())
      ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());

    stack.splitStack(1);
    return stack;
  }
  public ItemStack dispenseStack(IBlockSource BlockSource, ItemStack stack) {
    EnumFacing enumfacing = BlockDispenser.getFacing(BlockSource.getBlockMetadata());
    double d0 = BlockSource.getX() + (double) enumfacing.getFrontOffsetX();
    double d1 = BlockSource.getY() + (double) enumfacing.getFrontOffsetY();
    double d2 = BlockSource.getZ() + (double) enumfacing.getFrontOffsetZ();
    Entity entity =
        ItemGaiaSpawnEgg.spawnCreature(BlockSource.getWorld(), stack.getItemDamage(), d0, d1, d2);

    if (entity instanceof EntityLivingBase && stack.hasDisplayName()) {
      ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());
    }

    stack.splitStack(1);
    return stack;
  }
  @Override
  public void executeLogic(
      World par1World,
      int par2,
      int par3,
      int par4,
      ItemStack par5ItemStack,
      Entity triggerer,
      boolean willBlockBeRemoved) {
    EnumFacing enumfacing = getFacing(par1World, par2, par3, par4);
    double d0 = par2 + Math.random() + (double) enumfacing.getFrontOffsetX();
    double d1 = (double) ((float) par3 + 0.2F);
    double d2 = par4 + Math.random() + (double) enumfacing.getFrontOffsetZ();
    Entity entity =
        ItemMonsterPlacer.spawnCreature(par1World, par5ItemStack.getItemDamage(), d0, d1, d2);

    if (entity instanceof EntityLivingBase && par5ItemStack.hasDisplayName()) {
      ((EntityLiving) entity).setCustomNameTag(par5ItemStack.getDisplayName());
    }
  }
  /** Called when the block is placed in the world. */
  public void onBlockPlacedBy(
      World par1World,
      int par2,
      int par3,
      int par4,
      EntityLivingBase par5EntityLivingBase,
      ItemStack par6ItemStack) {
    // int l = par1World.getBlockId(par2, par3, par4 - 1);
    // int i1 = par1World.getBlockId(par2, par3, par4 + 1);
    // int j1 = par1World.getBlockId(par2 - 1, par3, par4);
    // int k1 = par1World.getBlockId(par2 + 1, par3, par4);
    byte b0 = 0;
    int l1 =
        MathHelper.floor_double((double) (par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D)
            & 3;

    if (l1 == 0) {
      b0 = 2;
    }

    if (l1 == 1) {
      b0 = 5;
    }

    if (l1 == 2) {
      b0 = 3;
    }

    if (l1 == 3) {
      b0 = 4;
    }

    par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 3);

    if (par6ItemStack.hasDisplayName()) {
      ((TileEntityBoundChest) par1World.getTileEntity(par2, par3, par4))
          .setChestGuiName(par6ItemStack.getDisplayName());
    }
  }
Ejemplo n.º 14
0
  /** Returns an Item that is the result of this recipe */
  public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) {
    int var2 = 0;
    ItemStack var3 = null;

    for (int var4 = 0; var4 < par1InventoryCrafting.getSizeInventory(); ++var4) {
      ItemStack var5 = par1InventoryCrafting.getStackInSlot(var4);

      if (var5 != null) {
        if (var5.getItem() == Items.written_book) {
          if (var3 != null) {
            return null;
          }

          var3 = var5;
        } else {
          if (var5.getItem() != Items.writable_book) {
            return null;
          }

          ++var2;
        }
      }
    }

    if (var3 != null && var2 >= 1) {
      ItemStack var6 = new ItemStack(Items.written_book, var2 + 1);
      var6.setTagCompound((NBTTagCompound) var3.getTagCompound().copy());

      if (var3.hasDisplayName()) {
        var6.setStackDisplayName(var3.getDisplayName());
      }

      return var6;
    } else {
      return null;
    }
  }
Ejemplo n.º 15
0
  @Override
  public void onBlockPlacedBy(
      World par1World,
      int par2,
      int par3,
      int par4,
      EntityLivingBase par5EntityLivingBase,
      ItemStack par6ItemStack) {
    int l = par1World.getBlockMetadata(par2, par3, par4);
    int i1 = l & 7;
    int j1 = l & 8;

    if (i1 == invertMetadata(1)) {
      if ((MathHelper.floor_double(
                  (double) (par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D)
              & 1)
          == 0) {
        par1World.setBlockMetadataWithNotify(par2, par3, par4, 5 | j1, 2);
      } else {
        par1World.setBlockMetadataWithNotify(par2, par3, par4, 6 | j1, 2);
      }
    } else if (i1 == invertMetadata(0)) {
      if ((MathHelper.floor_double(
                  (double) (par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D)
              & 1)
          == 0) {
        par1World.setBlockMetadataWithNotify(par2, par3, par4, 7 | j1, 2);
      } else {
        par1World.setBlockMetadataWithNotify(par2, par3, par4, 0 | j1, 2);
      }
    }

    if (par6ItemStack.hasDisplayName()) {
      ((TileEntityLandmine) par1World.getBlockTileEntity(par2, par3, par4))
          .setGuiDisplayName(par6ItemStack.getDisplayName());
    }
  }
Ejemplo n.º 16
0
  /**
   * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a
   * pig.
   */
  public boolean interact(EntityPlayer par1EntityPlayer) {
    ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem();

    if (var2 != null && var2.getItem() == Items.spawn_egg) {
      if (!this.worldObj.isClient) {
        Class var3 = EntityList.getClassFromID(var2.getItemDamage());

        if (var3 != null && var3.isAssignableFrom(this.getClass())) {
          EntityAgeable var4 = this.createChild(this);

          if (var4 != null) {
            var4.setGrowingAge(-24000);
            var4.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
            this.worldObj.spawnEntityInWorld(var4);

            if (var2.hasDisplayName()) {
              var4.setCustomNameTag(var2.getDisplayName());
            }

            if (!par1EntityPlayer.capabilities.isCreativeMode) {
              --var2.stackSize;

              if (var2.stackSize <= 0) {
                par1EntityPlayer.inventory.setInventorySlotContents(
                    par1EntityPlayer.inventory.currentItem, (ItemStack) null);
              }
            }
          }
        }
      }

      return true;
    } else {
      return false;
    }
  }
Ejemplo n.º 17
0
  /** Returns an Item that is the result of this recipe */
  public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) {
    int i = 0;
    ItemStack itemstack = null;

    for (int j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j) {
      ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(j);

      if (itemstack1 != null) {
        if (itemstack1.getItem() == Items.filled_map) {
          if (itemstack != null) {
            return null;
          }

          itemstack = itemstack1;
        } else {
          if (itemstack1.getItem() != Items.map) {
            return null;
          }

          ++i;
        }
      }
    }

    if (itemstack != null && i >= 1) {
      ItemStack itemstack2 = new ItemStack(Items.filled_map, i + 1, itemstack.getItemDamage());

      if (itemstack.hasDisplayName()) {
        itemstack2.setStackDisplayName(itemstack.getDisplayName());
      }

      return itemstack2;
    } else {
      return null;
    }
  }
Ejemplo n.º 18
0
  @Override
  public boolean onItemUse(
      ItemStack itemstack,
      EntityPlayer player,
      World world,
      int x,
      int y,
      int z,
      int side,
      float xOffset,
      float yOffset,
      float zOffset) {

    if (world.isRemote) {
      return true;
    }
    if (!containsSoul(itemstack)) {
      return false;
    }
    if (player == null) {
      return false;
    }

    Entity mob;
    NBTTagCompound root = itemstack.stackTagCompound;
    if (root.hasKey("isStub")) {
      String entityId = root.getString("id");
      mob = EntityList.createEntityByName(entityId, world);
    } else {
      mob = EntityList.createEntityFromNBT(root, world);
    }
    if (mob == null) {
      return true;
    }
    mob.readFromNBT(root);

    Block blk = world.getBlock(x, y, z);
    double spawnX = x + Facing.offsetsXForSide[side] + 0.5;
    double spawnY = y + Facing.offsetsYForSide[side];
    double spawnZ = z + Facing.offsetsZForSide[side] + 0.5;
    if (side == ForgeDirection.UP.ordinal()
        && (blk instanceof BlockFence || blk instanceof BlockWall)) {
      spawnY += 0.5;
    }
    mob.setLocationAndAngles(spawnX, spawnY, spawnZ, world.rand.nextFloat() * 360.0F, 0);

    boolean spaceClear =
        world.checkNoEntityCollision(mob.boundingBox)
            && world.getCollidingBoundingBoxes(mob, mob.boundingBox).isEmpty();
    if (!spaceClear) {
      return false;
    }

    if (itemstack.hasDisplayName() && mob instanceof EntityLiving) {
      ((EntityLiving) mob).setCustomNameTag(itemstack.getDisplayName());
    }

    world.spawnEntityInWorld(mob);
    if (mob instanceof EntityLiving) {
      ((EntityLiving) mob).playLivingSound();
    }

    Entity riddenByEntity = mob.riddenByEntity;
    while (riddenByEntity != null) {
      riddenByEntity.setLocationAndAngles(
          spawnX, spawnY, spawnZ, world.rand.nextFloat() * 360.0F, 0.0F);
      world.spawnEntityInWorld(riddenByEntity);
      if (riddenByEntity instanceof EntityLiving) {
        ((EntityLiving) riddenByEntity).playLivingSound();
      }
      riddenByEntity = riddenByEntity.riddenByEntity;
    }

    if (!player.capabilities.isCreativeMode) {
      if (itemstack.stackSize > 1) {
        itemstack.stackSize--;
        player.inventory.addItemStackToInventory(new ItemStack(this));
        player.inventoryContainer.detectAndSendChanges();
      } else {
        itemstack.setTagCompound(null);
      }
    }

    return true;
  }
 /**
  * Called when a block is placed by a player. Sets data of the tile entity, like custom container
  * title, enchantments or similar.
  */
 public void onBlockPlaced(EntityLivingBase player, ItemStack stack) {
   if (stack.hasDisplayName()) setCustomTitle(stack.getDisplayName());
 }
Ejemplo n.º 20
0
 @Override
 public boolean hasCustomInventoryName() {
   return invItem.hasDisplayName();
 }