Пример #1
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer entityPlayer,
      int par6,
      float par7,
      float par8,
      float par9) {
    TileEntityWire tileEntity = (TileEntityWire) world.getBlockTileEntity(x, y, z);

    if (entityPlayer.getCurrentEquippedItem() != null) {
      if (entityPlayer.getCurrentEquippedItem().itemID == Item.dyePowder.itemID) {
        tileEntity.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage());
        return true;
      } else if (entityPlayer.getCurrentEquippedItem().itemID == Block.cloth.blockID
          && !tileEntity.isInsulated) {
        tileEntity.setInsulated();
        tileEntity.setDye(
            BlockColored.getDyeFromBlock(entityPlayer.getCurrentEquippedItem().getItemDamage()));
        entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
        return true;
      }
    }

    return false;
  }
 @Override
 protected void entityInit() {
   super.entityInit();
   dataWatcher.addObject(18, new Float(getHealth()));
   dataWatcher.addObject(19, new Byte((byte) 0));
   dataWatcher.addObject(20, new Byte((byte) BlockColored.func_150032_b(1)));
 }
Пример #3
0
  /**
   * Returns true if the item can be used on the given entity, e.g. shears on sheep.
   *
   * @param stack the item stack of the item being used
   * @param player the player who used the item
   * @param target the target we hit with the item in hand
   */
  public boolean itemInteractionForEntity(
      ItemStack stack, EntityPlayer player, EntityLivingBase target) {
    if (target instanceof EntitySheep) {
      EntitySheep entitysheep = (EntitySheep) target;
      int i = BlockColored.func_150032_b(stack.getMetadata());

      if (!entitysheep.getSheared() && entitysheep.getFleeceColor() != i) {
        entitysheep.setFleeceColor(i);
        --stack.stackSize;
      }

      return true;
    } else {
      return false;
    }
  }
Пример #4
0
  @Override
  public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
    TileEntity tile = world.getBlockTileEntity(x, y, z);

    if (tile instanceof TileEntityWire) {
      TileEntityWire tileEntity = (TileEntityWire) tile;

      if (tileEntity.isInsulated) {
        dropBlockAsItem_do(
            world,
            x,
            y,
            z,
            new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(tileEntity.dyeID)));
      }
    }

    super.breakBlock(world, x, y, z, par5, par6);
  }
Пример #5
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 itemstack = par1EntityPlayer.inventory.getCurrentItem();

    if (this.isTamed()) {
      if (itemstack != null) {
        if (Item.itemsList[itemstack.itemID] instanceof ItemFood) {
          ItemFood itemfood = (ItemFood) Item.itemsList[itemstack.itemID];

          if (itemfood.isWolfsFavoriteMeat()
              && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) {
            if (!par1EntityPlayer.capabilities.isCreativeMode) {
              --itemstack.stackSize;
            }

            this.heal((float) itemfood.getHealAmount());

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

            return true;
          }
        } else if (itemstack.itemID == Item.dyePowder.itemID) {
          int i = BlockColored.getBlockFromDye(itemstack.getItemDamage());

          if (i != this.getCollarColor()) {
            this.setCollarColor(i);

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

            return true;
          }
        }
      }

      if (par1EntityPlayer.getCommandSenderName().equalsIgnoreCase(this.getOwnerName())
          && !this.worldObj.isRemote
          && !this.isBreedingItem(itemstack)) {
        this.aiSit.setSitting(!this.isSitting());
        this.isJumping = false;
        this.setPathToEntity((PathEntity) null);
        this.setTarget((Entity) null);
        this.setAttackTarget((EntityLivingBase) null);
      }
    } else if (itemstack != null && itemstack.itemID == Item.bone.itemID && !this.isAngry()) {
      if (!par1EntityPlayer.capabilities.isCreativeMode) {
        --itemstack.stackSize;
      }

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

      if (!this.worldObj.isRemote) {
        if (this.rand.nextInt(3) == 0) {
          this.setTamed(true);
          this.setPathToEntity((PathEntity) null);
          this.setAttackTarget((EntityLivingBase) null);
          this.aiSit.setSitting(true);
          this.setHealth(20.0F);
          this.setOwner(par1EntityPlayer.getCommandSenderName());
          this.playTameEffect(true);
          this.worldObj.setEntityState(this, (byte) 7);
        } else {
          this.playTameEffect(false);
          this.worldObj.setEntityState(this, (byte) 6);
        }
      }

      return true;
    }

    return super.interact(par1EntityPlayer);
  }
Пример #6
0
 protected void entityInit() {
   super.entityInit();
   this.dataWatcher.addObject(18, new Float(this.getHealth()));
   this.dataWatcher.addObject(19, new Byte((byte) 0));
   this.dataWatcher.addObject(20, new Byte((byte) BlockColored.getBlockFromDye(1)));
 }