Search in sources :

Example 1 with PatreonEffect

use of hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect 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 2 with PatreonEffect

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

the class ProviderFlare method buildEffect.

@Override
public PatreonEffect buildEffect(UUID playerUUID, List<String> effectParameters) throws Exception {
    UUID effectUUID = UUID.fromString(effectParameters.get(0));
    FlareColor fc = null;
    if (!"null".equals(effectParameters.get(1))) {
        fc = FlareColor.valueOf(effectParameters.get(1));
    }
    return new PatreonEffect(effectUUID, fc);
}
Also used : PatreonEffect(hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect) UUID(java.util.UUID) FlareColor(hellfirepvp.astralsorcery.common.base.patreon.FlareColor)

Example 3 with PatreonEffect

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

the class PatreonFlareDynamicColor method getColor.

@Override
@OnlyIn(Dist.CLIENT)
protected Color getColor() {
    PatreonEffect effect = getEffect();
    if (!(effect instanceof TypeFlareColor)) {
        return Color.WHITE;
    }
    Color color = ((TypeFlareColor) effect).getColorProvider().get();
    return rand.nextInt(3) == 0 ? color : color.brighter();
}
Also used : PatreonEffect(hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect) TypeFlareColor(hellfirepvp.astralsorcery.common.base.patreon.types.TypeFlareColor) TypeFlareColor(hellfirepvp.astralsorcery.common.base.patreon.types.TypeFlareColor) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 4 with PatreonEffect

use of hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect 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 PatreonEffect

use of hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect 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

PatreonEffect (hellfirepvp.astralsorcery.common.base.patreon.PatreonEffect)5 PatreonPartialEntity (hellfirepvp.astralsorcery.common.base.patreon.entity.PatreonPartialEntity)3 World (net.minecraft.world.World)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 FlareColor (hellfirepvp.astralsorcery.common.base.patreon.FlareColor)1 TypeFlareColor (hellfirepvp.astralsorcery.common.base.patreon.types.TypeFlareColor)1 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 UUID (java.util.UUID)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 ListNBT (net.minecraft.nbt.ListNBT)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 RegistryKey (net.minecraft.util.RegistryKey)1