2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.client;
|
2019-01-31 16:21:14 +01:00
|
|
|
|
2020-04-15 15:45:57 +02:00
|
|
|
import static com.minelittlepony.unicopia.EquinePredicates.MAGI;
|
|
|
|
|
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-27 17:37:22 +01:00
|
|
|
import com.minelittlepony.common.event.ClientReadyCallback;
|
|
|
|
import com.minelittlepony.jumpingcastle.api.Target;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.Config;
|
|
|
|
import com.minelittlepony.unicopia.InteractionManager;
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-04-16 00:44:58 +02:00
|
|
|
import com.minelittlepony.unicopia.Unicopia;
|
2020-04-15 17:22:29 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.Abilities;
|
2020-04-15 19:06:45 +02:00
|
|
|
import com.minelittlepony.unicopia.block.UBlocks;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.client.render.DisguiseRenderer;
|
2020-04-15 17:11:37 +02:00
|
|
|
import com.minelittlepony.unicopia.ducks.Colourful;
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2020-04-15 15:45:57 +02:00
|
|
|
import com.minelittlepony.unicopia.item.UItems;
|
|
|
|
import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
|
|
|
|
import com.minelittlepony.unicopia.util.dummy.DummyClientPlayerEntity;
|
2019-02-09 13:27:15 +01:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2020-01-27 11:05:22 +01:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
2019-01-30 11:26:00 +01:00
|
|
|
|
2020-01-27 17:37:22 +01:00
|
|
|
import net.fabricmc.api.ClientModInitializer;
|
2020-04-15 15:45:57 +02:00
|
|
|
import net.fabricmc.fabric.api.client.render.ColorProviderRegistry;
|
2020-01-27 17:37:22 +01:00
|
|
|
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
|
2020-04-15 15:45:57 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.client.MinecraftClient;
|
2020-04-15 15:45:57 +02:00
|
|
|
import net.minecraft.client.color.world.BiomeColors;
|
|
|
|
import net.minecraft.client.color.world.GrassColors;
|
2020-01-27 17:37:22 +01:00
|
|
|
import net.minecraft.client.world.ClientWorld;
|
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;
|
2020-04-15 15:45:57 +02:00
|
|
|
import net.minecraft.item.BlockItem;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.ExtendedBlockView;
|
2019-02-02 21:34:27 +01:00
|
|
|
|
2020-04-16 00:44:58 +02:00
|
|
|
public class UnicopiaClient extends InteractionManager implements ClientModInitializer {
|
2020-01-27 17:37:22 +01:00
|
|
|
|
2020-04-15 15:55:18 +02:00
|
|
|
private final KeyBindingsHandler keyboard = new KeyBindingsHandler();
|
2019-01-30 11:26:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04-15 18:12:00 +02:00
|
|
|
if (!Config.getInstance().ignoresMineLittlePony()
|
2020-01-16 12:35:46 +01:00
|
|
|
&& MinecraftClient.getInstance().player != null) {
|
2020-01-27 17:37:22 +01:00
|
|
|
Race race = MineLPConnector.getPlayerPonyRace();
|
2019-01-30 11:26:00 +01:00
|
|
|
|
|
|
|
if (!race.isDefault()) {
|
|
|
|
return race;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 21:34:27 +01:00
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
return Config.getInstance().getPrefferedRace();
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2020-01-27 17:37:22 +01:00
|
|
|
if (observer.world instanceof ClientWorld) {
|
|
|
|
return new DummyClientPlayerEntity((ClientWorld)observer.world, profile);
|
|
|
|
}
|
|
|
|
return super.createPlayer(observer, 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) {
|
2020-01-27 17:37:22 +01:00
|
|
|
if (MinecraftClient.getInstance().player == player) {
|
2019-01-30 21:17:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-27 17:37:22 +01:00
|
|
|
if (MinecraftClient.getInstance().player == null || player == null) {
|
2019-01-30 21:17:46 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
return Pony.equal(MinecraftClient.getInstance().player, player);
|
2019-01-30 21:17:46 +01:00
|
|
|
}
|
|
|
|
|
2019-02-02 17:50:15 +01:00
|
|
|
@Override
|
|
|
|
public int getViewMode() {
|
2020-01-27 17:37:22 +01:00
|
|
|
return MinecraftClient.getInstance().options.perspective;
|
2019-02-02 17:50:15 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 21:15:04 +01:00
|
|
|
public void postRenderEntity(Entity entity) {
|
2020-01-16 16:46:24 +01:00
|
|
|
if (entity instanceof PlayerEntity) {
|
2020-04-15 18:12:00 +02:00
|
|
|
Pony iplayer = Pony.of((PlayerEntity)entity);
|
2019-02-27 21:15:04 +01:00
|
|
|
|
|
|
|
if (iplayer.getGravity().getGravitationConstant() < 0) {
|
2020-01-27 17:37:22 +01:00
|
|
|
GlStateManager.translated(0, entity.getDimensions(entity.getPose()).height, 0);
|
2020-01-27 11:05:22 +01:00
|
|
|
GlStateManager.scalef(1, -1, 1);
|
|
|
|
entity.prevPitch *= -1;
|
|
|
|
entity.pitch *= -1;
|
2019-02-27 21:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 00:08:19 +01:00
|
|
|
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) {
|
2020-04-15 18:12:00 +02:00
|
|
|
Pony iplayer = Pony.of((PlayerEntity)entity);
|
2019-02-06 11:33:42 +01:00
|
|
|
|
2019-02-27 21:15:04 +01:00
|
|
|
if (iplayer.getGravity().getGravitationConstant() < 0) {
|
2020-01-27 11:05:22 +01:00
|
|
|
GlStateManager.scalef(1, -1, 1);
|
2020-01-27 17:37:22 +01:00
|
|
|
GlStateManager.translated(0, -entity.getDimensions(entity.getPose()).height, 0);
|
2020-01-27 11:05:22 +01:00
|
|
|
entity.prevPitch *= -1;
|
|
|
|
entity.pitch *= -1;
|
2019-02-27 21:15:04 +01:00
|
|
|
}
|
|
|
|
|
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
|
2020-01-27 17:37:22 +01:00
|
|
|
public void onInitializeClient() {
|
2019-01-30 11:26:00 +01:00
|
|
|
clientPlayerRace = getclientPlayerRace();
|
2020-04-15 15:55:18 +02:00
|
|
|
InteractionManager.instance = this;
|
2020-01-27 17:37:22 +01:00
|
|
|
|
|
|
|
ClientTickCallback.EVENT.register(this::tick);
|
|
|
|
ClientReadyCallback.EVENT.register(client -> {
|
2020-04-15 17:22:29 +02:00
|
|
|
Abilities.getInstance().getValues().forEach(keyboard::addKeybind);
|
2020-01-27 17:37:22 +01:00
|
|
|
});
|
2020-04-15 15:45:57 +02:00
|
|
|
|
|
|
|
//BuildInTexturesBakery.getBuiltInTextures().add(new Identifier(Unicopia.MODID, "items/empty_slot_gem"));
|
|
|
|
|
|
|
|
ColorProviderRegistry.ITEM.register((stack, tint) -> {
|
|
|
|
return getLeavesColor(((BlockItem)stack.getItem()).getBlock().getDefaultState(), null, null, tint);
|
|
|
|
}, UItems.apple_leaves);
|
2020-04-16 00:44:58 +02:00
|
|
|
ColorProviderRegistry.BLOCK.register(UnicopiaClient::getLeavesColor, UBlocks.apple_leaves);
|
2020-04-15 15:45:57 +02:00
|
|
|
ColorProviderRegistry.ITEM.register((stack, tint) -> {
|
|
|
|
if (MAGI.test(MinecraftClient.getInstance().player)) {
|
|
|
|
return SpellRegistry.instance().getSpellTintFromStack(stack);
|
|
|
|
}
|
|
|
|
return 0xFFFFFF;
|
|
|
|
}, UItems.spell, UItems.curse);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int getLeavesColor(BlockState state, @Nullable ExtendedBlockView world, @Nullable BlockPos pos, int tint) {
|
|
|
|
Block block = state.getBlock();
|
|
|
|
|
2020-04-15 17:11:37 +02:00
|
|
|
if (block instanceof Colourful) {
|
|
|
|
return ((Colourful)block).getCustomTint(state, tint);
|
2020-04-15 15:45:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (world != null && pos != null) {
|
|
|
|
return BiomeColors.getGrassColor(world, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GrassColors.getColor(0.5D, 1);
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 17:37:22 +01:00
|
|
|
private void tick(MinecraftClient client) {
|
|
|
|
PlayerEntity player = client.player;
|
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
|
|
|
|
2020-04-16 00:44:58 +02:00
|
|
|
Unicopia.getConnection().send(new MsgRequestCapabilities(player, clientPlayerRace), Target.SERVER);
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 17:37:22 +01:00
|
|
|
keyboard.onKeyInput();
|
2019-01-30 11:26:00 +01:00
|
|
|
}
|
|
|
|
}
|