Jump to content

Proper place to render an effect for an item's right click?


Recommended Posts

package com.natura.minestuckarsenal;

import java.util.Optional;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import com.natura.minestuckarsenal.item.ItemLaserWeapon;
import com.natura.minestuckarsenal.item.MinestuckArsenalItems;

import net.java.games.input.Mouse;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ClientEventHandler {
	public static final ResourceLocation LASER_LOC = new ResourceLocation(MinestuckArsenal.MODID, "textures/effects/laserbeam.png");

	public ClientEventHandler() {
	@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
	public void onRenderWorld(RenderWorldLastEvent e) {
			EntityPlayer player = Minecraft.getMinecraft().player;
			GameSettings gs = Minecraft.getMinecraft().gameSettings;
			if(player.getActiveItemStack().getItem() == MinestuckArsenalItems.ahabsCrosshairs && gs.keyBindUseItem.isKeyDown()) {
	public static void doRenderBeam(EntityLivingBase shooter) {
			GlStateManager.blendFunc(GL11.GL_ONE, GL11.GL_ONE);
			EntityPlayer player = Minecraft.getMinecraft().player;
			float partialTicks = Minecraft.getMinecraft().getRenderPartialTicks();
			double doubleX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
			double doubleY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
			double doubleZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
			Vec3d vec = new Vec3d(doubleX, doubleY+player.getEyeHeight(), doubleZ);
			Vec3d vec0 = shooter.getPositionVector().addVector(0, shooter.getEyeHeight()+0.2, 0);
			Vec3d vec1 = vec0;
				vec1 = Optional.ofNullable(ItemLaserWeapon.raytraceEntityPlayerLook(player, ItemLaserWeapon.range))
				.map(rtr -> rtr.hitVec)
			GlStateManager.translate(-doubleX, -doubleY, -doubleZ);
			Tessellator tessellator = Tessellator.getInstance();
			BufferBuilder buffer = tessellator.getBuffer();
			buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
			drawBeam(vec0, vec1, vec, 0.13f);
			GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	public static void drawBeam(Vec3d S, Vec3d E, Vec3d P, float width) {
		Vec3d PS = S.subtract(P);
		Vec3d SE = E.subtract(S);
		Vec3d normal = PS.crossProduct(SE).normalize();
		Vec3d half = normal.scale(width);
		Vec3d p1 = S.add(half);
		Vec3d p2 = S.subtract(half);
		Vec3d p3 = E.add(half);
		Vec3d p4 = E.subtract(half);
		drawQuad(Tessellator.getInstance(), p1, p3, p4, p2);

	private static void drawQuad(Tessellator tessellator, Vec3d p1, Vec3d p2, Vec3d p3, Vec3d p4) {
		int brightness = 240;
		int b1 = brightness >> 16 & 65535;
		int b2 = brightness & 65535;
		BufferBuilder buffer = tessellator.getBuffer();
		buffer.pos(p1.x, p1.y, p1.z).tex(0.0D, 0.0D).lightmap(b1, b2).color(255, 255, 255, 128)
		buffer.pos(p2.x, p2.y, p2.z).tex(1.0D, 0.0D).lightmap(b1, b2).color(255, 255, 255, 128)
		buffer.pos(p3.x, p3.y, p3.z).tex(1.0D, 1.0D).lightmap(b1, b2).color(255, 255, 255, 128)
		buffer.pos(p4.x, p4.y, p4.z).tex(0.0D, 1.0D).lightmap(b1, b2).color(255, 255, 255, 128)


This is my rendering code right now, but this never seems to do anything? I have the event handler registered in my main class.

Link to comment
Share on other sites

have you done debugging to find out what code is called?

On 08/05/2018 at 8:55 AM, naturaGodhead said:

I have the event handler registered in my main class.

I don't know how you have done this but I believe it is impossible and that you need to put

@Mod.EventBusSubscriber OR @EventBusSubscriber above your ClientEventHandler class and make your onRenderWorld method static. Also why is there 

public ClientEventHandler() {



About Me


My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.