use of net.minecraft.world.phys.Vec3 in project SpongeCommon 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.Vec3 in project SpongeCommon by SpongePowered.
the class CommandSourceStackMixin method impl$updateCauseOnWithPosition.
@Inject(method = "withPosition", at = @At("RETURN"))
private void impl$updateCauseOnWithPosition(final Vec3 pos, final CallbackInfoReturnable<CommandSourceStack> cir) {
if (cir.getReturnValue() != (Object) this) {
final org.spongepowered.math.vector.Vector3d position = VecHelper.toVector3d(pos);
final ServerLocation location = this.impl$cause.context().get(EventContextKeys.LOCATION).map(x -> ServerLocation.of(x.world(), position)).orElseGet(() -> ServerLocation.of((org.spongepowered.api.world.server.ServerWorld) cir.getReturnValue().getLevel(), position));
((CommandSourceStackBridge) cir.getReturnValue()).bridge$setCause(this.impl$applyToCause(EventContextKeys.LOCATION, location));
}
}
use of net.minecraft.world.phys.Vec3 in project Totemic by TeamTotemic.
the class SpiderEffect method applyEffectTick.
@Override
public void applyEffectTick(LivingEntity entity, int amplifier) {
if (entity.horizontalCollision) {
entity.fallDistance = 0.0F;
float velocity = 0.15F;
Vec3 motion = entity.getDeltaMovement();
double motionX = Mth.clamp(motion.x, -velocity, velocity);
double motionY = 0.2;
double motionZ = Mth.clamp(motion.z, -velocity, velocity);
if (entity.isSuppressingSlidingDownLadder()) {
motionY = 0.0;
}
entity.setDeltaMovement(motionX, motionY, motionZ);
}
}
use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.
the class FishingBobberEntity method updateRotation.
private void updateRotation() {
Vec3 Vector3d = this.getDeltaMovement();
float f = Mth.sqrt((float) distanceToSqr(Vector3d));
this.setYRot((float) (Mth.atan2(Vector3d.x, Vector3d.z) * (double) (180F / (float) Math.PI)));
for (this.setXRot((float) (Mth.atan2(Vector3d.y, (double) f) * (double) (180F / (float) Math.PI))); this.getXRot() - this.xRotO < -180.0F; this.xRotO -= 360.0F) {
}
while (this.getXRot() - this.xRotO >= 180.0F) {
this.xRotO += 360.0F;
}
while (this.getYRot() - this.yRotO < -180.0F) {
this.yRotO -= 360.0F;
}
while (this.getYRot() - this.yRotO >= 180.0F) {
this.yRotO += 360.0F;
}
this.setXRot(Mth.lerp(0.2F, this.xRotO, this.getXRot()));
this.setYRot(Mth.lerp(0.2F, this.yRotO, this.getYRot()));
}
use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.
the class EntityAIChillAtFire method tick.
@Override
public void tick() {
super.tick();
boolean isClose = false;
BlockPos blockposGoal = null;
if (this.entityObj.posLastFireplaceFound != null) {
// path to base of fire
blockposGoal = this.entityObj.posLastFireplaceFound.offset(0, -1, 0);
} else {
blockposGoal = this.entityObj.getRestrictCenter();
}
if (blockposGoal.equals(BlockPos.ZERO)) {
stop();
return;
}
// prevent walking into the fire
double dist = entityObj.position().distanceTo(new Vec3(blockposGoal.getX(), blockposGoal.getY(), blockposGoal.getZ()));
if (dist < 4D && entityObj.isOnGround()) {
entityObj.setSitting(true);
entityObj.getNavigation().stop();
isClose = true;
if (lookUpdateTimer <= 0) {
lookUpdateTimer = 200 + entityObj.level.random.nextInt(100);
int range = 2;
randXPos = entityObj.level.random.nextInt(range) - entityObj.level.random.nextInt(range);
// stargaze
if (entityObj.level.random.nextInt(3) == 0) {
randYPos = 5 + entityObj.level.random.nextInt(5);
} else {
randYPos = 0;
}
randZPos = entityObj.level.random.nextInt(range) - entityObj.level.random.nextInt(range);
if (entityObj.getId() % 3 == 0) {
entityObj.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(TropicraftItems.BAMBOO_MUG.get()));
} else if (entityObj.getId() % 5 == 0) {
entityObj.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(TropicraftItems.COOKED_FROG_LEG.get()));
} else {
entityObj.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(TropicraftItems.ORANGE.get()));
}
entityObj.heal(1);
}
this.entityObj.getLookControl().setLookAt(blockposGoal.getX() + randXPos, blockposGoal.getY() + randYPos + 1D, blockposGoal.getZ() + randZPos, 8F, 8F);
} else {
entityObj.setSitting(false);
}
if (!isClose) {
if ((this.entityObj.getNavigation().isDone() || walkingTimeout <= 0) && repathPentalty <= 0) {
int i = blockposGoal.getX();
int j = blockposGoal.getY();
int k = blockposGoal.getZ();
boolean success = false;
if (this.entityObj.distanceToSqr(Vec3.atCenterOf(blockposGoal)) > 256.0D) {
Vec3 Vector3d = DefaultRandomPos.getPosTowards(this.entityObj, 14, 3, new Vec3((double) i + 0.5D, (double) j, (double) k + 0.5D), (float) Math.PI / 2F);
if (Vector3d != null) {
success = this.entityObj.getNavigation().moveTo(Vector3d.x, Vector3d.y, Vector3d.z, 1.0D);
} else {
success = Util.tryMoveToXYZLongDist(this.entityObj, new BlockPos(i, j, k), 1);
}
} else {
success = this.entityObj.getNavigation().moveTo((double) i + 0.5D, (double) j, (double) k + 0.5D, 1.0D);
}
if (!success) {
repathPentalty = 40;
} else {
walkingTimeout = walkingTimeoutMax;
}
} else {
if (walkingTimeout > 0) {
walkingTimeout--;
} else {
}
}
}
if (repathPentalty > 0) {
repathPentalty--;
}
if (lookUpdateTimer > 0) {
lookUpdateTimer--;
}
}
Aggregations