use of net.minecraft.world.phys.BlockHitResult in project BYG by AOCAWOL.
the class BYGLilyItem method use.
public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {
ItemStack itemstack = playerIn.getItemInHand(handIn);
HitResult raytraceresult = getPlayerPOVHitResult(worldIn, playerIn, ClipContext.Fluid.SOURCE_ONLY);
if (raytraceresult.getType() == HitResult.Type.MISS) {
return new InteractionResultHolder<>(InteractionResult.PASS, itemstack);
} else {
if (raytraceresult.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockraytraceresult = (BlockHitResult) raytraceresult;
BlockPos blockpos = blockraytraceresult.getBlockPos();
Direction direction = blockraytraceresult.getDirection();
if (!worldIn.mayInteract(playerIn, blockpos) || !playerIn.mayUseItemAt(blockpos.relative(direction), direction, itemstack)) {
return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack);
}
BlockPos blockpos1 = blockpos.above();
BlockState blockstate = worldIn.getBlockState(blockpos);
Material material = blockstate.getMaterial();
FluidState FluidState = worldIn.getFluidState(blockpos);
if ((FluidState.getType() == Fluids.WATER || material == Material.ICE) && worldIn.isEmptyBlock(blockpos1)) {
// special case for handling block placement with water lilies
worldIn.setBlock(blockpos1, BYGBlocks.TINY_LILYPADS.defaultBlockState(), 11);
if (playerIn instanceof ServerPlayer) {
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) playerIn, blockpos1, itemstack);
}
if (!playerIn.getAbilities().instabuild) {
itemstack.shrink(1);
}
playerIn.awardStat(Stats.ITEM_USED.get(this));
worldIn.playSound(playerIn, blockpos, SoundEvents.LILY_PAD_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack);
}
}
return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack);
}
}
use of net.minecraft.world.phys.BlockHitResult in project BYG by AOCAWOL.
the class BYGWaterSilkItem method use.
public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {
ItemStack itemstack = playerIn.getItemInHand(handIn);
HitResult raytraceresult = getPlayerPOVHitResult(worldIn, playerIn, ClipContext.Fluid.SOURCE_ONLY);
if (raytraceresult.getType() == HitResult.Type.MISS) {
return new InteractionResultHolder<>(InteractionResult.PASS, itemstack);
} else {
if (raytraceresult.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockraytraceresult = (BlockHitResult) raytraceresult;
BlockPos blockpos = blockraytraceresult.getBlockPos();
Direction direction = blockraytraceresult.getDirection();
if (!worldIn.mayInteract(playerIn, blockpos) || !playerIn.mayUseItemAt(blockpos.relative(direction), direction, itemstack)) {
return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack);
}
BlockPos blockpos1 = blockpos.above();
BlockState blockstate = worldIn.getBlockState(blockpos);
Material material = blockstate.getMaterial();
FluidState FluidState = worldIn.getFluidState(blockpos);
if ((FluidState.getType() == Fluids.WATER || material == Material.ICE) && worldIn.isEmptyBlock(blockpos1)) {
// special case for handling block placement with water lilies
worldIn.setBlock(blockpos1, BYGBlocks.WATER_SILK.defaultBlockState(), 11);
if (playerIn instanceof ServerPlayer) {
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) playerIn, blockpos1, itemstack);
}
if (!playerIn.getAbilities().instabuild) {
itemstack.shrink(1);
}
playerIn.awardStat(Stats.ITEM_USED.get(this));
worldIn.playSound(playerIn, blockpos, SoundEvents.LILY_PAD_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack);
}
}
return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack);
}
}
use of net.minecraft.world.phys.BlockHitResult in project MysticTools by binary404.
the class ItemLootPickaxe method onBlockStartBreak.
@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
LootRarity rarity = LootRarity.fromId(ModAttributes.LOOT_RARITY.getOrDefault(stack, "common").getValue(stack));
if (rarity == LootRarity.fromId("unique")) {
BlockState state = player.level.getBlockState(pos);
UniqueEffect.getUniqueEffect(stack).breakBlock(pos, player.level, player, stack, state);
}
boolean onBreak = super.onBlockStartBreak(stack, pos, player);
LootItemHelper.handleBreak(stack, player, pos);
if (LootItemHelper.hasEffect(stack, LootEffect.getById("area_miner")) && LootItemHelper.getEffectLevel(stack) >= 1) {
HitResult raytrace = LootItemHelper.getBlockOnReach(player.level, player);
if (raytrace != null) {
int level = LootItemHelper.getEffectLevel(stack);
onBreak = LootItemHelper.breakBlocks(stack, level, player.level, pos, ((BlockHitResult) raytrace).getDirection(), player);
}
}
return onBreak;
}
use of net.minecraft.world.phys.BlockHitResult in project SimpleOres2 by Sinhika.
the class ForgeEventSubscriber method FillBucket.
// end LootLoad()
/**
* deal with copper bucket poking lava.
*/
@SubscribeEvent
public static void FillBucket(final FillBucketEvent event) {
if (event.getEmptyBucket().getItem() == ModItems.copper_bucket.get()) {
if (event.getTarget().getType() == HitResult.Type.BLOCK) {
BlockHitResult rtResult = (BlockHitResult) event.getTarget();
BlockPos blockpos = rtResult.getBlockPos();
Direction direction = rtResult.getDirection();
BlockPos blockpos1 = blockpos.relative(direction);
if (event.getWorld().mayInteract(event.getPlayer(), blockpos) && event.getPlayer().mayUseItemAt(blockpos1, direction, event.getEmptyBucket())) {
BlockState blockstate1 = event.getWorld().getBlockState(blockpos);
if (blockstate1.getBlock() instanceof LiquidBlock) {
FluidState fluid = ((LiquidBlock) blockstate1.getBlock()).getFluidState(blockstate1);
if (!fluid.isEmpty() && fluid.is(FluidTags.LAVA)) {
Item bucketItem = event.getEmptyBucket().getItem();
event.getPlayer().awardStat(Stats.ITEM_USED.get(bucketItem));
SoundEvent soundevent = SoundEvents.LAVA_EXTINGUISH;
event.getPlayer().playSound(soundevent, 1.0F, 1.0F);
event.setFilledBucket(ItemStack.EMPTY);
event.setResult(Result.ALLOW);
return;
}
}
// end-if
}
// end-if
}
// end-if
}
event.setResult(Result.DEFAULT);
}
use of net.minecraft.world.phys.BlockHitResult in project Botania by VazkiiMods.
the class SpawnerMoverTest method testSpawnerMover.
@GameTest(template = TestingUtil.EMPTY_STRUCTURE)
public void testSpawnerMover(GameTestHelper helper) {
var spawnerPos = BlockPos.ZERO;
var player = helper.makeMockPlayer();
var stack = new ItemStack(ModItems.spawnerMover);
helper.setBlock(spawnerPos, Blocks.SPAWNER);
player.setItemInHand(InteractionHand.MAIN_HAND, stack);
stack.useOn(new UseOnContext(player, InteractionHand.MAIN_HAND, new BlockHitResult(Vec3.ZERO, Direction.DOWN, helper.absolutePos(spawnerPos), false)));
TestingUtil.assertThat(ItemSpawnerMover.hasData(stack), () -> "Spawner mover should recognize saved data. Full NBT: " + stack.getTag());
helper.assertBlockState(spawnerPos, BlockState::isAir, () -> "Spawner should be gone");
stack.useOn(new UseOnContext(player, InteractionHand.MAIN_HAND, new BlockHitResult(Vec3.ZERO, Direction.UP, helper.absolutePos(spawnerPos.below()), false)));
helper.assertBlockPresent(Blocks.SPAWNER, spawnerPos);
TestingUtil.assertThat(stack.isEmpty(), () -> "Spawner mover should be broken after placing");
// Don't spawn mobs that interfere with other continuing tests
helper.setBlock(spawnerPos, Blocks.AIR);
helper.succeed();
}
Aggregations