net.minecraft.stats.StatList Java Examples

The following examples show how to use net.minecraft.stats.StatList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrinkSoymilkRamune.java    From TofuCraftReload with MIT License 6 votes vote down vote up
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
  {
if (entityLiving instanceof EntityPlayer)
      {
          EntityPlayer entityplayer = (EntityPlayer)entityLiving;
          entityplayer.getFoodStats().addStats(this, stack);
          worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
          this.onFoodEaten(stack, worldIn, entityplayer);
          entityplayer.addStat(StatList.getObjectUseStats(this));
          if (entityplayer instanceof EntityPlayerMP)
          {
              CriteriaTriggers.CONSUME_ITEM.trigger((EntityPlayerMP)entityplayer, stack);
          }
      }
return new ItemStack(Items.GLASS_BOTTLE);
  }
 
Example #2
Source File: BlockMarbleIce.java    From Chisel with GNU General Public License v2.0 6 votes vote down vote up
@Override
    public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
    {
        super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);

        par2EntityPlayer.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(this)], 1);
        par2EntityPlayer.addExhaustion(0.025F);

/*
        if(this.canSilkHarvest(par1World, par2EntityPlayer, par3, par4, par5, par6) && EnchantmentHelper.getSilkTouchModifier(par2EntityPlayer))
        {
            ItemStack itemstack = this.createStackedBlock(par6);

            if(itemstack != null)
            {
                this.dropBlockAsItem(par1World, par3, par4, par5, itemstack);
            }
        }
        */
    }
 
Example #3
Source File: CraftStatistic.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public static net.minecraft.stats.StatBase getMaterialStatistic(org.bukkit.Statistic stat, Material material) {
    try {
        if (stat == Statistic.MINE_BLOCK) {
            return StatList.mineBlockStatArray[material.getId()];
        }
        if (stat == Statistic.CRAFT_ITEM) {
            return StatList.objectCraftStats[material.getId()];
        }
        if (stat == Statistic.USE_ITEM) {
            return StatList.objectUseStats[material.getId()];
        }
        if (stat == Statistic.BREAK_ITEM) {
            return StatList.objectBreakStats[material.getId()];
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        return null;
    }
    return null;
}
 
Example #4
Source File: JSONWorldDataHelper.java    From malmo with MIT License 6 votes vote down vote up
/** Builds the basic achievement world data to be used as observation signals by the listener.
 * @param json a JSON object into which the achievement stats will be added.
 */
public static void buildAchievementStats(JsonObject json, EntityPlayerMP player)
{
    StatisticsManagerServer sfw = player.getStatFile();
    json.addProperty("DistanceTravelled", 
            sfw.readStat((StatBase)StatList.WALK_ONE_CM) 
            + sfw.readStat((StatBase)StatList.SWIM_ONE_CM)
            + sfw.readStat((StatBase)StatList.DIVE_ONE_CM) 
            + sfw.readStat((StatBase)StatList.FALL_ONE_CM)
            ); // TODO: there are many other ways of moving!
    json.addProperty("TimeAlive", sfw.readStat((StatBase)StatList.TIME_SINCE_DEATH));
    json.addProperty("MobsKilled", sfw.readStat((StatBase)StatList.MOB_KILLS));
    json.addProperty("PlayersKilled", sfw.readStat((StatBase)StatList.PLAYER_KILLS));
    json.addProperty("DamageTaken", sfw.readStat((StatBase)StatList.DAMAGE_TAKEN));
    json.addProperty("DamageDealt", sfw.readStat((StatBase)StatList.DAMAGE_DEALT));

    /* Other potential reinforcement signals that may be worth researching:
    json.addProperty("BlocksDestroyed", sfw.readStat((StatBase)StatList.objectBreakStats) - but objectBreakStats is an array of 32000 StatBase objects - indexed by block type.);
    json.addProperty("Blocked", ev.player.isMovementBlocked()) - but isMovementBlocker() is a protected method (can get round this with reflection)
    */
}
 
Example #5
Source File: EntityShopkeeper.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
public boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack) {
	boolean flag = stack != null && stack.getItem() == Items.SPAWN_EGG;

	if (!flag && isEntityAlive() && !isTrading() && !isChild() && !player.isSneaking()) {

		if (!this.world.isRemote) {

			RepData rep = getReputation(player);

			if (rep.rep.equals(ReputationLevel.OUTCAST) || rep.rep.equals(ReputationLevel.ENEMY) || rep.rep.equals(ReputationLevel.VILLAIN)) {
				chat(player, "I WILL NOT TRADE WITH A " + rep.rep);
			} else {
				this.setCustomer(player);
				player.displayVillagerTradeGui(this);
			}

		}

		player.addStat(StatList.TALKED_TO_VILLAGER);
		return true;
	} else {
		return super.processInteract(player, hand);
	}
}
 
