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-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;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.InteractionManager;
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
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-22 20:23:54 +02:00
|
|
|
import com.minelittlepony.unicopia.container.SpellbookResultSlot;
|
2020-04-15 17:11:37 +02:00
|
|
|
import com.minelittlepony.unicopia.ducks.Colourful;
|
2020-04-15 15:45:57 +02:00
|
|
|
import com.minelittlepony.unicopia.item.UItems;
|
|
|
|
import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
|
2020-04-22 20:23:54 +02:00
|
|
|
import com.minelittlepony.unicopia.mixin.client.DefaultTexturesRegistry;
|
2020-04-23 23:44:31 +02:00
|
|
|
import com.minelittlepony.unicopia.network.Channel;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
|
2020-01-27 17:37:22 +01:00
|
|
|
import net.fabricmc.api.ClientModInitializer;
|
2020-04-22 16:28:20 +02:00
|
|
|
import net.fabricmc.fabric.api.client.rendering.v1.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-04-22 20:23:54 +02:00
|
|
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
|
|
|
import net.minecraft.client.util.SpriteIdentifier;
|
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;
|
2020-04-22 16:28:20 +02:00
|
|
|
import net.minecraft.world.BlockRenderView;
|
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-04-15 15:55:18 +02:00
|
|
|
private final KeyBindingsHandler keyboard = new KeyBindingsHandler();
|
2019-01-30 11:26:00 +01:00
|
|
|
|
2020-04-25 13:32:33 +02:00
|
|
|
private Race lastPreferredRace = InteractionManager.instance().getPreferredRace();
|
2019-01-30 11:26:00 +01:00
|
|
|
|
2020-04-22 16:28:20 +02:00
|
|
|
@Override
|
|
|
|
public void onInitializeClient() {
|
2020-04-25 13:32:33 +02:00
|
|
|
lastPreferredRace = InteractionManager.instance().getPreferredRace();
|
|
|
|
InteractionManager.INSTANCE = new ClientInteractionManager();
|
2020-04-22 16:28:20 +02:00
|
|
|
|
2020-04-24 16:10:00 +02:00
|
|
|
URenderers.bootstrap();
|
|
|
|
|
2020-04-22 16:28:20 +02:00
|
|
|
ClientTickCallback.EVENT.register(this::tick);
|
2020-04-25 15:37:17 +02:00
|
|
|
ClientReadyCallback.EVENT.register(client -> Abilities.REGISTRY.stream().forEach(keyboard::addKeybind));
|
2020-04-22 16:28:20 +02:00
|
|
|
|
2020-04-22 20:23:54 +02:00
|
|
|
DefaultTexturesRegistry.getDefaultTextures().add(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, SpellbookResultSlot.EMPTY_GEM_SLOT));
|
2020-04-22 16:28:20 +02:00
|
|
|
|
|
|
|
ColorProviderRegistry.ITEM.register((stack, tint) -> {
|
|
|
|
return getLeavesColor(((BlockItem)stack.getItem()).getBlock().getDefaultState(), null, null, tint);
|
2020-04-24 15:23:36 +02:00
|
|
|
}, UItems.APPLE_LEAVES);
|
|
|
|
ColorProviderRegistry.BLOCK.register(UnicopiaClient::getLeavesColor, UBlocks.APPLE_LEAVES);
|
2020-04-22 16:28:20 +02:00
|
|
|
ColorProviderRegistry.ITEM.register((stack, tint) -> {
|
|
|
|
if (MAGI.test(MinecraftClient.getInstance().player)) {
|
|
|
|
return SpellRegistry.instance().getSpellTintFromStack(stack);
|
|
|
|
}
|
|
|
|
return 0xFFFFFF;
|
2020-04-24 15:23:36 +02:00
|
|
|
}, UItems.GEM, UItems.CORRUPTED_GEM);
|
2020-04-22 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void tick(MinecraftClient client) {
|
|
|
|
PlayerEntity player = client.player;
|
|
|
|
|
|
|
|
if (player != null && !player.removed) {
|
2020-04-25 13:32:33 +02:00
|
|
|
Race newRace = InteractionManager.instance().getPreferredRace();
|
2020-04-22 16:28:20 +02:00
|
|
|
|
2020-04-25 13:32:33 +02:00
|
|
|
if (newRace != lastPreferredRace) {
|
|
|
|
lastPreferredRace = newRace;
|
2020-04-22 16:28:20 +02:00
|
|
|
|
2020-04-25 13:32:33 +02:00
|
|
|
Channel.REQUEST_CAPABILITIES.send(new MsgRequestCapabilities(lastPreferredRace));
|
2020-04-22 16:28:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-25 15:37:17 +02:00
|
|
|
keyboard.tick(client);
|
2020-04-22 16:28:20 +02:00
|
|
|
}
|
2019-01-30 11:26:00 +01:00
|
|
|
|
2020-04-22 16:28:20 +02:00
|
|
|
private static int getLeavesColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tint) {
|
2020-04-15 15:45:57 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|