use of com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage in project endergetic by team-abnormals.
the class EntityEvents method onEntityTracked.
@SubscribeEvent
public static void onEntityTracked(PlayerEvent.StartTracking event) {
ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
Entity trackingEntity = event.getTarget();
if (trackingEntity instanceof BolloomBalloonEntity) {
BolloomBalloonEntity balloon = (BolloomBalloonEntity) trackingEntity;
Entity attachedEntity = balloon.getAttachedEntity();
if (attachedEntity != null) {
EndergeticExpansion.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new S2CUpdateBalloonsMessage(attachedEntity));
}
} else {
EndergeticExpansion.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new S2CUpdateBalloonsMessage(trackingEntity));
}
}
use of com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage in project endergetic by team-abnormals.
the class TrackedEntityMixin method updateBalloons.
@Inject(at = @At("HEAD"), method = "sendChanges")
private void updateBalloons(CallbackInfo info) {
List<BolloomBalloonEntity> currentBalloons = ((BalloonHolder) this.entity).getBalloons();
if (!currentBalloons.equals(this.prevBalloons)) {
this.prevBalloons = currentBalloons;
EndergeticExpansion.CHANNEL.send(PacketDistributor.TRACKING_ENTITY.with(() -> this.entity), new S2CUpdateBalloonsMessage(this.entity));
}
}
use of com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage in project endergetic by team-abnormals.
the class PlayerListMixin method spawnBalloons.
@Inject(at = @At("RETURN"), method = "placeNewPlayer")
private void spawnBalloons(NetworkManager netManager, ServerPlayerEntity player, CallbackInfo info) {
ServerWorld serverWorld = (ServerWorld) player.level;
CompoundNBT compound = this.server.getWorldData().getLoadedPlayerTag();
if (!(compound != null && player.getName().getString().equals(this.server.getSingleplayerName()))) {
try {
File playerDataFile = new File(this.playerIo.getPlayerDataFolder(), player.getStringUUID() + ".dat");
if (playerDataFile.exists() && playerDataFile.isFile()) {
compound = CompressedStreamTools.readCompressed(playerDataFile);
}
} catch (Exception exception) {
EndergeticExpansion.LOGGER.warn("Failed to load player data for {}", player.getName().getString());
}
}
if (compound != null && compound.contains("Balloons", 9)) {
ListNBT balloonsTag = compound.getList("Balloons", 10);
if (!balloonsTag.isEmpty()) {
for (int i = 0; i < balloonsTag.size(); i++) {
Entity entity = EntityType.loadEntityRecursive(balloonsTag.getCompound(i), serverWorld, (balloon -> !serverWorld.addWithUUID(balloon) ? null : balloon));
if (entity instanceof BolloomBalloonEntity) {
((BolloomBalloonEntity) entity).attachToEntity(player);
EndergeticExpansion.CHANNEL.send(PacketDistributor.TRACKING_ENTITY.with(() -> entity), new S2CUpdateBalloonsMessage(player));
}
}
}
}
}
Aggregations