Search in sources :

Example 6 with BolloomBalloonEntity

use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.

the class ServerWorldMixin method updateBalloons.

@SuppressWarnings("deprecation")
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;inChunk:Z", ordinal = 1, shift = At.Shift.AFTER), method = "tickNonPassenger")
private void updateBalloons(Entity entity, CallbackInfo info) {
    BalloonHolder balloonHolder = (BalloonHolder) entity;
    ServerChunkProvider chunkProvider = ((ServerWorld) (Object) this).getChunkSource();
    for (BolloomBalloonEntity balloon : balloonHolder.getBalloons()) {
        if (!balloon.removed && balloon.getAttachedEntity() == entity) {
            if (chunkProvider.isEntityTickingChunk(balloon)) {
                balloon.setPosAndOldPos(balloon.getX(), balloon.getY(), balloon.getZ());
                balloon.yRotO = balloon.yRot;
                balloon.xRotO = balloon.xRot;
                if (balloon.inChunk) {
                    balloon.tickCount++;
                    balloon.updateAttachedPosition();
                }
                ((ServerWorld) (Object) this).updateChunkPos(balloon);
            }
        } else {
            balloon.detachFromEntity();
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) BalloonHolder(com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 7 with BolloomBalloonEntity

use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.

the class BolloomBalloonItem method attachToEntity.

public static void attachToEntity(BalloonColor color, Entity target) {
    World world = target.level;
    BolloomBalloonEntity balloon = EEEntities.BOLLOOM_BALLOON.get().create(world);
    if (balloon != null) {
        balloon.setColor(color);
        balloon.attachToEntity(target);
        balloon.updateAttachedPosition();
        balloon.setUntied(true);
        world.addFreshEntity(balloon);
    }
}
Also used : World(net.minecraft.world.World) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity)

Example 8 with BolloomBalloonEntity

use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity 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)

Example 9 with BolloomBalloonEntity

use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.

the class PlayerListMixin method removeBalloons.

@SuppressWarnings("deprecation")
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;save(Lnet/minecraft/entity/player/ServerPlayerEntity;)V", shift = At.Shift.AFTER), method = "remove")
private void removeBalloons(ServerPlayerEntity player, CallbackInfo info) {
    List<BolloomBalloonEntity> balloons = ((BalloonHolder) player).getBalloons();
    if (!balloons.isEmpty()) {
        ServerWorld serverWorld = (ServerWorld) player.level;
        for (BolloomBalloonEntity balloon : balloons) {
            serverWorld.despawn(balloon);
            balloon.removed = true;
        }
        serverWorld.getChunk(player.xChunk, player.zChunk).markUnsaved();
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) BalloonHolder(com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with BolloomBalloonEntity

use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.

the class EntityEvents method onPlayerSwing.

@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void onPlayerSwing(InputEvent.ClickInputEvent event) {
    if (event.isAttack()) {
        ClientPlayerEntity player = ClientInfo.getClientPlayer();
        if (player.xRot > -25.0F)
            return;
        Entity ridingEntity = player.getVehicle();
        if (ridingEntity instanceof BoatEntity && BolloomBalloonItem.hasNoEntityTarget(player) && EntityUtil.rayTrace(player, BolloomBalloonItem.getPlayerReach(player), 1.0F).getType() == Type.MISS) {
            List<BolloomBalloonEntity> balloons = ((BalloonHolder) ridingEntity).getBalloons();
            if (!balloons.isEmpty()) {
                Minecraft.getInstance().gameMode.attack(player, balloons.get(player.getRandom().nextInt(balloons.size())));
                event.setSwingHand(true);
            }
        }
    }
}
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) BoatEntity(net.minecraft.entity.item.BoatEntity) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) BalloonHolder(com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

BolloomBalloonEntity (com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity)11 BalloonHolder (com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder)9 Inject (org.spongepowered.asm.mixin.injection.Inject)7 Entity (net.minecraft.entity.Entity)4 ServerWorld (net.minecraft.world.server.ServerWorld)4 S2CUpdateBalloonsMessage (com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)2 ClientChunkProvider (net.minecraft.client.multiplayer.ClientChunkProvider)2 ClientWorld (net.minecraft.client.world.ClientWorld)2 LivingEntity (net.minecraft.entity.LivingEntity)2 BoatEntity (net.minecraft.entity.item.BoatEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 PotionEntity (net.minecraft.entity.projectile.PotionEntity)2 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)2 World (net.minecraft.world.World)2 ServerChunkProvider (net.minecraft.world.server.ServerChunkProvider)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 EndergeticExpansion (com.minecraftabnormals.endergetic.core.EndergeticExpansion)1 File (java.io.File)1