-
Posts
12 -
Joined
-
Last visited
Everything posted by Prickles
-
[1.12] Getting the correct player movement speed in blocks per second
Prickles replied to Prickles's topic in Modder Support
How would I pass in the server world correctly? What world instance would I use? (mc.player.getServer().getEntityWorld() always returns null, and I can't think of how getting the world from the message handler class could work) And here's my packet initialization (Changed snw to INSTANCE): public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID); //... //In preInit INSTANCE.registerMessage(SpeedPacketHandler.class, SpeedPacket.class, 0, Side.CLIENT); -
[1.12] Getting the correct player movement speed in blocks per second
Prickles replied to Prickles's topic in Modder Support
Well, I tried doing that SpeedPacket.java Excerpt from NearBox#drawNearBox (I combined my rendering method and the HelmetHandler methods) According to the sys out prints, I got the speeds and UUIDs in toBytes(), however, fromBytes() was never even called ("Reading" from the sys out println in fromBytes() was never printed) So, I could never update the global hashmap in NearBox with the filled hashmap, because that's in fromBytes() These errors were also spammed in my console: Also, do I even need to use the IMessageHandler? -
[1.12] Getting the correct player movement speed in blocks per second
Prickles replied to Prickles's topic in Modder Support
1) Well, what this should be doing is iterating through every player in the world, adding them to a list if they are within a certain range, looping through every player on that list, and getting/displaying the speed of each player on that list. 2) I thought I need to calculate the speed on the server, not send the speed? 3) Whenever I try to cast an EntityPlayer to EntityPlayerMP, I get the following error: net.minecraft.client.entity.EntityOtherPlayerMP cannot be cast to net.minecraft.entity.player.EntityPlayerMP And adding a check to see if the EntityPlayer is an instance of EntityPlayerMP returns false and skips the line that sends the speed packet to the player. 4) Is this any better? SpeedPacket.java Excerpt from RenderUtils#drawNearBox -
[1.12] Getting the correct player movement speed in blocks per second
Prickles replied to Prickles's topic in Modder Support
Oh, forgot to mention that HelmetHandler#following is called within another method that has a subscribeevent annotation. The RenderGameOverlayEvent.Pre parameter is passed down all the way to RenderUtils#drawNearBox (Organization purposes) As for debugging, it turns out that apparently a player from a List<EntityPlayer> isn't an instance of EntityPlayerMP? How do I cast that correctly? -
[1.12] Getting the correct player movement speed in blocks per second
Prickles replied to Prickles's topic in Modder Support
I tried to interpret what you said, but it didn't work. No stacktrace/crash, but it couldn't find the player/change the speed value. This was also spammed in the console: [18:32:28] [main/WARN]: Received passengers for unknown entity Main#initialize Main#preInit HelmetHandler#following Part of RenderUtils#drawNearBox SpeedPacket.java SpeedPacketHandler.java A little help? -
[1.12] Getting the correct player movement speed in blocks per second
Prickles replied to Prickles's topic in Modder Support
So would I have to send a packet to the server with an EntityPlayer in it and return the speed in an Imessage in PacketHandler#onMessage? How would I access that speed then? -
So I have a pretty basic method to get a player's movement speed: However, when testing it, I ran into a problem On singleplayer, walking speed was about 4.3 blocks per second (accurate according to minecraft wiki), but on a multiplayer server, it was at 5.2 bps. Correct me if I'm wrong, but I think this difference is because of the server's tickrate being higher than 20 tps, which is what I'm multiplying the distance that the player moved in 1 tick by to get the distance moved in 1 second. I've tried things like e.getServer().getTickCounter() and other methods that include using system time and whatnot to get the tps, but to no avail. So how would I get the server's actual tps to multiply by, if that is what's wrong here?
-
[1.12] Getting and Using world.loadedEntities remotely
Prickles replied to Prickles's topic in Modder Support
Alright, thanks for helping me clean up my code -
[1.12] Getting and Using world.loadedEntities remotely
Prickles replied to Prickles's topic in Modder Support
This is more of a private mod, so I just made a list of the usernames of my friends and I, and that whole thing with Arrays.binarySearch is to remove the player's username from that list so he doesn't draw a box on himself. I guess I should use UUIDs tho lol. Any player not on that list gets a red esp and any player on it gets a green one. And I am using Arrays.asList I totally forgot about needing to sort that list and remembered a simple substitute search method I made haha Here's some new code: Equipped is just defined by whether or not the player is wearing a gold helmet I need to access it because I have a class called RenderOverlayHandler that has a RenderGameOverlayEvent method that renders an overlay if the player is wearing said helmet: I guess I could just combine the two classes but I don't think it would really make a difference -
[1.12] Getting and Using world.loadedEntities remotely
Prickles replied to Prickles's topic in Modder Support
Okay, so would this be any better?: @SubscribeEvent @SideOnly(Side.CLIENT) public static void helmet(RenderWorldLastEvent event) { Minecraft mc = Minecraft.getMinecraft(); EntityPlayer p = (EntityPlayer) mc.player; List<Entity> entities = mc.world.loadedEntityList; if (Main.friendlyUsernames.contains(p.getName())) { Main.friendlyUsernames.remove(Arrays.binarySearch(Main.friendlyNamesArr, p.getName())); } if (p.inventory.armorItemInSlot(3).getItem() == Item.getItemById(314)) { equipped = true; } else { equipped = false; } if (equipped) { for (Entity e : entities) { if(!(e instanceof EntityLiving)) { continue; } if (e instanceof EntityOtherPlayerMP) { if (Main.friendlyUsernames.contains(e.getName())) { RenderUtils.drawESP(event, e, 2f, 0, 255, 0); } else { RenderUtils.drawESP(event, e, 2f, 255, 0, 0); } } if (e instanceof EntityMob) { RenderUtils.drawESP(event, e, 2f, 255, 187, 0); } if (e instanceof EntityAnimal) { RenderUtils.drawESP(event, e, 2f, 0, 150, 255); } } } } Or would I need to use a packet system (IMessage example in the docs) and constantly get the server world and player to use instead of mc.player and mc.world? -
[1.12] Getting and Using world.loadedEntities remotely
Prickles replied to Prickles's topic in Modder Support
Alright I fixed it (Pretty shameful errors) Here's what I did New HelmetHandler class: package prickles.insight.hud; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import net.minecraft.client.entity.EntityOtherPlayerMP; import net.minecraft.entity.Entity; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import prickles.insight.hud.utils.RenderUtils; import prickles.insightsq.core.Main; public class HelmetHandler { public static boolean equipped; public static List<Entity> worldEntities; @SubscribeEvent public static void helmet(TickEvent.PlayerTickEvent event) { EntityPlayer p = event.player; if (p.inventory.armorItemInSlot(3).getItem() == Item.getItemById(314)) { equipped = true; } else { equipped = false; } if (Main.friendlyUsernames.contains(p.getName())) { Main.friendlyUsernames.remove(Arrays.binarySearch(Main.friendlyNamesArr, p.getName())); } } @SubscribeEvent public static void worldLoader(TickEvent.WorldTickEvent event) { worldEntities = event.world.loadedEntityList; } @SubscribeEvent public static void render(RenderWorldLastEvent event) { if (equipped) { if (worldEntities != null) { for (int i = 0; i < worldEntities.size(); i++) { Entity e = worldEntities.get(i); if (e instanceof EntityOtherPlayerMP) { if (Main.friendlyUsernames.contains(e.getName())) { RenderUtils.drawESP(event, e, 1f, 0, 255, 0); } else { RenderUtils.drawESP(event, e, 1f, 255, 0, 0); } } if (e instanceof EntityMob) { RenderUtils.drawESP(event, e, 1f, 255, 187, 0); } if (e instanceof EntityAnimal) { RenderUtils.drawESP(event, e, 1f, 0, 150, 255); } } } } } } -
So I basically have a mod that's supposed to draw an esp over every mob in the world (or at least within viewing distance) Main.java package prickles.insightsq.core; import java.util.ArrayList; import java.util.Arrays; import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import prickles.insight.hud.HelmetHandler; import prickles.insight.hud.RenderOverlayHandler; import prickles.insightsq.core.proxies.CommonProxy; @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION) public class Main { @Instance public static Main instance; @SidedProxy(clientSide = Reference.CLIENT, serverSide = Reference.COMMON) public static CommonProxy proxy; public static Minecraft mc; public static ArrayList<String> friendlyUsernames = new ArrayList<String>(); public static String[] friendlyNamesArr; @EventHandler public static void preInit(FMLPreInitializationEvent e) { proxy.preInit(e); } @EventHandler public static void init(FMLInitializationEvent e) { proxy.init(e); initialize(); MinecraftForge.EVENT_BUS.register(HelmetHandler.class); } @EventHandler public static void postInit(FMLPostInitializationEvent e) { proxy.postInit(e); MinecraftForge.EVENT_BUS.register(new RenderOverlayHandler(mc)); } public static void initialize() { mc = Minecraft.getMinecraft(); friendlyNamesArr = new String[] { "Pr1ckl3s", "DoubleBrackets", "UnderCoverChicken", "Cutout", "Generaltyler1", "EmeraldUpsilon" }; friendlyUsernames.addAll(Arrays.asList(friendlyNamesArr)); } } HelmetHandler.java package prickles.insight.hud; import java.util.Arrays; import java.util.Iterator; import java.util.List; import net.minecraft.client.entity.EntityOtherPlayerMP; import net.minecraft.entity.Entity; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import prickles.insight.hud.utils.RenderUtils; import prickles.insightsq.core.Main; public class HelmetHandler { public static boolean equipped; public static List<Entity> worldEntities; @SubscribeEvent public static void helmet(TickEvent.PlayerTickEvent event) { EntityPlayer p = event.player; if (p.inventory.armorItemInSlot(3).getItem() == Item.getItemById(314)) { equipped = true; } else { equipped = false; } if (Main.friendlyUsernames.contains(p.getName())) { Main.friendlyUsernames.remove(Arrays.binarySearch(Main.friendlyNamesArr, p.getName())); } } @SubscribeEvent public static void worldLoader(TickEvent.WorldTickEvent event) { worldEntities = event.world.loadedEntityList; } @SubscribeEvent public static void render(RenderWorldLastEvent event) { if (equipped) { if (worldEntities != null) { Iterator<Entity> iter = worldEntities.iterator(); while (iter.hasNext()) { Entity e = iter.next(); if (e instanceof EntityOtherPlayerMP) { if (Main.friendlyUsernames.contains(e.getName())) { RenderUtils.drawESP(event, e, 1f, 0, 255, 0); } else { RenderUtils.drawESP(event, e, 1f, 255, 0, 0); } } if (e instanceof EntityMob) { RenderUtils.drawESP(event, e, 1f, 255, 187, 0); } if (e instanceof EntityAnimal) { RenderUtils.drawESP(event, e, 1f, 0, 150, 255); } } } } } } RenderUtils.java package prickles.insight.hud.utils; import java.awt.Color; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.util.math.Vec3d; import net.minecraftforge.client.event.RenderWorldLastEvent; public class RenderUtils { public static void drawESP(RenderWorldLastEvent evt, Entity e, float lineWidth, int r, int g, int b) { double eX = e.lastTickPosX + (e.posX - e.lastTickPosX) * (double) evt.getPartialTicks(); double eY = e.lastTickPosY + (e.posY - e.lastTickPosY) * (double) evt.getPartialTicks(); double eZ = e.lastTickPosZ + (e.posZ - e.lastTickPosZ) * (double) evt.getPartialTicks(); Entity p = Minecraft.getMinecraft().getRenderViewEntity(); double pX = p.lastTickPosX + (p.posX - p.lastTickPosX) * (double) evt.getPartialTicks(); double pY = p.lastTickPosY + (p.posY - p.lastTickPosY) * (double) evt.getPartialTicks(); double pZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * (double) evt.getPartialTicks(); if (p.getDistanceSqToEntity(e) <= Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16) { Tessellator.getInstance().getBuffer().setTranslation(-pX, -pY, -pZ); renderESP(Tessellator.getInstance(), new Vec3d(eX, eY, eZ), new Vec3d(eX + 1, eY + 1, eZ + 1), r, g, b, lineWidth); Tessellator.getInstance().getBuffer().setTranslation(0, 0, 0); } } public static void BBP(BufferBuilder bufferBuilder, double x, double y, double z, Color c) { bufferBuilder.pos(x, y, z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).endVertex();; } public static void renderESP(Tessellator t, Vec3d posA, Vec3d posB, int r, int g, int b, float lineWidth) { GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); Color c = new Color(r, g, b, 255); GL11.glColor3d(r, g, b); GL11.glLineWidth(lineWidth); GL11.glDepthMask(false); Tessellator tessellator = t.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR); double dx = Math.abs(posA.x - posB.x); double dy = Math.abs(posA.y - posB.y); double dz = Math.abs(posA.z - posB.z); BBP(bufferBuilder, posA.x, posA.y, posA.z, c); BBP(bufferBuilder, posA.x, posA.y, posA.z + dz, c); BBP(bufferBuilder, posA.x, posA.y, posA.z + dz, c); BBP(bufferBuilder, posA.x + dx, posA.y, posA.z + dz, c); BBP(bufferBuilder, posA.x + dx, posA.y, posA.z + dz, c); BBP(bufferBuilder, posA.x + dx, posA.y, posA.z, c); BBP(bufferBuilder, posA.x + dx, posA.y, posA.z, c); BBP(bufferBuilder, posA.x, posA.y, posA.z, c); BBP(bufferBuilder, posA.x, posA.y + dy, posA.z, c); BBP(bufferBuilder, posA.x, posA.y + dy, posA.z + dz, c); BBP(bufferBuilder, posA.x, posA.y + dy, posA.z+dz, c); BBP(bufferBuilder, posA.x+dx, posA.y + dy, posA.z+dz, c); BBP(bufferBuilder, posA.x + dx, posA.y + dy, posA.z + dz, c); BBP(bufferBuilder, posA.x + dx, posA.y + dy, posA.z, c); BBP(bufferBuilder, posA.x + dx, posA.y + dy, posA.z, c); BBP(bufferBuilder, posA.x, posA.y + dy, posA.z, c); BBP(bufferBuilder, posA.x, posA.y, posA.z, c); BBP(bufferBuilder, posA.x, posA.y +dy, posA.z, c); BBP(bufferBuilder, posA.x, posA.y, posA.z + dz, c); BBP(bufferBuilder, posA.x, posA.y + dy, posA.z + dz, c); BBP(bufferBuilder, posA.x + dx, posA.y, posA.z + dz, c); BBP(bufferBuilder, posA.x + dx, posA.y + dy, posA.z + dz, c); BBP(bufferBuilder, posA.x + dx, posA.y, posA.z, c); BBP(bufferBuilder, posA.x + dx, posA.y + dy, posA.z, c); tessellator.draw(); GL11.glDepthMask(true); GL11.glPopAttrib(); } } This is just the way I'm drawing my boxes if it's necessary (Will be changed to look better) As far as I know, I need the RenderWorldLastEvent as a parameter for my drawESP method to render my boxes When I tried using Minecraft.getMinecraft().getRenderPartialTicks() instead, I would get this error: Currently, with the above code, I get the following error: Any suggestions?