2020-04-25 13:32:33 +02:00
|
|
|
package com.minelittlepony.unicopia.client;
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-04-25 13:32:33 +02:00
|
|
|
|
2021-08-17 20:55:35 +02:00
|
|
|
import com.minelittlepony.unicopia.FlightType;
|
2020-04-25 13:32:33 +02:00
|
|
|
import com.minelittlepony.unicopia.InteractionManager;
|
2021-08-13 14:46:54 +02:00
|
|
|
import com.minelittlepony.unicopia.USounds;
|
2021-12-31 23:00:18 +01:00
|
|
|
import com.minelittlepony.unicopia.client.gui.DismissSpellScreen;
|
2021-08-13 14:46:54 +02:00
|
|
|
import com.minelittlepony.unicopia.client.sound.LoopingSoundInstance;
|
2021-08-18 20:14:22 +02:00
|
|
|
import com.minelittlepony.unicopia.client.sound.MotionBasedSoundInstance;
|
2021-08-19 16:30:05 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.effect.UEffects;
|
2021-08-17 20:55:35 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.PlayerPhysics;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
|
|
import com.minelittlepony.unicopia.entity.player.dummy.DummyClientPlayerEntity;
|
2021-08-13 14:46:54 +02:00
|
|
|
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandler;
|
|
|
|
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandlerImpl;
|
2020-04-25 13:32:33 +02:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2021-08-18 17:30:59 +02:00
|
|
|
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
2020-04-25 13:32:33 +02:00
|
|
|
|
|
|
|
import net.minecraft.client.MinecraftClient;
|
2021-08-13 14:46:54 +02:00
|
|
|
import net.minecraft.client.sound.AggressiveBeeSoundInstance;
|
|
|
|
import net.minecraft.client.sound.MovingMinecartSoundInstance;
|
|
|
|
import net.minecraft.client.sound.PassiveBeeSoundInstance;
|
|
|
|
import net.minecraft.client.sound.SoundManager;
|
2020-04-25 13:32:33 +02:00
|
|
|
import net.minecraft.client.world.ClientWorld;
|
|
|
|
import net.minecraft.entity.Entity;
|
2021-08-13 14:46:54 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.passive.BeeEntity;
|
2020-04-25 13:32:33 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2021-08-13 14:46:54 +02:00
|
|
|
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
2021-08-18 20:14:22 +02:00
|
|
|
import net.minecraft.sound.SoundEvents;
|
2021-08-18 17:30:59 +02:00
|
|
|
import net.minecraft.world.World;
|
2020-04-25 13:32:33 +02:00
|
|
|
|
|
|
|
public class ClientInteractionManager extends InteractionManager {
|
2021-08-13 14:46:54 +02:00
|
|
|
|
|
|
|
private final ClientNetworkHandler handler = new ClientNetworkHandlerImpl();
|
|
|
|
private final MinecraftClient client = MinecraftClient.getInstance();
|
|
|
|
|
2021-08-18 17:30:59 +02:00
|
|
|
@Override
|
|
|
|
public MinecraftSessionService getSessionService(World world) {
|
|
|
|
return MinecraftClient.getInstance().getSessionService();
|
|
|
|
}
|
|
|
|
|
2021-08-13 14:46:54 +02:00
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public ClientNetworkHandler getClientNetworkHandler() {
|
|
|
|
return handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void playLoopingSound(Entity source, int type) {
|
2021-08-19 01:31:22 +02:00
|
|
|
client.execute(() -> {
|
|
|
|
SoundManager soundManager = client.getSoundManager();
|
2021-08-13 14:46:54 +02:00
|
|
|
|
2021-08-19 01:31:22 +02:00
|
|
|
if (type == SOUND_EARS_RINGING && source instanceof LivingEntity) {
|
2021-08-19 16:30:05 +02:00
|
|
|
soundManager.play(new LoopingSoundInstance<>((LivingEntity)source, e -> e.hasStatusEffect(UEffects.SUN_BLINDNESS), USounds.ENTITY_PLAYER_EARS_RINGING, 1F, 1F));
|
2021-08-19 01:31:22 +02:00
|
|
|
} else if (type == SOUND_BEE && source instanceof BeeEntity) {
|
|
|
|
soundManager.playNextTick(
|
|
|
|
((BeeEntity)source).hasAngerTime()
|
|
|
|
? new AggressiveBeeSoundInstance(((BeeEntity)source))
|
|
|
|
: new PassiveBeeSoundInstance(((BeeEntity)source))
|
|
|
|
);
|
|
|
|
} else if (type == SOUND_MINECART && source instanceof AbstractMinecartEntity) {
|
|
|
|
soundManager.play(new MovingMinecartSoundInstance((AbstractMinecartEntity)source));
|
|
|
|
} else if (type == SOUND_CHANGELING_BUZZ && source instanceof PlayerEntity) {
|
|
|
|
soundManager.play(new LoopingSoundInstance<>((PlayerEntity)source, e -> {
|
|
|
|
PlayerPhysics physics = Pony.of(e).getPhysics();
|
|
|
|
return physics.isFlying() && physics.getFlightType() == FlightType.INSECTOID;
|
|
|
|
}, USounds.ENTITY_PLAYER_CHANGELING_BUZZ, 1F, 1F));
|
|
|
|
} else if (type == SOUND_GLIDING && source instanceof PlayerEntity) {
|
|
|
|
soundManager.play(new MotionBasedSoundInstance(SoundEvents.ITEM_ELYTRA_FLYING, (PlayerEntity)source));
|
|
|
|
}
|
|
|
|
});
|
2021-08-13 14:46:54 +02:00
|
|
|
}
|
|
|
|
|
2021-12-31 23:00:18 +01:00
|
|
|
@Override
|
|
|
|
public void openScreen(int type) {
|
|
|
|
client.execute(() -> {
|
|
|
|
if (type == SCREEN_DISPELL_ABILITY) {
|
|
|
|
client.setScreen(new DismissSpellScreen());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-25 13:32:33 +02:00
|
|
|
@Override
|
2021-08-04 15:38:03 +02:00
|
|
|
@NotNull
|
2021-08-18 17:30:59 +02:00
|
|
|
public PlayerEntity createPlayer(World world, GameProfile profile) {
|
|
|
|
if (world instanceof ClientWorld) {
|
|
|
|
return new DummyClientPlayerEntity((ClientWorld)world, profile);
|
2020-04-25 13:32:33 +02:00
|
|
|
}
|
2021-08-18 17:30:59 +02:00
|
|
|
return super.createPlayer(world, profile);
|
2020-04-25 13:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isClientPlayer(@Nullable PlayerEntity player) {
|
2021-08-13 14:46:54 +02:00
|
|
|
return (client.player != null && player != null)
|
|
|
|
&& (client.player == player
|
|
|
|
|| Pony.equal(client.player, player));
|
2020-04-25 13:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewMode() {
|
2021-08-13 14:46:54 +02:00
|
|
|
return client.options.getPerspective().ordinal();
|
2020-04-25 13:32:33 +02:00
|
|
|
}
|
|
|
|
}
|