Add Chams module
- Renders entity models through walls as translucent fill and/or outline in the no-depth-test global layers, drawn at Render3DEvent - Settings: Players/Hostiles/Passives/Crystals/Friends targets, Mode (Fill/Outline/Both), Pulse, DamageModify, OutlineWidth and per-purpose colors; friends win over damage color like the reference - MixinEntityRenderDispatcher maps render states back to entities (states carry no name) and opens the capture context around each entity's submit; prepare() resets the mapping every frame
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
package cc.fros.features.modules.render;
|
||||
|
||||
import cc.fros.Fros;
|
||||
import cc.fros.event.impl.render.Render3DEvent;
|
||||
import cc.fros.features.modules.Module;
|
||||
import cc.fros.features.settings.Setting;
|
||||
import cc.fros.util.render.ChamsRenderer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ChamsModule extends Module {
|
||||
|
||||
private final Setting<Page> page = mode("Page", Page.Entities);
|
||||
|
||||
private final Setting<Boolean> players = bool("Players", true);
|
||||
private final Setting<Boolean> hostiles = bool("Hostiles", false);
|
||||
private final Setting<Boolean> passives = bool("Passives", false);
|
||||
private final Setting<Boolean> crystals = bool("Crystals", true);
|
||||
private final Setting<Boolean> friends = bool("Friends", true);
|
||||
|
||||
private final Setting<Mode> renderMode = mode("Mode", Mode.Both);
|
||||
private final Setting<Boolean> pulse = bool("Pulse", false);
|
||||
private final Setting<Boolean> damageModify = bool("DamageModify", false);
|
||||
private final Setting<Float> outlineWidth = num("OutlineWidth", 1.0f, 0.5f, 5.0f);
|
||||
|
||||
private final Setting<Color> fillColor = color("FillColor", 130, 202, 255, 40);
|
||||
private final Setting<Color> outlineColor = color("OutlineColor", 130, 202, 255, 120);
|
||||
private final Setting<Color> friendFillColor = color("FriendFillColor", 85, 255, 255, 40);
|
||||
private final Setting<Color> friendOutlineColor = color("FriendOutlineColor", 85, 255, 255, 120);
|
||||
private final Setting<Color> damageColor = color("DamageColor", 255, 0, 0, 255);
|
||||
|
||||
private static final long UPTIME = System.currentTimeMillis();
|
||||
|
||||
public ChamsModule() {
|
||||
super("Chams", "Renders entity models on top of the world so they show through walls", Category.RENDER);
|
||||
refreshVisibility();
|
||||
}
|
||||
|
||||
private void refreshVisibility() {
|
||||
players.setVisibility(v -> on(Page.Entities));
|
||||
hostiles.setVisibility(v -> on(Page.Entities));
|
||||
passives.setVisibility(v -> on(Page.Entities));
|
||||
crystals.setVisibility(v -> on(Page.Entities));
|
||||
friends.setVisibility(v -> on(Page.Entities));
|
||||
|
||||
renderMode.setVisibility(v -> on(Page.Render));
|
||||
pulse.setVisibility(v -> on(Page.Render));
|
||||
damageModify.setVisibility(v -> on(Page.Render));
|
||||
outlineWidth.setVisibility(v -> on(Page.Render) && outlineEnabled());
|
||||
|
||||
fillColor.setVisibility(v -> on(Page.Colors) && fillEnabled());
|
||||
outlineColor.setVisibility(v -> on(Page.Colors) && outlineEnabled());
|
||||
friendFillColor.setVisibility(v -> on(Page.Colors) && fillEnabled() && friends.getValue());
|
||||
friendOutlineColor.setVisibility(v -> on(Page.Colors) && outlineEnabled() && friends.getValue());
|
||||
damageColor.setVisibility(v -> on(Page.Colors) && damageModify.getValue());
|
||||
}
|
||||
|
||||
private boolean on(Page p) {
|
||||
return page.getValue() == p;
|
||||
}
|
||||
|
||||
private boolean fillEnabled() {
|
||||
return renderMode.getValue() != Mode.Outline;
|
||||
}
|
||||
|
||||
private boolean outlineEnabled() {
|
||||
return renderMode.getValue() != Mode.Fill;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the entity render dispatcher for every submitted entity.
|
||||
* Picks the colors for this entity and opens the capture context that the
|
||||
* model submission mixin reads; rejected entities close it again.
|
||||
*/
|
||||
public void prepare(Entity entity) {
|
||||
if (!validTarget(entity)) {
|
||||
ChamsRenderer.clearContext();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean doFill = fillEnabled();
|
||||
boolean doOutline = outlineEnabled();
|
||||
|
||||
Color fill = fillColor.getValue();
|
||||
Color outline = outlineColor.getValue();
|
||||
|
||||
boolean friend = friends.getValue() && entity instanceof Player player
|
||||
&& Fros.friendManager.isFriend(player);
|
||||
if (friend) {
|
||||
fill = friendFillColor.getValue();
|
||||
outline = friendOutlineColor.getValue();
|
||||
} else if (damageModify.getValue() && entity instanceof LivingEntity living && living.hurtTime > 0) {
|
||||
Color damage = damageColor.getValue();
|
||||
fill = new Color(damage.getRed(), damage.getGreen(), damage.getBlue(), fill.getAlpha());
|
||||
outline = new Color(damage.getRed(), damage.getGreen(), damage.getBlue(), outline.getAlpha());
|
||||
}
|
||||
|
||||
if (pulse.getValue()) {
|
||||
fill = pulsed(fill);
|
||||
outline = pulsed(outline);
|
||||
}
|
||||
|
||||
ChamsRenderer.setContext(doFill, doOutline, fill.getRGB(), outline.getRGB(), outlineWidth.getValue());
|
||||
}
|
||||
|
||||
private boolean validTarget(Entity entity) {
|
||||
if (entity instanceof EndCrystal) return crystals.getValue();
|
||||
if (!(entity instanceof LivingEntity)) return false;
|
||||
if (entity instanceof Player) return players.getValue();
|
||||
|
||||
MobCategory category = entity.getType().getCategory();
|
||||
if (category == MobCategory.MONSTER) return hostiles.getValue();
|
||||
return isPassive(category) && passives.getValue();
|
||||
}
|
||||
|
||||
private static boolean isPassive(MobCategory category) {
|
||||
return category == MobCategory.CREATURE
|
||||
|| category == MobCategory.WATER_CREATURE
|
||||
|| category == MobCategory.WATER_AMBIENT
|
||||
|| category == MobCategory.UNDERGROUND_WATER_CREATURE
|
||||
|| category == MobCategory.AXOLOTLS;
|
||||
}
|
||||
|
||||
private static Color pulsed(Color color) {
|
||||
double sin = Math.sin(2 * Math.PI * (15 / 20f) * ((System.currentTimeMillis() - UPTIME) / 1000f));
|
||||
double scale = (sin + 1) / 2;
|
||||
return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (color.getAlpha() * scale));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRender3D(Render3DEvent event) {
|
||||
ChamsRenderer.draw(event.getMatrix());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
ChamsRenderer.clearContext();
|
||||
}
|
||||
|
||||
public enum Page {
|
||||
Entities, Render, Colors
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
Fill, Outline, Both
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import cc.fros.features.modules.player.FastPlaceModule;
|
||||
import cc.fros.features.modules.player.NoFallModule;
|
||||
import cc.fros.features.modules.player.VelocityModule;
|
||||
import cc.fros.features.modules.render.BlockHighlightModule;
|
||||
import cc.fros.features.modules.render.ChamsModule;
|
||||
import cc.fros.features.modules.render.FullbrightModule;
|
||||
import cc.fros.features.modules.render.NametagsModule;
|
||||
import cc.fros.util.traits.Jsonable;
|
||||
@@ -81,6 +82,7 @@ public class ModuleManager implements Jsonable, Util {
|
||||
register(new BlockHighlightModule());
|
||||
register(new FullbrightModule());
|
||||
register(new NametagsModule());
|
||||
register(new ChamsModule());
|
||||
register(new NoFallModule());
|
||||
register(new KeyPearlModule());
|
||||
register(new KillAuraModule());
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package cc.fros.mixin.render;
|
||||
|
||||
import cc.fros.Fros;
|
||||
import cc.fros.features.modules.render.ChamsModule;
|
||||
import cc.fros.util.render.ChamsRenderer;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.entity.state.EntityRenderState;
|
||||
import net.minecraft.client.renderer.state.CameraRenderState;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
/**
|
||||
* Bridges entities and the model capture: extraction records which entity each
|
||||
* render state belongs to (states carry no name), and submit opens the capture
|
||||
* context for exactly the duration of one entity's rendering so only that
|
||||
* entity's models are captured.
|
||||
*/
|
||||
@Mixin(EntityRenderDispatcher.class)
|
||||
public class MixinEntityRenderDispatcher {
|
||||
|
||||
@Inject(method = "prepare", at = @At("RETURN"))
|
||||
private void chamsResetFrame(Camera camera, Entity crosshairEntity, CallbackInfo ci) {
|
||||
// render states are recreated every frame, so drop last frame's mapping
|
||||
// even when the module is disabled and no draw runs to clear it
|
||||
ChamsRenderer.clearFrame();
|
||||
}
|
||||
|
||||
@Inject(method = "extractEntity", at = @At("RETURN"))
|
||||
private <E extends Entity> void chamsTrackState(E entity, float partialTick, CallbackInfoReturnable<EntityRenderState> cir) {
|
||||
if (cir.getReturnValue() != null) {
|
||||
ChamsRenderer.track(cir.getReturnValue(), entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "submit", at = @At("HEAD"))
|
||||
private void chamsBeginContext(EntityRenderState state, CameraRenderState cameraRenderState,
|
||||
double x, double y, double z, PoseStack poseStack,
|
||||
SubmitNodeCollector collector, CallbackInfo ci) {
|
||||
ChamsRenderer.clearContext();
|
||||
Entity entity = ChamsRenderer.entityOf(state);
|
||||
if (entity == null) return;
|
||||
ChamsModule module = Fros.moduleManager.getModuleByClass(ChamsModule.class);
|
||||
if (module == null || !module.isEnabled()) return;
|
||||
module.prepare(entity);
|
||||
}
|
||||
|
||||
@Inject(method = "submit", at = @At("RETURN"))
|
||||
private void chamsEndContext(EntityRenderState state, CameraRenderState cameraRenderState,
|
||||
double x, double y, double z, PoseStack poseStack,
|
||||
SubmitNodeCollector collector, CallbackInfo ci) {
|
||||
ChamsRenderer.clearContext();
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,11 @@ public final class ChamsRenderer {
|
||||
return ENTITIES.get(state);
|
||||
}
|
||||
|
||||
public static void clearFrame() {
|
||||
ENTITIES.clear();
|
||||
clearContext();
|
||||
}
|
||||
|
||||
public static void setContext(boolean fill, boolean outline, int fillArgb, int outlineArgb, float width) {
|
||||
active = true;
|
||||
doFill = fill;
|
||||
@@ -187,19 +192,19 @@ public final class ChamsRenderer {
|
||||
if (lineCount > 0) {
|
||||
BufferBuilder buffer = Tesselator.getInstance()
|
||||
.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL_LINE_WIDTH);
|
||||
PoseStack.Pose linePose = pose.last();
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
int p = i * 3;
|
||||
buffer.addVertex(pose.last().pose(), linePos[p], linePos[p + 1], linePos[p + 2])
|
||||
buffer.addVertex(linePose, linePos[p], linePos[p + 1], linePos[p + 2])
|
||||
.setColor(lineCol[i])
|
||||
.setNormal(lineNormal[p], lineNormal[p + 1], lineNormal[p + 2])
|
||||
.setNormal(linePose, lineNormal[p], lineNormal[p + 1], lineNormal[p + 2])
|
||||
.setLineWidth(drawWidth);
|
||||
}
|
||||
Layers.lines().draw(buffer.buildOrThrow());
|
||||
lineCount = 0;
|
||||
}
|
||||
|
||||
clearContext();
|
||||
ENTITIES.clear();
|
||||
clearFrame();
|
||||
}
|
||||
|
||||
// ---- consumer ----
|
||||
|
||||
Reference in New Issue
Block a user