diff options
| author | Lorenz <lo.scherf@gmail.com> | 2022-08-06 11:46:08 +0200 |
|---|---|---|
| committer | Lorenz <lo.scherf@gmail.com> | 2022-08-06 11:46:08 +0200 |
| commit | bfa53ca5b4cb9a0ef31256746612cb6289b06a49 (patch) | |
| tree | 949cf71ede55fbb7ee33bfec0fcf9ec32873b8d5 /src/main/java/at/hannibal2/skyhanni/test | |
| parent | 283a986d3d0f84afc5c38fb4c8465abc5de0d2b2 (diff) | |
| download | skyhanni-bfa53ca5b4cb9a0ef31256746612cb6289b06a49.tar.gz skyhanni-bfa53ca5b4cb9a0ef31256746612cb6289b06a49.tar.bz2 skyhanni-bfa53ca5b4cb9a0ef31256746612cb6289b06a49.zip | |
Merge branch 'master' of C:\Users\Lorenz\IdeaProjects\SkyHanni with conflicts.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test')
3 files changed, 544 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/GriffinJavaUtils.java b/src/main/java/at/hannibal2/skyhanni/test/GriffinJavaUtils.java new file mode 100644 index 000000000..431cfbe6f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/test/GriffinJavaUtils.java @@ -0,0 +1,353 @@ +package at.hannibal2.skyhanni.test; + +import at.hannibal2.skyhanni.utils.LorenzVec; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.text.DecimalFormat; +import java.util.*; +import java.util.List; +import java.util.function.Function; + +public class GriffinJavaUtils { + public static <T> void permute(ArrayList<ArrayList<T>> result, T[] a, int k) { + if (k == a.length) { + ArrayList<T> subResult = new ArrayList<>(); + result.add(subResult); + Collections.addAll(subResult, a); + } else { + for (int i = k; i < a.length; i++) { + T temp = a[k]; + a[k] = a[i]; + a[i] = temp; + + permute(result, a, k + 1); + + temp = a[k]; + a[k] = a[i]; + a[i] = temp; + } + } + } + +// public static <T> ArrayList<T> sortLocationListC(LorenzVec start, Map<T, LorenzVec> map, boolean brokenMath) { +// Map<T, Double> fastestWithout = new HashMap<>(); +// for (T without : map.keySet()) { +// +// ArrayList<ArrayList<T>> variants = new ArrayList<>(); +// ArrayList<T> values = new ArrayList<>(map.keySet()); +// +// values.remove(without); +// T[] array = (T[]) values.toArray(); +// +// permute(variants, array, 0); +// +// LinkedHashMap<ArrayList<T>, Double> distances = new LinkedHashMap<>(); +// +// for (ArrayList<T> list : variants) { +// +// double distance = 0; +// LorenzVec last = start; +// +// for (T t : list) { +// LorenzVec location = map.get(t); +// distance += last.distanceSq(location); +// last = location; +// } +// +// distances.put(list, distance); +// } +// +// Map<ArrayList<T>, Double> sort; +// if (brokenMath) { +// sort = sortByValue(distances); +// } else { +// sort = sortByValueAsc(distances); +// } +// +// double fastestDistance = sort.values().iterator().next(); +// fastestWithout.put(without, fastestDistance); +// } +// +// T skip = sortByValueAsc(fastestWithout).keySet().iterator().next(); +// +// +// map.remove(skip); +// ArrayList<T> result = sortLocationListB(start, map, brokenMath, false, T -> false, 0); +// result.add(skip); +// +// return result; +// } + + public static <T> ArrayList<LorenzVec> sortLocationListB(LorenzVec start, Map<T, LorenzVec> map, boolean brokenMath, + boolean skipWorst, Function<T, Boolean> shouldAddToHostile, int addToHostileLastValue) { + +// if (skipWorst) { +// return sortLocationListC(start, map, brokenMath); +// } + ArrayList<ArrayList<T>> variants = new ArrayList<>(); + Set<T> values = map.keySet(); + T[] array = (T[]) values.toArray(); + + permute(variants, array, 0); + + LinkedHashMap<ArrayList<T>, Double> distances = new LinkedHashMap<>(); + + int with = 0; + int without = 0; + + for (ArrayList<T> list : variants) { + + double distance = 0; + LorenzVec last = start; + T lastT = null; + + for (T t : list) { + LorenzVec location = map.get(t); + distance += last.distanceSq(location); + last = location; + lastT = t; + } + if (shouldAddToHostile.apply(lastT)) { + distance += addToHostileLastValue; + with++; + } else { + without++; + } + + distances.put(list, distance); + } +// LorenzUtils.Companion.chat("with: " + with); +// LorenzUtils.Companion.chat("without: " + without); + + Map<ArrayList<T>, Double> sort; + if (brokenMath) { + sort = sortByValue(distances); + } else { + sort = sortByValueAsc(distances); + } + ArrayList<T> result = sort.keySet().iterator().next(); + ArrayList<LorenzVec> resultList = new ArrayList<>(); + for (T t : result) { + resultList.add(map.get(t)); + } + + return resultList; + } + + //descending + public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { + List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); + list.sort(Map.Entry.comparingByValue()); + Collections.reverse(list); + + Map<K, V> result = new LinkedHashMap<>(); + for (Map.Entry<K, V> entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + + return result; + } + + //ascending + public static <K, V extends Comparable<? super V>> Map<K, V> sortByValueAsc(Map<K, V> map) { + List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); + list.sort(Map.Entry.comparingByValue()); + + Map<K, V> result = new LinkedHashMap<>(); + for (Map.Entry<K, V> entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + + return result; + } + + public static String formatInteger(int i) { + return new DecimalFormat("#,##0").format(i).replace(',', '.'); + } + + public static List<ItemStack> getItemsInInventory() { + return getItemsInInventory(false); + } + + public static List<ItemStack> getItemsInInventory(boolean withCursorItem) { + List<ItemStack> list = new ArrayList<>(); + +// EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + if (player == null) { + System.err.println("loadCurrentInventory: player is null!"); + return list; + } + + InventoryPlayer inventory = player.inventory; + ItemStack[] mainInventory = inventory.mainInventory; + + ArrayList<ItemStack> helpList = new ArrayList<>(); + helpList.addAll(Arrays.asList(mainInventory)); + + if (withCursorItem) { + helpList.add(inventory.getItemStack()); + } + + for (ItemStack item : helpList) { + if (item == null) continue; + String name = item.getDisplayName(); + if (name.equalsIgnoreCase("air")) continue; + if (name.equalsIgnoreCase("luft")) continue; + list.add(item); + } + + return list; + } + + public static void drawWaypoint(LorenzVec pos, float partialTicks, Color color, boolean beacon) { + drawWaypoint(pos, partialTicks, color, beacon, false); + } + + public static void drawWaypoint(LorenzVec pos, float partialTicks, Color color, boolean beacon, boolean forceBeacon) { + Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); + double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; + double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; + double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; + + double x = pos.getX() - viewerX; + double y = pos.getY() - viewerY; + double z = pos.getZ() - viewerZ; + + + GlStateManager.disableDepth(); + GlStateManager.disableCull(); + GlStateManager.disableTexture2D(); + if (beacon) { + double distSq = x * x + y * y + z * z; + if (distSq > 5 * 5 || forceBeacon) { + //TODO add beacon +// GriffinUtils.renderBeaconBeam(x, y, z, color.getRGB(), 1.0f, partialTicks); + } + } +// BlockPos a = pos.toBlocPos(); +// BlockPos b = pos.add(1, 1, 1).toBlocPos(); +// draw3DBox(new AxisAlignedBB(a, b), color, partialTicks); + + AxisAlignedBB aabb = new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1); + + draw3DBox(aabb, color, partialTicks); + GlStateManager.disableLighting(); + GlStateManager.enableTexture2D(); + GlStateManager.enableDepth(); + + } + + public static void draw3DLine(LorenzVec p1, LorenzVec p2, Color color, int lineWidth, boolean depth, float partialTicks) { + GlStateManager.disableDepth(); + GlStateManager.disableCull(); + +// Vec3 pos1 = new Vec3(p1.getX(), p1.getY(), p1.getZ()); +// Vec3 pos2 = new Vec3(p2.getX(), p2.getY(), p2.getZ()); + + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GL11.glLineWidth(lineWidth); + + + if (!depth) { + GL11.glDisable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(false); + } + GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); + worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); + + worldRenderer.pos(p1.getX(), p1.getY(), p1.getZ()).endVertex(); + worldRenderer.pos(p2.getX(), p2.getY(), p2.getZ()).endVertex(); + Tessellator.getInstance().draw(); + + GlStateManager.translate(realX, realY, realZ); + if (!depth) { + GL11.glEnable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(true); + } + + + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + + + GlStateManager.disableLighting(); + GlStateManager.enableDepth(); + } + + public static void draw3DBox(AxisAlignedBB aabb, Color colour, float partialTicks) { + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GL11.glLineWidth(2); + GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue() / 255f, colour.getAlpha() / 255f); + worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); + + worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); + Tessellator.getInstance().draw(); + worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); + Tessellator.getInstance().draw(); + worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); + worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex(); + Tessellator.getInstance().draw(); + + GlStateManager.translate(realX, realY, realZ); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt b/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt new file mode 100644 index 000000000..8b77dc6e3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt @@ -0,0 +1,116 @@ +package at.hannibal2.skyhanni.test + +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzVec +import net.minecraftforge.client.event.RenderWorldLastEvent + +object GriffinUtils { + + + fun RenderWorldLastEvent.drawWaypoint(location: LorenzVec, color: LorenzColor, beacon: Boolean = false) { + GriffinJavaUtils.drawWaypoint(location, partialTicks, color.toColor(), beacon) + } + + fun RenderWorldLastEvent.draw3DLine( + p1: LorenzVec, + p2: LorenzVec, + color: LorenzColor, + lineWidth: Int, + depth: Boolean + ) { + + GriffinJavaUtils.draw3DLine(p1, p2, color.toColor(), lineWidth, depth, partialTicks) + } + +// fun renderBeaconBeam(x: Double, y: Double, z: Double, rgb: Int, alphaMultiplier: Float, partialTicks: Float) { +// val height = 300 +// val bottomOffset = 0 +// val topOffset = bottomOffset + height +// val tessellator = Tessellator.getInstance() +// val worldrenderer = tessellator.worldRenderer +// +//// Skytils.mc.textureManager.bindTexture(RenderUtil.beaconBeam) +// GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0f) +// GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0f) +// GlStateManager.disableLighting() +// GlStateManager.enableCull() +// GlStateManager.enableTexture2D() +// GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0) +// GlStateManager.enableBlend() +// GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) +// val time = Skytils.mc.theWorld.totalWorldTime + partialTicks.toDouble() +// val d1 = MathHelper.func_181162_h( +// -time * 0.2 - MathHelper.floor_double(-time * 0.1) +// .toDouble() +// ) +// val r = (rgb shr 16 and 0xFF) / 255f +// val g = (rgb shr 8 and 0xFF) / 255f +// val b = (rgb and 0xFF) / 255f +// val d2 = time * 0.025 * -1.5 +// val d4 = 0.5 + cos(d2 + 2.356194490192345) * 0.2 +// val d5 = 0.5 + sin(d2 + 2.356194490192345) * 0.2 +// val d6 = 0.5 + cos(d2 + Math.PI / 4.0) * 0.2 +// val d7 = 0.5 + sin(d2 + Math.PI / 4.0) * 0.2 +// val d8 = 0.5 + cos(d2 + 3.9269908169872414) * 0.2 +// val d9 = 0.5 + sin(d2 + 3.9269908169872414) * 0.2 +// val d10 = 0.5 + cos(d2 + 5.497787143782138) * 0.2 +// val d11 = 0.5 + sin(d2 + 5.497787143782138) * 0.2 +// val d14 = -1.0 + d1 +// val d15 = height.toDouble() * 2.5 + d14 +// worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR) +// worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(1.0, d14).color(r, g, b, 1.0f).endVertex() +// worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(0.0, d14).color(r, g, b, 1.0f).endVertex() +// worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(1.0, d14).color(r, g, b, 1.0f).endVertex() +// worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(0.0, d14).color(r, g, b, 1.0f).endVertex() +// worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(1.0, d14).color(r, g, b, 1.0f).endVertex() +// worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(0.0, d14).color(r, g, b, 1.0f).endVertex() +// worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(1.0, d14).color(r, g, b, 1.0f).endVertex() +// worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(0.0, d14).color(r, g, b, 1.0f).endVertex() +// worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier) +// .endVertex() +// tessellator.draw() +// GlStateManager.disableCull() +// val d12 = -1.0 + d1 +// val d13 = height + d12 +// worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR) +// worldrenderer.pos(x + 0.2, y + topOffset, z + 0.2).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.2).tex(1.0, d12).color(r, g, b, 0.25f).endVertex() +// worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.2).tex(0.0, d12).color(r, g, b, 0.25f).endVertex() +// worldrenderer.pos(x + 0.8, y + topOffset, z + 0.2).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + 0.8, y + topOffset, z + 0.8).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.8).tex(1.0, d12).color(r, g, b, 0.25f).endVertex() +// worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.8).tex(0.0, d12).color(r, g, b, 0.25f).endVertex() +// worldrenderer.pos(x + 0.2, y + topOffset, z + 0.8).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + 0.8, y + topOffset, z + 0.2).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.2).tex(1.0, d12).color(r, g, b, 0.25f).endVertex() +// worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.8).tex(0.0, d12).color(r, g, b, 0.25f).endVertex() +// worldrenderer.pos(x + 0.8, y + topOffset, z + 0.8).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + 0.2, y + topOffset, z + 0.8).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier) +// .endVertex() +// worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.8).tex(1.0, d12).color(r, g, b, 0.25f).endVertex() +// worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.2).tex(0.0, d12).color(r, g, b, 0.25f).endVertex() +// worldrenderer.pos(x + 0.2, y + topOffset, z + 0.2).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier) +// .endVertex() +// tessellator.draw() +// } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt index 3d2611517..df176a02e 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt @@ -1,20 +1,22 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.GuiRender.renderString +import at.hannibal2.skyhanni.utils.ItemUtils.cleanName import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.LorenzDebug -import at.hannibal2.skyhanni.utils.LorenzLogger -import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getSBItemID import net.minecraft.client.Minecraft +import net.minecraft.entity.item.EntityArmorStand import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class LorenzTest { - var log = LorenzLogger("debug/packets") + var packetLog = LorenzLogger("debug/packets") companion object { var enabled = false @@ -28,7 +30,7 @@ class LorenzTest { print("===") print("ITEM LORE") print("display name: '" + itemStack.displayName.toString() + "'") - val itemID = itemStack.getInternalName() + val itemID = itemStack.getSBItemID() print("itemID: '$itemID'") // val rarity: ItemRarityOld = ItemUtils.getRarity(itemStack) // print("rarity: '$rarity'") @@ -91,6 +93,68 @@ class LorenzTest { private fun print(text: String) { LorenzDebug.log(text) } + + fun testCommand() { + val minecraft = Minecraft.getMinecraft() + val start = minecraft.thePlayer.position.toLorenzVec() + val world = minecraft.theWorld + for (entity in world.loadedEntityList) { + val position = entity.position + val vec = position.toLorenzVec() + val distance = start.distance(vec) + if (distance < 10) { + LorenzDebug.log("found entity: " + entity.name) + val displayName = entity.displayName + LorenzDebug.log("displayName: $displayName") + val simpleName = entity.javaClass.simpleName + LorenzDebug.log("simpleName: $simpleName") + LorenzDebug.log("vec: $vec") + LorenzDebug.log("distance: $distance") + + val rotationYaw = entity.rotationYaw + val rotationPitch = entity.rotationPitch + LorenzDebug.log("rotationYaw: $rotationYaw") + LorenzDebug.log("rotationPitch: $rotationPitch") + + if (entity is EntityArmorStand) { + LorenzDebug.log("armor stand data:") + val headRotation = entity.headRotation.toLorenzVec() + val bodyRotation = entity.bodyRotation.toLorenzVec() + LorenzDebug.log("headRotation: $headRotation") + LorenzDebug.log("bodyRotation: $bodyRotation") + + /** + * xzLen = cos(pitch) + x = xzLen * cos(yaw) + y = sin(pitch) + z = xzLen * sin(-yaw) + */ + +// val xzLen = cos(0.0) +// val x = xzLen * cos(rotationYaw) +// val y = sin(0.0) +// val z = xzLen * sin(-rotationYaw) + + val dir = LorenzVec.getFromYawPitch(rotationYaw.toDouble(), 0.0) + +// val direction = Vec3(1.0, 1.0, 1.0).rotateYaw(rotationYaw).toLorenzVec() +// val direction = LorenzVec(x, y, z) + + for ((id, stack) in entity.inventory.withIndex()) { + LorenzDebug.log("id $id = $stack") + if (stack != null) { + val cleanName = stack.cleanName() + val type = stack.javaClass.name + LorenzDebug.log("cleanName: $cleanName") + LorenzDebug.log("type: $type") + + } + } + } + LorenzDebug.log("") + } + } + } } @SubscribeEvent @@ -102,6 +166,11 @@ class LorenzTest { } } + @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) + fun onChatPacket(event: PacketEvent.ReceiveEvent) { + packetLog.log(event.packet.toString()) + } + // @SubscribeEvent // fun onGetBlockModel(event: RenderBlockInWorldEvent) { // if (!LorenzUtils.inSkyblock || !SkyHanniMod.feature.debug.enabled) return |
