2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.client;
|
|
|
|
|
2023-10-31 21:38:28 +01:00
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2023-08-14 21:31:33 +02:00
|
|
|
import com.minelittlepony.unicopia.Unicopia;
|
2022-09-25 00:14:29 +02:00
|
|
|
import com.minelittlepony.unicopia.block.*;
|
2023-12-04 15:49:24 +01:00
|
|
|
import com.minelittlepony.unicopia.block.cloud.CloudChestBlock;
|
2020-04-22 16:28:20 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.ChangelingMagicParticle;
|
2021-02-19 15:56:01 +01:00
|
|
|
import com.minelittlepony.unicopia.client.particle.CloudsEscapingParticle;
|
2020-04-22 16:28:20 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.DiskParticle;
|
2021-02-05 20:19:41 +01:00
|
|
|
import com.minelittlepony.unicopia.client.particle.GroundPoundParticle;
|
2021-02-02 11:52:50 +01:00
|
|
|
import com.minelittlepony.unicopia.client.particle.HealthDrainParticle;
|
2021-12-28 01:19:26 +01:00
|
|
|
import com.minelittlepony.unicopia.client.particle.LightningBoltParticle;
|
2020-04-22 16:28:20 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.MagicParticle;
|
2020-10-13 17:44:49 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.RainboomParticle;
|
2020-10-14 21:07:36 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.RainbowTrailParticle;
|
2020-04-22 16:28:20 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.RaindropsParticle;
|
2021-03-03 19:03:16 +01:00
|
|
|
import com.minelittlepony.unicopia.client.particle.RunesParticle;
|
2023-10-11 14:54:23 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.ShockwaveParticle;
|
2020-04-22 16:28:20 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.SphereParticle;
|
2022-09-11 15:42:26 +02:00
|
|
|
import com.minelittlepony.unicopia.client.render.*;
|
2022-09-15 00:51:07 +02:00
|
|
|
import com.minelittlepony.unicopia.client.render.entity.*;
|
2023-10-22 00:16:54 +02:00
|
|
|
import com.minelittlepony.unicopia.client.render.spell.SpellRendererFactory;
|
2023-09-02 19:34:57 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.mob.UEntities;
|
2021-02-14 21:15:30 +01:00
|
|
|
import com.minelittlepony.unicopia.item.ChameleonItem;
|
2023-02-28 17:44:14 +01:00
|
|
|
import com.minelittlepony.unicopia.item.EnchantableItem;
|
2023-11-25 04:05:45 +01:00
|
|
|
import com.minelittlepony.unicopia.item.FancyBedItem;
|
2021-02-03 21:25:42 +01:00
|
|
|
import com.minelittlepony.unicopia.item.UItems;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.particle.UParticles;
|
2023-08-14 21:31:33 +02:00
|
|
|
import com.terraformersmc.terraform.boat.api.client.TerraformBoatClientHelper;
|
2022-09-11 15:42:26 +02:00
|
|
|
|
|
|
|
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
|
2020-04-22 16:28:20 +02:00
|
|
|
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
|
2020-09-27 17:44:39 +02:00
|
|
|
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry.PendingParticleFactory;
|
2022-10-12 15:46:15 +02:00
|
|
|
import net.fabricmc.fabric.api.client.rendering.v1.*;
|
2023-10-31 17:45:41 +01:00
|
|
|
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry.DynamicItemRenderer;
|
2022-09-25 00:14:29 +02:00
|
|
|
import net.minecraft.block.Block;
|
2023-10-31 17:45:41 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
2023-10-31 21:38:28 +01:00
|
|
|
import net.minecraft.block.entity.BlockEntity;
|
2021-02-14 21:15:30 +01:00
|
|
|
import net.minecraft.client.MinecraftClient;
|
2022-09-23 23:25:00 +02:00
|
|
|
import net.minecraft.client.color.world.BiomeColors;
|
|
|
|
import net.minecraft.client.color.world.FoliageColors;
|
2022-06-25 00:19:55 +02:00
|
|
|
import net.minecraft.client.item.ModelPredicateProviderRegistry;
|
2020-09-27 17:44:39 +02:00
|
|
|
import net.minecraft.client.particle.Particle;
|
|
|
|
import net.minecraft.client.particle.SpriteProvider;
|
2022-09-25 01:55:29 +02:00
|
|
|
import net.minecraft.client.render.*;
|
2023-06-02 21:20:30 +02:00
|
|
|
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
|
2020-09-22 15:11:20 +02:00
|
|
|
import net.minecraft.client.render.entity.FlyingItemEntityRenderer;
|
2021-02-14 21:15:30 +01:00
|
|
|
import net.minecraft.client.render.item.ItemRenderer;
|
2023-06-02 21:20:30 +02:00
|
|
|
import net.minecraft.client.render.model.json.ModelTransformationMode;
|
2023-10-31 17:45:41 +01:00
|
|
|
import net.minecraft.client.util.math.MatrixStack;
|
2020-09-27 17:44:39 +02:00
|
|
|
import net.minecraft.client.world.ClientWorld;
|
2022-09-11 15:42:26 +02:00
|
|
|
import net.minecraft.fluid.Fluids;
|
2022-09-25 00:14:29 +02:00
|
|
|
import net.minecraft.item.*;
|
2020-09-27 17:44:39 +02:00
|
|
|
import net.minecraft.particle.ParticleEffect;
|
2021-03-02 14:40:37 +01:00
|
|
|
import net.minecraft.util.Identifier;
|
2023-10-31 17:45:41 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.BlockRenderView;
|
2020-04-15 14:22:03 +02:00
|
|
|
|
|
|
|
public interface URenderers {
|
2023-12-04 15:49:24 +01:00
|
|
|
BlockEntity CHEST_RENDER_ENTITY = new CloudChestBlock.TileData(BlockPos.ORIGIN, UBlocks.CLOUD_CHEST.getDefaultState());
|
|
|
|
|
2020-04-15 14:22:03 +02:00
|
|
|
static void bootstrap() {
|
2020-09-27 17:44:39 +02:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.UNICORN_MAGIC, createFactory(MagicParticle::new));
|
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.CHANGELING_MAGIC, createFactory(ChangelingMagicParticle::new));
|
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.RAIN_DROPS, createFactory(RaindropsParticle::new));
|
2021-12-26 09:49:04 +01:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.HEALTH_DRAIN, createFactory(HealthDrainParticle::create));
|
2020-10-13 17:44:49 +02:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.RAINBOOM_RING, RainboomParticle::new);
|
2020-10-14 21:07:36 +02:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.RAINBOOM_TRAIL, RainbowTrailParticle::new);
|
2023-10-11 14:54:23 +02:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.SHOCKWAVE, ShockwaveParticle::new);
|
2021-03-03 19:03:16 +01:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.MAGIC_RUNES, RunesParticle::new);
|
2020-05-03 19:20:51 +02:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.SPHERE, SphereParticle::new);
|
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.DISK, DiskParticle::new);
|
2021-02-05 20:19:41 +01:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.GROUND_POUND, GroundPoundParticle::new);
|
2021-02-19 15:56:01 +01:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.CLOUDS_ESCAPING, CloudsEscapingParticle::new);
|
2021-12-28 01:19:26 +01:00
|
|
|
ParticleFactoryRegistry.getInstance().register(UParticles.LIGHTNING_BOLT, LightningBoltParticle::new);
|
2020-04-26 22:40:43 +02:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
AccessoryFeatureRenderer.register(
|
|
|
|
BraceletFeatureRenderer::new, AmuletFeatureRenderer::new, GlassesFeatureRenderer::new,
|
|
|
|
WingsFeatureRenderer::new, HornFeatureRenderer::new, IcarusWingsFeatureRenderer::new, BatWingsFeatureRenderer::new,
|
|
|
|
HeldEntityFeatureRenderer::new
|
|
|
|
);
|
2021-02-27 16:47:54 +01:00
|
|
|
|
2021-12-22 10:15:09 +01:00
|
|
|
EntityRendererRegistry.register(UEntities.THROWN_ITEM, FlyingItemEntityRenderer::new);
|
2022-03-27 16:02:14 +02:00
|
|
|
EntityRendererRegistry.register(UEntities.MUFFIN, FlyingItemEntityRenderer::new);
|
2022-01-11 17:19:36 +01:00
|
|
|
EntityRendererRegistry.register(UEntities.MAGIC_BEAM, MagicBeamEntityRenderer::new);
|
2021-12-22 10:15:09 +01:00
|
|
|
EntityRendererRegistry.register(UEntities.BUTTERFLY, ButterflyEntityRenderer::new);
|
|
|
|
EntityRendererRegistry.register(UEntities.FLOATING_ARTEFACT, FloatingArtefactEntityRenderer::new);
|
|
|
|
EntityRendererRegistry.register(UEntities.CAST_SPELL, CastSpellEntityRenderer::new);
|
2021-12-27 13:05:31 +01:00
|
|
|
EntityRendererRegistry.register(UEntities.TWITTERMITE, FairyEntityRenderer::new);
|
2021-12-22 10:15:09 +01:00
|
|
|
EntityRendererRegistry.register(UEntities.SPELLBOOK, SpellbookEntityRenderer::new);
|
2023-08-17 20:53:13 +02:00
|
|
|
EntityRendererRegistry.register(UEntities.SOMBRA, SombraEntityRenderer::new);
|
2023-08-25 23:06:08 +02:00
|
|
|
EntityRendererRegistry.register(UEntities.CRYSTAL_SHARDS, CrystalShardsEntityRenderer::new);
|
|
|
|
EntityRendererRegistry.register(UEntities.STORM_CLOUD, StormCloudEntityRenderer::new);
|
2022-09-15 00:51:07 +02:00
|
|
|
EntityRendererRegistry.register(UEntities.AIR_BALLOON, AirBalloonEntityRenderer::new);
|
2023-10-16 16:18:36 +02:00
|
|
|
EntityRendererRegistry.register(UEntities.FRIENDLY_CREEPER, FriendlyCreeperEntityRenderer::new);
|
2023-11-07 19:20:41 +01:00
|
|
|
EntityRendererRegistry.register(UEntities.LOOT_BUG, LootBugEntityRenderer::new);
|
2024-01-02 23:03:41 +01:00
|
|
|
EntityRendererRegistry.register(UEntities.TENTACLE, TentacleEntityRenderer::new);
|
2024-01-03 21:51:24 +01:00
|
|
|
EntityRendererRegistry.register(UEntities.IGNIMEOUS_BULB, IgnimeousBulbEntityRenderer::new);
|
2021-02-03 21:25:42 +01:00
|
|
|
|
2023-06-02 21:20:30 +02:00
|
|
|
BlockEntityRendererFactories.register(UBlockEntities.WEATHER_VANE, WeatherVaneBlockEntityRenderer::new);
|
2023-10-31 21:38:28 +01:00
|
|
|
BlockEntityRendererFactories.register(UBlockEntities.FANCY_BED, CloudBedBlockEntityRenderer::new);
|
2023-12-04 15:49:24 +01:00
|
|
|
BlockEntityRendererFactories.register(UBlockEntities.CLOUD_CHEST, CloudChestBlockEntityRenderer::new);
|
2022-10-12 15:46:15 +02:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
register(URenderers::renderJarItem, UItems.FILLED_JAR);
|
2023-10-31 21:38:28 +01:00
|
|
|
register(URenderers::renderBedItem, UItems.CLOTH_BED, UItems.CLOUD_BED);
|
2023-12-04 15:49:24 +01:00
|
|
|
register(URenderers::renderChestItem, UBlocks.CLOUD_CHEST.asItem());
|
2023-10-31 17:45:41 +01:00
|
|
|
PolearmRenderer.register(UItems.WOODEN_POLEARM, UItems.STONE_POLEARM, UItems.IRON_POLEARM, UItems.GOLDEN_POLEARM, UItems.DIAMOND_POLEARM, UItems.NETHERITE_POLEARM);
|
|
|
|
ModelPredicateProviderRegistry.register(UItems.GEMSTONE, new Identifier("affinity"), (stack, world, entity, seed) -> EnchantableItem.isEnchanted(stack) ? EnchantableItem.getSpellKey(stack).getAffinity().getAlignment() : 0);
|
|
|
|
ModelPredicateProviderRegistry.register(UItems.ROCK_CANDY, new Identifier("count"), (stack, world, entity, seed) -> stack.getCount() / (float)stack.getMaxCount());
|
|
|
|
|
|
|
|
ColorProviderRegistry.BLOCK.register(URenderers::getTintedBlockColor, TintedBlock.REGISTRY.stream().toArray(Block[]::new));
|
|
|
|
ColorProviderRegistry.ITEM.register((stack, i) -> getTintedBlockColor(Block.getBlockFromItem(stack.getItem()).getDefaultState(), null, null, i), TintedBlock.REGISTRY.stream().map(Block::asItem).filter(i -> i != Items.AIR).toArray(Item[]::new));
|
2021-02-03 21:25:42 +01:00
|
|
|
ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 ? -1 : ((DyeableItem)stack.getItem()).getColor(stack), UItems.FRIENDSHIP_BRACELET);
|
2023-10-31 17:45:41 +01:00
|
|
|
ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 || !EnchantableItem.isEnchanted(stack) ? -1 : EnchantableItem.getSpellKey(stack).getColor(), UItems.GEMSTONE);
|
|
|
|
ColorProviderRegistry.ITEM.register((stack, i) -> i == 1 && EnchantableItem.isEnchanted(stack) ? EnchantableItem.getSpellKey(stack).getColor() : -1, UItems.MAGIC_STAFF);
|
2021-02-14 21:15:30 +01:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), UBlocks.TRANSLUCENT_BLOCKS.stream().toArray(Block[]::new));
|
|
|
|
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(), UBlocks.SEMI_TRANSPARENT_BLOCKS.stream().toArray(Block[]::new));
|
|
|
|
// for lava boats
|
|
|
|
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), Fluids.LAVA, Fluids.FLOWING_LAVA);
|
2021-02-14 21:15:30 +01:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
TerraformBoatClientHelper.registerModelLayers(Unicopia.id("palm"), false);
|
2021-02-14 21:15:30 +01:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
SpellRendererFactory.bootstrap();
|
|
|
|
}
|
2021-02-14 21:15:30 +01:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
private static void register(DynamicItemRenderer renderer, ItemConvertible...items) {
|
|
|
|
for (ItemConvertible item : items) {
|
|
|
|
BuiltinItemRendererRegistry.INSTANCE.register(item, renderer);
|
|
|
|
}
|
|
|
|
}
|
2021-02-14 21:15:30 +01:00
|
|
|
|
2023-10-31 21:38:28 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2023-10-31 17:45:41 +01:00
|
|
|
private static void renderBedItem(ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertices, int light, int overlay) {
|
2023-11-25 04:05:45 +01:00
|
|
|
BlockEntity entity = ((Supplier<BlockEntity>)stack.getItem()).get();
|
|
|
|
((FancyBedBlock.Tile)entity).setPattern(FancyBedItem.getPattern(stack));
|
|
|
|
MinecraftClient.getInstance().getBlockEntityRenderDispatcher().renderEntity(entity, matrices, vertices, light, overlay);
|
2023-10-31 17:45:41 +01:00
|
|
|
}
|
2021-02-14 21:15:30 +01:00
|
|
|
|
2023-12-04 15:49:24 +01:00
|
|
|
private static void renderChestItem(ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertices, int light, int overlay) {
|
|
|
|
MinecraftClient.getInstance().getBlockEntityRenderDispatcher().renderEntity(CHEST_RENDER_ENTITY, matrices, vertices, light, overlay);
|
|
|
|
}
|
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
private static void renderJarItem(ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertices, int light, int overlay) {
|
|
|
|
ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
|
2021-02-14 21:15:30 +01:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
ChameleonItem item = (ChameleonItem)stack.getItem();
|
|
|
|
|
|
|
|
// Reset stuff done in the beforelands
|
|
|
|
matrices.pop();
|
|
|
|
|
|
|
|
if (mode == ModelTransformationMode.GUI) {
|
|
|
|
DiffuseLighting.disableGuiDepthLighting();
|
|
|
|
}
|
2022-09-23 23:25:00 +02:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
|
|
|
ClientWorld world = MinecraftClient.getInstance().world;
|
|
|
|
|
|
|
|
if (item.hasAppearance(stack)) {
|
|
|
|
matrices.push();
|
|
|
|
if (mode.isFirstPerson()) {
|
|
|
|
matrices.translate(0.05, 0.06, 0.06);
|
|
|
|
} else if (mode == ModelTransformationMode.HEAD) {
|
|
|
|
matrices.translate(0, 0.4, 0);
|
|
|
|
} else if (mode == ModelTransformationMode.GROUND
|
|
|
|
|| mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND || mode == ModelTransformationMode.THIRD_PERSON_RIGHT_HAND) {
|
|
|
|
matrices.translate(0, 0.06, 0);
|
2023-05-23 19:49:56 +02:00
|
|
|
}
|
2023-10-31 17:45:41 +01:00
|
|
|
// GUI, FIXED, NONE - translate(0, 0, 0)
|
|
|
|
//matrices.scale(0.5F, 0.5F, 0.5F);
|
2023-05-23 19:49:56 +02:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
float scale = 0.5F;
|
|
|
|
matrices.scale(scale, scale, scale);
|
2022-09-25 00:14:29 +02:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
ItemStack appearance = item.getAppearanceStack(stack);
|
|
|
|
renderer.renderItem(appearance, mode, light, overlay, matrices, immediate, world, 0);
|
|
|
|
matrices.pop();
|
|
|
|
}
|
|
|
|
renderer.renderItem(item.createAppearanceStack(stack, UItems.EMPTY_JAR), mode, light, OverlayTexture.DEFAULT_UV, matrices, vertices, world, 0);
|
2022-09-11 15:42:26 +02:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
if (mode == ModelTransformationMode.GUI) {
|
|
|
|
DiffuseLighting.enableGuiDepthLighting();
|
|
|
|
}
|
|
|
|
matrices.push();
|
|
|
|
}
|
2023-08-14 21:31:33 +02:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
private static int getTintedBlockColor(BlockState state, @Nullable BlockRenderView view, @Nullable BlockPos pos, int color) {
|
|
|
|
if (view == null || pos == null) {
|
|
|
|
color = FoliageColors.getDefaultColor();
|
|
|
|
} else {
|
|
|
|
color = BiomeColors.getFoliageColor(view, pos);
|
|
|
|
}
|
2023-10-22 00:16:54 +02:00
|
|
|
|
2023-10-31 17:45:41 +01:00
|
|
|
if (state.getBlock() instanceof TintedBlock block) {
|
|
|
|
return block.getTint(state, view, pos, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
2020-04-15 14:22:03 +02:00
|
|
|
}
|
2020-09-27 17:44:39 +02:00
|
|
|
|
|
|
|
static <T extends ParticleEffect> PendingParticleFactory<T> createFactory(ParticleSupplier<T> supplier) {
|
2021-02-02 11:52:50 +01:00
|
|
|
return provider -> (effect, world, x, y, z, dx, dy, dz) -> supplier.get(effect, provider, world, x, y, z, dx, dy, dz);
|
2020-09-27 17:44:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ParticleSupplier<T extends ParticleEffect> {
|
2021-02-02 11:52:50 +01:00
|
|
|
Particle get(T effect, SpriteProvider provider, ClientWorld world, double x, double y, double z, double dx, double dy, double dz);
|
2020-09-27 17:44:39 +02:00
|
|
|
}
|
2020-04-15 14:22:03 +02:00
|
|
|
}
|