Search in sources :

Example 1 with S2CUpdateBalloonsMessage

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));
    }
}
Also used : BoatEntity(net.minecraft.entity.item.BoatEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) Entity(net.minecraft.entity.Entity) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) S2CUpdateBalloonsMessage(com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with S2CUpdateBalloonsMessage

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));
    }
}
Also used : BalloonHolder(com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) S2CUpdateBalloonsMessage(com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with S2CUpdateBalloonsMessage

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));
                }
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) EntityType(net.minecraft.entity.EntityType) ListNBT(net.minecraft.nbt.ListNBT) Entity(net.minecraft.entity.Entity) ServerWorld(net.minecraft.world.server.ServerWorld) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) Inject(org.spongepowered.asm.mixin.injection.Inject) CompoundNBT(net.minecraft.nbt.CompoundNBT) PlayerData(net.minecraft.world.storage.PlayerData) NetworkManager(net.minecraft.network.NetworkManager) PlayerList(net.minecraft.server.management.PlayerList) Final(org.spongepowered.asm.mixin.Final) File(java.io.File) PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) Mixin(org.spongepowered.asm.mixin.Mixin) S2CUpdateBalloonsMessage(com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage) EndergeticExpansion(com.minecraftabnormals.endergetic.core.EndergeticExpansion) CompressedStreamTools(net.minecraft.nbt.CompressedStreamTools) Shadow(org.spongepowered.asm.mixin.Shadow) BalloonHolder(com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) At(org.spongepowered.asm.mixin.injection.At) Entity(net.minecraft.entity.Entity) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) File(java.io.File) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) S2CUpdateBalloonsMessage(com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

BolloomBalloonEntity (com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity)3 S2CUpdateBalloonsMessage (com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage)3 BalloonHolder (com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder)2 Entity (net.minecraft.entity.Entity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 EndergeticExpansion (com.minecraftabnormals.endergetic.core.EndergeticExpansion)1 File (java.io.File)1 List (java.util.List)1 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)1 EntityType (net.minecraft.entity.EntityType)1 LivingEntity (net.minecraft.entity.LivingEntity)1 BoatEntity (net.minecraft.entity.item.BoatEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 PotionEntity (net.minecraft.entity.projectile.PotionEntity)1 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 CompressedStreamTools (net.minecraft.nbt.CompressedStreamTools)1 ListNBT (net.minecraft.nbt.ListNBT)1 NetworkManager (net.minecraft.network.NetworkManager)1