Search in sources :

Example 6 with BalloonHolder

use of com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder 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 7 with BalloonHolder

use of com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder 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)

Example 8 with BalloonHolder

use of com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder in project endergetic by team-abnormals.

the class S2CUpdateBalloonsMessage method handle.

public static void handle(S2CUpdateBalloonsMessage message, Supplier<NetworkEvent.Context> ctx) {
    NetworkEvent.Context context = ctx.get();
    if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT) {
        context.enqueueWork(() -> {
            World world = ClientInfo.getClientPlayerWorld();
            Entity entity = world.getEntity(message.entityId);
            if (entity == null) {
                EndergeticExpansion.LOGGER.warn("Received balloons for unknown entity!");
            } else {
                ((BalloonHolder) entity).detachBalloons();
                for (int id : message.balloonIds) {
                    Entity balloon = world.getEntity(id);
                    if (balloon instanceof BolloomBalloonEntity) {
                        ((BolloomBalloonEntity) balloon).attachToEntity(entity);
                    }
                }
            }
        });
    }
    context.setPacketHandled(true);
}
Also used : Entity(net.minecraft.entity.Entity) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) World(net.minecraft.world.World) BalloonHolder(com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity)

Aggregations

BolloomBalloonEntity (com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity)8 BalloonHolder (com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder)8 Inject (org.spongepowered.asm.mixin.injection.Inject)6 ServerWorld (net.minecraft.world.server.ServerWorld)3 ClientChunkProvider (net.minecraft.client.multiplayer.ClientChunkProvider)2 ClientWorld (net.minecraft.client.world.ClientWorld)2 Entity (net.minecraft.entity.Entity)2 ServerChunkProvider (net.minecraft.world.server.ServerChunkProvider)2 S2CUpdateBalloonsMessage (com.minecraftabnormals.endergetic.common.network.entity.S2CUpdateBalloonsMessage)1 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 BoatEntity (net.minecraft.entity.item.BoatEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 PotionEntity (net.minecraft.entity.projectile.PotionEntity)1 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)1 World (net.minecraft.world.World)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 NetworkEvent (net.minecraftforge.fml.network.NetworkEvent)1