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

91 lines
3.5 KiB
Java
Raw Normal View History

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;
import com.minelittlepony.common.event.ScreenInitCallback;
import com.minelittlepony.common.event.ScreenInitCallback.ButtonList;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.Unicopia;
2021-08-07 22:31:09 +02:00
import com.minelittlepony.unicopia.client.gui.LanSettingsScreen;
import com.minelittlepony.unicopia.client.gui.UHud;
import com.minelittlepony.unicopia.client.minelittlepony.MineLPConnector;
2021-11-10 18:26:25 +01:00
import com.minelittlepony.unicopia.container.SpellbookScreen;
import com.minelittlepony.unicopia.container.UScreenHandlers;
2020-10-04 12:58:01 +02:00
import com.minelittlepony.unicopia.entity.player.PlayerCamera;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.fabricmc.api.ClientModInitializer;
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;
2021-11-10 18:26:25 +01:00
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
import net.minecraft.client.MinecraftClient;
2021-08-07 22:31:09 +02:00
import net.minecraft.client.gui.screen.OpenToLanScreen;
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;
2020-04-25 13:32:33 +02:00
public class UnicopiaClient implements ClientModInitializer {
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();
}
public static Race getPreferredRace() {
if (!Unicopia.getConfig().ignoreMineLP.get()
&& MinecraftClient.getInstance().player != null) {
Race race = MineLPConnector.getPlayerPonyRace();
if (!race.isDefault()) {
return race;
}
}
return Unicopia.getConfig().preferredRace.get();
}
public static float getWorldBrightness(float initial) {
return initial > 0 ? 3 : 2;
}
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
KeyBindingsHandler.bootstrap();
2020-04-24 16:10:00 +02:00
URenderers.bootstrap();
2021-11-10 18:26:25 +01:00
ScreenRegistry.register(UScreenHandlers.SPELL_BOOK, SpellbookScreen::new);
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());
Unicopia.SIDE = () -> Optional.ofNullable(MinecraftClient.getInstance().player).map(Pony::of);
}
2020-04-22 16:28:20 +02:00
private void onTick(MinecraftClient client) {
KeyBindingsHandler.INSTANCE.tick(client);
UHud.INSTANCE.tick();
}
2020-04-22 16:28:20 +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))
2021-12-22 10:15:09 +01:00
.onClick(b -> MinecraftClient.getInstance().setScreen(new LanSettingsScreen(screen)))
2021-08-07 22:31:09 +02:00
.getStyle().setText(new TranslatableText("unicopia.options.title"));
}
2020-04-22 16:28:20 +02:00
}
2021-02-22 14:53:13 +01:00
}