Fix active textures not being properly tracked, add EventDrawNameplate
This commit is contained in:
parent
6348fe7c20
commit
cb032e3806
|
@ -0,0 +1,31 @@
|
|||
package me.rigamortis.seppuku.api.event.render;
|
||||
|
||||
import me.rigamortis.seppuku.api.event.EventCancellable;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
||||
public class EventDrawNameplate extends EventCancellable {
|
||||
|
||||
public final FontRenderer fontRenderer;
|
||||
public final String str;
|
||||
public final float x;
|
||||
public final float y;
|
||||
public final float z;
|
||||
public final int verticalShift;
|
||||
public final float viewerYaw;
|
||||
public final float viewerPitch;
|
||||
public final boolean isThirdPersonFrontal;
|
||||
public final boolean isSneaking;
|
||||
|
||||
public EventDrawNameplate(FontRenderer fontRenderer, String str, float x, float y, float z, int verticalShift, float viewerYaw, float viewerPitch, boolean isThirdPersonFrontal, boolean isSneaking) {
|
||||
this.fontRenderer = fontRenderer;
|
||||
this.str = str;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.verticalShift = verticalShift;
|
||||
this.viewerYaw = viewerYaw;
|
||||
this.viewerPitch = viewerPitch;
|
||||
this.isThirdPersonFrontal = isThirdPersonFrontal;
|
||||
this.isSneaking = isSneaking;
|
||||
}
|
||||
}
|
|
@ -759,7 +759,7 @@ public class ShaderProgram {
|
|||
this.depthTextureCounter++;
|
||||
|
||||
if (this.depthTextureCounter == 1) {
|
||||
OpenGlHelper.setActiveTexture(GL_TEXTURE3); // nothing special about texture 3, it's just never used (at least in vanilla)
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE3); // nothing special about texture 3, it's just never used (at least in vanilla)
|
||||
GlStateManager.enableTexture2D();
|
||||
FramebufferUtil.bindDepthTexture();
|
||||
}
|
||||
|
@ -768,7 +768,7 @@ public class ShaderProgram {
|
|||
this.setUniform(DEPTHDIMS_UNIFORM, (float)FramebufferUtil.getWidth(), (float)FramebufferUtil.getHeight());
|
||||
|
||||
if (this.depthTextureCounter == 1) {
|
||||
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -785,10 +785,10 @@ public class ShaderProgram {
|
|||
if (this.depthTextureCounter < 0) {
|
||||
throw new RuntimeException("Too many depth texture unbinds; there's a bug somewhere, report this");
|
||||
} else if(this.depthTextureCounter == 0) {
|
||||
OpenGlHelper.setActiveTexture(GL_TEXTURE3);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE3);
|
||||
GlStateManager.bindTexture(0);
|
||||
GlStateManager.disableTexture2D();
|
||||
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,18 @@ import me.rigamortis.seppuku.Seppuku;
|
|||
import me.rigamortis.seppuku.api.event.EventStageable;
|
||||
import me.rigamortis.seppuku.api.event.render.EventRender3D;
|
||||
import me.rigamortis.seppuku.api.event.render.EventRenderEntity;
|
||||
import me.rigamortis.seppuku.api.event.render.EventRenderName;
|
||||
import me.rigamortis.seppuku.api.event.render.EventDrawNameplate;
|
||||
import me.rigamortis.seppuku.api.module.Module;
|
||||
import me.rigamortis.seppuku.api.util.RenderUtil;
|
||||
import me.rigamortis.seppuku.api.util.shader.ShaderProgram;
|
||||
import me.rigamortis.seppuku.api.value.Shader;
|
||||
import me.rigamortis.seppuku.api.value.Value;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityBoat;
|
||||
|
@ -28,6 +27,7 @@ import net.minecraft.entity.passive.IAnimals;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.awt.*;
|
||||
|
||||
|
@ -84,7 +84,6 @@ public final class ChamsModule extends Module {
|
|||
public final EntityType entityType;
|
||||
public final boolean hasShadow;
|
||||
public final Render<Entity> render;
|
||||
public boolean needsNametag = false;
|
||||
|
||||
public QueuedEntity(Entity entity, double x, double y, double z, float yaw, float partialTicks, EntityType entityType, boolean hasShadow) {
|
||||
this.x = x;
|
||||
|
@ -104,6 +103,7 @@ public final class ChamsModule extends Module {
|
|||
}
|
||||
|
||||
private final HashMap<Entity, QueuedEntity> queuedEntities = new HashMap<Entity, QueuedEntity>();
|
||||
private final ArrayList<EventDrawNameplate> queuedNameplates = new ArrayList<EventDrawNameplate>();
|
||||
private boolean renderShadow = false;
|
||||
private boolean renderingShaded = false;
|
||||
|
||||
|
@ -204,6 +204,7 @@ public final class ChamsModule extends Module {
|
|||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
if (!this.mode.getValue().name().equalsIgnoreCase("shader") || mc.getRenderManager().renderEngine == null) {
|
||||
this.queuedEntities.clear();
|
||||
this.queuedNameplates.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -255,38 +256,33 @@ public final class ChamsModule extends Module {
|
|||
}
|
||||
}
|
||||
|
||||
this.queuedEntities.clear();
|
||||
|
||||
// release shader
|
||||
this.renderingShaded = false;
|
||||
if (prog != null) {
|
||||
prog.release();
|
||||
}
|
||||
|
||||
// draw name tags
|
||||
// draw queued name tags
|
||||
GlStateManager.color(1.0f, 1.0f, 1.0f);
|
||||
for (HashMap.Entry<Entity, QueuedEntity> entry : this.queuedEntities.entrySet()) {
|
||||
final Entity entity = entry.getKey();
|
||||
final QueuedEntity qEntity = entry.getValue();
|
||||
if (qEntity.render != null && qEntity.needsNametag) {
|
||||
((RenderLivingBase)qEntity.render).renderName((EntityLivingBase)entity, qEntity.x, qEntity.y, qEntity.z);
|
||||
}
|
||||
for (EventDrawNameplate nEvent : this.queuedNameplates) {
|
||||
EntityRenderer.drawNameplate(nEvent.fontRenderer, nEvent.str, nEvent.x, nEvent.y, nEvent.z, nEvent.verticalShift, nEvent.viewerYaw, nEvent.viewerPitch, nEvent.isThirdPersonFrontal, nEvent.isSneaking);
|
||||
}
|
||||
|
||||
this.queuedNameplates.clear();
|
||||
|
||||
// clean up context
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
mc.entityRenderer.disableLightmap();
|
||||
this.queuedEntities.clear();
|
||||
GlStateManager.color(1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onRenderName(EventRenderName event) {
|
||||
public void onDrawNameplate(EventDrawNameplate event) {
|
||||
if (this.renderingShaded) {
|
||||
final Entity entity = event.getEntity();
|
||||
final QueuedEntity qEntity = this.queuedEntities.get(entity);
|
||||
if (qEntity != null && qEntity.render instanceof RenderLivingBase) { // should never be null, but just in case
|
||||
event.setCanceled(true);
|
||||
qEntity.needsNametag = true;
|
||||
}
|
||||
event.setCanceled(true);
|
||||
this.queuedNameplates.add(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import me.rigamortis.seppuku.Seppuku;
|
|||
import me.rigamortis.seppuku.api.event.player.EventFovModifier;
|
||||
import me.rigamortis.seppuku.api.event.player.EventGetMouseOver;
|
||||
import me.rigamortis.seppuku.api.event.player.EventPlayerReach;
|
||||
import me.rigamortis.seppuku.api.event.render.EventDrawNameplate;
|
||||
import me.rigamortis.seppuku.api.event.render.EventHurtCamEffect;
|
||||
import me.rigamortis.seppuku.api.event.render.EventOrientCamera;
|
||||
import me.rigamortis.seppuku.api.event.render.EventRender2D;
|
||||
|
@ -15,6 +16,7 @@ import me.rigamortis.seppuku.api.patch.MethodPatch;
|
|||
import me.rigamortis.seppuku.api.util.ASMUtil;
|
||||
import me.rigamortis.seppuku.impl.management.PatchManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
@ -325,4 +327,69 @@ public final class EntityRendererPatch extends ClassPatch {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is where minecraft renders name plates
|
||||
*
|
||||
* @param methodNode
|
||||
* @param env
|
||||
*/
|
||||
@MethodPatch(
|
||||
mcpName = "drawNameplate",
|
||||
notchName = "a",
|
||||
mcpDesc = "(Lnet/minecraft/client/gui/FontRenderer;Ljava/lang/String;FFFIFFZZ)V",
|
||||
notchDesc = "(Lbip;Ljava/lang/String;FFFIFFZZ)V")
|
||||
public void drawNameplate(MethodNode methodNode, PatchManager.Environment env) {
|
||||
//create a list of instructions and add the needed instructions to call our hook function
|
||||
final InsnList insnList = new InsnList();
|
||||
//add ALOAD instructions to pass all arguments into our hook function
|
||||
//drawNameplate is static so argument indices start from 0 since there is no `this`
|
||||
insnList.add(new VarInsnNode(ALOAD, 0)); // fontRenderer
|
||||
insnList.add(new VarInsnNode(ALOAD, 1)); // str
|
||||
insnList.add(new VarInsnNode(FLOAD, 2)); // x
|
||||
insnList.add(new VarInsnNode(FLOAD, 3)); // y
|
||||
insnList.add(new VarInsnNode(FLOAD, 4)); // z
|
||||
insnList.add(new VarInsnNode(ILOAD, 5)); // verticalShift
|
||||
insnList.add(new VarInsnNode(FLOAD, 6)); // viewerYaw
|
||||
insnList.add(new VarInsnNode(FLOAD, 7)); // viewerPitch
|
||||
insnList.add(new VarInsnNode(ILOAD, 8)); // isThirdPersonFrontal
|
||||
insnList.add(new VarInsnNode(ILOAD, 9)); // isSneaking
|
||||
//call our hook function
|
||||
insnList.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(this.getClass()), "drawNameplateHook", env == PatchManager.Environment.IDE ? "(Lnet/minecraft/client/gui/FontRenderer;Ljava/lang/String;FFFIFFZZ)Z" : "(Lbip;Ljava/lang/String;FFFIFFZZ)Z", false));
|
||||
//add a label to jump to
|
||||
final LabelNode jmp = new LabelNode();
|
||||
//add if equals and pass the label
|
||||
insnList.add(new JumpInsnNode(IFEQ, jmp));
|
||||
//add return so the rest of the function doesn't get called
|
||||
insnList.add(new InsnNode(RETURN));
|
||||
//add our label
|
||||
insnList.add(jmp);
|
||||
//insert the list of instructions at the top of the function
|
||||
methodNode.instructions.insert(insnList);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is our renderName hook
|
||||
* Used to disable rendering minecrafts default
|
||||
* name tags on certain entities
|
||||
*
|
||||
* @param fontRenderer
|
||||
* @param str
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param verticalShift
|
||||
* @param viewerYaw
|
||||
* @param viewerPitch
|
||||
* @param isThirdPersonFrontal
|
||||
* @param isSneaking
|
||||
* @return
|
||||
*/
|
||||
public static boolean drawNameplateHook(FontRenderer fontRenderer, String str, float x, float y, float z, int verticalShift, float viewerYaw, float viewerPitch, boolean isThirdPersonFrontal, boolean isSneaking) {
|
||||
//dispatch our event and pass the entity in
|
||||
final EventDrawNameplate event = new EventDrawNameplate(fontRenderer, str, x, y, z, verticalShift, viewerYaw, viewerPitch, isThirdPersonFrontal, isSneaking);
|
||||
Seppuku.INSTANCE.getEventManager().dispatchEvent(event);
|
||||
|
||||
return event.isCanceled();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue