IDEA resource fix, LogoutSpots, texture stuff

This commit is contained in:
noil 2019-11-05 22:53:21 -05:00
parent 2394d544c1
commit 6ef7c8576a
9 changed files with 247 additions and 46 deletions

View File

@ -30,7 +30,7 @@ compileJava {
minecraft {
version = "1.12.2-14.23.5.2768"
runDir = "run"
// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
@ -75,7 +75,7 @@ shadowJar {
attributes 'FMLCorePluginContainsFMLMod': 'true'
attributes 'FMLAT': 'seppuku_at.cfg'
}
exclude 'dummyThing'
exclude 'LICENSE.txt'
classifier = 'full'
@ -94,11 +94,13 @@ task signJar(type: SignJar, dependsOn: reobfJar) {
outputFile = jar.archivePath
}
build.dependsOn {[
'shadowJar',
'reobfShadowJar',
'signJar'
]}
build.dependsOn {
[
'shadowJar',
'reobfShadowJar',
'signJar'
]
}
processResources {
// this will ensure that this task is redone when the versions change.
@ -108,13 +110,19 @@ processResources {
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
expand 'version': project.version, 'mcversion': project.minecraft.version
}
// copy everything else except the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
sourceSets {
main {
output.resourcesDir = output.classesDir
}
}

View File

@ -0,0 +1,33 @@
package me.rigamortis.seppuku.api.texture;
import me.rigamortis.seppuku.api.util.RenderUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
/**
* created by noil on 11/5/19 at 8:51 PM
*/
public class Texture {
private final ResourceLocation textureLocation;
public Texture(String name) {
this.textureLocation = new ResourceLocation("seppukumod", "textures/" + name);
}
public void render(float x, float y, float width, float height, float u, float v, float t, float s) {
this.bind();
GlStateManager.enableTexture2D();
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
RenderUtil.drawTexture(x, y, width, height, 0, 0, 1, 1);
}
public void render(float x, float y, float width, float height) {
this.render(x, y, width, height, 0, 0, 1, 1);
}
public void bind() {
Minecraft.getMinecraft().getTextureManager().bindTexture(this.textureLocation);
}
}

View File

@ -0,0 +1,51 @@
package me.rigamortis.seppuku.api.util;
import org.apache.commons.io.IOUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.UUID;
/**
* created by noil on 11/5/19 at 7:53 PM
*/
public final class NetworkUtil {
public static String resolveUsername(UUID id) {
final String url = "https://api.mojang.com/user/profiles/" + id.toString().replace("-", "") + "/names";
try {
final String nameJson = IOUtils.toString(new URL(url));
if (nameJson != null) {
final JSONArray nameValue = (JSONArray) JSONValue.parseWithException(nameJson);
if (nameValue != null) {
final String playerSlot = nameValue.get(nameValue.size() - 1).toString();
if (playerSlot != null) {
final JSONObject nameObject = (JSONObject) JSONValue.parseWithException(playerSlot);
if (nameObject != null) {
return nameObject.get("name").toString();
}
}
}
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
return null;
}
public static BufferedImage getIcon(UUID id) {
try {
URL url = new URL("https://minotar.net/avatar/" + id.toString().replace("-", ""));
return ImageIO.read(url);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -356,16 +356,29 @@ public final class RenderUtil {
GlStateManager.scale(scaleDistance, scaleDistance, scaleDistance);
}
public static void drawTexturedModalRect(float x, float y, float textureX, float textureY, float width, float height) {
public static void drawTexture(float x, float y, float textureX, float textureY, float width, float height) {
float f = 0.00390625F;
float f1 = 0.00390625F;
final Tessellator tessellator = Tessellator.getInstance();
final BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.begin(GL_QUADS, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(x, (y + height), 0.0D).tex((textureX * f), ((textureY + height) * f1)).endVertex();
bufferbuilder.pos((x + width), (y + height), 0.0D).tex(((textureX + width) * f), ((textureY + height) * f1)).endVertex();
bufferbuilder.pos((x + width), y, 0.0D).tex(((textureX + width) * f), (textureY * f1)).endVertex();
bufferbuilder.pos(x, y, 0.0D).tex((textureX * f), (textureY * f1)).endVertex();
tessellator.draw();
}
public static void drawTexture(float x, float y, float width, float height, float u, float v, float t, float s) {
final Tessellator tessellator = Tessellator.getInstance();
final BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(GL_TRIANGLES, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(x + width, y, 0F).tex(t, v).endVertex();
bufferbuilder.pos(x, y, 0F).tex(u, v).endVertex();
bufferbuilder.pos(x, y + height, 0F).tex(u, s).endVertex();
bufferbuilder.pos(x, y + height, 0F).tex(u, s).endVertex();
bufferbuilder.pos(x + width, y + height, 0F).tex(t, s).endVertex();
bufferbuilder.pos(x + width, y, 0F).tex(t, v).endVertex();
tessellator.draw();
}
}

View File

@ -5,19 +5,11 @@ import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.network.EventReceivePacket;
import me.rigamortis.seppuku.api.event.player.EventPlayerJoin;
import me.rigamortis.seppuku.api.event.player.EventPlayerLeave;
import me.rigamortis.seppuku.api.util.NetworkUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.network.play.server.SPacketPlayerListItem;
import org.apache.commons.io.IOUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.io.IOException;
import java.net.URL;
import java.util.UUID;
/**
* Author Seth
* 7/23/2019 @ 7:38 AM.
@ -39,7 +31,7 @@ public final class JoinLeaveManager {
for (SPacketPlayerListItem.AddPlayerData playerData : packet.getEntries()) {
if (playerData.getProfile().getId() != mc.session.getProfile().getId()) {
new Thread(() -> {
final String name = resolveUsername(playerData.getProfile().getId());
final String name = NetworkUtil.resolveUsername(playerData.getProfile().getId());
if (name != null) {
Seppuku.INSTANCE.getEventManager().dispatchEvent(new EventPlayerJoin(name, playerData.getProfile().getId().toString()));
}
@ -51,7 +43,7 @@ public final class JoinLeaveManager {
for (SPacketPlayerListItem.AddPlayerData playerData : packet.getEntries()) {
if (playerData.getProfile().getId() != mc.session.getProfile().getId()) {
new Thread(() -> {
final String name = resolveUsername(playerData.getProfile().getId());
final String name = NetworkUtil.resolveUsername(playerData.getProfile().getId());
if (name != null) {
Seppuku.INSTANCE.getEventManager().dispatchEvent(new EventPlayerLeave(name, playerData.getProfile().getId().toString()));
}
@ -64,28 +56,6 @@ public final class JoinLeaveManager {
}
}
public String resolveUsername(UUID id) {
final String url = "https://api.mojang.com/user/profiles/" + id.toString().replace("-", "") + "/names";
try {
final String nameJson = IOUtils.toString(new URL(url));
if (nameJson != null) {
final JSONArray nameValue = (JSONArray) JSONValue.parseWithException(nameJson);
if (nameValue != null) {
final String playerSlot = nameValue.get(nameValue.size() - 1).toString();
if (playerSlot != null) {
final JSONObject nameObject = (JSONObject) JSONValue.parseWithException(playerSlot);
if (nameObject != null) {
return nameObject.get("name").toString();
}
}
}
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
return null;
}
public void unload() {
Seppuku.INSTANCE.getEventManager().removeEventListener(this);
}

View File

@ -140,6 +140,7 @@ public final class ModuleManager {
add(new PullDownModule());
add(new PortalFinderModule());
add(new ShulkerPreviewModule());
add(new LogoutSpotsModule());
this.loadExternalModules();
}

View File

@ -0,0 +1,125 @@
package me.rigamortis.seppuku.impl.module.render;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile;
import me.rigamortis.seppuku.api.event.player.EventPlayerJoin;
import me.rigamortis.seppuku.api.event.player.EventPlayerLeave;
import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate;
import me.rigamortis.seppuku.api.event.render.EventRender2D;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.texture.Texture;
import me.rigamortis.seppuku.api.util.GLUProjection;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.util.Map;
/**
* created by noil on 11/5/2019 at 6:37 PM
*/
public final class LogoutSpotsModule extends Module {
private final Map<GameProfile, PlayerData> playerCache = Maps.newConcurrentMap();
private final Map<GameProfile, PlayerData> logoutCache = Maps.newConcurrentMap();
private final Texture playerIcon = new Texture("location.png");
public LogoutSpotsModule() {
super("LogoutSpots", new String[]{"Logout", "Spots"}, "Draws the location of nearby player logouts.", "NONE", -1, ModuleType.RENDER);
}
@Override
public void onToggle() {
super.onToggle();
playerCache.clear();
logoutCache.clear();
logoutCache.put(Minecraft.getMinecraft().player.getGameProfile(), new PlayerData(Minecraft.getMinecraft().player.getPosition()));
}
@Listener
public void onPlayerUpdate(EventPlayerUpdate event) {
final Minecraft mc = Minecraft.getMinecraft();
for (EntityPlayer player : mc.world.playerEntities) {
if (player == null || player.equals(mc.player))
continue;
this.updateCache(player.getGameProfile(), new PlayerData(player.getPosition()));
}
}
@Listener
public void onRender2D(EventRender2D event) {
final Minecraft mc = Minecraft.getMinecraft();
for (GameProfile profile : this.logoutCache.keySet()) {
final PlayerData data = this.logoutCache.get(profile);
final GLUProjection.Projection projection = GLUProjection.getInstance().project(data.position.getX() - mc.getRenderManager().renderPosX, data.position.getY() - mc.getRenderManager().renderPosY, data.position.getZ() - mc.getRenderManager().renderPosZ, GLUProjection.ClampMode.NONE, true);
if (projection != null) {
GlStateManager.pushMatrix();
GlStateManager.translate(projection.getX(), projection.getY(), 0);
String text = profile.getName() + " logout";
float textWidth = mc.fontRenderer.getStringWidth(text);
playerIcon.render(-8, -16 - 2, 16, 16);
mc.fontRenderer.drawStringWithShadow(text, -(textWidth / 2), 0, -1);
GlStateManager.translate(-projection.getX(), -projection.getY(), 0);
GlStateManager.popMatrix();
}
}
}
@Listener
public void onPlayerLeave(EventPlayerLeave event) {
final Minecraft mc = Minecraft.getMinecraft();
for (GameProfile profile : this.playerCache.keySet()) {
if (!profile.getId().toString().equals(event.getUuid())) // not matching uuid
continue;
final PlayerData data = this.playerCache.get(profile);
if (!hasPlayerLogged(profile)) {
this.logoutCache.put(profile, data);
}
}
this.playerCache.clear();
}
@Listener
public void onPlayerJoin(EventPlayerJoin event) {
final Minecraft mc = Minecraft.getMinecraft();
for (GameProfile profile : this.playerCache.keySet()) {
if (!profile.getId().toString().equals(event.getUuid())) // not matching uuid
continue;
if (hasPlayerLogged(profile)) {
this.logoutCache.remove(profile);
}
}
this.playerCache.clear();
}
private void updateCache(GameProfile profile, PlayerData data) {
this.playerCache.put(profile, data);
}
private boolean hasPlayerLogged(GameProfile profile) {
return this.logoutCache.containsKey(profile);
}
private class PlayerData {
BlockPos position;
PlayerData(BlockPos position) {
this.position = position;
}
}
}

View File

@ -223,7 +223,7 @@ public final class WallHackModule extends Module {
}
// draw the textured icon
RenderUtil.drawTexturedModalRect(offsetX, offsetY, iconIndex % 8 * 18, 198 + iconIndex / 8 * 18, 18, 18);
RenderUtil.drawTexture(offsetX, offsetY, iconIndex % 8 * 18, 198 + iconIndex / 8 * 18, 18, 18);
GlStateManager.popMatrix();
offsetY += 16;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB