Search in sources :

Example 6 with Vec3

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()));
    });
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockGetterBridge(org.spongepowered.common.bridge.world.level.BlockGetterBridge) FluidState(net.minecraft.world.level.material.FluidState) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 7 with Vec3

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));
    }
}
Also used : EventContextKey(org.spongepowered.api.event.EventContextKey) CommandSourceStackAccessor(org.spongepowered.common.accessor.commands.CommandSourceStackAccessor) EventContextKeys(org.spongepowered.api.event.EventContextKeys) CommandSourceStack(net.minecraft.commands.CommandSourceStack) Inject(org.spongepowered.asm.mixin.injection.Inject) HashMap(java.util.HashMap) ServerLevel(net.minecraft.server.level.ServerLevel) EventContext(org.spongepowered.api.event.EventContext) Supplier(java.util.function.Supplier) EntityAnchorArgument(net.minecraft.commands.arguments.EntityAnchorArgument) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) MinecraftServer(net.minecraft.server.MinecraftServer) Mixin(org.spongepowered.asm.mixin.Mixin) CommandSourceStackBridge(org.spongepowered.common.bridge.commands.CommandSourceStackBridge) Map(java.util.Map) EntityAccessor(org.spongepowered.common.accessor.world.entity.EntityAccessor) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Nullable(org.checkerframework.checker.nullness.qual.Nullable) At(org.spongepowered.asm.mixin.injection.At) Mutable(org.spongepowered.asm.mixin.Mutable) Component(net.minecraft.network.chat.Component) Sponge(org.spongepowered.api.Sponge) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Final(org.spongepowered.asm.mixin.Final) SpongePermissions(org.spongepowered.common.service.server.permission.SpongePermissions) CommandSourceBridge(org.spongepowered.common.bridge.commands.CommandSourceBridge) Cause(org.spongepowered.api.event.Cause) CommandCause(org.spongepowered.api.command.CommandCause) Entity(net.minecraft.world.entity.Entity) Vec2(net.minecraft.world.phys.Vec2) Vec3(net.minecraft.world.phys.Vec3) VecHelper(org.spongepowered.common.util.VecHelper) Shadow(org.spongepowered.asm.mixin.Shadow) CommandSource(net.minecraft.commands.CommandSource) ResultConsumer(com.mojang.brigadier.ResultConsumer) ServerLocation(org.spongepowered.api.world.server.ServerLocation) ServerLocation(org.spongepowered.api.world.server.ServerLocation) CommandSourceStackBridge(org.spongepowered.common.bridge.commands.CommandSourceStackBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 8 with Vec3

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);
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3)

Example 9 with Vec3

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()));
}
Also used : Vec3(net.minecraft.world.phys.Vec3)

Example 10 with Vec3

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--;
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

Vec3 (net.minecraft.world.phys.Vec3)368 BlockPos (net.minecraft.core.BlockPos)100 LivingEntity (net.minecraft.world.entity.LivingEntity)39 Entity (net.minecraft.world.entity.Entity)37 ServerLevel (net.minecraft.server.level.ServerLevel)30 BlockHitResult (net.minecraft.world.phys.BlockHitResult)29 Direction (net.minecraft.core.Direction)28 AABB (net.minecraft.world.phys.AABB)28 Player (net.minecraft.world.entity.player.Player)26 BlockState (net.minecraft.world.level.block.state.BlockState)24 ItemStack (net.minecraft.world.item.ItemStack)22 HitResult (net.minecraft.world.phys.HitResult)21 ClipContext (net.minecraft.world.level.ClipContext)17 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)13 ServerPlayer (net.minecraft.server.level.ServerPlayer)13 Level (net.minecraft.world.level.Level)12 ItemEntity (net.minecraft.world.entity.item.ItemEntity)11 EntityHitResult (net.minecraft.world.phys.EntityHitResult)10 ItemStack (org.bukkit.inventory.ItemStack)10 Inject (org.spongepowered.asm.mixin.injection.Inject)9