Example #6
Source File: SpigotConfig.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
private static void stats() {
    disableStatSaving = getBoolean("stats.disable-saving", false);

    if (!config.contains("stats.forced-stats")) {
        config.createSection("stats.forced-stats");
    }

    ConfigurationSection section = config.getConfigurationSection("stats.forced-stats");
    for (String name : section.getKeys(true)) {
        if (section.isInt(name)) {
            if (StatList.getOneShotStat(name) == null) {
                Bukkit.getLogger().log(Level.WARNING, "Ignoring non existent stats.forced-stats " + name);
                continue;
            }
            forcedStats.put(name, section.getInt(name));
        }
    }
}
 
Example #7
Source File: CraftStatistic.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static StatBase getMaterialStatistic(Statistic stat, Material material) {
    try {
        if (stat == Statistic.MINE_BLOCK) {
            return StatList.getBlockStats(CraftMagicNumbers.getBlock(material)); // PAIL: getMineBlockStatistic
        }
        if (stat == Statistic.CRAFT_ITEM) {
            return StatList.getCraftStats(CraftMagicNumbers.getItem(material)); // PAIL: getCraftItemStatistic
        }
        if (stat == Statistic.USE_ITEM) {
            return StatList.getObjectUseStats(CraftMagicNumbers.getItem(material)); // PAIL: getUseItemStatistic
        }
        if (stat == Statistic.BREAK_ITEM) {
            return StatList.getObjectBreakStats(CraftMagicNumbers.getItem(material)); // PAIL: getBreakItemStatistic
        }
        if (stat == Statistic.PICKUP) {
            return StatList.getObjectsPickedUpStats(CraftMagicNumbers.getItem(material)); // PAIL: getPickupStatistic
        }
        if (stat == Statistic.DROP) {
            return StatList.getDroppedObjectStats(CraftMagicNumbers.getItem(material)); // PAIL: getDropItemStatistic
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        return null;
    }
    return null;
}
 
Example #8
Source File: BlockYuba.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, @Nullable ItemStack stack)
{
    player.addStat(StatList.getBlockStats(this), 1);
    player.addExhaustion(0.025F);

    if (this.canSilkHarvest(worldIn, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
    {
        this.dropYuba(worldIn, pos, state);
    }
    else
    {
        if (stack != null && OreDictionary.containsMatch(false, OreDictionary.getOres("stickWood"), new ItemStack(Items.STICK)))
        {
            this.dropYuba(worldIn, pos, state);
        }
    }
}
 
Example #9
Source File: ItemFukumame.java    From TofuCraftReload with MIT License 6 votes vote down vote up
/**
 * Called when the equipped item is right clicked.
 */
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack stack = playerIn.getHeldItem(handIn);

    if (!playerIn.capabilities.isCreativeMode) {
        stack.damageItem(1, playerIn);
    }

    worldIn.playSound((EntityPlayer) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_EGG_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
    playerIn.getCooldownTracker().setCooldown(this, 4);

    if (!worldIn.isRemote) {
        for (int i = 0; i < 6; i++) {
            EntityFukumame entityfukumame = new EntityFukumame(worldIn, playerIn);

            float d0 = (worldIn.rand.nextFloat() * 12.0F) - 6.0F;
            applyEffect(entityfukumame, stack);

            entityfukumame.shoot(playerIn, playerIn.rotationPitch,playerIn.rotationYaw + d0,0.0F, 1.5f, 1.0F);
            worldIn.spawnEntity(entityfukumame);
        }
    }

    playerIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example #10
Source File: BlockUnderVine.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
    if (!worldIn.isRemote && stack.getItem() == Items.SHEARS) {
        player.addStat(StatList.getBlockStats(this));
        spawnAsEntity(worldIn, pos, new ItemStack(this, 1));
    } else {
        super.harvestBlock(worldIn, player, pos, state, te, stack);
    }
}
 
Example #11
Source File: OpenBlock.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, @Nonnull ItemStack stack) {
	player.addStat(StatList.getBlockStats(this));
	player.addExhaustion(0.025F);

	if (canSilkHarvest(world, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0) {
		handleSilkTouchDrops(world, player, pos, state, te);
	} else {
		handleNormalDrops(world, player, pos, state, te, stack);
	}
}
 
Example #12
Source File: MoCBlockLeaf.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l)
{
    if (!world.isRemote && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.shears.itemID)
    {
        entityplayer.addStat(StatList.mineBlockStatArray[blockID], 1);
        dropBlockAsItem_do(world, i, j, k, new ItemStack(MoCreatures.mocLeaf.blockID, 1, l & 3));
    }
    else
    {
        super.harvestBlock(world, entityplayer, i, j, k, l);
    }
}
 
Example #13
Source File: BlockBackpack.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
	player.addStat(StatList.getBlockStats(this));
	player.addExhaustion(0.005F);

	harvesters.set(player);
	dropBackpack(worldIn, pos, te);
	harvesters.set(null);
}
 
