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