[Feature] Accesor to generate colorable particles

This commit is contained in:
Frank 2023-06-21 01:39:48 +02:00
parent 00ef6fcfa1
commit 1c61c0e3cc
5 changed files with 126 additions and 7 deletions

View file

@ -0,0 +1,21 @@
package org.betterx.bclib.interfaces;
import net.minecraft.client.particle.Particle;
import net.minecraft.core.particles.ParticleOptions;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public interface ClientLevelAccess {
@Nullable
LevelRendererAccess bcl_getLevelRenderer();
@Nullable
Particle bcl_addParticle(
ParticleOptions particleOptions,
double x, double y, double z,
double vx, double vy, double vz
);
}

View file

@ -0,0 +1,19 @@
package org.betterx.bclib.interfaces;
import net.minecraft.client.particle.Particle;
import net.minecraft.core.particles.ParticleOptions;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public interface LevelRendererAccess {
@Nullable Particle bcl_addParticle(
ParticleOptions particleOptions,
double x, double y, double z,
double vx, double vy, double vz
);
}

View file

@ -0,0 +1,53 @@
package org.betterx.bclib.mixin.client;
import org.betterx.bclib.interfaces.ClientLevelAccess;
import org.betterx.bclib.interfaces.LevelRendererAccess;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.core.particles.ParticleOptions;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.jetbrains.annotations.Nullable;
@Mixin(ClientLevel.class)
@Environment(EnvType.CLIENT)
public class ClientLevelMixin implements ClientLevelAccess {
@Shadow
@Final
private LevelRenderer levelRenderer;
@Override
@Nullable
public LevelRendererAccess bcl_getLevelRenderer() {
if (this.levelRenderer instanceof LevelRendererAccess a) {
return a;
}
return null;
}
@Override
@Nullable
public Particle bcl_addParticle(
ParticleOptions particleOptions,
double x,
double y,
double z,
double vx,
double vy,
double vz
) {
var renderer = this.bcl_getLevelRenderer();
if (renderer != null) {
return renderer.bcl_addParticle(particleOptions, x, y, z, vx, vy, vz);
}
return null;
}
}

View file

@ -2,13 +2,16 @@ package org.betterx.bclib.mixin.client;
import org.betterx.bclib.BCLib; import org.betterx.bclib.BCLib;
import org.betterx.bclib.interfaces.AirSelectionItem; import org.betterx.bclib.interfaces.AirSelectionItem;
import org.betterx.bclib.interfaces.LevelRendererAccess;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.*;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.util.FastColor; import net.minecraft.util.FastColor;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
@ -19,6 +22,9 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -27,8 +33,11 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.jetbrains.annotations.Nullable;
@Mixin(LevelRenderer.class) @Mixin(LevelRenderer.class)
public abstract class LevelRendererMixin { @Environment(EnvType.CLIENT)
public abstract class LevelRendererMixin implements LevelRendererAccess {
@Final @Final
@Shadow @Shadow
private Minecraft minecraft; private Minecraft minecraft;
@ -36,20 +45,36 @@ public abstract class LevelRendererMixin {
@Final @Final
private RenderBuffers renderBuffers; private RenderBuffers renderBuffers;
public Particle bcl_addParticle(
ParticleOptions particleOptions,
double x, double y, double z,
double vx, double vy, double vz
) {
return this.addParticleInternal(particleOptions, false, x, y, z, vx, vy, vz);
}
@Shadow @Shadow
protected static void renderShape( protected static void renderShape(
PoseStack poseStack, PoseStack poseStack,
VertexConsumer vertexConsumer, VertexConsumer vertexConsumer,
VoxelShape voxelShape, VoxelShape voxelShape,
double x, double y, double z,
float r, float g, float b, float a
) {
}
@Shadow
@Nullable
protected abstract Particle addParticleInternal(
ParticleOptions particleOptions,
boolean bl,
double d, double d,
double e, double e,
double f, double f,
float g, double g,
float h, double h,
float i, double i
float j );
) {
}
@Inject(method = "renderLevel", at = @At( @Inject(method = "renderLevel", at = @At(
value = "INVOKE", value = "INVOKE",

View file

@ -7,6 +7,7 @@
"AnvilScreenMixin", "AnvilScreenMixin",
"AtlasSetMixin", "AtlasSetMixin",
"BlockMixin", "BlockMixin",
"ClientLevelMixin",
"ClientPacketListenerMixin", "ClientPacketListenerMixin",
"ClientRecipeBookMixin", "ClientRecipeBookMixin",
"FogRendererMixin", "FogRendererMixin",