Example #14
Source File: DyeWashingHandler.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPlayerInteractBlock(PlayerInteractEvent.RightClickBlock event) {
	
	if (event.getWorld().isRemote ||
	    event.getEntityPlayer().isSneaking()) return;
	
	// Check if item is washable and currently dyed.
	ItemStack stack = event.getItemStack();
	if (!(stack.getItem() instanceof IDyeableItem) ||
	    !((IDyeableItem)stack.getItem()).canWash(stack) ||
	    !NbtUtils.has(stack, "display", "color")) return;
	
	// Check if block is a cauldron.
	IBlockState state = event.getWorld().getBlockState(event.getPos());
	if (!(state.getBlock() instanceof BlockCauldron)) return;
	BlockCauldron block = (BlockCauldron)state.getBlock();
	
	// Check if water is in the cauldron.
	int level = state.getValue(BlockCauldron.LEVEL);
	if (level <= 0) return;
	
	// Remove the color from the item!
	NbtUtils.remove(stack, "display", "color");
	// Use up some water from the cauldron!
	block.setWaterLevel(event.getWorld(), event.getPos(), state, level - 1);
	// Increase "armor cleaned" statistic! Wheee!
	event.getEntityPlayer().addStat(StatList.ARMOR_CLEANED);
	
	// Cancel the event, as the item / cauldron was used.
	event.setCanceled(true);
	
}
 
Example #15
Source File: EntityTofunian.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public boolean processInteract(EntityPlayer player, EnumHand hand) {
    ItemStack itemstack = player.getHeldItem(hand);
    boolean flag = itemstack.getItem() == Items.NAME_TAG;

    if (flag) {
        itemstack.interactWithEntity(player, this, hand);
        return true;
    } else if (!this.holdingSpawnEggOfClass(itemstack, this.getClass()) && this.isEntityAlive() && !this.isTrading() && !this.isChild() && !player.isSneaking()) {
        if (this.buyingList == null) {
            this.initTrades();
        }

        if (hand == EnumHand.MAIN_HAND) {
            player.addStat(StatList.TALKED_TO_VILLAGER);
        }

        if (!this.world.isRemote && !this.buyingList.isEmpty()) {
            this.setCustomer(player);
            player.displayVillagerTradeGui(this);
        } else if (this.buyingList.isEmpty()) {
            return super.processInteract(player, hand);
        }

        return true;
    } else {
        return super.processInteract(player, hand);
    }
}
 
Example #16
Source File: ItemBaseOmnitool.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    if (player.worldObj.isRemote) {
        return false;
    }
    Block block = player.worldObj.getBlock(x, y, z);
    if (block instanceof IShearable) {
        IShearable target = (IShearable) block;
        if (target.isShearable(stack, player.worldObj, x, y, z)) {
            ArrayList<ItemStack> drops = target.onSheared(stack, player.worldObj, x, y, z,
                    EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
            Random rand = new Random();
            for (ItemStack drop : drops) {
                float f = 0.7F;
                double d = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                double d1 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                double d2 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                EntityItem entityitem = new EntityItem(player.worldObj, (double) x + d, (double) y + d1, (double) z + d2, drop);
                entityitem.delayBeforeCanPickup = 10;
                player.worldObj.spawnEntityInWorld(entityitem);
            }
            stack.damageItem(1, player);
            player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1);
        }
    }
    return false;
}
 
Example #17
Source File: ItemBaseChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    if (player.worldObj.isRemote) {
        return false;
    }
    Block block = player.worldObj.getBlock(x, y, z);
    if (block instanceof IShearable) {
        IShearable target = (IShearable) block;
        if (target.isShearable(stack, player.worldObj, x, y, z)) {
            ArrayList<ItemStack> drops = target.onSheared(stack, player.worldObj, x, y, z,
                    EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
            Random rand = new Random();
            for (ItemStack drop : drops) {
                float f = 0.7F;
                double d = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                double d1 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                double d2 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                EntityItem entityitem = new EntityItem(player.worldObj, (double) x + d, (double) y + d1, (double) z + d2, drop);
                entityitem.delayBeforeCanPickup = 10;
                player.worldObj.spawnEntityInWorld(entityitem);
            }
            stack.damageItem(1, player);
            player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1);
        }
    }
    return false;
}
 
