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

156 lines
9.2 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.client;
import com.minelittlepony.unicopia.block.*;
2020-04-22 16:28:20 +02:00
import com.minelittlepony.unicopia.client.particle.ChangelingMagicParticle;
import com.minelittlepony.unicopia.client.particle.CloudsEscapingParticle;
2020-04-22 16:28:20 +02:00
import com.minelittlepony.unicopia.client.particle.DiskParticle;
import com.minelittlepony.unicopia.client.particle.GroundPoundParticle;
import com.minelittlepony.unicopia.client.particle.HealthDrainParticle;
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;
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.*;
import com.minelittlepony.unicopia.entity.UEntities;
2021-02-14 21:15:30 +01:00
import com.minelittlepony.unicopia.item.ChameleonItem;
2021-03-02 14:40:37 +01:00
import com.minelittlepony.unicopia.item.GemstoneItem;
2021-02-03 21:25:42 +01:00
import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.particle.UParticles;
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;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry.PendingParticleFactory;
2021-12-22 10:15:09 +01:00
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
2021-02-14 21:15:30 +01:00
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
2021-02-03 21:25:42 +01:00
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.minecraft.block.Block;
2021-02-14 21:15:30 +01:00
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.block.BlockColorProvider;
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;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.SpriteProvider;
2021-02-14 21:15:30 +01:00
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.FlyingItemEntityRenderer;
2021-02-14 21:15:30 +01:00
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.world.ClientWorld;
2022-09-11 15:42:26 +02:00
import net.minecraft.fluid.Fluids;
import net.minecraft.item.*;
import net.minecraft.particle.ParticleEffect;
2021-03-02 14:40:37 +01:00
import net.minecraft.util.Identifier;
public interface URenderers {
static void bootstrap() {
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));
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);
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);
ParticleFactoryRegistry.getInstance().register(UParticles.GROUND_POUND, GroundPoundParticle::new);
ParticleFactoryRegistry.getInstance().register(UParticles.CLOUDS_ESCAPING, CloudsEscapingParticle::new);
ParticleFactoryRegistry.getInstance().register(UParticles.LIGHTNING_BOLT, LightningBoltParticle::new);
2020-04-26 22:40:43 +02:00
AccessoryFeatureRenderer.register(BraceletFeatureRenderer::new);
AccessoryFeatureRenderer.register(AmuletFeatureRenderer::new);
AccessoryFeatureRenderer.register(WingsFeatureRenderer::new);
2021-08-08 18:36:56 +02:00
AccessoryFeatureRenderer.register(IcarusWingsFeatureRenderer::new);
AccessoryFeatureRenderer.register(BatWingsFeatureRenderer::new);
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);
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);
2022-09-15 00:51:07 +02:00
EntityRendererRegistry.register(UEntities.AIR_BALLOON, AirBalloonEntityRenderer::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);
2021-02-14 21:15:30 +01:00
BuiltinItemRendererRegistry.INSTANCE.register(UItems.FILLED_JAR, (stack, mode, matrices, vertexConsumers, light, overlay) -> {
ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
ChameleonItem item = (ChameleonItem)stack.getItem();
// Reset stuff done in the beforelands
matrices.pop();
if (mode == ModelTransformation.Mode.GUI) {
DiffuseLighting.disableGuiDepthLighting();
}
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
if (item.hasAppearance(stack)) {
matrices.push();
matrices.scale(0.5F, 0.5F, 0.5F);
matrices.translate(0.0125, 0.1, 0);
2021-08-04 15:38:03 +02:00
renderer.renderItem(item.getAppearanceStack(stack), mode, light, overlay, matrices, immediate, 0);
2021-02-14 21:15:30 +01:00
matrices.pop();
}
2021-08-04 15:38:03 +02:00
renderer.renderItem(item.createAppearanceStack(stack, UItems.EMPTY_JAR), mode, light, OverlayTexture.DEFAULT_UV, matrices, immediate, 0);
2021-02-14 21:15:30 +01:00
immediate.draw();
if (mode == ModelTransformation.Mode.GUI) {
DiffuseLighting.enableGuiDepthLighting();
}
matrices.push();
});
2022-09-18 21:39:42 +02:00
PolearmRenderer.register(UItems.WOODEN_POLEARM);
PolearmRenderer.register(UItems.STONE_POLEARM);
PolearmRenderer.register(UItems.IRON_POLEARM);
PolearmRenderer.register(UItems.GOLDEN_POLEARM);
PolearmRenderer.register(UItems.DIAMOND_POLEARM);
PolearmRenderer.register(UItems.NETHERITE_POLEARM);
2022-06-25 00:19:55 +02:00
ModelPredicateProviderRegistry.register(UItems.GEMSTONE, new Identifier("affinity"), (stack, world, entity, seed) -> {
2021-03-02 21:10:52 +01:00
return GemstoneItem.isEnchanted(stack) ? 1 + GemstoneItem.getSpellKey(stack).getAffinity().ordinal() : 0;
2021-03-02 14:40:37 +01:00
});
ColorProviderRegistry.ITEM.register((stack, i) -> {
return i > 0 || !GemstoneItem.isEnchanted(stack) ? -1 : GemstoneItem.getSpellKey(stack).getColor();
}, UItems.GEMSTONE);
BlockColorProvider tintedProvider = (state, view, pos, color) -> {
2022-09-23 23:25:00 +02:00
if (view == null || pos == null) {
color = FoliageColors.getDefaultColor();
} else {
color = BiomeColors.getFoliageColor(view, pos);
}
return ((TintedBlock)state.getBlock()).getTint(state, view, pos, color);
};
ColorProviderRegistry.BLOCK.register(tintedProvider, TintedBlock.REGISTRY.stream().toArray(Block[]::new));
ColorProviderRegistry.ITEM.register((stack, i) -> {
Block block = Block.getBlockFromItem(stack.getItem());
return block instanceof TintedBlock ? tintedProvider.getColor(block.getDefaultState(), null, null, i) : FoliageColors.getDefaultColor();
}, TintedBlock.REGISTRY.stream().map(Block::asItem).filter(i -> i != Items.AIR).toArray(Item[]::new));
2022-09-11 15:42:26 +02:00
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayers.getTranslucent(), FruitBlock.REGISTRY.stream().toArray(FruitBlock[]::new));
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayers.getTranslucent(), Tree.REGISTRY.stream().flatMap(tree -> tree.sapling().stream()).toArray(Block[]::new));
2022-09-11 15:42:26 +02:00
// for lava boats
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayers.getTranslucent(), Fluids.LAVA, Fluids.FLOWING_LAVA);
}
static <T extends ParticleEffect> PendingParticleFactory<T> createFactory(ParticleSupplier<T> supplier) {
return provider -> (effect, world, x, y, z, dx, dy, dz) -> supplier.get(effect, provider, world, x, y, z, dx, dy, dz);
}
interface ParticleSupplier<T extends ParticleEffect> {
Particle get(T effect, SpriteProvider provider, ClientWorld world, double x, double y, double z, double dx, double dy, double dz);
}
}