use of net.minecraft.util.TypedActionResult in project wildmod by Osmiooo.
the class FrogSpawnItem method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
BlockHitResult blockHitResult = FrogSpawnItem.raycast(world, user, RaycastContext.FluidHandling.SOURCE_ONLY);
BlockHitResult blockHitResult2 = blockHitResult.withBlockPos(blockHitResult.getBlockPos().up());
ActionResult actionResult = super.useOnBlock(new ItemUsageContext(user, hand, blockHitResult2));
return new TypedActionResult<ItemStack>(actionResult, user.getStackInHand(hand));
}
use of net.minecraft.util.TypedActionResult in project MCDungeonsWeapons by chronosacaria.
the class IOffhandAttack method useOffhand.
default TypedActionResult<ItemStack> useOffhand(World worldIn, PlayerEntity playerIn, Hand handIn) {
if (handIn == Hand.OFF_HAND && worldIn.isClient) {
CombatEventHandler.checkForOffHandAttack();
ItemStack offhand = playerIn.getStackInHand(handIn);
return new TypedActionResult<>(ActionResult.SUCCESS, offhand);
} else {
return new TypedActionResult<>(ActionResult.PASS, playerIn.getStackInHand(handIn));
}
}
use of net.minecraft.util.TypedActionResult in project CopperEquipment by Redy1aye.
the class CopperBucket method use.
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack itemStack = user.getStackInHand(hand);
BlockHitResult blockHitResult = raycast(world, user, this.fluid == Fluids.EMPTY ? RaycastContext.FluidHandling.SOURCE_ONLY : RaycastContext.FluidHandling.NONE);
if (blockHitResult.getType() == HitResult.Type.MISS) {
return TypedActionResult.pass(itemStack);
} else if (blockHitResult.getType() != HitResult.Type.BLOCK) {
return TypedActionResult.pass(itemStack);
} else {
BlockPos blockPos = blockHitResult.getBlockPos();
Direction direction = blockHitResult.getSide();
BlockPos blockPos2 = blockPos.offset(direction);
if (world.canPlayerModifyAt(user, blockPos) && user.canPlaceOn(blockPos2, direction, itemStack)) {
BlockState blockState;
if (this.fluid == Fluids.EMPTY) {
blockState = world.getBlockState(blockPos);
if (blockState.getBlock() instanceof FluidDrainable) {
FluidDrainable fluidDrainable = (FluidDrainable) blockState.getBlock();
ItemStack itemStack2 = fluidDrainable.tryDrainFluid(world, blockPos, blockState);
if (!itemStack2.isEmpty()) {
user.incrementStat(Stats.USED.getOrCreateStat(this));
fluidDrainable.getBucketFillSound().ifPresent((sound) -> {
user.playSound(sound, 1.0F, 1.0F);
});
world.emitGameEvent(user, GameEvent.FLUID_PICKUP, blockPos);
ItemStack itemStack3 = ItemUsage.exchangeStack(itemStack, user, itemStack2);
if (!world.isClient) {
Criteria.FILLED_BUCKET.trigger((ServerPlayerEntity) user, itemStack2);
}
return TypedActionResult.success(itemStack3, world.isClient());
}
}
return TypedActionResult.fail(itemStack);
} else {
blockState = world.getBlockState(blockPos);
BlockPos blockPos3 = blockState.getBlock() instanceof FluidFillable && this.fluid == Fluids.WATER ? blockPos : blockPos2;
if (this.placeFluid(user, world, blockPos3, blockHitResult)) {
this.onEmptied(user, world, itemStack, blockPos3);
if (user instanceof ServerPlayerEntity) {
Criteria.PLACED_BLOCK.trigger((ServerPlayerEntity) user, blockPos3, itemStack);
}
user.incrementStat(Stats.USED.getOrCreateStat(this));
return TypedActionResult.success(getEmptiedStack(itemStack, user), world.isClient());
} else {
return TypedActionResult.fail(itemStack);
}
}
} else {
return TypedActionResult.fail(itemStack);
}
}
}
use of net.minecraft.util.TypedActionResult in project LittleMaidReBirth-Fabric by SistrScarlet.
the class IFFCopyBookItem method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
if (world.isClient) {
return super.use(world, user, hand);
}
ItemStack stack = user.getStackInHand(hand);
Vec3d start = user.getCameraPosVec(1F);
Vec3d end = start.add(user.getRotationVector().multiply(4D));
BlockHitResult bResult = world.raycast(new RaycastContext(start, end, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, user));
if (bResult.getType() != HitResult.Type.MISS) {
end = bResult.getPos();
}
Box box = new Box(start, end).expand(1);
EntityHitResult eResult = ProjectileUtil.getEntityCollision(world, user, start, end, box, entity -> entity instanceof HasIFF);
if (eResult == null || eResult.getType() == HitResult.Type.MISS)
return super.use(world, user, hand);
Entity target = eResult.getEntity();
if (user.isSneaking()) {
ListTag list = new ListTag();
((HasIFF) target).getIFFs().forEach(iff -> list.add(iff.writeTag()));
CompoundTag tag = stack.getOrCreateTag();
tag.put("IFFs", list);
user.sendMessage(new TranslatableText("item.littlemaidrebirth.iff_copy_book.message_written"), true);
} else {
CompoundTag tag = stack.getOrCreateTag();
if (!tag.contains("IFFs")) {
return super.use(world, user, hand);
}
ListTag list = tag.getList("IFFs", 10);
((HasIFF) target).setIFFs(list.stream().map(t -> (CompoundTag) t).map(t -> IFFTypeManager.getINSTANCE().loadIFF(t)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
user.sendMessage(new TranslatableText("item.littlemaidrebirth.iff_copy_book.message_apply"), true);
}
user.world.playSound(null, user.getX(), user.getY(), user.getZ(), SoundEvents.BLOCK_NOTE_BLOCK_PLING, SoundCategory.PLAYERS, 1F, 1F);
return TypedActionResult.success(stack);
}
Aggregations