Example #18
Source File: BlockCarvableIce.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) {
	super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);

	par2EntityPlayer.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(this)], 1);
	par2EntityPlayer.addExhaustion(0.025F);

	/*
	 * if(this.canSilkHarvest(par1World, par2EntityPlayer, par3, par4, par5, par6) && EnchantmentHelper.getSilkTouchModifier(par2EntityPlayer)) { ItemStack itemstack =
	 * this.createStackedBlock(par6);
	 * 
	 * if(itemstack != null) { this.dropBlockAsItem(par1World, par3, par4, par5, itemstack); } }
	 */
}
 
Example #19
Source File: BlockCarvablePackedIce.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) {
	super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);

	par2EntityPlayer.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(this)], 1);
	par2EntityPlayer.addExhaustion(0.025F);

	/*
	 * if(this.canSilkHarvest(par1World, par2EntityPlayer, par3, par4, par5, par6) && EnchantmentHelper.getSilkTouchModifier(par2EntityPlayer)) { ItemStack itemstack =
	 * this.createStackedBlock(par6);
	 * 
	 * if(itemstack != null) { this.dropBlockAsItem(par1World, par3, par4, par5, itemstack); } }
	 */
}
 
Example #20
Source File: ItemPLFood.java    From Production-Line with MIT License 5 votes vote down vote up
@Nullable
@Override
public ItemStack onItemUseFinish(@Nonnull ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
    --stack.stackSize;

    if (entityLiving instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) entityLiving;
        entityplayer.getFoodStats().addStats(healAmount, saturationModifier);
        worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
        this.onEaten(stack, worldIn, entityplayer);
        entityplayer.addStat(StatList.getObjectUseStats(this));
    }

    return stack;
}
 
Example #21
Source File: ItemBugle.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack stack = playerIn.getHeldItem(handIn);

    playerIn.getCooldownTracker().setCooldown(stack.getItem(), 100);

    playerIn.playSound(TofuSounds.TOFUBUGLE, 20.0F, 1.0F);
    playerIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example #22
Source File: CraftMagicNumbers.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<String> tabCompleteInternalStatisticOrAchievementName(String token, List<String> completions) {
    List<String> matches = new ArrayList<String>();
    Iterator iterator = StatList.ALL_STATS.iterator();
    while (iterator.hasNext()) {
        String statistic = ((net.minecraft.stats.StatBase) iterator.next()).statId;
        if (statistic.startsWith(token)) {
            matches.add(statistic);
        }
    }
    return matches;
}
 
Example #23
Source File: GTItemFluidTube.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActionResult<ItemStack> tryPlaceFluid(@Nonnull World world, @Nonnull EntityPlayer player,
		@Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) {
	RayTraceResult mop = this.rayTrace(world, player, false);
	ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop);
	if (ret != null)
		return ret;
	if (mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK) {
		return ActionResult.newResult(EnumActionResult.PASS, itemstack);
	}
	BlockPos clickPos = mop.getBlockPos();
	if (world.isBlockModifiable(player, clickPos)) {
		BlockPos targetPos = clickPos.offset(mop.sideHit);
		if (player.canPlayerEdit(targetPos, mop.sideHit, itemstack)) {
			FluidActionResult result = FluidUtil.tryPlaceFluid(player, world, targetPos, itemstack, fluidStack);
			if (result.isSuccess() && !player.capabilities.isCreativeMode) {
				player.addStat(StatList.getObjectUseStats(this));
				itemstack.shrink(1);
				ItemStack emptyStack = new ItemStack(GTItems.testTube);
				if (itemstack.isEmpty()) {
					return ActionResult.newResult(EnumActionResult.SUCCESS, emptyStack);
				} else {
					ItemHandlerHelper.giveItemToPlayer(player, emptyStack);
					return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
				}
			}
		}
	}
	return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
 
Example #24
Source File: BlockTofuYuba.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
    if (!worldIn.isRemote && stack.getItem() == Items.SHEARS) {
        player.addStat(StatList.getBlockStats(this));
        spawnAsEntity(worldIn, pos, new ItemStack(BlockLoader.yubaGrass, 1));
    } else {
        super.harvestBlock(worldIn, player, pos, state, te, stack);
    }
}
 
