use of net.minecraft.util.ActionResult in project DefiledLands by Lykrast.
the class ItemBlastemFruit method onItemRightClick.
/**
* Called when the equipped item is right clicked.
*/
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
if (!playerIn.capabilities.isCreativeMode) {
itemstack.shrink(1);
}
worldIn.playSound((EntityPlayer) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
playerIn.getCooldownTracker().setCooldown(this, 20);
if (!worldIn.isRemote) {
EntityBlastemFruit projectile = new EntityBlastemFruit(worldIn, playerIn);
projectile.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
worldIn.spawnEntity(projectile);
}
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
use of net.minecraft.util.ActionResult in project DefiledLands by Lykrast.
the class ItemRavager method onItemRightClick.
/**
* Called when the equipped item is right clicked.
*/
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
boolean flag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, itemstack) > 0;
ItemStack ammo = findAmmo(playerIn);
if (!ammo.isEmpty() || flag) {
if (ammo.isEmpty()) {
ammo = new ItemStack(ModItems.pelletUmbrium);
}
worldIn.playSound((EntityPlayer) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!worldIn.isRemote) {
Vec3d vec3d = playerIn.getLook(1.0F);
EntityRavagerProjectile projectile = new EntityRavagerProjectile(worldIn, playerIn, vec3d.x, vec3d.y, vec3d.z, getSharpshooterBonus(itemstack));
projectile.posY = playerIn.posY + (double) playerIn.getEyeHeight();
if (ammo.getItem() instanceof ItemPellet) {
((ItemPellet) ammo.getItem()).applyAttributes(projectile);
}
worldIn.spawnEntity(projectile);
itemstack.damageItem(1, playerIn);
}
if (!flag) {
consumeAmmo(itemstack, ammo, playerIn, worldIn.rand);
}
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult(EnumActionResult.SUCCESS, itemstack);
} else {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
}
}
use of net.minecraft.util.ActionResult in project DefiledLands by Lykrast.
the class ItemUmbraBlaster method onItemRightClick.
/**
* Called when the equipped item is right clicked.
*/
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
boolean flag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, itemstack) > 0;
ItemStack ammo = findAmmo(playerIn);
if (!ammo.isEmpty() || flag) {
if (ammo.isEmpty()) {
ammo = new ItemStack(ModItems.blastemFruit);
}
worldIn.playSound((EntityPlayer) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
playerIn.getCooldownTracker().setCooldown(this, 10);
if (!worldIn.isRemote) {
EntityBlastemFruit projectile;
if (ammo.getItem() == ModItems.blastemFruitBlazing || EnchantmentHelper.getEnchantmentLevel(ModEnchantments.blazing, itemstack) > 0)
projectile = new EntityBlastemFruitBlazing(worldIn, playerIn);
else
projectile = new EntityBlastemFruit(worldIn, playerIn);
float f = getSharpshooterBonus(itemstack);
projectile.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F * f, 1.0F / f);
if (EnchantmentHelper.getEnchantmentLevel(ModEnchantments.safeguard, itemstack) > 0) {
projectile.setDestructive(false);
}
float j = getDestructiveBonus(itemstack);
projectile.setDamage(projectile.getDamage() * j);
projectile.setExplosionStrength(projectile.getExplosionStrength() * j);
worldIn.spawnEntity(projectile);
itemstack.damageItem(1, playerIn);
}
if (!flag) {
consumeAmmo(itemstack, ammo, playerIn, worldIn.rand);
}
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult(EnumActionResult.SUCCESS, itemstack);
} else {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
}
}
use of net.minecraft.util.ActionResult in project Charset by CharsetMC.
the class ToolsUtils method placeBlockOrRollback.
public static ActionResult<ItemStack> placeBlockOrRollback(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos) {
ItemStack oldStack = stack.copy();
ItemStack heldItem = playerIn.getHeldItem(EnumHand.MAIN_HAND);
// Take a snapshot
IBlockState state = worldIn.getBlockState(pos);
NBTTagCompound nbtTile = null;
if (state.getBlock().hasTileEntity(state)) {
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity != null) {
nbtTile = tileEntity.writeToNBT(new NBTTagCompound());
}
}
worldIn.setBlockToAir(pos);
playerIn.setHeldItem(EnumHand.MAIN_HAND, stack);
EnumActionResult result1 = stack.onItemUse(playerIn, worldIn, pos, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
ItemStack placedItem = playerIn.getHeldItem(EnumHand.MAIN_HAND);
playerIn.setHeldItem(EnumHand.MAIN_HAND, heldItem);
if (result1 == EnumActionResult.SUCCESS && !worldIn.isAirBlock(pos)) {
// Hooray!
return new ActionResult<>(EnumActionResult.SUCCESS, placedItem);
} else {
// Rollback...
worldIn.setBlockState(pos, state);
if (nbtTile != null) {
worldIn.setTileEntity(pos, TileEntity.create(worldIn, nbtTile));
}
return new ActionResult<>(EnumActionResult.FAIL, oldStack);
}
}
use of net.minecraft.util.ActionResult in project ConvenientAdditions by Necr0.
the class ItemLocationModule method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack item = player.getHeldItem(hand);
if (!world.isRemote) {
if (!item.hasTagCompound())
item.setTagCompound(new NBTTagCompound());
if (player.isSneaking()) {
item.getTagCompound().removeTag("MODULE_LOCATION");
player.sendMessage(new TextComponentString(Helper.localize("message." + ModConstants.Mod.MODID + ":locationReset")));
return new ActionResult<>(EnumActionResult.SUCCESS, item);
}
}
return new ActionResult<>(EnumActionResult.PASS, item);
}
Aggregations