2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.client;
|
2019-01-31 16:21:14 +01:00
|
|
|
|
2020-10-04 12:58:01 +02:00
|
|
|
import java.util.Optional;
|
2021-08-07 22:31:09 +02:00
|
|
|
|
|
|
|
import com.minelittlepony.common.client.gui.element.Button;
|
2020-09-23 21:56:57 +02:00
|
|
|
import com.minelittlepony.common.event.ScreenInitCallback;
|
|
|
|
import com.minelittlepony.common.event.ScreenInitCallback.ButtonList;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.InteractionManager;
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-09-23 21:56:57 +02:00
|
|
|
import com.minelittlepony.unicopia.Unicopia;
|
2021-08-07 22:31:09 +02:00
|
|
|
import com.minelittlepony.unicopia.client.gui.LanSettingsScreen;
|
2020-10-09 14:37:49 +02:00
|
|
|
import com.minelittlepony.unicopia.client.gui.UHud;
|
2021-03-01 08:41:14 +01:00
|
|
|
import com.minelittlepony.unicopia.client.minelittlepony.MineLPConnector;
|
2020-10-04 12:58:01 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.PlayerCamera;
|
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2020-01-27 17:37:22 +01:00
|
|
|
import net.fabricmc.api.ClientModInitializer;
|
2020-09-22 15:11:20 +02:00
|
|
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
2021-02-22 14:53:13 +01:00
|
|
|
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
2020-09-23 21:56:57 +02:00
|
|
|
import net.minecraft.client.MinecraftClient;
|
2021-08-07 22:31:09 +02:00
|
|
|
import net.minecraft.client.gui.screen.OpenToLanScreen;
|
2020-09-23 21:56:57 +02:00
|
|
|
import net.minecraft.client.gui.screen.Screen;
|
|
|
|
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
|
2020-10-04 12:58:01 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2021-08-07 22:31:09 +02:00
|
|
|
import net.minecraft.text.TranslatableText;
|
2019-02-02 21:34:27 +01:00
|
|
|
|
2020-04-25 13:32:33 +02:00
|
|
|
public class UnicopiaClient implements ClientModInitializer {
|
2020-01-27 17:37:22 +01:00
|
|
|
|
2020-10-04 12:58:01 +02:00
|
|
|
public static Optional<PlayerCamera> getCamera() {
|
|
|
|
PlayerEntity player = MinecraftClient.getInstance().player;
|
|
|
|
|
|
|
|
if (player != null && MinecraftClient.getInstance().cameraEntity == player) {
|
|
|
|
return Optional.of(Pony.of(player).getCamera());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Optional.empty();
|
|
|
|
}
|
|
|
|
|
2020-09-23 21:56:57 +02:00
|
|
|
public static Race getPreferredRace() {
|
2021-02-07 18:57:35 +01:00
|
|
|
if (!Unicopia.getConfig().ignoreMineLP.get()
|
2020-09-23 21:56:57 +02:00
|
|
|
&& MinecraftClient.getInstance().player != null) {
|
|
|
|
Race race = MineLPConnector.getPlayerPonyRace();
|
|
|
|
|
|
|
|
if (!race.isDefault()) {
|
|
|
|
return race;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 18:57:35 +01:00
|
|
|
return Unicopia.getConfig().preferredRace.get();
|
2020-09-23 21:56:57 +02:00
|
|
|
}
|
2019-01-30 11:26:00 +01:00
|
|
|
|
2020-09-25 23:39:57 +02:00
|
|
|
public static float getWorldBrightness(float initial) {
|
2021-08-09 13:25:53 +02:00
|
|
|
return initial > 0 ? 3 : 2;
|
2020-09-25 23:39:57 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 16:28:20 +02:00
|
|
|
@Override
|
|
|
|
public void onInitializeClient() {
|
2020-04-25 13:32:33 +02:00
|
|
|
InteractionManager.INSTANCE = new ClientInteractionManager();
|
2020-04-22 16:28:20 +02:00
|
|
|
|
2020-09-25 13:06:41 +02:00
|
|
|
KeyBindingsHandler.bootstrap();
|
2020-04-24 16:10:00 +02:00
|
|
|
URenderers.bootstrap();
|
|
|
|
|
2020-09-23 21:56:57 +02:00
|
|
|
ClientTickEvents.END_CLIENT_TICK.register(this::onTick);
|
|
|
|
ScreenInitCallback.EVENT.register(this::onScreenInit);
|
2021-02-22 14:53:13 +01:00
|
|
|
ItemTooltipCallback.EVENT.register(new ModifierTooltipRenderer());
|
2021-03-01 14:09:38 +01:00
|
|
|
|
|
|
|
Unicopia.SIDE = () -> Optional.ofNullable(MinecraftClient.getInstance().player).map(Pony::of);
|
2020-09-23 21:56:57 +02:00
|
|
|
}
|
2020-04-22 16:28:20 +02:00
|
|
|
|
2020-09-23 21:56:57 +02:00
|
|
|
private void onTick(MinecraftClient client) {
|
|
|
|
KeyBindingsHandler.INSTANCE.tick(client);
|
2020-10-11 13:14:11 +02:00
|
|
|
UHud.INSTANCE.tick();
|
2020-09-23 21:56:57 +02:00
|
|
|
}
|
2020-04-22 16:28:20 +02:00
|
|
|
|
2020-09-23 21:56:57 +02:00
|
|
|
private void onScreenInit(Screen screen, ButtonList buttons) {
|
|
|
|
if (screen instanceof CreateWorldScreen) {
|
2021-08-07 22:31:09 +02:00
|
|
|
buttons.addButton(LanSettingsScreen.createRaceSelector(screen));
|
|
|
|
}
|
|
|
|
if (screen instanceof OpenToLanScreen) {
|
|
|
|
buttons.addButton(new Button(screen.width / 2 - 155, 130, 150, 20))
|
|
|
|
.onClick(b -> MinecraftClient.getInstance().openScreen(new LanSettingsScreen(screen)))
|
|
|
|
.getStyle().setText(new TranslatableText("unicopia.options.title"));
|
2020-09-23 21:56:57 +02:00
|
|
|
}
|
2020-04-22 16:28:20 +02:00
|
|
|
}
|
2021-02-22 14:53:13 +01:00
|
|
|
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|