Posted August 18, 20196 yr I need to render a line kind of like the Immersive Engineering cables. I tried to use Minecraft's RenderFish class as example, but I had no luck doing it. Spoiler public class MesHandler implements IMessageHandler<Mes, IMessage>{ @Override public IMessage onMessage(Mes message, MessageContext ctx) { if (ctx.side != Side.CLIENT) { System.err.println("Message received on wrong side:" + ctx.side); return null; } int x = message.x; int y = message.y; int z = message.z; Vec3d vec1 = new Vec3d(x, y, z); Vec3d vec2 = new Vec3d(x + 2, y , z ); //IThreadListener mainThread = Minecraft.getMinecraft(); Minecraft mainThread = Minecraft.getMinecraft(); mainThread.addScheduledTask(new Runnable() { @Override public void run() { draw(vec1, vec2); System.out.println(x + " " + y + " " + z); } }); return null; } public static void draw(Vec3d posA, Vec3d posB) { GlStateManager.pushMatrix(); GlStateManager.disableTexture2D(); GlStateManager.disableLighting(); GlStateManager.glLineWidth(2.0F); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); buffer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR); buffer.pos(posA.x, posA.y, posA.z).color(Color.BLACK.getRed(), Color.BLACK.getGreen(), Color.BLACK.getBlue(), Color.BLACK.getAlpha()).endVertex(); buffer.pos(posB.x, posB.y, posB.z).color(Color.BLACK.getRed(), Color.BLACK.getGreen(), Color.BLACK.getBlue(), Color.BLACK.getAlpha()).endVertex(); tessellator.draw(); GlStateManager.enableLighting(); GlStateManager.enableTexture2D(); } Spoiler public class Mes implements IMessage{ public int x , y , z; public Mes(){} public Mes(int x , int y , int z){ this.x = x; this.y = y; this.z = z; } @Override public void fromBytes(ByteBuf buf) { x = buf.readInt(); y = buf.readInt(); z = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); } } Spoiler @Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { PacketHandler.INSTANCE.sendToAll(new Mes(player.getPosition().getX() , player.getPosition().getY() , player.getPosition().getZ())); }
August 18, 20196 yr popMatrix() is missing, does rendering using addScheduledTask really work? Shouldnt you use one of the world render events for that? RenderWorldLastEvent together with a place to store the cables client side is what I would do. https://github.com/CAS-ual-TY/Visibilis [1.14] How to Villagers, Trades, Professions, Fix Trades https://minecraft.curseforge.com/projects/gun-customization-infinity / https://github.com/CAS-ual-TY/GunCus https://minecraft.curseforge.com/projects/ygo-dueling-mod https://minecraft.curseforge.com/projects/mundus-magicus https://minecraft.curseforge.com/projects/deuf-duplicate-entity-uuid-fix
August 18, 20196 yr Author So I managed to render a line using RenderWorldLastEvent, but I have no idea how to store the TileEntities on client side. Spoiler @SubscribeEvent public static void renderWorldLastEvent(RenderWorldLastEvent event) { GlStateManager.pushMatrix(); //GlStateManager.pushAttrib(); double x = 70; double y = 80; double z = 4; EntityPlayer rootPlayer = Minecraft.getMinecraft().player; double px = rootPlayer.lastTickPosX + (rootPlayer.posX - rootPlayer.lastTickPosX) * event.getPartialTicks(); double py = rootPlayer.lastTickPosY + (rootPlayer.posY - rootPlayer.lastTickPosY) * event.getPartialTicks(); double pz = rootPlayer.lastTickPosZ + (rootPlayer.posZ - rootPlayer.lastTickPosZ) * event.getPartialTicks(); GlStateManager.translate(-px, -py, -pz); Vec3d vec1 = new Vec3d(x, y, z); Vec3d vec2 = new Vec3d(x + 2, y + 2, z + 2); LineRender.drawLine(vec1, vec2); GlStateManager.popMatrix(); //GlStateManager.popAttrib(); }
August 19, 20196 yr 3 hours ago, xxTFxx said: So I managed to render a line using RenderWorldLastEvent, but I have no idea how to store the TileEntities on client side. Reveal hidden contents @SubscribeEvent public static void renderWorldLastEvent(RenderWorldLastEvent event) { GlStateManager.pushMatrix(); //GlStateManager.pushAttrib(); double x = 70; double y = 80; double z = 4; EntityPlayer rootPlayer = Minecraft.getMinecraft().player; double px = rootPlayer.lastTickPosX + (rootPlayer.posX - rootPlayer.lastTickPosX) * event.getPartialTicks(); double py = rootPlayer.lastTickPosY + (rootPlayer.posY - rootPlayer.lastTickPosY) * event.getPartialTicks(); double pz = rootPlayer.lastTickPosZ + (rootPlayer.posZ - rootPlayer.lastTickPosZ) * event.getPartialTicks(); GlStateManager.translate(-px, -py, -pz); Vec3d vec1 = new Vec3d(x, y, z); Vec3d vec2 = new Vec3d(x + 2, y + 2, z + 2); LineRender.drawLine(vec1, vec2); GlStateManager.popMatrix(); //GlStateManager.popAttrib(); } Use packets to sync tile entity’s data from server to client. 15 hours ago, CAS_ual_TY said: RenderWorldLastEvent together with a place to store the cables client side is what I would do. I would suggest making a TileEntityRenderer and do the rendering of cables there. Each tile entity would only renders its cables, therefore making another storage of cables unnecessary. Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
August 19, 20196 yr Author Can I do something, so the TileEntity renders the cable when I don't look at the TileEntity? Or do I need to render the cables twice from each end.
August 19, 20196 yr 18 minutes ago, xxTFxx said: Can I do something, so the TileEntity renders the cable when I don't look at the TileEntity? Or do I need to render the cables twice from each end. Oof. You might be better off just querying the nearby area for all instances of your TE (there's a chunk TE cache, don't examine every block) and render all* the cables all the time. *I would only look at the 9 or 16 chunks directly around the player, if you have cables longer or farther away than that, fuck'em. (1) don't let cables be that long and (2) if they're that far away you don't need to be able to see them. Additionally you can cull any cables that aren't within 32 vertical blocks of the player as well (you'll need to write a check for this). Culling for things behind the camera will be too difficult and not worth it. Edited August 19, 20196 yr by Draco18s Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
August 19, 20196 yr Author 23 minutes ago, Draco18s said: *I would only look at the 9 or 16 chunks directly around the player, if you have cables longer or farther away than that, fuck'em. That makes sense, but the problem is that TESR doesn't render the cable if I'm not looking at the TileEntity. Spoiler public class ConnectorRender extends TileEntitySpecialRenderer<TE_Connector>{ @Override public void render(TE_Connector te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { if(te.isConnected()) { BlockPos linkTo = te.getLinkTo(); int dx = (te.getPos().getX() - linkTo.getX()); int dy = (te.getPos().getY() - linkTo.getY()); int dz = (te.getPos().getZ() - linkTo.getZ()); GlStateManager.pushMatrix(); GlStateManager.disableTexture2D(); GlStateManager.glLineWidth(2.0F); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); buffer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR); buffer.pos(x + 0.5D , y + 0.5D , z + 0.5D).color(Color.BLACK.getRed(), Color.BLACK.getGreen(), Color.BLACK.getBlue(), Color.BLACK.getAlpha()).endVertex(); buffer.pos(x - dx + 0.5D , y - dy + 0.5D , z - dz + 0.5D).color(Color.BLACK.getRed(), Color.BLACK.getGreen(), Color.BLACK.getBlue(), Color.BLACK.getAlpha()).endVertex(); tessellator.draw(); GlStateManager.enableTexture2D(); GlStateManager.popMatrix(); } super.render(te, x, y, z, partialTicks, destroyStage, alpha); } } Edited August 19, 20196 yr by xxTFxx
August 19, 20196 yr Well, of course, because TEs are culled when they are outside the view frustum. I was assuming that this was true: 14 hours ago, DavidM said: So I managed to render a line using RenderWorldLastEvent You don't need to *store* the cables anywhere. Inside the event you get the world from the Minecraft instance, query the TE cache that already exists, find your TEs, get their cables, render them. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
August 19, 20196 yr 8 hours ago, xxTFxx said: Can I do something, so the TileEntity renders the cable when I don't look at the TileEntity? Or do I need to render the cables twice from each end. Override TileEntity#getRenderBoundingBox and return NULL_AABB to make the tile entity render at all times (when you are not looking at it). Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
August 21, 20196 yr Author On 8/20/2019 at 1:34 AM, DavidM said: Override TileEntity#getRenderBoundingBox and return NULL_AABB to make the tile entity render at all times (when you are not looking at it). When I do that it gives NullPointerException.
August 21, 20196 yr That should be impossible. Show your code. Note that NULL_AABB might had been renamed to INFINITE_EXTENT_AABB. Edited August 21, 20196 yr by DavidM Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
August 21, 20196 yr Author INFINITE_EXTENT_AABB seems to work, but only when I'm within the same chunk as the TE. Edited August 21, 20196 yr by xxTFxx
August 22, 20196 yr Author Is there something I can do to make this work? It renders properly even if I'm not looking at the TE, but only when I'm in the same chunk as TE. My code: Spoiler public class ConnectorRender extends TileEntitySpecialRenderer<TE_Connector>{ @Override public void render(TE_Connector te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { if(te.hasConnectionTo()) { BlockPos linkTo = te.getLinkTo(); Vec3d vec1 = new Vec3d(x + 0.5D, y + 0.5D, z + 0.5D); Vec3d vec2 = new Vec3d(linkTo.getX() + 0.5D , linkTo.getY() + 0.5D, linkTo.getZ() + 0.5D); GlStateManager.pushMatrix(); GlStateManager.disableTexture2D(); GlStateManager.glLineWidth(2.0F); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); buffer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR); double lenght = Math.sqrt( (te.getPos().getX() + 0.5D - vec2.x) * (te.getPos().getX() + 0.5D - vec2.x) + (te.getPos().getY() + 0.5D - vec2.y) * (te.getPos().getY() + 0.5D - vec2.y) + (te.getPos().getZ() + 0.5D - vec2.z) * (te.getPos().getZ() + 0.5D - vec2.z) ); double a = 1 / (25 * Math.sqrt(lenght)); for(double i = 0 ; i <= lenght + 0.1D ; i += 0.2D) { double y1 = a * (i) * (i - lenght); Vec3d vec3; if( te.getPos().getX() + 0.5D - vec2.x > 0 || te.getPos().getX() + 0.5D - vec2.x == 0 ) { vec3 = new Vec3d(vec1.x - i, vec1.y + y1, vec1.z); } else { vec3 = new Vec3d(vec1.x + i, vec1.y + y1, vec1.z); } buffer.pos(vec3.x , vec3.y , vec3.z).color(Color.BLACK.getRed(), Color.BLACK.getGreen(), Color.BLACK.getBlue(), Color.BLACK.getAlpha()).endVertex(); } if(te.getPos().getZ() != linkTo.getZ()) { double l_x = Math.sqrt( (te.getPos().getX() + 0.5D - vec2.x) * (te.getPos().getX() + 0.5D - vec2.x) ); double l_z = Math.sqrt( (te.getPos().getZ() + 0.5D - vec2.z) * (te.getPos().getZ() + 0.5D - vec2.z) ); double atan = Math.atan( l_z / l_x ); double angle = Math.toDegrees(atan); if(te.getPos().getZ() + 0.5D - vec2.z > 0) angle = -angle; if(te.getPos().getX() + 0.5D - vec2.x < 0) angle = -angle; if(angle != 0) { GlStateManager.translate(x + 0.5D, 0, z + 0.5D); GlStateManager.rotate((float) angle, 0, 1, 0); GlStateManager.translate(-x - 0.5D , 0, -z - 0.5D ); } } if(te.getPos().getY() != linkTo.getY()) { double l_x = te.getPos().getX() + 0.5D - vec2.x; double l_z = te.getPos().getZ() + 0.5D - vec2.z; double l_y = Math.sqrt( l_x * l_x + l_z * l_z); double atan = Math.atan( (te.getPos().getY() + 0.5D - vec2.y) / l_y ); double angle = Math.toDegrees(atan); if(Math.abs(te.getPos().getX()) + 0.5D - Math.abs(vec2.x) < 0) { angle = -angle; } if(angle != 0) { GlStateManager.translate(x + 0.5D, y + 0.5D, z + 0.5D); GlStateManager.rotate((float) angle, 0, 0, 1); GlStateManager.translate(-x - 0.5D , -y - 0.5D , -z - 0.5D); } } tessellator.draw(); GlStateManager.enableTexture2D(); GlStateManager.popMatrix(); } super.render(te, x, y, z, partialTicks, destroyStage, alpha); } } Spoiler public class TE_Connector extends TileEntity implements ITickable{ private boolean connectionTo = false; private boolean connectionFrom = false; private BlockPos linkTo; private BlockPos linkFrom; private int timer = 0; private CustomEnergyStorage storage = new CustomEnergyStorage(100, 100); private int output = 100; @Override public void update() { if(storage.getEnergyStored() >= output) { if(connectionTo) { TileEntity tile = world.getTileEntity(linkTo); if(tile instanceof TE_Connector) { if(tile.hasCapability(CapabilityEnergy.ENERGY, null)) { IEnergyStorage handler = tile.getCapability(CapabilityEnergy.ENERGY, null); if(handler != null && handler.getEnergyStored() + output <= handler.getMaxEnergyStored()) { handler.receiveEnergy(output, false); storage.consumeEnergy(output); } } } } } sendEnergy(); } public boolean hasConnectionTo() { return this.connectionTo; } public boolean hasConnectionFrom() { return this.connectionFrom; } public void changeConnectionToState(boolean state) { this.connectionTo = state; } public void changeConnectionFromState(boolean state) { this.connectionFrom = state; } public void setLinkTo(int x , int y , int z) { this.linkTo = new BlockPos(x, y, z); } public void setLinkFrom(int x , int y , int z) { this.linkFrom = new BlockPos(x, y, z); } public BlockPos getLinkTo() { return this.linkTo; } public BlockPos getLinkFrom() { return this.linkFrom; } private void sendEnergy() { if(storage.getEnergyStored() >= output ) { for(EnumFacing facing : EnumFacing.VALUES) { TileEntity tile = world.getTileEntity(pos.offset(facing)); if(tile != null && !(tile instanceof TE_Connector) && tile.hasCapability(CapabilityEnergy.ENERGY, facing.getOpposite())) { IEnergyStorage handler = tile.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()); if(handler != null && handler.canReceive() && handler.getEnergyStored() + output <= handler.getMaxEnergyStored()) { handler.receiveEnergy(output, false); storage.consumeEnergy(output); } else return; } } markDirty(); } } @Override public AxisAlignedBB getRenderBoundingBox() { //return new AxisAlignedBB(this.pos.getX() - 32, this.pos.getY() -32, this.pos.getZ() - 32, this.pos.getX() + 32, this.pos.getY() + 32, this.pos.getZ() + 32); return INFINITE_EXTENT_AABB; } public IBlockState getState() { return world.getBlockState(pos); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if(capability.equals(CapabilityEnergy.ENERGY)) { return true; } return super.hasCapability(capability, facing); } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if(capability.equals(CapabilityEnergy.ENERGY)) { return (T)this.storage; } return super.getCapability(capability, facing); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); this.storage.writeToNBT(compound); compound.setBoolean("hasConnection", this.connectionTo); compound.setBoolean("hasConnectionFrom", this.connectionFrom); if(this.connectionTo) { compound.setInteger("xTo", this.linkTo.getX()); compound.setInteger("yTo", this.linkTo.getY()); compound.setInteger("zTo", this.linkTo.getZ()); } if(this.connectionFrom) { compound.setInteger("xFrom", this.linkFrom.getX()); compound.setInteger("yFrom", this.linkFrom.getY()); compound.setInteger("zFrom", this.linkFrom.getZ()); } return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.storage.readFromNBT(compound); this.connectionTo = compound.getBoolean("hasConnection"); this.connectionFrom = compound.getBoolean("hasConnectionFrom"); if(this.connectionTo) { this.setLinkTo(compound.getInteger("xTo"), compound.getInteger("yTo"), compound.getInteger("zTo")); } if(this.connectionFrom) { this.setLinkFrom(compound.getInteger("xFrom"), compound.getInteger("yFrom"), compound.getInteger("zFrom")); } } } I know it's not well optimised, but for now I'm just trying to make this work.
August 22, 20196 yr 17 minutes ago, xxTFxx said: but only when I'm in the same chunk as TE. You also need to override TileEntity#getMaxRenderDIstanceSquared for reference the Beacon returns a value of 65536.0D VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 22, 20196 yr Author 32 minutes ago, Animefan8888 said: You also need to override TileEntity#getMaxRenderDIstanceSquared for reference the Beacon returns a value of 65536.0D Ok, I've tested it and it also works only when I'm looking at the TE.
August 22, 20196 yr 4 minutes ago, xxTFxx said: Ok, I've tested it and it also works only when I'm looking at the TE. Did you change the bounding box away from INFINITE_EXTENT_AABB? Because otherwise it should assume you are always looking at it. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 22, 20196 yr This might not help (sorry) but I have a TESR which draws long tracks which used to disappear when looked at from a certain angle, with the block off the screen. That was only fixed by overriding isGlobalRenderer, returning true. This might hurt performance if you plan to have a lot of these blocks but I didn't have any problems with about 50 of those blocks on the screen (didn't try any higher).
August 22, 20196 yr Author 5 minutes ago, FredTargaryen said: This might not help (sorry) but I have a TESR which draws long tracks which used to disappear when looked at from a certain angle, with the block off the screen. That was only fixed by overriding isGlobalRenderer, returning true. This might hurt performance if you plan to have a lot of these blocks but I didn't have any problems with about 50 of those blocks on the screen (didn't try any higher). Thanks, that did actually helped.
August 22, 20196 yr 40 minutes ago, xxTFxx said: Ok, I've tested it and it also works only when I'm looking at the TE. This is also what the TileEntityBeaconRenderer does ??? 6 minutes ago, FredTargaryen said: This might not help (sorry) but I have a TESR which draws long tracks which used to disappear when looked at from a certain angle, with the block off the screen. That was only fixed by overriding isGlobalRenderer, returning true. This might hurt performance if you plan to have a lot of these blocks but I didn't have any problems with about 50 of those blocks on the screen (didn't try any higher). VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.