use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.
the class PloughMovementBehaviour method visitNewPosition.
@Override
public void visitNewPosition(MovementContext context, BlockPos pos) {
super.visitNewPosition(context, pos);
Level world = context.world;
if (world.isClientSide)
return;
BlockPos below = pos.below();
if (!world.isLoaded(below))
return;
Vec3 vec = VecHelper.getCenterOf(pos);
PloughFakePlayer player = getPlayer(context);
if (player == null)
return;
BlockHitResult ray = world.clip(new ClipContext(vec, vec.add(0, -1, 0), Block.OUTLINE, Fluid.NONE, player));
if (ray.getType() != Type.BLOCK)
return;
UseOnContext ctx = new UseOnContext(player, InteractionHand.MAIN_HAND, ray);
new ItemStack(Items.DIAMOND_HOE).useOn(ctx);
}
use of net.minecraft.world.phys.BlockHitResult in project MoreBoots by North-West-Wind.
the class ViscousBootsItem method onLivingUpdate.
@Override
public void onLivingUpdate(final LivingEvent.LivingUpdateEvent event) {
LivingEntity entity = event.getEntityLiving();
ItemStack boots = entity.getItemBySlot(EquipmentSlot.FEET);
boolean climable = !Utils.isSurroundedByInvalidBlocks(entity) && !entity.isInLava() && !entity.isInWater() && !entity.isSpectator() && !entity.isOnGround();
Vec3 motion = entity.getDeltaMovement();
motion = motion.multiply(1, 0, 1);
boolean ascending = entity.horizontalCollision;
boolean descending = !ascending && entity.isCrouching();
if (climable) {
if (!ascending && !descending)
entity.setDeltaMovement(motion);
else if (ascending)
entity.setDeltaMovement(motion.add(0, 0.2, 0));
else
entity.setDeltaMovement(motion.subtract(0, 0.2, 0));
if (entity.getRandom().nextInt(Math.max(1, boots.getMaxDamage() - boots.getDamageValue())) == 0)
boots.hurtAndBreak(1, entity, entity1 -> entity1.playSound(SoundEvents.ITEM_BREAK, 1, 1));
entity.fallDistance = 0f;
}
BlockState state = entity.level.getBlockState(entity.blockPosition().below());
BlockState blockState = entity.level.getBlockState(entity.blockPosition());
if (blockState.is(BlockInit.VISCOUS_GOO) || !Block.isFaceFull(state.getCollisionShape(entity.level, entity.blockPosition()), Direction.UP) && (blockState.isAir() || !blockState.canBeReplaced(new BlockPlaceContext((Player) entity, InteractionHand.MAIN_HAND, new ItemStack(ItemInit.VISCOUS_GOO), new BlockHitResult(new Vec3(0.5, 1, 0.5), Direction.UP, entity.blockPosition().below(), false)))))
return;
entity.level.setBlockAndUpdate(entity.blockPosition(), BlockInit.VISCOUS_GOO.defaultBlockState());
}
use of net.minecraft.world.phys.BlockHitResult in project MoreBoots by North-West-Wind.
the class SuperAvianFeetItem method onLivingUpdate.
@Override
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
LivingEntity entity = event.getEntityLiving();
ItemStack boots = entity.getItemBySlot(EquipmentSlot.FEET);
if (!entity.hasEffect(MobEffects.MOVEMENT_SPEED) || entity.getEffect(MobEffects.MOVEMENT_SPEED).getAmplifier() < 1)
entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 5, 0, false, false, false));
if (entity.getDeltaMovement().y() < 0.02 && !entity.isCrouching()) {
entity.setDeltaMovement(entity.getDeltaMovement().multiply(1.05, 0, 1.05).add(0, -0.02, 0));
entity.hasImpulse = true;
entity.fallDistance = 0;
}
if (entity.isCrouching() && entity.isOnGround()) {
CompoundTag tag = boots.getOrCreateTag();
long tickSneak = tag.getLong("tickSneak");
tag.putLong("tickSneak", tag.getLong("tickSneak") + 1);
tickSneak += 1;
if (entity instanceof Player && !entity.level.isClientSide)
((Player) entity).displayClientMessage(new TranslatableComponent("message.moreboots.building_speed", tickSneak), true);
if (tickSneak >= 864000 && !entity.isSpectator()) {
Vec3 pos = entity.position();
tag.putLong("tickSneak", 0);
boots.setDamageValue(boots.getMaxDamage());
entity.level.explode(entity, pos.x, entity.getY(-0.0625D), pos.z, 10.0F, Explosion.BlockInteraction.BREAK);
entity.setDeltaMovement(entity.getDeltaMovement().add(0, 0.01 * 864000, 0));
if (entity instanceof Player && !entity.level.isClientSide) {
MinecraftServer server = entity.level.getServer();
ServerPlayer serverPlayerEntity = (ServerPlayer) entity;
serverPlayerEntity.getAdvancements().award(server.getAdvancements().getAdvancement(new ResourceLocation("moreboots", "moreboots/twelve_hours")), "twelve_hours");
}
}
boots.setTag(tag);
}
boolean climable = !Utils.isSurroundedByInvalidBlocks(entity) && !entity.isInLava() && !entity.isInWater() && !entity.isSpectator() && !entity.isOnGround();
Vec3 motion = entity.getDeltaMovement();
motion = motion.multiply(1, 0, 1);
boolean ascending = entity.horizontalCollision;
boolean descending = !ascending && entity.isCrouching();
if (climable) {
if (!ascending && !descending)
entity.setDeltaMovement(motion);
else if (ascending)
entity.setDeltaMovement(motion.add(0, 0.2, 0));
else
entity.setDeltaMovement(motion.subtract(0, 0.2, 0));
entity.fallDistance = 0f;
}
BlockState state = entity.level.getBlockState(entity.blockPosition().below());
if (state.getFriction(entity.level, entity.blockPosition().below(), entity) > 0.6f)
entity.addEffect(new MobEffectInstance(EffectInit.SLIPPERINESS, 600, 1, false, false));
BlockState blockState = entity.level.getBlockState(entity.blockPosition());
if (blockState.is(BlockInit.VISCOUS_GOO) || !Block.isFaceFull(state.getCollisionShape(entity.level, entity.blockPosition()), Direction.UP) && (blockState.isAir() || !blockState.canBeReplaced(new BlockPlaceContext((Player) entity, InteractionHand.MAIN_HAND, new ItemStack(ItemInit.VISCOUS_GOO), new BlockHitResult(new Vec3(0.5, 1, 0.5), Direction.UP, entity.blockPosition().below(), false)))))
return;
entity.level.setBlockAndUpdate(entity.blockPosition(), BlockInit.VISCOUS_GOO.defaultBlockState());
}
use of net.minecraft.world.phys.BlockHitResult in project Sponge by SpongePowered.
the class BlockGetterMixin_RayTraceChunkLoadOptimizations method clip.
// @formatter:on
/**
* Can be modified later when
* <a href="https://github.com/SpongePowered/Mixin/issues/355">the mixin feature</a>
* is resolved.
* <p>
* Check if a chunk is loaded before attempting to check the state of the block
* return null if the chunk is not loaded. Based on
* <a href="https://github.com/PaperMC/Paper/blob/ver/1.15.2/Spigot-Server-Patches/0331-Prevent-rayTrace-from-loading-chunks.patch#L16">a Paper patch</a>
*
* @author gabizou - Minecraft 1.15.2 - October 16th, 2020
* @reason Because this patch requires a lambda injection, I don't want
* to risk the breakages that can be caused by injecting into an interface.
*/
@Overwrite
default BlockHitResult clip(final ClipContext context) {
return BlockGetter.traverseBlocks(context, (p_217297_1_, p_217297_2_) -> {
// Sponge start - check if the blockstate is loaded/null
// final BlockState blockstate = this.shadow$getBlockState(p_217297_2_); // Vanilla
@Nullable final BlockState lvt_3_1_ = ((BlockGetterBridge) this).bridge$getBlockIfLoaded(p_217297_2_);
if (lvt_3_1_ == null) {
// copied the last function parameter (listed below)
final Vec3 vec3d = p_217297_1_.getFrom().subtract(p_217297_1_.getTo());
return BlockHitResult.miss(context.getTo(), Direction.getNearest(vec3d.x, vec3d.y, vec3d.z), new BlockPos(p_217297_1_.getTo()));
}
// Sponge end
final FluidState lvt_4_1_ = this.shadow$getFluidState(p_217297_2_);
final Vec3 lvt_5_1_ = p_217297_1_.getFrom();
final Vec3 lvt_6_1_ = p_217297_1_.getTo();
final VoxelShape lvt_7_1_ = p_217297_1_.getBlockShape(lvt_3_1_, (BlockGetter) this, p_217297_2_);
final BlockHitResult lvt_8_1_ = this.shadow$clipWithInteractionOverride(lvt_5_1_, lvt_6_1_, p_217297_2_, lvt_7_1_, lvt_3_1_);
final VoxelShape lvt_9_1_ = p_217297_1_.getFluidShape(lvt_4_1_, (BlockGetter) this, p_217297_2_);
final BlockHitResult lvt_10_1_ = lvt_9_1_.clip(lvt_5_1_, lvt_6_1_, p_217297_2_);
final double lvt_11_1_ = lvt_8_1_ == null ? 1.7976931348623157E308D : p_217297_1_.getFrom().distanceToSqr(lvt_8_1_.getLocation());
final double lvt_13_1_ = lvt_10_1_ == null ? 1.7976931348623157E308D : p_217297_1_.getFrom().distanceToSqr(lvt_10_1_.getLocation());
return lvt_11_1_ <= lvt_13_1_ ? lvt_8_1_ : lvt_10_1_;
}, (p_217302_0_) -> {
final Vec3 lvt_1_1_ = p_217302_0_.getFrom().subtract(p_217302_0_.getTo());
return BlockHitResult.miss(p_217302_0_.getTo(), Direction.getNearest(lvt_1_1_.x, lvt_1_1_.y, lvt_1_1_.z), new BlockPos(p_217302_0_.getTo()));
});
}
use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.
the class PonderScene method rayTraceScene.
public Pair<ItemStack, BlockPos> rayTraceScene(Vec3 from, Vec3 to) {
MutableObject<Pair<WorldSectionElement, BlockPos>> nearestHit = new MutableObject<>();
MutableDouble bestDistance = new MutableDouble(0);
forEach(WorldSectionElement.class, wse -> {
wse.resetSelectedBlock();
if (!wse.isVisible())
return;
Pair<Vec3, BlockPos> rayTrace = wse.rayTrace(world, from, to);
if (rayTrace == null)
return;
double distanceTo = rayTrace.getFirst().distanceTo(from);
if (nearestHit.getValue() != null && distanceTo >= bestDistance.getValue())
return;
nearestHit.setValue(Pair.of(wse, rayTrace.getSecond()));
bestDistance.setValue(distanceTo);
});
if (nearestHit.getValue() == null)
return Pair.of(ItemStack.EMPTY, null);
BlockPos selectedPos = nearestHit.getValue().getSecond();
BlockPos origin = new BlockPos(basePlateOffsetX, 0, basePlateOffsetZ);
if (!world.getBounds().isInside(selectedPos))
return Pair.of(ItemStack.EMPTY, null);
if (BoundingBox.fromCorners(origin, origin.offset(new Vec3i(basePlateSize - 1, 0, basePlateSize - 1))).isInside(selectedPos)) {
if (PonderIndex.editingModeActive())
nearestHit.getValue().getFirst().selectBlock(selectedPos);
return Pair.of(ItemStack.EMPTY, selectedPos);
}
nearestHit.getValue().getFirst().selectBlock(selectedPos);
BlockState blockState = world.getBlockState(selectedPos);
ItemStack pickBlock = blockState.getCloneItemStack(new BlockHitResult(VecHelper.getCenterOf(selectedPos), Direction.UP, selectedPos, true), world, selectedPos, Minecraft.getInstance().player);
return Pair.of(pickBlock, selectedPos);
}
Aggregations