Search in sources :

Example 1 with PatreonPartialEntity

use of hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity in project AstralSorcery by HellFirePvP.

the class DataPatreonFlares method writeAllDataToPacket.

@Override
public void writeAllDataToPacket(CompoundNBT compound) {
    ListNBT entities = new ListNBT();
    for (UUID playerUUID : this.entitiesServer.keySet()) {
        CompoundNBT tag = new CompoundNBT();
        tag.putUniqueId("playerUUID", playerUUID);
        ListNBT entityList = new ListNBT();
        for (PatreonPartialEntity entity : this.entitiesServer.get(playerUUID)) {
            CompoundNBT entityNBT = new CompoundNBT();
            entityNBT.putUniqueId("id", entity.getEffectUUID());
            CompoundNBT data = new CompoundNBT();
            entity.writeToNBT(data);
            entityNBT.put("data", data);
            entityList.add(entityNBT);
        }
        tag.put("entityList", entityList);
        entities.add(tag);
    }
    compound.put("entities", entities);
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) PatreonPartialEntity(hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity)

Example 2 with PatreonPartialEntity

use of hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity in project AstralSorcery by HellFirePvP.

the class DataPatreonFlares method writeDiffDataToPacket.

@Override
public void writeDiffDataToPacket(CompoundNBT compound) {
    ListNBT listUpdates = new ListNBT();
    for (UUID playerUUID : this.flarePlayerUpdates) {
        CompoundNBT tag = new CompoundNBT();
        tag.putUniqueId("playerUUID", playerUUID);
        ListNBT entityList = new ListNBT();
        for (PatreonPartialEntity entity : this.entitiesServer.get(playerUUID)) {
            CompoundNBT entityNBT = new CompoundNBT();
            entityNBT.putUniqueId("id", entity.getEffectUUID());
            CompoundNBT data = new CompoundNBT();
            entity.writeToNBT(data);
            entityNBT.put("data", data);
            entityList.add(entityNBT);
        }
        tag.put("entityList", entityList);
        listUpdates.add(tag);
    }
    ListNBT listRemovals = new ListNBT();
    for (UUID playerUUID : this.flareRemovals) {
        CompoundNBT playerTag = new CompoundNBT();
        playerTag.putUniqueId("playerUUID", playerUUID);
        listRemovals.add(playerTag);
    }
    compound.put("updates", listUpdates);
    compound.put("removals", listRemovals);
    this.flarePlayerUpdates.clear();
    this.flareRemovals.clear();
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) PatreonPartialEntity(hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity)

Example 3 with PatreonPartialEntity

use of hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity in project AstralSorcery by HellFirePvP.

the class PatreonManager method tick.