Example #25
Source File: CraftStatistic.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public static net.minecraft.stats.Achievement getNMSAchievement(org.bukkit.Achievement achievement) {
    return (net.minecraft.stats.Achievement) StatList.func_151177_a(achievements.inverse().get(achievement));
}
 
Example #26
Source File: ItemRiceSeed.java    From TofuCraftReload with MIT License 4 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

    if (raytraceresult == null)
    {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
    }
    else
    {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
            {
                return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
            }

            BlockPos blockpos1 = blockpos.up();
            IBlockState iblockstate = worldIn.getBlockState(blockpos);

            if (iblockstate.getMaterial() == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
            {
                // special case for handling block placement with water lilies
                net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
                worldIn.setBlockState(blockpos1, BlockLoader.RICECROP.getDefaultState());
                if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, handIn).isCanceled())
                {
                    blocksnapshot.restore(true, false);
                    return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
                }

                worldIn.setBlockState(blockpos1, BlockLoader.RICECROP.getDefaultState(), 11);

                if (playerIn instanceof EntityPlayerMP)
                {
                    CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)playerIn, blockpos1, itemstack);
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    itemstack.shrink(1);
                }

                playerIn.addStat(StatList.getObjectUseStats(this));
                worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
            }
        }

        return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
    }
}
 
Example #27
Source File: CraftStatistic.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public static net.minecraft.stats.StatBase getNMSStatistic(org.bukkit.Statistic statistic) {
    return StatList.func_151177_a(statistics.inverse().get(statistic));
}
 
Example #28
Source File: ItemWaterHyacinth.java    From Production-Line with MIT License 4 votes vote down vote up
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

    if (raytraceresult == null) {
        return new ActionResult<>(EnumActionResult.PASS, itemStackIn);
    } else {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn)) {
                return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
            }

            BlockPos blockpos1 = blockpos.up();
            IBlockState iblockstate = worldIn.getBlockState(blockpos);

            if (iblockstate.getMaterial() == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL) == 0 && worldIn.isAirBlock(blockpos1)) {
                // special case for handling block placement with water lilies
                net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
                worldIn.setBlockState(blockpos1, PLBlocks.waterHyacinth.getDefaultState());
                if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP).isCanceled()) {
                    blocksnapshot.restore(true, false);
                    return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
                }

                worldIn.setBlockState(blockpos1, PLBlocks.waterHyacinth.getDefaultState(), 11);

                if (!playerIn.capabilities.isCreativeMode) {
                    --itemStackIn.stackSize;
                }

                playerIn.addStat(StatList.getObjectUseStats(this));
                worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
            }
        }

        return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
    }
}
 
Example #29
Source File: BlockPitKiln.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
	player.addStat(StatList.getBlockStats(this));
	player.addExhaustion(0.005F);
}
 
Example #30
Source File: ItemZundaBow.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
{
    if (entityLiving instanceof EntityPlayer)
    {
        EntityPlayer entityplayer = (EntityPlayer)entityLiving;
        boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemstack = this.findAmmo(entityplayer);

        int i = this.getMaxItemUseDuration(stack) - timeLeft;
        i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
        if (i < 0) return;

        if (!itemstack.isEmpty() || flag)
        {
            if (itemstack.isEmpty())
            {
                itemstack = new ItemStack(Items.ARROW);
            }

            float f = getArrowVelocity(i);

            if ((double)f >= 0.1D)
            {
                boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));

                if (!worldIn.isRemote)
                {
                    ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
                    EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
                    entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.05F, 1.0F);

                    if (f == 1.0F)
                    {
                        entityarrow.setIsCritical(true);
                    }

                    int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);

                    if(entityarrow instanceof EntityZundaArrow){
                        entityarrow.setDamage(entityarrow.getDamage() + 2.0D);
                    }

                    if (j > 0)
                    {
                        entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
                    }


                    int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);

                    if (k > 0)
                    {
                        entityarrow.setKnockbackStrength(k);
                    }

                    if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
                    {
                        entityarrow.setFire(100);
                    }

                    stack.damageItem(1, entityplayer);

                    if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW))
                    {
                        entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                    }

                    worldIn.spawnEntity(entityarrow);
                }

                worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

                if (!flag1 && !entityplayer.capabilities.isCreativeMode)
                {
                    itemstack.shrink(1);

                    if (itemstack.isEmpty())
                    {
                        entityplayer.inventory.deleteStack(itemstack);
                    }
                }

                entityplayer.addStat(StatList.getObjectUseStats(this));
            }
        }
    }
}