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);
}
});
}
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);
}
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();
}
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);
}
}
});
}
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;
}
Aggregations