Search in sources :

Example 71 with org.bukkit.craftbukkit.v1_18_R2.entity

use of org.bukkit.craftbukkit.v1_18_R2.entity in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method updateEntityNameTagVisibilityForPlayer.

@Override
public void updateEntityNameTagVisibilityForPlayer(Player player, org.bukkit.entity.Entity entity, boolean customNameVisible) {
    try {
        List<SynchedEntityData.DataItem<?>> dataItems = Lists.newArrayList(new SynchedEntityData.DataItem<>(EntityDataSerializers.BOOLEAN.createAccessor(3), customNameVisible));
        ClientboundSetEntityDataPacket entityDataPacket = new ClientboundSetEntityDataPacket(entity.getEntityId(), new SynchedEntityDataWrapper(dataItems), false);
        ((CraftPlayer) player).getHandle().connection.send(entityDataPacket);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) SynchedEntityDataWrapper(dev.rosewood.rosestacker.nms.v1_18_R2.entity.SynchedEntityDataWrapper) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)

Example 72 with org.bukkit.craftbukkit.v1_18_R2.entity

use of org.bukkit.craftbukkit.v1_18_R2.entity in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method createEntityFromNBT.

@Override
public LivingEntity createEntityFromNBT(StackedEntityDataEntry<?> serialized, Location location, boolean addToWorld, EntityType entityType) {
    try {
        NBTTagCompound nbt = (NBTTagCompound) serialized.get();
        NBTTagList positionTagList = nbt.getList("Pos", 6);
        if (positionTagList == null)
            positionTagList = new NBTTagList();
        this.setTag(positionTagList, 0, NBTTagDouble.a(location.getX()));
        this.setTag(positionTagList, 1, NBTTagDouble.a(location.getY()));
        this.setTag(positionTagList, 2, NBTTagDouble.a(location.getZ()));
        nbt.set("Pos", positionTagList);
        NBTTagList rotationTagList = nbt.getList("Rotation", 5);
        if (rotationTagList == null)
            rotationTagList = new NBTTagList();
        this.setTag(rotationTagList, 0, NBTTagFloat.a(location.getYaw()));
        this.setTag(rotationTagList, 1, NBTTagFloat.a(location.getPitch()));
        nbt.set("Rotation", rotationTagList);
        // Reset the UUID to resolve possible duplicates
        nbt.a("UUID", UUID.randomUUID());
        Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType.getKey().getKey());
        if (optionalEntity.isPresent()) {
            WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
            Entity entity = this.createCreature(optionalEntity.get(), world, nbt, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), EnumMobSpawn.COMMAND);
            if (entity == null)
                throw new NullPointerException("Unable to create entity from NBT");
            // Load NBT
            entity.load(nbt);
            if (addToWorld) {
                IChunkAccess ichunkaccess = world.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true);
                if (!(ichunkaccess instanceof Chunk))
                    throw new NullPointerException("Unable to spawn entity from NBT, couldn't get chunk");
                ichunkaccess.a(entity);
                method_WorldServer_registerEntity.invoke(world, entity);
                entity.noDamageTicks = 0;
            }
            return (LivingEntity) entity.getBukkitEntity();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : EntityTypes(net.minecraft.server.v1_16_R2.EntityTypes) IChunkAccess(net.minecraft.server.v1_16_R2.IChunkAccess) Entity(net.minecraft.server.v1_16_R2.Entity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) TileEntity(net.minecraft.server.v1_16_R2.TileEntity) GroupDataEntity(net.minecraft.server.v1_16_R2.GroupDataEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity) BlockPosition(net.minecraft.server.v1_16_R2.BlockPosition) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) WorldServer(net.minecraft.server.v1_16_R2.WorldServer) Chunk(net.minecraft.server.v1_16_R2.Chunk) NBTTagList(net.minecraft.server.v1_16_R2.NBTTagList) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R2.CraftWorld)

Example 73 with org.bukkit.craftbukkit.v1_18_R2.entity

use of org.bukkit.craftbukkit.v1_18_R2.entity in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method createNewEntityUnspawned.

