Search in sources :

Example 1 with Vec3

use of net.minecraft.world.phys.Vec3 in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method forceInteraction.

@Override
public void forceInteraction(Player player, Location location) {
    CraftPlayer craftPlayer = (CraftPlayer) player;
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    ((CraftBlock) location.getBlock()).getNMS().use(((CraftWorld) location.getWorld()).getHandle(), craftPlayer != null ? craftPlayer.getHandle() : null, InteractionHand.MAIN_HAND, new BlockHitResult(new Vec3(0, 0, 0), null, pos, false));
}
Also used : Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 2 with Vec3

use of net.minecraft.world.phys.Vec3 in project Denizen-For-Bukkit by DenizenScript.

the class FishingHelperImpl method getRandomReward.

public ItemStack getRandomReward(FishingHook hook, ResourceLocation key) {
    ServerLevel worldServer = (ServerLevel) hook.level;
    LootContext.Builder playerFishEvent2 = new LootContext.Builder(worldServer);
    LootTables registry = ((ServerLevel) hook.level).getServer().getLootTables();
    // registry.getLootTable(key).getLootContextParameterSet()
    LootContext info = playerFishEvent2.withOptionalParameter(LootContextParams.ORIGIN, new Vec3(hook.getX(), hook.getY(), hook.getZ())).withOptionalParameter(LootContextParams.TOOL, new ItemStack(Items.FISHING_ROD)).create(LootContextParamSets.FISHING);
    List<ItemStack> itemStacks = registry.get(key).getRandomItems(info);
    return itemStacks.get(worldServer.random.nextInt(itemStacks.size()));
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LootContext(net.minecraft.world.level.storage.loot.LootContext) BuiltInLootTables(net.minecraft.world.level.storage.loot.BuiltInLootTables) LootTables(net.minecraft.world.level.storage.loot.LootTables) Vec3(net.minecraft.world.phys.Vec3) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with Vec3

use of net.minecraft.world.phys.Vec3 in project MyPet by xXKeyleXx.

the class EntityMyAquaticPet method ride.

// Special riding for Underwater
@Override
protected void ride(double motionSideways, double motionForward, double motionUpwards, float speedModifier) {
    float speed;
    if (this.isEyeInFluid(FluidTags.WATER)) {
        // No floating, just riding
        double minY;
        minY = this.getBoundingBox().minY;
        float friction = 0.91F;
        if (this.onGround) {
            friction = this.level.getBlockState(new BlockPos(Mth.floor(this.getX()), Mth.floor(minY) - 1, Mth.floor(this.getZ()))).getBlock().getFriction() * 0.91F;
        }
        speed = speedModifier * (0.16277136F / (friction * friction * friction));
        this.moveRelative(speed, new Vec3(motionSideways, motionUpwards, motionForward));
        double motX = this.getDeltaMovement().x();
        double motY = this.getDeltaMovement().y();
        double motZ = this.getDeltaMovement().z();
        Vec3 mot = new Vec3(motX, motY, motZ);
        this.move(MoverType.SELF, mot);
        motY -= 0.1D;
        motY *= 0.6D;
        motY *= 0.9800000190734863D;
        motX *= friction;
        motZ *= friction;
        this.setDeltaMovement(motX, motY, motZ);
        this.startRiding(this, false);
    } else {
        // Call normal riding when not in water
        super.ride(motionSideways, motionForward, motionUpwards, speedModifier);
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos)

Example 4 with Vec3

use of net.minecraft.world.phys.Vec3 in project MyPet by xXKeyleXx.

the class EntityMyStrider method ride.

// Special riding for Lava
@Override
protected void ride(double motionSideways, double motionForward, double motionUpwards, float speedModifier) {
    float speed;
    if (this.specialFloat()) {
        // This already has the floating/walking on Lava logic -> Now we just ride it like it's solid
        double minY;
        minY = this.getBoundingBox().minY;
        float friction = 0.91F;
        if (this.onGround) {
            friction = this.level.getBlockState(new BlockPos(Mth.floor(this.getX()), Mth.floor(minY) - 1, Mth.floor(this.getZ()))).getBlock().getFriction() * 0.91F;
        }
        speed = speedModifier * (0.16277136F / (friction * friction * friction));
        this.moveRelative(speed, new Vec3(motionSideways, motionUpwards, motionForward));
        double motX = this.getDeltaMovement().x();
        double motY = this.getDeltaMovement().y();
        double motZ = this.getDeltaMovement().z();
        Vec3 mot = new Vec3(motX, motY, motZ);
        this.move(MoverType.SELF, mot);
        if (this.horizontalCollision && this.onClimbable()) {
            motY = 0.2D;
        }
        motY -= 0.08D;
        motY *= 0.9800000190734863D;
        motX *= friction;
        motZ *= friction;
        this.setDeltaMovement(motX, motY, motZ);
        this.startRiding(this, false);
    } else {
        // Call normal riding when not in lava aka when specialFloat returned false
        super.ride(motionSideways, motionForward, motionUpwards, speedModifier);
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos)

Example 5 with Vec3

use of net.minecraft.world.phys.Vec3 in project SpongeCommon by SpongePowered.

the class ServerLevelMixin method impl$constructPostEventForEntityAdd.

@Inject(method = "addEntity", at = @At("HEAD"))
private void impl$constructPostEventForEntityAdd(final Entity entity, final CallbackInfoReturnable<Boolean> cir) {
    if (!(entity instanceof EntityBridge)) {
        return;
    }
    if (!((EntityBridge) entity).bridge$isConstructing()) {
        return;
    }
    ((EntityBridge) entity).bridge$fireConstructors();
    final Vec3 position = entity.position();
    final ServerLocation location = ServerLocation.of((ServerWorld) this, position.x(), position.y(), position.z());
    final Vec2 rotationVector = entity.getRotationVector();
    final Vector3d rotation = new Vector3d(rotationVector.x, rotationVector.y, 0);
    try (final CauseStackManager.StackFrame frame = PhaseTracker.SERVER.pushCauseFrame()) {
        frame.pushCause(entity);
        final Event construct = SpongeEventFactory.createConstructEntityEventPost(frame.currentCause(), (org.spongepowered.api.entity.Entity) entity, location, rotation, ((EntityType<?>) entity.getType()));
        SpongeCommon.post(construct);
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) ServerLocation(org.spongepowered.api.world.server.ServerLocation) Vector3d(org.spongepowered.math.vector.Vector3d) Vec2(net.minecraft.world.phys.Vec2) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Vec3(net.minecraft.world.phys.Vec3) ExplosionEvent(org.spongepowered.api.event.world.ExplosionEvent) PlaySoundEvent(org.spongepowered.api.event.sound.PlaySoundEvent) ChangeWeatherEvent(org.spongepowered.api.event.world.ChangeWeatherEvent) LightningEvent(org.spongepowered.api.event.action.LightningEvent) Event(org.spongepowered.api.event.Event) EntityBridge(org.spongepowered.common.bridge.world.entity.EntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Vec3 (net.minecraft.world.phys.Vec3)20 BlockPos (net.minecraft.core.BlockPos)9 ServerLevel (net.minecraft.server.level.ServerLevel)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 BlockHitResult (net.minecraft.world.phys.BlockHitResult)4 CauseStackManager (org.spongepowered.api.event.CauseStackManager)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 ItemStack (net.minecraft.world.item.ItemStack)3 Vec2 (net.minecraft.world.phys.Vec2)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)3 Cause (org.spongepowered.api.event.Cause)3 CommandSource (net.minecraft.commands.CommandSource)2 CommandSourceStack (net.minecraft.commands.CommandSourceStack)2 Component (net.minecraft.network.chat.Component)2 Entity (net.minecraft.world.entity.Entity)2 FluidState (net.minecraft.world.level.material.FluidState)2 BuiltInLootTables (net.minecraft.world.level.storage.loot.BuiltInLootTables)2 LootContext (net.minecraft.world.level.storage.loot.LootContext)2 LootTables (net.minecraft.world.level.storage.loot.LootTables)2 NonNull (org.checkerframework.checker.nullness.qual.NonNull)2