Unicopia/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java

198 lines
6 KiB
Java
Raw Normal View History

2020-01-17 14:27:26 +01:00
package com.minelittlepony.unicopia.client;
import java.util.List;
2019-01-31 16:21:14 +01:00
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
2020-01-17 14:27:26 +01:00
import com.minelittlepony.unicopia.MineLP;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.Config;
import com.minelittlepony.unicopia.UEntities;
import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.client.ability.render.DisguiseRenderer;
2020-01-16 12:35:46 +01:00
import com.minelittlepony.unicopia.client.gui.SettingsScreen;
import com.minelittlepony.unicopia.client.input.Keyboard;
import com.minelittlepony.unicopia.client.input.MouseControl;
2020-01-17 14:27:26 +01:00
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
2020-01-16 12:35:46 +01:00
import com.minelittlepony.unicopia.client.input.InversionAwareKeyboardInput;
import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
import com.mojang.authlib.GameProfile;
2020-01-16 12:35:46 +01:00
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.input.Input;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.player.PlayerEntity;
public class UnicopiaClient extends UClient {
/**
* The race preferred by the client - as determined by mine little pony.
* Human if minelp was not installed.
*
* This is not neccessarily the _actual_ race used for the player,
* as the server may not allow certain race types, or the player may override
* this option in-game themselves.
*/
private static Race clientPlayerRace = getclientPlayerRace();
private static Race getclientPlayerRace() {
2020-01-17 14:27:26 +01:00
if (!Config.instance().ignoresMineLittlePony()
2020-01-16 12:35:46 +01:00
&& MinecraftClient.getInstance().player != null) {
2019-02-02 12:23:22 +01:00
Race race = MineLP.getPlayerPonyRace();
if (!race.isDefault()) {
return race;
}
}
2020-01-17 14:27:26 +01:00
return Config.instance().getPrefferedRace();
}
@Override
2020-01-16 16:46:24 +01:00
public void displayGuiToPlayer(PlayerEntity player, IInteractionObject inventory) {
if (player instanceof PlayerEntitySP) {
if ("unicopia:itemofholding".equals(inventory.getGuiID())) {
2020-01-16 12:35:46 +01:00
MinecraftClient.getInstance().displayGuiScreen(new GuiOfHolding(inventory));
}
} else {
super.displayGuiToPlayer(player, inventory);
}
}
2019-01-31 16:21:14 +01:00
@Override
@Nullable
2020-01-16 16:46:24 +01:00
public PlayerEntity getPlayer() {
2020-01-16 12:35:46 +01:00
return MinecraftClient.getInstance().player;
}
2019-01-31 16:21:14 +01:00
@Override
@Nullable
2020-01-16 16:46:24 +01:00
public PlayerEntity getPlayerByUUID(UUID playerId) {
2020-01-16 12:35:46 +01:00
Minecraft mc = MinecraftClient.getInstance();
2019-01-31 16:21:14 +01:00
if (mc.player.getUniqueID().equals(playerId)) {
return mc.player;
}
return mc.world.getPlayerEntityByUUID(playerId);
}
2020-01-16 12:35:46 +01:00
@Override
@Nonnull
2020-01-16 16:46:24 +01:00
public PlayerEntity createPlayer(Entity observer, GameProfile profile) {
return new EntityFakeClientPlayer(observer.world, profile);
}
@Override
2020-01-16 16:46:24 +01:00
public boolean isClientPlayer(@Nullable PlayerEntity player) {
if (getPlayer() == player) {
return true;
}
if (getPlayer() == null || player == null) {
return false;
}
return IPlayer.equal(getPlayer(), player);
}
@Override
public int getViewMode() {
2020-01-16 12:35:46 +01:00
return MinecraftClient.getInstance().gameSettings.thirdPersonView;
}
@Override
public void postRenderEntity(Entity entity) {
2020-01-16 16:46:24 +01:00
if (entity instanceof PlayerEntity) {
IPlayer iplayer = SpeciesList.instance().getPlayer((PlayerEntity)entity);
if (iplayer.getGravity().getGravitationConstant() < 0) {
GlStateManager.translate(0, entity.height, 0);
GlStateManager.scale(1, -1, 1);
entity.prevRotationPitch *= -1;
entity.rotationPitch *= -1;
}
}
}
@Override
public boolean renderEntity(Entity entity, float renderPartialTicks) {
2020-01-16 12:35:46 +01:00
if (DisguiseRenderer.getInstance().renderDisguise(entity, renderPartialTicks)) {
return true;
}
2020-01-16 16:46:24 +01:00
if (entity instanceof PlayerEntity) {
IPlayer iplayer = SpeciesList.instance().getPlayer((PlayerEntity)entity);
if (iplayer.getGravity().getGravitationConstant() < 0) {
GlStateManager.scale(1, -1, 1);
GlStateManager.translate(0, -entity.height, 0);
entity.prevRotationPitch *= -1;
entity.rotationPitch *= -1;
}
2020-01-16 12:35:46 +01:00
if (DisguiseRenderer.getInstance().renderDisguiseToGui(iplayer)) {
return true;
}
if (iplayer.isInvisible()) {
return true;
}
}
return false;
}
@Override
public void preInit() {
UEntities.preInit();
UParticles.init();
}
@Override
public void init() {
clientPlayerRace = getclientPlayerRace();
}
2020-01-16 12:35:46 +01:00
@Override
public void tick() {
2020-01-16 12:35:46 +01:00
PlayerEntity player = UClient.instance().getPlayer();
2020-01-16 12:35:46 +01:00
if (player != null && !player.removed) {
Race newRace = getclientPlayerRace();
if (newRace != clientPlayerRace) {
clientPlayerRace = newRace;
Unicopia.getConnection().send(new MsgRequestCapabilities(player, clientPlayerRace), Target.SERVER);
}
}
Keyboard.getKeyHandler().onKeyInput();
2020-01-16 12:35:46 +01:00
MinecraftClient client = MinecraftClient.getInstance();
2020-01-16 12:35:46 +01:00
if (player instanceof ClientPlayerEntity) {
ClientPlayerEntity sp = (ClientPlayerEntity)player;
2020-01-16 12:35:46 +01:00
Input movement = sp.input;
if (!(movement instanceof InversionAwareKeyboardInput)) {
sp.input = new InversionAwareKeyboardInput(client, movement);
}
}
2020-01-16 12:35:46 +01:00
if (!(client.mouse instanceof MouseControl)) {
client.mouse = new MouseControl(client);
}
}
}