@Override
public void tick(TickEvent.Type type, Object... context) {
    MinecraftServer server = LogicalSidedProvider.INSTANCE.get(LogicalSide.SERVER);
    if (server == null) {
        return;
    }
    SyncDataHolder.executeServer(SyncDataHolder.DATA_PATREON_FLARES, DataPatreonFlares.class, data -> {
        Collection<UUID> owners = new ArrayList<>(data.getOwners());
        Set<UUID> foundValidOwners = new HashSet<>();
        Map<UUID, List<PatreonEffect>> playerEffects = PatreonEffectHelper.getPatreonEffects(server.getPlayerList().getPlayers());
        for (UUID playerUUID : playerEffects.keySet()) {
            ServerPlayerEntity player = server.getPlayerList().getPlayerByUUID(playerUUID);
            if (player == null) {
                continue;
            }
            Collection<PatreonPartialEntity> knownEntities = new ArrayList<>(data.getEntities(playerUUID));
            for (PatreonEffect effect : PatreonEffectHelper.getPatreonEffects(LogicalSide.SERVER, playerUUID)) {
                if (effect == null || !effect.hasPartialEntity()) {
                    continue;
                }
                foundValidOwners.add(playerUUID);
                PatreonPartialEntity effectEntity = MiscUtils.iterativeSearch(knownEntities, e -> e.getEffectUUID().equals(effect.getEffectUUID()));
                if (effectEntity == null) {
                    effectEntity = data.createEntity(player, effect);
                }
                World playerWorld = player.getServerWorld();
                if (effectEntity.getLastTickedDimension() != null && !playerWorld.getDimensionKey().equals(effectEntity.getLastTickedDimension())) {
                    effectEntity.placeNear(player);
                }
                if (effectEntity.tick(playerWorld)) {
                    data.updateEntitiesOf(playerUUID);
                }
            }
        }
        for (UUID owner : owners) {
            if (foundValidOwners.contains(owner)) {
                continue;
            }
            data.removeEntities(owner);
        }
    });
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PatreonPartialEntity(hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) PatreonEffect(hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect)

Example 4 with PatreonPartialEntity

use of hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity in project AstralSorcery by HellFirePvP.

the class PatreonManagerClient method tick.

@Override
public void tick(TickEvent.Type type, Object... context) {
    World clWorld = Minecraft.getInstance().world;
    PlayerEntity thisPlayer = Minecraft.getInstance().player;
    if (clWorld == null || thisPlayer == null) {
        return;
    }
    RegistryKey<World> clientWorld = clWorld.getDimensionKey();
    Vector3 thisPlayerPos = Vector3.atEntityCenter(thisPlayer);
    SyncDataHolder.executeClient(SyncDataHolder.DATA_PATREON_FLARES, ClientPatreonFlares.class, data -> {
        for (Collection<PatreonPartialEntity> playerEntities : data.getEntities()) {
            for (PatreonPartialEntity entity : playerEntities) {
                if (entity.getLastTickedDimension() == null || !entity.getLastTickedDimension().equals(clientWorld)) {
                    continue;
                }
                if (entity.getPos().distanceSquared(thisPlayerPos) <= RenderingConfig.CONFIG.getMaxEffectRenderDistanceSq()) {
                    entity.tickClient();
                }
                entity.tick(clWorld);
            }
        }
    });
    SyncDataHolder.executeClient(SyncDataHolder.DATA_PATREON_FLARES, ClientPatreonFlares.class, data -> {
        for (PlayerEntity player : clWorld.getPlayers()) {
            for (PatreonEffect effect : PatreonEffectHelper.getPatreonEffects(LogicalSide.CLIENT, player.getUniqueID())) {
                effect.doClientEffect(player);
            }
        }
    });
}
Also used : PatreonEffect(hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) PatreonPartialEntity(hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 5 with PatreonPartialEntity

use of hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity in project AstralSorcery by HellFirePvP.

the class DataPatreonFlares method createEntity.

// Only actually called when there's an entity to be provided.
@Nullable
public PatreonPartialEntity createEntity(PlayerEntity player, PatreonEffect value) {
    UUID owner = player.getUniqueID();
    PatreonPartialEntity entity = value.createEntity(owner);
    if (entity == null) {
        return null;
    }
    entity.placeNear(player);
    entitiesServer.computeIfAbsent(owner, o -> new HashSet<>()).add(entity);
    flareRemovals.remove(owner);
    flarePlayerUpdates.add(owner);
    markDirty();
    return entity;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) java.util(java.util) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) CompoundNBT(net.minecraft.nbt.CompoundNBT) DimensionType(net.minecraft.world.DimensionType) AbstractDataProvider(hellfirepvp.astralsorcery.common.data.sync.base.AbstractDataProvider) RegistryKey(net.minecraft.util.RegistryKey) ClientDataReader(hellfirepvp.astralsorcery.common.data.sync.base.ClientDataReader) ClientPatreonFlares(hellfirepvp.astralsorcery.common.data.sync.client.ClientPatreonFlares) PatreonEffect(hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect) ResourceLocation(net.minecraft.util.ResourceLocation) AbstractData(hellfirepvp.astralsorcery.common.data.sync.base.AbstractData) PatreonPartialEntity(hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PatreonPartialEntity(hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity) Nullable(javax.annotation.Nullable)

Aggregations

PatreonPartialEntity (hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity)5 PatreonEffect (hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 ListNBT (net.minecraft.nbt.ListNBT)3 World (net.minecraft.world.World)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 AbstractData (hellfirepvp.astralsorcery.common.data.sync.base.AbstractData)1 AbstractDataProvider (hellfirepvp.astralsorcery.common.data.sync.base.AbstractDataProvider)1 ClientDataReader (hellfirepvp.astralsorcery.common.data.sync.base.ClientDataReader)1 ClientPatreonFlares (hellfirepvp.astralsorcery.common.data.sync.client.ClientPatreonFlares)1 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)1 java.util (java.util)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 RegistryKey (net.minecraft.util.RegistryKey)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 DimensionType (net.minecraft.world.DimensionType)1