use of net.minecraft.util.ActionResult in project Random-Things by lumien231.
the class ItemStableEnderpearl method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ItemStack itemStackIn = playerIn.getHeldItem(hand);
if (!worldIn.isRemote) {
if (itemStackIn.getTagCompound() == null) {
itemStackIn.setTagCompound(new NBTTagCompound());
}
NBTTagCompound compound = itemStackIn.getTagCompound();
GameProfile gameProfile = playerIn.getGameProfile();
compound.setString("player-uuid", gameProfile.getId().toString());
compound.setString("player-name", gameProfile.getName());
}
return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
}
use of net.minecraft.util.ActionResult in project KalStuff by TEAMModding.
the class ItemClosedSoda method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
super.onItemRightClick(worldIn, playerIn, hand);
worldIn.playSound(playerIn, playerIn.posX, playerIn.posY, playerIn.posZ, KalStuffSoundEvents.CAN_OPEN, SoundCategory.PLAYERS, 1.0F, 1.0F);
ItemStack stack = playerIn.getHeldItem(hand);
stack.shrink(1);
if (stack.getCount() <= 0)
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, this.getReturnStack());
playerIn.inventory.addItemStackToInventory(this.getReturnStack());
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
use of net.minecraft.util.ActionResult in project BloodMagic by WayofTime.
the class ItemSentientArmourGem method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
boolean hasSentientArmour = false;
NonNullList<ItemStack> armourInventory = player.inventory.armorInventory;
for (ItemStack armourStack : armourInventory) {
if (armourStack != null && armourStack.getItem() instanceof ItemSentientArmour) {
hasSentientArmour = true;
}
}
if (hasSentientArmour) {
ItemSentientArmour.revertAllArmour(player);
} else {
EnumDemonWillType type = PlayerDemonWillHandler.getLargestWillType(player);
double will = PlayerDemonWillHandler.getTotalDemonWill(type, player);
// PlayerDemonWillHandler.consumeDemonWill(player, willBracket[bracket]);
ItemSentientArmour.convertPlayerArmour(type, will, player);
}
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
use of net.minecraft.util.ActionResult in project Ceramics by KnightMiner.
the class ItemClayBucket method onItemRightClick.
/* Bucket behavior */
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
// milk we set active and return success, drinking code is done elsewhere
if (getSpecialFluid(stack) == SpecialFluid.MILK) {
player.setActiveHand(hand);
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
// empty bucket logic is just an event :)
if (!hasFluid(stack)) {
ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, stack, this.rayTrace(world, player, true));
if (ret != null) {
return ret;
}
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
// clicked on a block?
RayTraceResult mop = this.rayTrace(world, player, false);
if (mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK) {
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
BlockPos clickPos = mop.getBlockPos();
// can we place liquid there?
if (world.isBlockModifiable(player, clickPos)) {
FluidStack fluidStack = getFluid(stack);
// first, try cauldron
IBlockState clickState = world.getBlockState(clickPos);
if (!player.isSneaking() && clickState.getBlock() == Blocks.CAULDRON) {
ItemStack returnStack = stack.copy();
if (clickState.getValue(BlockCauldron.LEVEL).intValue() < 3 && fluidStack.getFluid() == FluidRegistry.WATER) {
if (!player.capabilities.isCreativeMode) {
returnStack.shrink(1);
ItemStack drained = new ItemStack(this);
// if the stack is empty, relace it with the empty bucket
if (returnStack.isEmpty()) {
returnStack = drained;
} else if (!drained.isEmpty()) {
// otheriwise add empty bucket to player inventory
ItemHandlerHelper.giveItemToPlayer(player, drained);
}
}
player.addStat(StatList.CAULDRON_FILLED);
if (!world.isRemote) {
Blocks.CAULDRON.setWaterLevel(world, clickPos, clickState, 3);
}
world.playSound((EntityPlayer) null, clickPos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, returnStack);
// try fluid positions then
// can the player place there?
} else if (player.canPlayerEdit(clickPos, mop.sideHit, stack)) {
BlockPos targetPos = clickPos.offset(mop.sideHit);
// next, try special fluids
if (hasSpecialFluid(stack)) {
// get the state from the fluid
IBlockState state = getSpecialFluid(stack).getState();
// if we got a block state (not milk basically)
if (state != null) {
IBlockState currentState = world.getBlockState(targetPos);
if (currentState.getBlock().isReplaceable(world, targetPos)) {
// place block
if (!world.isRemote) {
world.setBlockState(targetPos, state);
}
// sound effect
world.playSound(player, targetPos, state.getBlock().getSoundType(state, world, targetPos, player).getPlaceSound(), SoundCategory.BLOCKS, 1.0F, 0.8F);
// only empty if not creative
if (!player.capabilities.isCreativeMode) {
player.addStat(StatList.getObjectUseStats(this));
setSpecialFluid(stack, SpecialFluid.EMPTY);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
}
// try placing liquid
} else {
FluidActionResult result = FluidUtil.tryPlaceFluid(player, player.getEntityWorld(), targetPos, stack, fluidStack);
if (result.isSuccess()) {
// water and lava place non-flowing for some reason
if (fluidStack.getFluid() == FluidRegistry.WATER || fluidStack.getFluid() == FluidRegistry.LAVA) {
IBlockState state = world.getBlockState(targetPos);
world.neighborChanged(targetPos, state.getBlock(), targetPos);
}
ItemStack returnStack = stack.copy();
if (!player.capabilities.isCreativeMode) {
returnStack.shrink(1);
ItemStack drained = result.getResult().copy();
// if the stack is empty, relace it with the empty bucket
if (returnStack.isEmpty()) {
returnStack = drained;
} else if (!drained.isEmpty()) {
// otheriwise add empty bucket to player inventory
ItemHandlerHelper.giveItemToPlayer(player, drained);
}
}
return ActionResult.newResult(EnumActionResult.SUCCESS, returnStack);
}
}
}
}
// couldn't place liquid there
return ActionResult.newResult(EnumActionResult.FAIL, stack);
}
use of net.minecraft.util.ActionResult in project CompositeGear by TwilightWingsStudio.
the class ItemCGBow 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 = !this.findAmmo(playerIn).isEmpty();
ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
if (ret != null)
return ret;
if (!playerIn.capabilities.isCreativeMode && !flag) {
return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
} else {
playerIn.setActiveHand(handIn);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
}
Aggregations