Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
1.0.0: Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
symt committed Dec 3, 2019
1 parent 1964771 commit cb96084
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 37 deletions.
40 changes: 29 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

// For those who want the bleeding edge
buildscript {
repositories {
jcenter()
Expand All @@ -9,29 +7,40 @@ buildscript {
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'java'
plugins {
id "com.github.johnrengelman.shadow" version "1.2.3"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.0"
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
version = "1.0.0"
group= "io.github.symt"
archivesBaseName = "ZealotCounter"



minecraft {
version = "1.8.9-11.15.1.2318-1.8.9"
runDir = "run"
mappings = "stable_20"
}

processResources
{
repositories {
jcenter()
}


dependencies {
compile group: 'org.json', name: 'json', version: '20190722'
}

processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
from(sourceSets.main.resources.srcDirs) {
Expand All @@ -42,3 +51,12 @@ processResources
exclude 'mcmod.info'
}
}

shadowJar {
classifier = ""

relocate "org.json", "io.github.symt.repack.org.json"
}

reobf { shadowJar { mappingType = "SEARGE" } }
tasks.reobfShadowJar.mustRunAfter shadowJar
Binary file not shown.
Binary file not shown.
Binary file not shown.
101 changes: 91 additions & 10 deletions src/main/java/io/github/symt/EventHandler.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package io.github.symt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DecimalFormat;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
Expand All @@ -13,42 +21,49 @@
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import org.json.JSONObject;

public class EventHandler {

private boolean firstJoin = true;
private FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
private int attackedEntity = -1;
private int prevEntity = -1;
private long lastHit = 0;

@SubscribeEvent(priority = EventPriority.HIGH)
public void onMobDeath(LivingDeathEvent event) {
System.out.println(event.entity.getCustomNameTag());
MovingObjectPosition objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
if (((objectMouseOver != null && objectMouseOver.typeOfHit == MovingObjectType.ENTITY
&& objectMouseOver.entityHit.getEntityId() == event.entity.getEntityId())
|| attackedEntity == event.entity.getEntityId())
&& (event.entity.getName().substring(2).equals("Enderman")
|| event.entity instanceof EntityEnderman)
&& prevEntity != event.entity.getEntityId()) {
&& prevEntity != event.entity.getEntityId()
&& System.currentTimeMillis() - lastHit < 150
&& ZealotCounter.dragonsNest) {
prevEntity = event.entity.getEntityId();
ZealotCounter.zealotCount++;
ZealotCounter.sinceLastEye++;
}
}

@SubscribeEvent(priority = EventPriority.HIGH)
public void onAttack(AttackEntityEvent event) {
if (Minecraft.getMinecraft().thePlayer.worldObj.isRemote
&& event.entity.getEntityId() == Minecraft.getMinecraft().thePlayer.getEntityId() &&
if (event.entity.getEntityId() == Minecraft.getMinecraft().thePlayer.getEntityId() &&
(event.target.getName().substring(2).equals("Enderman")
|| event.target instanceof EntityEnderman)) {
|| event.target instanceof EntityEnderman) && ZealotCounter.dragonsNest) {
attackedEntity = event.target.getEntityId();
lastHit = System.currentTimeMillis();
}
}

@SubscribeEvent(priority = EventPriority.HIGH)
public void onChatMessageReceived(ClientChatReceivedEvent e) {
if (e.message.getUnformattedText().equals("A special Zealot has spawned nearby!")) {
ZealotCounter.summoningEyes++;
ZealotCounter.sinceLastEye = 0;
}
}

Expand All @@ -57,8 +72,63 @@ public void onPlayerJoinEvent(FMLNetworkEvent.ClientConnectedToServerEvent event
if (firstJoin) {
ZealotCounter.loggedIn = true;
firstJoin = false;
}
Minecraft.getMinecraft().addScheduledTask(() -> {
new Thread(() -> {
try {
URL url = new URL("https://api.github.com/repos/symt/zealot-counter/releases/latest");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
int responseCode = con.getResponseCode();

if (responseCode == 200) {
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

JSONObject json = new JSONObject(response.toString());
String latest = ((String) json.get("tag_name"));
String[] latestTag = latest.split("\\.");
String current = ZealotCounter.VERSION;
String[] currentTag = current.split("\\.");

System.out.println(latestTag.length + " " + currentTag.length);
if (latestTag.length == 3 && currentTag.length == 3) {
for (int i = 0; i < latestTag.length; i++) {
if (latestTag[i].compareTo(currentTag[i]) != 0) {
Minecraft.getMinecraft().thePlayer
.addChatMessage(new ChatComponentTranslation("", new Object[0]));
if (latestTag[i].compareTo(currentTag[i]) <= -1) {
Minecraft.getMinecraft().thePlayer
.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN +
"You are currently on a pre-release build of ZealotCounter. Please report any bugs that you may come across"));
} else if (latestTag[i].compareTo(currentTag[i]) >= 1) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
EnumChatFormatting.GREEN + "You are currently on version "
+ EnumChatFormatting.DARK_GREEN + current + EnumChatFormatting.GREEN
+ " and the latest version is " + EnumChatFormatting.DARK_GREEN
+ latest + EnumChatFormatting.GREEN
+ ". Please update to the latest version of ZealotCounter."));
}
Minecraft.getMinecraft().thePlayer
.addChatMessage(new ChatComponentTranslation("", new Object[0]));
break;
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}).start();
});
}
}

@SubscribeEvent
Expand All @@ -76,18 +146,27 @@ public void renderGameOverlayEvent(RenderGameOverlayEvent event) {
.format(ZealotCounter.zealotCount / (ZealotCounter.summoningEyes * 1.0d)));
String zealot = "Zealots: " + ZealotCounter.zealotCount;
String eye = "Eyes: " + ZealotCounter.summoningEyes;
String lastEye = "Zealots since last eye: " + ZealotCounter.sinceLastEye;
String longest =
(lastEye.length() > zealot.length() && lastEye.length() > zealotEye.length()) ? lastEye
: (zealot.length() > zealotEye.length()) ? zealot : zealotEye;
if (ZealotCounter.align.equals("right")) {
renderer.drawString(zealot, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(zealotEye) -
renderer.getStringWidth(longest) -
renderer.getStringWidth(zealot),
ZealotCounter.guiLocation[1], ZealotCounter.color, true);
renderer.drawString(eye,
ZealotCounter.guiLocation[0] +
renderer.getStringWidth(zealotEye) -
renderer.drawString(eye, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(eye),
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT, ZealotCounter.color, true);
renderer.drawString(zealotEye, ZealotCounter.guiLocation[0],
renderer.drawString(zealotEye, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(zealotEye),
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 2, ZealotCounter.color, true);
renderer.drawString(lastEye, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(lastEye),
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 3, ZealotCounter.color, true);
} else {
renderer.drawString(zealot, ZealotCounter.guiLocation[0],
ZealotCounter.guiLocation[1], ZealotCounter.color, true);
Expand All @@ -96,6 +175,8 @@ public void renderGameOverlayEvent(RenderGameOverlayEvent event) {
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT, ZealotCounter.color, true);
renderer.drawString(zealotEye, ZealotCounter.guiLocation[0],
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 2, ZealotCounter.color, true);
renderer.drawString(lastEye, ZealotCounter.guiLocation[0],
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 3, ZealotCounter.color, true);
}
}
}
Expand Down
Loading

0 comments on commit cb96084

Please sign in to comment.