Search in sources :

Example 16 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class BasiliskLizardEntity method maybeBackOffFromEdge.

@Override
protected Vec3 maybeBackOffFromEdge(Vec3 offset, MoverType mover) {
    if (this.shouldWaterWalk()) {
        Vec3 result = WaterWalking.collide(this.level, this.getBoundingBox(), offset);
        this.onWaterSurface = offset.y < 0.0 && result.y != offset.y;
        return result;
    } else {
        this.onWaterSurface = false;
        return offset;
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3)

Example 17 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class ChairEntity method positionRider.

@Override
public void positionRider(Entity passenger) {
    if (this.hasPassenger(passenger)) {
        Vec3 xzOffset = new Vec3(0, 0, -0.125).yRot((float) Math.toRadians(-getYRot()));
        passenger.setPos(getX() + xzOffset.x, getY() + getPassengersRidingOffset() + passenger.getMyRidingOffset(), getZ() + xzOffset.z);
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3)

Example 18 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class BlowGunItem method fireProjectile.

public static void fireProjectile(Level world, LivingEntity shooter, InteractionHand hand, ItemStack heldItem, ItemStack projectile, float soundPitch, boolean isCreativeMode, float dmg, float pitch) {
    if (!world.isClientSide) {
        AbstractArrow arrowEntity = createArrow(world, shooter, projectile);
        if (isCreativeMode) {
            arrowEntity.pickup = AbstractArrow.Pickup.CREATIVE_ONLY;
        }
        Vec3 lookVec = shooter.getLookAngle();
        Quaternion quaternion = new Quaternion(new Vector3f(lookVec), 0, true);
        Vec3 look = shooter.getViewVector(1.0F);
        Vector3f look3f = new Vector3f(look);
        look3f.transform(quaternion);
        arrowEntity.shoot(look3f.x(), look3f.y(), look3f.z(), dmg, pitch);
        heldItem.hurtAndBreak(1, shooter, (i) -> {
            i.broadcastBreakEvent(hand);
        });
        projectile.split(1);
        if (projectile.isEmpty() && shooter instanceof Player) {
            ((Player) shooter).getInventory().removeItem(projectile);
        }
        world.addFreshEntity(arrowEntity);
        world.playSound(null, shooter.getX(), shooter.getY(), shooter.getZ(), SoundEvents.CROSSBOW_SHOOT, SoundSource.PLAYERS, 1.0F, soundPitch);
    }
}
Also used : Player(net.minecraft.world.entity.player.Player) Quaternion(com.mojang.math.Quaternion) Vec3(net.minecraft.world.phys.Vec3) Vector3f(com.mojang.math.Vector3f) AbstractArrow(net.minecraft.world.entity.projectile.AbstractArrow)

Example 19 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class FurnitureItem method use.

@Override
public InteractionResultHolder<ItemStack> use(Level world, Player placer, InteractionHand hand) {
    ItemStack heldItem = placer.getItemInHand(hand);
    HitResult rayTraceResult = getPlayerPOVHitResult(world, placer, ClipContext.Fluid.ANY);
    if (rayTraceResult.getType() == net.minecraft.world.phys.HitResult.Type.MISS) {
        return new InteractionResultHolder<>(InteractionResult.PASS, heldItem);
    } else {
        Vec3 lookvec = placer.getViewVector(1.0F);
        List<Entity> nearbyEntities = world.getEntities(placer, placer.getBoundingBox().expandTowards(lookvec.scale(5.0D)).inflate(1.0D), EntitySelector.NO_SPECTATORS);
        if (!nearbyEntities.isEmpty()) {
            Vec3 eyePosition = placer.getEyePosition(1.0F);
            Iterator<Entity> nearbyEntityIterator = nearbyEntities.iterator();
            while (nearbyEntityIterator.hasNext()) {
                Entity nearbyEnt = nearbyEntityIterator.next();
                AABB nearbyBB = nearbyEnt.getBoundingBox().inflate((double) nearbyEnt.getPickRadius());
                if (nearbyBB.contains(eyePosition)) {
                    return new InteractionResultHolder<>(InteractionResult.PASS, heldItem);
                }
            }
        }
        if (rayTraceResult.getType() == net.minecraft.world.phys.HitResult.Type.BLOCK) {
            Vec3 hitVec = rayTraceResult.getLocation();
            final T entity = this.entityType.get().create(world);
            entity.moveTo(new BlockPos(hitVec.x, hitVec.y, hitVec.z), 0, 0);
            entity.setDeltaMovement(Vec3.ZERO);
            entity.setRotation(placer.getYRot() + 180);
            entity.setColor(this.color);
            if (!world.noCollision(entity, entity.getBoundingBox().inflate(-0.1D))) {
                return new InteractionResultHolder<>(InteractionResult.FAIL, heldItem);
            } else {
                if (!world.isClientSide) {
                    world.addFreshEntity(entity);
                }
                if (!placer.getAbilities().instabuild) {
                    heldItem.shrink(1);
                }
                placer.awardStat(Stats.ITEM_USED.get(this));
                return new InteractionResultHolder<>(InteractionResult.SUCCESS, heldItem);
            }
        } else {
            return new InteractionResultHolder<>(InteractionResult.PASS, heldItem);
        }
    }
}
Also used : HitResult(net.minecraft.world.phys.HitResult) Entity(net.minecraft.world.entity.Entity) FurnitureEntity(net.tropicraft.core.common.entity.placeable.FurnitureEntity) InteractionResultHolder(net.minecraft.world.InteractionResultHolder) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) AABB(net.minecraft.world.phys.AABB)

Example 20 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class ScubaData method onPlayerTick.

@SubscribeEvent
public static void onPlayerTick(PlayerTickEvent event) {
    Level world = event.player.level;
    if (event.phase == Phase.END) {
        // TODO support more than chest slot?
        ItemStack chestStack = event.player.getItemBySlot(EquipmentSlot.CHEST);
        Item chestItem = chestStack.getItem();
        if (chestItem instanceof ScubaArmorItem) {
            LazyOptional<ScubaData> data = event.player.getCapability(CAPABILITY);
            if (!world.isClientSide) {
                underwaterPlayers.add((ServerPlayer) event.player);
            }
            if (isUnderWater(event.player)) {
                data.ifPresent(d -> {
                    d.tick(event.player);
                    if (!world.isClientSide) {
                        d.updateClient((ServerPlayer) event.player, false);
                    }
                });
                ((ScubaArmorItem) chestItem).tickAir(event.player, EquipmentSlot.CHEST, chestStack);
                if (!world.isClientSide && world.getGameTime() % 60 == 0) {
                    // TODO this effect could be better, custom packet?
                    Vec3 eyePos = event.player.getEyePosition(0);
                    Vec3 motion = event.player.getDeltaMovement();
                    Vec3 particlePos = eyePos.add(motion.reverse());
                    ((ServerLevel) world).sendParticles(ParticleTypes.BUBBLE, particlePos.x(), particlePos.y(), particlePos.z(), 4 + world.random.nextInt(3), 0.25, 0.25, 0.25, motion.length());
                }
            } else if (!world.isClientSide && underwaterPlayers.remove(event.player)) {
                // Update client state as they leave the water
                data.ifPresent(d -> d.updateClient((ServerPlayer) event.player, false));
            }
        }
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Direction(net.minecraft.core.Direction) Item(net.minecraft.world.item.Item) CapabilityManager(net.minecraftforge.common.capabilities.CapabilityManager) EventBusSubscriber(net.minecraftforge.fml.common.Mod.EventBusSubscriber) PacketDistributor(net.minecraftforge.fmllegacy.network.PacketDistributor) TropicraftDimension(net.tropicraft.core.common.dimension.TropicraftDimension) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ServerLevel(net.minecraft.server.level.ServerLevel) LazyOptional(net.minecraftforge.common.util.LazyOptional) ServerPlayer(net.minecraft.server.level.ServerPlayer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) Nonnull(javax.annotation.Nonnull) Phase(net.minecraftforge.event.TickEvent.Phase) MessageUpdateScubaData(net.tropicraft.core.common.network.message.MessageUpdateScubaData) Nullable(javax.annotation.Nullable) WeakHashMap(java.util.WeakHashMap) PlayerEvent(net.minecraftforge.event.entity.player.PlayerEvent) PlayerTickEvent(net.minecraftforge.event.TickEvent.PlayerTickEvent) PlayerChangedDimensionEvent(net.minecraftforge.event.entity.player.PlayerEvent.PlayerChangedDimensionEvent) FluidTags(net.minecraft.tags.FluidTags) Set(java.util.Set) AttachCapabilitiesEvent(net.minecraftforge.event.AttachCapabilitiesEvent) Capability(net.minecraftforge.common.capabilities.Capability) Player(net.minecraft.world.entity.player.Player) PlayerRespawnEvent(net.minecraftforge.event.entity.player.PlayerEvent.PlayerRespawnEvent) TropicraftPackets(net.tropicraft.core.common.network.TropicraftPackets) ICapabilitySerializable(net.minecraftforge.common.capabilities.ICapabilitySerializable) CompoundTag(net.minecraft.nbt.CompoundTag) Entity(net.minecraft.world.entity.Entity) BlockPos(net.minecraft.core.BlockPos) Vec3(net.minecraft.world.phys.Vec3) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) Constants(net.tropicraft.Constants) PlayerLoggedInEvent(net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) CapabilityToken(net.minecraftforge.common.capabilities.CapabilityToken) ParticleTypes(net.minecraft.core.particles.ParticleTypes) Bus(net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus) Collections(java.util.Collections) INBTSerializable(net.minecraftforge.common.util.INBTSerializable) Item(net.minecraft.world.item.Item) MessageUpdateScubaData(net.tropicraft.core.common.network.message.MessageUpdateScubaData) ServerLevel(net.minecraft.server.level.ServerLevel) Vec3(net.minecraft.world.phys.Vec3) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) ItemStack(net.minecraft.world.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

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