2019-01-30 11:26:00 +01:00
|
|
|
package com.minelittlepony.unicopia;
|
|
|
|
|
2019-02-02 21:34:27 +01:00
|
|
|
import java.util.List;
|
2019-01-31 16:21:14 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2019-02-09 13:27:15 +01:00
|
|
|
import javax.annotation.Nonnull;
|
2019-01-30 11:26:00 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.powers.render.DisguiseRenderer;
|
|
|
|
import com.minelittlepony.unicopia.client.gui.SettingsScreen;
|
|
|
|
import com.minelittlepony.unicopia.client.input.Keyboard;
|
|
|
|
import com.minelittlepony.unicopia.client.input.MouseControl;
|
|
|
|
import com.minelittlepony.unicopia.client.input.InversionAwareKeyboardInput;
|
|
|
|
import com.minelittlepony.unicopia.entity.player.IPlayer;
|
2019-01-30 11:26:00 +01:00
|
|
|
import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
|
2019-02-09 13:27:15 +01:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2019-01-30 11:26:00 +01:00
|
|
|
|
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;
|
2019-02-06 11:33:42 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2019-02-02 21:34:27 +01:00
|
|
|
|
2019-01-30 11:26:00 +01:00
|
|
|
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() {
|
2019-02-17 00:08:19 +01:00
|
|
|
if (!UConfig.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();
|
2019-01-30 11:26:00 +01:00
|
|
|
|
|
|
|
if (!race.isDefault()) {
|
|
|
|
return race;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 21:34:27 +01:00
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
return UConfig.instance().getPrefferedRace();
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-16 16:46:24 +01:00
|
|
|
public void displayGuiToPlayer(PlayerEntity player, IInteractionObject inventory) {
|
|
|
|
if (player instanceof PlayerEntitySP) {
|
2019-01-30 11:26:00 +01:00
|
|
|
if ("unicopia:itemofholding".equals(inventory.getGuiID())) {
|
2020-01-16 12:35:46 +01:00
|
|
|
MinecraftClient.getInstance().displayGuiScreen(new GuiOfHolding(inventory));
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
super.displayGuiToPlayer(player, inventory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 16:21:14 +01:00
|
|
|
@Override
|
2019-01-30 11:26:00 +01:00
|
|
|
@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-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
|
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
|
2019-02-09 13:27:15 +01:00
|
|
|
@Nonnull
|
2020-01-16 16:46:24 +01:00
|
|
|
public PlayerEntity createPlayer(Entity observer, GameProfile profile) {
|
2019-02-09 15:34:17 +01:00
|
|
|
return new EntityFakeClientPlayer(observer.world, profile);
|
2019-02-09 13:27:15 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 21:17:46 +01:00
|
|
|
@Override
|
2020-01-16 16:46:24 +01:00
|
|
|
public boolean isClientPlayer(@Nullable PlayerEntity player) {
|
2019-01-30 21:17:46 +01:00
|
|
|
if (getPlayer() == player) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getPlayer() == null || player == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-11 16:41:24 +01:00
|
|
|
return IPlayer.equal(getPlayer(), player);
|
2019-01-30 21:17:46 +01:00
|
|
|
}
|
|
|
|
|
2019-02-02 17:50:15 +01:00
|
|
|
@Override
|
|
|
|
public int getViewMode() {
|
2020-01-16 12:35:46 +01:00
|
|
|
return MinecraftClient.getInstance().gameSettings.thirdPersonView;
|
2019-02-02 17:50:15 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 21:15:04 +01:00
|
|
|
@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);
|
2019-02-27 21:15:04 +01:00
|
|
|
|
|
|
|
if (iplayer.getGravity().getGravitationConstant() < 0) {
|
|
|
|
GlStateManager.translate(0, entity.height, 0);
|
|
|
|
GlStateManager.scale(1, -1, 1);
|
|
|
|
entity.prevRotationPitch *= -1;
|
|
|
|
entity.rotationPitch *= -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
@Override
|
|
|
|
public boolean renderEntity(Entity entity, float renderPartialTicks) {
|
2019-02-11 16:41:24 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
if (DisguiseRenderer.getInstance().renderDisguise(entity, renderPartialTicks)) {
|
2019-02-17 00:08:19 +01:00
|
|
|
return true;
|
2019-02-11 16:41:24 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 16:46:24 +01:00
|
|
|
if (entity instanceof PlayerEntity) {
|
|
|
|
IPlayer iplayer = SpeciesList.instance().getPlayer((PlayerEntity)entity);
|
2019-02-06 11:33:42 +01:00
|
|
|
|
2019-02-27 21:15:04 +01:00
|
|
|
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)) {
|
2019-02-17 00:08:19 +01:00
|
|
|
return true;
|
2019-02-06 11:33:42 +01:00
|
|
|
}
|
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
if (iplayer.isInvisible()) {
|
|
|
|
return true;
|
2019-02-11 16:41:24 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 11:33:42 +01:00
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
return false;
|
2019-02-02 17:50:15 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 11:26:00 +01:00
|
|
|
@Override
|
2019-02-17 00:08:19 +01:00
|
|
|
public void preInit() {
|
2019-01-30 11:26:00 +01:00
|
|
|
UEntities.preInit();
|
|
|
|
UParticles.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-17 00:08:19 +01:00
|
|
|
public void init() {
|
2019-01-30 11:26:00 +01:00
|
|
|
clientPlayerRace = getclientPlayerRace();
|
|
|
|
}
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
@Override
|
2019-02-17 00:08:19 +01:00
|
|
|
public void tick() {
|
2020-01-16 12:35:46 +01:00
|
|
|
PlayerEntity player = UClient.instance().getPlayer();
|
2019-01-30 21:17:46 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
if (player != null && !player.removed) {
|
2019-02-17 00:08:19 +01:00
|
|
|
Race newRace = getclientPlayerRace();
|
2019-01-30 11:26:00 +01:00
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
if (newRace != clientPlayerRace) {
|
|
|
|
clientPlayerRace = newRace;
|
2019-01-30 11:26:00 +01:00
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
Unicopia.getConnection().send(new MsgRequestCapabilities(player, clientPlayerRace), Target.SERVER);
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
Keyboard.getKeyHandler().onKeyInput();
|
2019-02-27 21:15:04 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
MinecraftClient client = MinecraftClient.getInstance();
|
2019-02-27 21:15:04 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
if (player instanceof ClientPlayerEntity) {
|
|
|
|
ClientPlayerEntity sp = (ClientPlayerEntity)player;
|
2019-02-27 21:15:04 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
Input movement = sp.input;
|
|
|
|
|
|
|
|
if (!(movement instanceof InversionAwareKeyboardInput)) {
|
|
|
|
sp.input = new InversionAwareKeyboardInput(client, movement);
|
2019-02-27 21:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
if (!(client.mouse instanceof MouseControl)) {
|
|
|
|
client.mouse = new MouseControl(client);
|
2019-02-27 21:15:04 +01:00
|
|
|
}
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
}
|