Search in sources :

Example 26 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 27 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 28 with Vec3

use of net.minecraft.world.phys.Vec3 in project MagicPlugin by elBukkit.

the class CompatibilityUtils method setEntityMotion.

@Override
public void setEntityMotion(Entity entity, Vector motion) {
    net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle();
    nms.setDeltaMovement(new Vec3(motion.getX(), motion.getY(), motion.getZ()));
}
Also used : Vec3(net.minecraft.world.phys.Vec3) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)

Example 29 with Vec3

use of net.minecraft.world.phys.Vec3 in project MagicPlugin by elBukkit.

the class CompatibilityUtils method spawnFireworkEffect.

@Override
public Entity spawnFireworkEffect(Material fireworkMaterial, Server server, Location location, FireworkEffect effect, int power, Vector direction, Integer expectedLifespan, Integer ticksFlown, boolean silent) {
    Entity entity = null;
    try {
        if (fireworkMaterial == null) {
            return null;
        }
        ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
        ItemStack itemStack = new ItemStack(fireworkMaterial);
        FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
        meta.addEffect(effect);
        meta.setPower(power);
        itemStack.setItemMeta(meta);
        Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(itemStack));
        final FireworkRocketEntity fireworkHandle = new FireworkRocketEntity(level, location.getX(), location.getY(), location.getZ(), (net.minecraft.world.item.ItemStack) item);
        fireworkHandle.setSilent(silent);
        if (direction != null) {
            fireworkHandle.setDeltaMovement(new Vec3(direction.getX(), direction.getY(), direction.getZ()));
        }
        if (ticksFlown != null) {
            ReflectionUtils.setPrivateNeedsFixing(platform.getLogger(), fireworkHandle, FireworkRocketEntity.class, "life", "e", ticksFlown);
        }
        if (expectedLifespan != null) {
            fireworkHandle.lifetime = expectedLifespan;
        }
        if (direction == null) {
            ClientboundAddEntityPacket fireworkPacket = new ClientboundAddEntityPacket(fireworkHandle, CompatibilityConstants.FIREWORK_TYPE);
            int fireworkId = fireworkHandle.getId();
            SynchedEntityData watcher = fireworkHandle.getEntityData();
            ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(fireworkId, watcher, true);
            ClientboundEntityEventPacket statusPacket = new ClientboundEntityEventPacket(fireworkHandle, (byte) 17);
            ClientboundRemoveEntityPacket destroyPacket = new ClientboundRemoveEntityPacket(fireworkId);
            Collection<? extends Player> players = server.getOnlinePlayers();
            sendPacket(server, location, players, fireworkPacket);
            sendPacket(server, location, players, metadataPacket);
            sendPacket(server, location, players, statusPacket);
            sendPacket(server, location, players, destroyPacket);
            return null;
        }
        level.addEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
        entity = fireworkHandle.getBukkitEntity();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return entity;
}
Also used : FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Entity(org.bukkit.entity.Entity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) HumanEntity(org.bukkit.entity.HumanEntity) ServerLevel(net.minecraft.server.level.ServerLevel) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) ClientboundRemoveEntityPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntityPacket) Vec3(net.minecraft.world.phys.Vec3) ClientboundEntityEventPacket(net.minecraft.network.protocol.game.ClientboundEntityEventPacket) ItemStack(org.bukkit.inventory.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)

Example 30 with Vec3

use of net.minecraft.world.phys.Vec3 in project MagicPlugin by elBukkit.

the class CompatibilityUtils method setAutoBlockState.

@Override
public boolean setAutoBlockState(Block block, Location target, BlockFace facing, boolean physics, Player originator) {
    if (block == null || facing == null || target == null)
        return false;
    net.minecraft.world.level.block.state.BlockState blockState = ((CraftBlock) block).getNMS();
    if (blockState == null)
        return false;
    net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
    ItemStack blockItem = new ItemStack(block.getType());
    ServerPlayer originatorHandle = ((CraftPlayer) originator).getHandle();
    ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
    Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(blockItem));
    if (originatorHandle == null || world == null || item == null) {
        return false;
    }
    BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
    Vec3 vec3D = new Vec3(target.getX(), target.getY(), target.getZ());
    Direction direction;
    try {
        direction = Direction.valueOf(facing.name());
    } catch (Exception ex) {
        platform.getLogger().log(Level.SEVERE, "Could not translate to NMS direction: " + facing);
        return false;
    }
    BlockHitResult hitResult = new BlockHitResult(vec3D, direction, blockPosition, false);
    BlockPlaceContext actionContext = new BlockPlaceContext(originatorHandle, InteractionHand.MAIN_HAND, (net.minecraft.world.item.ItemStack) item, hitResult);
    net.minecraft.world.level.block.state.BlockState state = nmsBlock.getStateForPlacement(actionContext);
    if (state == null)
        return false;
    ((CraftBlock) block).setTypeAndData(state, physics);
    return true;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock) Direction(net.minecraft.core.Direction) ServerPlayer(net.minecraft.server.level.ServerPlayer) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) ItemStack(org.bukkit.inventory.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Aggregations

Vec3 (net.minecraft.world.phys.Vec3)1131 BlockPos (net.minecraft.core.BlockPos)341 ItemStack (net.minecraft.world.item.ItemStack)189 Entity (net.minecraft.world.entity.Entity)133 Direction (net.minecraft.core.Direction)127 AABB (net.minecraft.world.phys.AABB)125 LivingEntity (net.minecraft.world.entity.LivingEntity)124 BlockState (net.minecraft.world.level.block.state.BlockState)111 Player (net.minecraft.world.entity.player.Player)91 BlockHitResult (net.minecraft.world.phys.BlockHitResult)85 Level (net.minecraft.world.level.Level)81 ServerLevel (net.minecraft.server.level.ServerLevel)74 ItemEntity (net.minecraft.world.entity.item.ItemEntity)74 InputWindowElement (com.simibubi.create.foundation.ponder.element.InputWindowElement)61 Selection (com.simibubi.create.foundation.ponder.Selection)53 ClipContext (net.minecraft.world.level.ClipContext)53 ServerPlayer (net.minecraft.server.level.ServerPlayer)51 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)43 HitResult (net.minecraft.world.phys.HitResult)43 WorldSectionElement (com.simibubi.create.foundation.ponder.element.WorldSectionElement)40