Skip to content

Commit

Permalink
Added Different Spyglass GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTrollNugNug committed Oct 2, 2016
1 parent 58af05b commit b305d2d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public class ClientEventHandler
public static int disabledEquippItemAnimationTime = 0;

private ItemStack selected;
private static final ResourceLocation OVERLAY_TEXTURE = new ResourceLocation(ARKCraft.MODID,
private static final ResourceLocation SCOPE_OVERLAY = new ResourceLocation(ARKCraft.MODID,
"textures/gui/scope.png");
private static final ResourceLocation SPYGLASS_OVERLAY = new ResourceLocation(ARKCraft.MODID,
"textures/gui/spyglass.png");
public boolean showScopeOverlap = false;

public static void init()
Expand Down Expand Up @@ -166,26 +168,32 @@ public void onMouseEvent(MouseEvent evt)
InventoryAttachment att = InventoryAttachment.create(stack);
if (stack != null)
{
if (att != null && att.isScopePresent() || stack.getItem().equals(ARKCraftItems.spy_glass))
if (att != null && att.isScopePresent())
{
showScopeOverlap = evt.buttonstate;
selected = stack;
if (showScopeOverlap) evt.setCanceled(true);
}
else if (stack.getItem().equals(ARKCraftItems.spy_glass))
{
showSpyglassOverlay = evt.buttonstate;
selected = stack;
if (showSpyglassOverlay) evt.setCanceled(true);
}
}
}
}
} private static boolean showSpyglassOverlay;

@SubscribeEvent
public void onFOVUpdate(FOVUpdateEvent evt)
{
if (mc.gameSettings.thirdPersonView == 0 && showScopeOverlap) evt.newfov /= 6.0F;
if (mc.gameSettings.thirdPersonView == 0 && (showScopeOverlap || showSpyglassOverlay)) evt.newfov /= 6.0F;
}

@SubscribeEvent
public void onRenderHand(RenderHandEvent evt)
{
if (showScopeOverlap)
if (showScopeOverlap || showSpyglassOverlay)
{
evt.setCanceled(true);
}
Expand All @@ -195,23 +203,25 @@ public void onRenderHand(RenderHandEvent evt)
public void onRender(RenderGameOverlayEvent evt)
{
Minecraft mc = Minecraft.getMinecraft();
if (showScopeOverlap && (mc.thePlayer.getCurrentEquippedItem() != selected || !Mouse.isButtonDown(0)))
if ((showScopeOverlap || showSpyglassOverlay) && (mc.thePlayer.getCurrentEquippedItem() != selected || !Mouse.isButtonDown(0)))
{
showScopeOverlap = false;
showSpyglassOverlay = false;
}
if (showScopeOverlap)
if (showScopeOverlap || showSpyglassOverlay)
{
// Render scope
if (evt.type == RenderGameOverlayEvent.ElementType.HELMET)
{
if (mc.gameSettings.thirdPersonView == 0)
{
evt.setCanceled(true);
showScope();
if (showScopeOverlap) showScope() ;
else if (showSpyglassOverlay) showSpyglass();
}
}
// Remove crosshairs
else if (evt.type == RenderGameOverlayEvent.ElementType.CROSSHAIRS && showScopeOverlap) evt.setCanceled(
else if (evt.type == RenderGameOverlayEvent.ElementType.CROSSHAIRS && (showScopeOverlap || showSpyglassOverlay)) evt.setCanceled(
true);
}
else if (evt.type == RenderGameOverlayEvent.ElementType.CROSSHAIRS && !Minecraft.getMinecraft().isGamePaused())
Expand Down Expand Up @@ -281,7 +291,58 @@ public void showScope()
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_ALPHA_TEST);

mc.renderEngine.bindTexture(OVERLAY_TEXTURE);
mc.renderEngine.bindTexture(SCOPE_OVERLAY);

ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
double width = res.getScaledWidth_double();
double height = res.getScaledHeight_double();

Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();

worldrenderer.startDrawingQuads();
worldrenderer.addVertexWithUV(0.0D, height, -90.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV(width, height, -90.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV(width, 0.0D, -90.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV(0.0D, 0.0D, -90.0D, 0.0D, 0.0D);
tessellator.draw();

GL11.glPopMatrix();
}
public void showSpyglass()
{
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer thePlayer = mc.thePlayer;

// add sway
swayTicks++;
if (swayTicks > maxTicks)
{
swayTicks = 0;
if (!thePlayer.isSneaking())
{
yawSway = ((random.nextFloat() * 2 - 1) / 5) / maxTicks;
pitchSway = ((random.nextFloat() * 2 - 1) / 5) / maxTicks;
}
else
{
yawSway = ((random.nextFloat() * 2 - 1) / 16) / maxTicks;
pitchSway = ((random.nextFloat() * 2 - 1) / 16) / maxTicks;
}
}

EntityPlayer p = mc.thePlayer;
p.rotationPitch += yawSway;
p.rotationYaw += pitchSway;

GL11.glPushMatrix();
mc.entityRenderer.setupOverlayRendering();
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_ALPHA_TEST);

mc.renderEngine.bindTexture(SPYGLASS_OVERLAY);

ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
double width = res.getScaledWidth_double();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b305d2d

Please sign in to comment.