@Override
public LivingEntity createNewEntityUnspawned(EntityType entityType, Location location, SpawnReason spawnReason) {
    World world = location.getWorld();
    if (world == null)
        return null;
    Class<? extends org.bukkit.entity.Entity> entityClass = entityType.getEntityClass();
    if (entityClass == null || !LivingEntity.class.isAssignableFrom(entityClass))
        throw new IllegalArgumentException("EntityType must be of a LivingEntity");
    EntityTypes<? extends Entity> nmsEntityType = IRegistry.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(entityType.getKey()));
    Entity nmsEntity = this.createCreature(nmsEntityType, ((CraftWorld) world).getHandle(), null, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), this.toNmsSpawnReason(spawnReason));
    return nmsEntity == null ? null : (LivingEntity) nmsEntity.getBukkitEntity();
}
Also used : Entity(net.minecraft.server.v1_16_R2.Entity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) TileEntity(net.minecraft.server.v1_16_R2.TileEntity) GroupDataEntity(net.minecraft.server.v1_16_R2.GroupDataEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity) BlockPosition(net.minecraft.server.v1_16_R2.BlockPosition) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_16_R2.CraftWorld)

Example 74 with org.bukkit.craftbukkit.v1_18_R2.entity

use of org.bukkit.craftbukkit.v1_18_R2.entity in project LibsDisguises by libraryaddict.

the class ReflectionManager method getSize.

public float[] getSize(Entity entity) {
    net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
    EntityDimensions dimensions = nmsEntity.getDimensions(net.minecraft.world.entity.Pose.STANDING);
    return new float[] { dimensions.width, nmsEntity.getEyeHeight() };
}
Also used : EntityDimensions(net.minecraft.world.entity.EntityDimensions) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)

Example 75 with org.bukkit.craftbukkit.v1_18_R2.entity

use of org.bukkit.craftbukkit.v1_18_R2.entity in project Insights by InsightsPlugin.

the class ChunkContainer method get.

