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;
|
|
|
|
|
|
|
|
import com.minelittlepony.jumpingcastle.api.Target;
|
2019-02-09 15:34:17 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.EntityFakeClientPlayer;
|
2019-02-18 18:48:06 +01:00
|
|
|
import com.minelittlepony.unicopia.extern.MineLP;
|
2019-02-17 00:08:19 +01:00
|
|
|
import com.minelittlepony.unicopia.init.UEntities;
|
|
|
|
import com.minelittlepony.unicopia.init.UParticles;
|
2019-01-30 11:26:00 +01:00
|
|
|
import com.minelittlepony.unicopia.input.Keyboard;
|
|
|
|
import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding;
|
|
|
|
import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
|
|
|
|
import com.minelittlepony.unicopia.player.IPlayer;
|
|
|
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
2019-02-11 16:41:24 +01:00
|
|
|
import com.minelittlepony.unicopia.render.DisguiseRenderer;
|
2019-02-02 21:34:27 +01:00
|
|
|
import com.minelittlepony.util.gui.ButtonGridLayout;
|
|
|
|
import com.minelittlepony.util.gui.UButton;
|
2019-02-19 10:48:00 +01:00
|
|
|
import com.minelittlepony.util.lang.ClientLocale;
|
2019-02-09 13:27:15 +01:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2019-01-30 11:26:00 +01:00
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
2019-02-02 21:34:27 +01:00
|
|
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
2019-01-30 11:26:00 +01:00
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
2019-02-02 21:34:27 +01:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2019-02-06 11:33:42 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2019-01-30 11:26:00 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2019-02-02 21:34:27 +01:00
|
|
|
import net.minecraft.init.SoundEvents;
|
2019-01-30 11:26:00 +01:00
|
|
|
import net.minecraft.world.IInteractionObject;
|
|
|
|
|
2019-02-02 21:34:27 +01:00
|
|
|
import static com.minelittlepony.util.gui.ButtonGridLayout.*;
|
|
|
|
|
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()
|
2019-02-02 12:23:22 +01:00
|
|
|
&& Minecraft.getMinecraft().player != null) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
static void addUniButton(List<GuiButton> buttons) {
|
|
|
|
ButtonGridLayout layout = new ButtonGridLayout(buttons);
|
|
|
|
|
2019-02-19 10:48:00 +01:00
|
|
|
GuiButton uni = new UButton(layout.getNextButtonId(), 0, 0, 150, 20, ClientLocale.format("gui.unicopia"), b -> {
|
2019-02-17 00:08:19 +01:00
|
|
|
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.BLOCK_ANVIL_USE, 1));
|
|
|
|
b.displayString = "<< WIP >>";
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
List<Integer> possibleXCandidates = list(layout.getColumns());
|
|
|
|
List<Integer> possibleYCandidates = list(layout.getRows());
|
|
|
|
|
|
|
|
uni.y = last(possibleYCandidates, 1);
|
|
|
|
|
|
|
|
if (layout.getRows()
|
|
|
|
.filter(y -> layout.getRow(y).size() == 1).count() < 2) {
|
|
|
|
uni.y += 25;
|
|
|
|
uni.x = first(possibleXCandidates, 0);
|
|
|
|
|
|
|
|
layout.getRow(last(possibleYCandidates, 0)).forEach(button -> {
|
|
|
|
button.y = Math.max(button.y, uni.y + uni.height + 13);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
uni.x = first(possibleXCandidates, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.getElements().add(uni);
|
|
|
|
}
|
2019-01-30 11:26:00 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void displayGuiToPlayer(EntityPlayer player, IInteractionObject inventory) {
|
|
|
|
if (player instanceof EntityPlayerSP) {
|
|
|
|
if ("unicopia:itemofholding".equals(inventory.getGuiID())) {
|
|
|
|
Minecraft.getMinecraft().displayGuiScreen(new GuiOfHolding(inventory));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
super.displayGuiToPlayer(player, inventory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 16:21:14 +01:00
|
|
|
@Override
|
2019-01-30 11:26:00 +01:00
|
|
|
@Nullable
|
|
|
|
public EntityPlayer getPlayer() {
|
|
|
|
return Minecraft.getMinecraft().player;
|
|
|
|
}
|
|
|
|
|
2019-01-31 16:21:14 +01:00
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public EntityPlayer getPlayerByUUID(UUID playerId) {
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
|
|
|
|
if (mc.player.getUniqueID().equals(playerId)) {
|
|
|
|
return mc.player;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mc.world.getPlayerEntityByUUID(playerId);
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:27:15 +01:00
|
|
|
@Nonnull
|
|
|
|
public EntityPlayer 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
|
|
|
|
public boolean isClientPlayer(@Nullable EntityPlayer player) {
|
|
|
|
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() {
|
|
|
|
return Minecraft.getMinecraft().gameSettings.thirdPersonView;
|
|
|
|
}
|
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
@Override
|
|
|
|
public boolean renderEntity(Entity entity, float renderPartialTicks) {
|
2019-02-11 16:41:24 +01:00
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
if (DisguiseRenderer.instance().renderDisguise(entity, renderPartialTicks)) {
|
|
|
|
return true;
|
2019-02-11 16:41:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entity instanceof EntityPlayer) {
|
|
|
|
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity);
|
2019-02-06 11:33:42 +01:00
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
if (DisguiseRenderer.instance().renderDisguiseToGui(iplayer)) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
public void tick() {
|
|
|
|
EntityPlayer player = UClient.instance().getPlayer();
|
2019-01-30 21:17:46 +01:00
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
if (player != null && !player.isDead) {
|
|
|
|
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-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
}
|