@Override
public DistributionStorage get() {
    ChunkVector min = cuboid.getMin();
    ChunkVector max = cuboid.getMax();
    int minX = min.getX();
    int maxX = max.getX();
    int minZ = min.getZ();
    int maxZ = max.getZ();
    int blockMinY = Math.max(min.getY(), 0);
    int blockMaxY = Math.abs(Math.min(min.getY(), 0)) + max.getY();
    ServerLevel serverLevel = ((CraftWorld) world).getHandle();
    if (options.materials()) {
        LevelChunkSection[] chunkSections;
        try {
            chunkSections = getChunkSections();
        } catch (IOException ex) {
            throw new ChunkIOException(ex);
        }
        int minSectionY = blockMinY >> 4;
        int maxSectionY = blockMaxY >> 4;
        for (int sectionY = minSectionY; sectionY <= maxSectionY; sectionY++) {
            int minY = sectionY == minSectionY ? blockMinY & 15 : 0;
            int maxY = sectionY == maxSectionY ? blockMaxY & 15 : 15;
            LevelChunkSection section = chunkSections[sectionY];
            if (section == null) {
                // Section is empty, count everything as air
                long count = (maxX - minX + 1L) * (maxY - minY + 1L) * (maxZ - minZ + 1L);
                materialMap.merge(Material.AIR, count, Long::sum);
            } else if (minX == 0 && maxX == 15 && minY == 0 && maxY == 15 && minZ == 0 && maxZ == 15) {
                // Section can be counted as a whole
                section.getStates().count((state, count) -> {
                    try {
                        materialMap.merge(CraftMagicNumbers.getMaterial(state.getBlock()), (long) count, Long::sum);
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                });
            } else {
                // Section must be scanned block by block
                for (int x = minX; x <= maxX; x++) {
                    for (int y = minY; y <= maxY; y++) {
                        for (int z = minZ; z <= maxZ; z++) {
                            materialMap.merge(CraftMagicNumbers.getMaterial(section.getBlockState(x, y, z).getBlock()), 1L, Long::sum);
                        }
                    }
                }
            }
        }
    }
    if (options.entities()) {
        PersistentEntitySectionManager<Entity> entityManager = serverLevel.entityManager;
        long chunkKey = getChunkKey();
        final Stream<Entity> entityStream;
        if (entityManager.areEntitiesLoaded(chunkKey)) {
            EntitySectionStorage<Entity> sectionStorage;
            try {
                sectionStorage = RPersistentEntitySectionManager.getSectionStorage(entityManager);
            } catch (Throwable th) {
                throw new ChunkReflectionException(th);
            }
            entityStream = sectionStorage.getExistingSectionsInChunk(chunkKey).flatMap(EntitySection::getEntities);
        } else {
            EntityPersistentStorage<Entity> permanentStorage;
            try {
                permanentStorage = RPersistentEntitySectionManager.getPermanentStorage(entityManager);
            } catch (Throwable th) {
                throw new ChunkReflectionException(th);
            }
            entityStream = permanentStorage.loadEntities(new ChunkPos(chunkX, chunkZ)).join().getEntities();
        }
        entityStream.filter(entity -> {
            int x = entity.getBlockX() & 15;
            int y = entity.getBlockY();
            int z = entity.getBlockZ() & 15;
            return minX <= x && x <= maxX && blockMinY <= y && y <= blockMaxY && minZ <= z && z <= maxZ;
        }).forEach(entity -> entityMap.merge(entity.getBukkitEntity().getType(), 1L, Long::sum));
    }
    return DistributionStorage.of(materialMap, entityMap);
}
Also used : ChunkVector(dev.frankheijden.insights.api.objects.chunk.ChunkVector) ChunkIOException(dev.frankheijden.insights.api.exceptions.ChunkIOException) ServerLevel(net.minecraft.server.level.ServerLevel) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) ScanOptions(dev.frankheijden.insights.api.concurrent.ScanOptions) World(org.bukkit.World) Map(java.util.Map) EntitySection(net.minecraft.world.level.entity.EntitySection) ChunkReflectionException(dev.frankheijden.insights.api.exceptions.ChunkReflectionException) Material(org.bukkit.Material) EnumMap(java.util.EnumMap) RPersistentEntitySectionManager(dev.frankheijden.insights.api.reflection.RPersistentEntitySectionManager) ChunkCuboid(dev.frankheijden.insights.api.objects.chunk.ChunkCuboid) ChunkUtils(dev.frankheijden.insights.api.utils.ChunkUtils) IOException(java.io.IOException) EntityPersistentStorage(net.minecraft.world.level.entity.EntityPersistentStorage) EntityType(org.bukkit.entity.EntityType) ChunkPos(net.minecraft.world.level.ChunkPos) CraftMagicNumbers(org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers) Entity(net.minecraft.world.entity.Entity) Stream(java.util.stream.Stream) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) PersistentEntitySectionManager(net.minecraft.world.level.entity.PersistentEntitySectionManager) EntitySectionStorage(net.minecraft.world.level.entity.EntitySectionStorage) DistributionStorage(dev.frankheijden.insights.api.concurrent.storage.DistributionStorage) ServerLevel(net.minecraft.server.level.ServerLevel) ChunkIOException(dev.frankheijden.insights.api.exceptions.ChunkIOException) Entity(net.minecraft.world.entity.Entity) ChunkVector(dev.frankheijden.insights.api.objects.chunk.ChunkVector) ChunkReflectionException(dev.frankheijden.insights.api.exceptions.ChunkReflectionException) ChunkIOException(dev.frankheijden.insights.api.exceptions.ChunkIOException) IOException(java.io.IOException) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) ChunkPos(net.minecraft.world.level.ChunkPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)114 Entity (org.hypertrace.entity.data.service.v1.Entity)110 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)102 Test (org.junit.jupiter.api.Test)95 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)53 Entity (net.minecraft.world.entity.Entity)42 Location (org.bukkit.Location)41 ArrayList (java.util.ArrayList)39 Entity (com.google.datastore.v1.Entity)33 net.minecraft.world.entity (net.minecraft.world.entity)33 org.bukkit.entity (org.bukkit.entity)32 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)32 Player (org.bukkit.entity.Player)29 ServerPlayer (net.minecraft.server.level.ServerPlayer)28 LivingEntity (net.minecraft.world.entity.LivingEntity)28 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)28 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)27 Event (org.hypertrace.core.datamodel.Event)27 Mob (net.minecraft.world.entity.Mob)25 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)23