Jump to content

TheEpicTekkit

Members
  • Posts

    361
  • Joined

  • Last visited

Everything posted by TheEpicTekkit

  1. Thanks for this. I haven't had much time to read through this method, but it looks pretty nice. Though I am looking for an explanation of how the transferStackInSlot method works and how it is used. I don't want to just have code to copy and paste, because I wont learn anything from that.
  2. Hello. I would like help understanding the unnecessarily complicated and undocumented method: transferStackInSlot(EntityPlayer player, int slotIndex) I have looked around for tutorials on how to use this method, and only found things like a custom furnace, which has pretty much the exact same code as the vanilla furnace, and a badly explained transferStackInSlot method. I have also looked at the code of some mods such as EnderIO on Github and just found more confusion. I think that the best documentation on transferStackInSlot that I have found is this. What I would like is for someone to explain this method and how to implement it. I want to actually understand the code, and not have a tutorial that tells me what to write with no explanation, like a lot of tutorials do. I understand that the EntityPlayer parameter is the player using the inventory (obviously), the slotIndex is the slot that was shift-clicked, and the methods goal is to handle shift-clicking of slots, but I don't understand things like the mergeItemStack method, what the ItemStack that transferStackInSlot returns represents, or how to implement this method. Furthermore, if I can understand this method properly, I would like to be able to implement a generic version of this method that automatically works for all containers. EnderIO seems to have it setup this way. But currently, I am trying to implement this for a machine with one input slot, 3 output slots, and a battery slot. Thanks.
  3. Oh... oops, that was just a stupid mistake Now what about the multiple masters issue?
  4. Okay, I just realised that int x, y, and z were being set wrong in the method. x was being set to xCoord + i whixh is the height, and y was yCoord + j which is the width. I fixed this, and now its finding even more masters and has 426 out of 213 blocks... so its finding twice the number of blocks there are.
  5. console is being weird... [15:51:27] [Client thread/INFO] [sTDOUT]: [net.modulartechnology.modtech.moduleModtech.common.tileentity.TileEntityDistillationChamber:checkMultiBlockForm:245]: 285 / 213 for master at 166, 81, 230 [15:51:27] [Client thread/INFO] [sTDOUT]: [net.modulartechnology.modtech.moduleModtech.common.tileentity.TileEntityDistillationChamber:checkMultiBlockForm:245]: 285 / 213 for master at 164, 81, 232 [15:51:27] [server thread/INFO] [sTDOUT]: [net.modulartechnology.modtech.moduleModtech.common.tileentity.TileEntityDistillationChamber:checkMultiBlockForm:245]: 282 / 213 for master at 164, 65, 232 [15:51:28] [Client thread/INFO] [sTDOUT]: [net.modulartechnology.modtech.moduleModtech.common.tileentity.TileEntityDistillationChamber:checkMultiBlockForm:245]: 282 / 213 for master at 164, 65, 232 its finding multiple masters, and 282 out of 213 blocks in the structure... I feel like my method to check the pattern needs to be completely redone ;/
  6. Hi. I have been working on a multiblock system for my mod, this mod will have a lot of multiblocks in it in the future, so I want this system to be dynamic and easy to use. So I decided to use a 3D array of characters to represent blocks in the multiblock. I have this working pretty smothely, but I am now stuck on actually comparing blocks in the world to the 3D char array. These are the classes that handle the characters: MultiblockHandler.java MultiblockPattern.java Here is the method that is currently called in the tileentity every 2 seconds to check the form: (This isn't working) Any help would be much appreciated.
  7. so it doesnt matter that the console says: [15:48:42] [Client thread/INFO] [sTDOUT]: [net.modulartechnology.modtech.common.tileentity.TileEntityMetallurgicLiquefier:updateEntity:50]: Machine energy: 0.0 / 64000.0, on the client [15:48:42] [server thread/INFO] [sTDOUT]: [net.modulartechnology.modtech.common.tileentity.TileEntityMetallurgicLiquefier:updateEntity:50]: Machine energy: 32000.0 / 64000.0, on the server
  8. The client needs to know because otherwise the energy won't display in the machines GUIs... um, so how do I use the toBytes / fromBytes methods then? can you direct me to a detailed tutorial?
  9. So I have an energy network working in my mod (mostly), but I have a problem with client-server synchronization. In my energy network, I have a method that allows a machine to request energy from the network, as follows: public double requestEnergy(TileEntity tile, double energyRequested, boolean doWork) { NetworkHandler.sendToClient(new MessageUpdateEnergy().setVariables(this, tile, energyRequested)); IEnergyProvider provider = getNextAvailableProvider(); if (provider == null) { return 0; } double result = provider.getStoredEnergy(); provider.addEnergy(-result); return result; } but I found out that this is only called server-side. Now because of this, I decided to do some research into packets, before this I had never touched packets. I have made packet handler and a packet to update the energy for the client to receive, but in the packet, the variables are nullified, and I cant figure out why... Here is my packet class: public class MessageUpdateEnergy extends MessageBase<MessageUpdateEnergy> { private Grid grid; private double energyRequested; private TileEntity tile; public MessageUpdateEnergy setVariables(Grid grid, TileEntity tile, double energyRequested) { this.grid = grid; this.tile = tile; this.energyRequested = energyRequested; return this; } @Override public void handleServerSide(MessageUpdateEnergy message, EntityPlayer player) { if (grid == null) { System.out.println("Grid is null"); } if (tile != null && energyRequested > 0) { grid.requestEnergy(tile, energyRequested, true); System.out.println("Sending packet"); } } @Override public void handleClientSide(MessageUpdateEnergy message, EntityPlayer player) { } @Override public void fromBytes(ByteBuf buf) { } @Override public void toBytes(ByteBuf buf) { } } At first I tried setting these variables through the constructor, but I quickly found out that I need a nullary constructor or it crashes. I also tried adding a second constructor to set the variables, this constructor was being called from the grid class, and the variables were set, but they were null again when the handleServer/ClientSide methods were called. Currently I am using a setter method to set these variables, but this is also not working. For the example above, I un-commented out the code in the handleServerSide method, and this kicks the player from the server with a NullPointerException because the grid is null. How would I get an instance of the grid this packet is being sent from, the tileentity asking for energy and the energy the tile wants? I dont really know if this is the best way of doing this, or if it's even possible... if not, please tell me the proper way. Thanks for the help. P.S Sorry if I come across as not understanding packets very well, I probably don't.
  10. Okay, I have seen both of these before, and neither really helped. For the rendering one, I don't understand scala very well, and I don't intend to do any scala code where I can do java. For the transfering the tileentity data post by Whov, I found it hard to understand, and unclear.
  11. Hi everyone. So I have started modding again, and I have run into a problem with multiparts. I am working on a cable, and have decided to make it a multipart, mainly because I want to have each connection of the cable have a separate bounding box, but also because I want functionality such as disabling a connection by clicking with a certain tool, and it also allows for the cable to easily be hidden. The problem I have is that the original tileentity of the cable is deleted when a multipart is added, and the cable's tileentity is replaced with a TMultipart. A side effect of this is also that the cable doesn't render anymore, and I know this is because the TESR cant find the tileentity. How should I transfer the data of the original tileentity to the new one, and make the TESR recognize the TMultipart? I have found plenty of tutorials on multiparts, but none of them explain how to convert a tileentity to a multipart. Any help here would be appreciated. Thanks.
  12. I have done so much research into graph traversal algorithms before attempting this. Mainly DFS, BFS, A-Star, and Diejkstra's algorithm (probably not spelled right) The problem though, is they all have to be parsed two nodes, a from node, and a to node, and they will simply find the shortest route. Now what I need it to do, is locate all the nodes in the first place, and so, from the knowledge of the algorithms I have researched, I have sort of written my own to do so. That is why it is so messy, because it has been trial and error to get it to a working (well, semi working) state. So, you are saying that I should scrap my current method, and rewrite it so that it doesn't recurse? What might be best, and this idea came to me from what Hugo said and would probably involve rewriting the majority of the method anyway, is maybe I could have it split off at a junction, so it will traverse both routes simultaneously, but how would I achieve this?
  13. Okay, I have definitely not cut anything short from the console output (other than everything irrelevant before I placed the fusebox like logging in etc) And I did notice that it was outputting some strange things, eg, the fact that it scanned 3, 4, 5 (and then without recursing) scanned 3, 4, 5 again. Currently, as soon as it finds an available / valid node to move to, it will go to it, and forget about whatever remaining directions there are left to scan. To be honest, come to think of it, this probably shouldn't be the case. So what you are saying, is that I should have it scan al six sides before moving onto the next cable? or that it should have a ForgeDirection parameter in the method to use when recursing? I have a backtrack because, it doesn't split off in both (or more) directions at a junction. I don't know how I would achieve this, and so what it does, is go down the first valid direction it can, and as a result, only travels down one path, any junction (before I set up the backtrack code) would be left completely alone. Also, the cables (Node) gets marked as scanned, so when it returns to the head of the backTrack queue, logically, it should take the unscanned path, and not continue back down the already scanned path. Also, without marking it as scanned, the method would scan around the first cable, find an adjacent cable, scan around that, find the first cable, scan around it, find the second cable, scan around it, find the first cable etc, it would just jump back and forth between those two until it has recursed 64 times (the range limit). This was what was occurring before I figured out how to mark the node as scanned (I discovered that in the Node class I had to override equals(Object o) {...} to hold some custom info, and compare the coords of the nodes, hashCode() {...} because that is apparently good practice to override when overriding equals, and also I had to implement Comparable<T> to make the list / set / queue work properly with the Node) You said to find out why it isn't stopping at already scanned cables, it is though. That is kind of the strange thing.
  14. Bump* Really need help, I have been trying to figure this out for the last 7 to 8 hours now... And annoyingly the debug perspective in eclipse isn't behaving properly.
  15. Hello everyone. So I have been working on an energy network for my mod. If you have seen my other posts about actually getting it to cascade down the path, I have achieved this, but there are some problems, i.e. the game freezes (doesn't crash, and this is the annoying thing, as I cant diagnose the problem as there is no error report, it just hangs until closed) when it encounters a junction in the path. So what I have done, is make it place a stone block above the cable it is scanning, so that I can visually see what it is doing, and it seems to work fine without a junction. But when it encounters a junction, it hangs. So, when it encounters a junction, what I have made it do is create a new Node (the class that represents the x, y, z coords, and other info about the block) at the currently being scanned coords, and then add it to a PriorityQueue of backtrack locations, also, it saves the currently scanned range to a HashMap with the node as the key so that when it resumes the search from the head of the queue, the scanned range is reset back to whatever it was when it added that backtrack node to the queue. When this happens, it still remembers which cables have already been scanned, so really, from the backtrack point, the only possible direction, is the route it didn't transverse. But instead, it freezes up when this happens. A point that may be helpful is that it scans in the order of ForgeDirection. So it will scan down (side 0) first, then it will scan up (side 1), then north (side 2) etc. This is a simple example of a path it will freeze up on: C C C C C 3 4 5 C 2 C 1 F 0 (This looks weird in the "modify message" page, I hope it looks okay in the main page... It is a 'T' shape of cables) "C" represents the cable, and "F" represents the fuse box (this is the block that triggers the scan when placed. It will store all the network data). The numbers represent the weight (or range) that has been scanned. So the moment the fuse box is placed at the end of the cables there, it will place stone blocks above each of the cables that I have shown to have a weight, and the other two don't get scanned, instead, it freezes. It should backtrack to the cable with the weight of 3, as there was more than one possible route for it to take. This is my code (This is quite a long class and method): public class Search { //This class is a nested class of "Grid". grid stores all the main data of the network, this class just locates everything in the network if needed private int xStart, yStart, zStart, x, y, z, maxRange, currentRange; private Grid grid; //The "Grid" this search is a part of public boolean isFinished = false; public boolean debug, doBacktrack; /**A list of available nodes that are networked. This does not include cables, instead machines that can supply power*/ public List<Node> supplyers = new ArrayList<Node>(); /**A list of available nodes that are networked. This does not include cables, instead machines that can consume power*/ public List<Node> consumers = new ArrayList<Node>(); /**A map of cables.*/ public List<Node> cableMap = new ArrayList<Node>(); /**This is a list of locations where there would have been a junction in the cable, and after reaching the max range, or the end of the current route, will backtrack to this location and scan down the un-scanned route*/ public PriorityQueue<Node> backTrack = new PriorityQueue<Node>(); /**A list of scanned nodes*/ public HashSet<Node> scannedNodes = new HashSet<Node>(); /**This map contains the range that had been scanned from a backtracked point. So, if it backtracks to a point, the currently scanned range will be set to whatever it was when this point was added to the list*/ public Map<Node, Integer> backTrackRange = new HashMap<Node, Integer>(); public Search(int x, int y, int z, int range, Grid g) { System.out.println(x + " " + y + " " + z); this.xStart = x; this.yStart = y; this.zStart = z; this.maxRange = range; this.grid = g; currentRange = -1; } public void initNodeSearch() { this.x = xStart; this.y = yStart; this.z = zStart; doBacktrack = false; currentRange = 0; locateNodes(true, x, y, z); } /** * Locate all the nodes connected to the TileEntity calling this method at the parsed coords. This is a recursive * method until it has reached the maximum range. 1 is added to the current range each time the method successfully runs. */ public void locateNodes(boolean doWork, int x, int y, int z) { System.out.println(""); //These are just to make it clear where the method gets recursed, because there is a lot printed in the console. System.out.println(""); System.out.println("Recursing..."); if (doWork) { int directionsScanned = 0; boolean[] validDirections = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; boolean hasValidRoute = false; int validCount = 0; for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) { System.out.println(""); //This is just to separate each side scanned with a space. System.out.println("Scanning side " + d.ordinal()); int x1 = d.offsetX + x, y1 = d.offsetY + y, z1 = d.offsetZ + z; TileEntity t = world.getTileEntity(x1, y1, z1); Node target = new Node(x1, y1, z1, grid); System.out.println(x1 + ", " + y1 + ", " + z1 + " Being Scanned"); ++directionsScanned; System.out.println(directionsScanned + " scanned"); //System.out.println("Validating TileEntity on side " + d.ordinal() + " At coordinates X: " + x1 + ", Y: " + y1 + ", Z: " + z1 + ". " + " That node has " + (hasBeenScanned(target) ? "been scanned" : "not been scanned")); System.out.println((t == null ? "Null tileentity" : "TileEntity is not null")); if (t != null) { System.out.println("A tile exists to scan"); if (isTileValid(t) && !hasBeenScanned(target)) { System.out.println("Valid TileEntity"); validDirections[d.ordinal()] = true; //Update the current x, y, z coords being scanned x = x1; y = y1; z = z1; if (t instanceof TileEntityFuseBox) { //The controller block of the network. This stores all the data of the network, and triggers this search when placed (and under other circumstances, but not every tick. Too laggy) System.out.println("Found fuse box at " + x1 + ", " + y1 + ", " + z1 + ". Current range is " + currentRange + " / " + maxRange + ", and " + (hasValidRoute ? "a valid route exists" : "a valid route does not exist")); if (currentRange < maxRange) { System.out.println("Recursing from fuse box"); locateNodes(true, x1, y1, z1); } } if (t instanceof TileEntityCable || t instanceof IEnergyConductor) { System.out.println("Found cable at " + x1 + ", " + y1 + ", " + z1 + ". Current range is " + currentRange + " / " + maxRange + ", and " + (hasValidRoute ? "a valid route exists" : "a valid route does not exist")); target.setValidation(getValidation(t)); this.cableMap.add(target); markScanned(target, true); currentRange++; //Only add to the range if this is a cable, else it is a machine, and should not affect the current range if (currentRange < maxRange) { world.setBlock(x1, y1 + 1, z1, Blocks.stone); System.out.println("Recursing from cable"); locateNodes(true, x1, y1, z1); } } if (t instanceof IEnergySupplyer) { System.out.println("Found supplyer at " + x1 + ", " + y1 + ", " + z1 + ". Current range is " + currentRange + " / " + maxRange + ", and " + (hasValidRoute ? "a valid route exists" : "a valid route does not exist")); target.setValidation(getValidation(t)); this.supplyers.add(target); markScanned(target, true); if (currentRange < maxRange) { System.out.println("Recursing from supplyer"); world.setBlock(x1, y1 + 1, z1, Blocks.gold_block); locateNodes(true, x1, y1, z1); } } if (t instanceof IEnergyConsumer) { System.out.println("Found consumer at " + x1 + ", " + y1 + ", " + z1 + ". Current range is " + currentRange + " / " + maxRange + ", and " + (hasValidRoute ? "a valid route exists" : "a valid route does not exist")); target.setValidation(getValidation(t)); this.consumers.add(target); markScanned(target, true); if (currentRange < maxRange) { System.out.println("Recursing from consumer"); world.setBlock(x1, y1 + 1, z1, Blocks.coal_block); locateNodes(true, x1, y1, z1); } } } } if (directionsScanned >= 6) { for (boolean b : validDirections) { //Count the number of true values in the array. validCount += (b ? 1 : 0); } if (validCount > 0) { //There is a possible routes (it is not a dead end) hasValidRoute = true; doBacktrack = false; if (validCount > 1) { //If there is more than one possible route Node n = new Node(x, y, z, grid); System.out.println("Adding backtrack point at X: " + x + ", Y: " + y + ", Z: " + z + ", with a range of " + currentRange); this.backTrack.add(n); //Add this location to the list to return to later System.out.println("Success. Saving range"); this.backTrackRange.put(n, currentRange); System.out.println("Range saved"); } } else { System.out.println("No valid routes, attempting backtrack"); doBacktrack = !backTrack.isEmpty(); } if (currentRange >= maxRange) { System.out.println("Reached maximum range... Attempting backtrack"); doBacktrack = !backTrack.isEmpty(); } if (doBacktrack) { System.out.println("Attempting backtrack - the queue is " + (backTrack.isEmpty() ? "empty" : "not empty")); if (!backTrack.isEmpty()) { System.out.println("Has available backtrack point"); Node n = backTrack.poll(); //Get the last backtrack point from the queue (I am right in thinking that poll( ) gets the value, then removes it, right?) System.out.println("Retreiving range from map"); if (backTrackRange.get(n) >= 0) { //Get the range the scan was on when this backtrack point was added to the list System.out.println("Backtrack range is positive, backtracking"); currentRange = backTrackRange.get(n); System.out.println("Backtracking to possible junction at X: " + n.x() + ", Y: " + n.y() + ", Z: " + n.z() + " with backtrack range of " + backTrackRange.get(n)); locateNodes(true, n.x(), n.y(), n.z()); //Recurse this method from the coordinated of the last backtrack point in the queue. } } } else if (!doBacktrack && !hasValidRoute && !isFinished && backTrack.isEmpty()) { System.out.println("Finished 1"); //Labelled "Finished" with 1 or 2 so that I could tell which case it was terminating on. isFinished = true; return; } } } } else { System.out.println("Finished 2"); return; } } So as you can see, there are a lot of System.out.println()s in there, I dod this to help me track where the problem is, but I cant seem to figure it out. This is the console output for the path example I showed above if it helps: Recursing... Scanning side 0 221, 70, 247 Being Scanned 1 scanned Null tileentity Scanning side 1 221, 72, 247 Being Scanned 2 scanned Null tileentity Scanning side 2 221, 71, 246 Being Scanned 3 scanned TileEntity is not null A tile exists to scan Valid TileEntity Found cable at 221, 71, 246. Current range is 0 / 64, and a valid route does not exist Recursing from cable Recursing... Scanning side 0 221, 70, 246 Being Scanned 1 scanned Null tileentity Scanning side 1 221, 72, 246 Being Scanned 2 scanned Null tileentity Scanning side 2 221, 71, 245 Being Scanned 3 scanned TileEntity is not null A tile exists to scan Valid TileEntity Found cable at 221, 71, 245. Current range is 1 / 64, and a valid route does not exist Recursing from cable Recursing... Scanning side 0 221, 70, 245 Being Scanned 1 scanned Null tileentity Scanning side 1 221, 72, 245 Being Scanned 2 scanned Null tileentity Scanning side 2 221, 71, 244 Being Scanned 3 scanned TileEntity is not null A tile exists to scan Valid TileEntity Found cable at 221, 71, 244. Current range is 2 / 64, and a valid route does not exist Recursing from cable Recursing... Scanning side 0 221, 70, 244 Being Scanned 1 scanned Null tileentity Scanning side 1 221, 72, 244 Being Scanned 2 scanned Null tileentity Scanning side 2 221, 71, 243 Being Scanned 3 scanned Null tileentity Scanning side 3 221, 71, 245 Being Scanned 4 scanned TileEntity is not null A tile exists to scan Scanning side 4 220, 71, 244 Being Scanned 5 scanned TileEntity is not null A tile exists to scan Valid TileEntity Found cable at 220, 71, 244. Current range is 3 / 64, and a valid route does not exist Recursing from cable Recursing... Scanning side 0 220, 70, 244 Being Scanned 1 scanned Null tileentity Scanning side 1 220, 72, 244 Being Scanned 2 scanned Null tileentity Scanning side 2 220, 71, 243 Being Scanned 3 scanned Null tileentity Scanning side 3 220, 71, 245 Being Scanned 4 scanned Null tileentity Scanning side 4 219, 71, 244 Being Scanned 5 scanned TileEntity is not null A tile exists to scan Valid TileEntity Found cable at 219, 71, 244. Current range is 4 / 64, and a valid route does not exist Recursing from cable Recursing... Scanning side 0 219, 70, 244 Being Scanned 1 scanned Null tileentity Scanning side 1 219, 72, 244 Being Scanned 2 scanned Null tileentity Scanning side 2 219, 71, 243 Being Scanned 3 scanned Null tileentity Scanning side 3 219, 71, 245 Being Scanned 4 scanned Null tileentity Scanning side 4 218, 71, 244 Being Scanned 5 scanned Null tileentity Scanning side 5 220, 71, 244 Being Scanned 6 scanned TileEntity is not null A tile exists to scan No valid routes, attempting backtrack Finished 1 Scanning side 5 220, 71, 244 Being Scanned 6 scanned TileEntity is not null A tile exists to scan Scanning side 5 221, 71, 244 Being Scanned 6 scanned TileEntity is not null A tile exists to scan Scanning side 3 221, 71, 245 Being Scanned 4 scanned TileEntity is not null A tile exists to scan Scanning side 4 220, 71, 244 Being Scanned 5 scanned TileEntity is not null A tile exists to scan Scanning side 5 222, 71, 244 Being Scanned 6 scanned TileEntity is not null A tile exists to scan Valid TileEntity Found cable at 222, 71, 244. Current range is 5 / 64, and a valid route does not exist Recursing from cable Recursing... Scanning side 0 222, 70, 244 Being Scanned 1 scanned Null tileentity Scanning side 1 222, 72, 244 Being Scanned 2 scanned Null tileentity Scanning side 2 222, 71, 243 Being Scanned 3 scanned Null tileentity Scanning side 3 222, 71, 245 Being Scanned 4 scanned Null tileentity Scanning side 4 221, 71, 244 Being Scanned 5 scanned TileEntity is not null A tile exists to scan Scanning side 5 223, 71, 244 Being Scanned 6 scanned TileEntity is not null A tile exists to scan Valid TileEntity Found cable at 223, 71, 244. Current range is 6 / 64, and a valid route does not exist Recursing from cable Recursing... Scanning side 0 223, 70, 244 Being Scanned 1 scanned Null tileentity Scanning side 1 223, 72, 244 Being Scanned 2 scanned Null tileentity Scanning side 2 223, 71, 243 Being Scanned 3 scanned Null tileentity Scanning side 3 223, 71, 245 Being Scanned 4 scanned Null tileentity Scanning side 4 222, 71, 244 Being Scanned 5 scanned TileEntity is not null A tile exists to scan Scanning side 5 224, 71, 244 Being Scanned 6 scanned Null tileentity No valid routes, attempting backtrack Adding backtrack point at X: 222, Y: 71, Z: 244, with a range of 7 Success. Saving range Range saved Scanning side 3 221, 71, 246 Being Scanned 4 scanned TileEntity is not null A tile exists to scan Scanning side 4 220, 71, 245 Being Scanned 5 scanned Null tileentity Scanning side 5 222, 71, 245 Being Scanned 6 scanned Null tileentity Scanning side 3 221, 71, 247 Being Scanned 4 scanned TileEntity is not null A tile exists to scan Scanning side 4 220, 71, 246 Being Scanned 5 scanned Null tileentity Scanning side 5 222, 71, 246 Being Scanned 6 scanned Null tileentity And that is the point that it crashes. From here, there are just "Can't keep up! Did the system time change, or is the server overloaded?" posted in the console every minute or so. Any help diagnosing why this is happening, and even how I could fix this would be appreciated. I mainly just want to know why this is happening for now, I could probably fix it if I know that. Thanks.
  16. I know that, but I mean, how would I make it render the furthest face from the player first? or would I need to do this?
  17. Okay, so, to do this, you would probably need a pretty good understanding of the concept of pathfinding and how it works, How well do you know A-Star, DFS (Depth-First Search), or BFS (Breadth-First Search)? Here is a good source to help you decide which is best suited for what you require. I would say that the pathfinding bit is the difficult bit, once you have a path for the player, all you need is a way to make the player move. As mentioned above by shadowmage4513, EntityPlayer does share a lot of code with EntityLivingBase, so you could override some code in there, or (what I would do) have a fake key presser for the player, so it simulates 'w' 'a' 's' 'd' or 'space' which may be more efficient than making the player move like a mob. Hope this helped. Here are some good sources for the three algorithms: A-Star in games Introduction to A-Star DFS BFS I would recoment using A-Star, but the other two should also work.
  18. Okay, that makes sense now. Okay, so my model is an OBJ model, if I split it into the separate faces in Maya, and then export it as an OBJ, would I be able to somehow control the render order of the faces? If so, how would I achieve this?
  19. Okay, I have solved the problem of things behind getting culled, or rendering on top of the pipe. SanAndreasP's suggestion worked, with some tweaking of my GL11 methods too. I also removed the getRenderPass() method from my block class. This is my updated renderTileEntityAt method: public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) { int meta = 0; if (tile instanceof TileEntityCable) meta = tile.getBlockMetadata(); if (tile instanceof TileEntityPipe) meta = tile.getBlockMetadata() + 8; // add 8 because cables have 8 subtypes, and for the pipes, the first resource is 8 after the cables first resource. GL11.glPushMatrix(); GL11.glTranslated(x, y, z); GL11.glScalef(0.5F, 0.5F, 0.5F); GL11.glTranslatef(1.0F, 0.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); //Calling all the render methods from here with the model and texture specified above. //if (this.resource[meta][4] != null) { if (tile instanceof TileEntityCable) { TileEntityCable connectable = (TileEntityCable) tile; for (int i = 0; i < 6; i++) { //System.out.println("Connections " + i + " = " + connectable.connections[i] + " in Cable"); } if (resource[meta][4] != null) this.bindTexture(resource[meta][4]); if ((!connectable.hasOppositeConnection(connectable.connections))) { if (this.model[meta][0] != null) this.drawCore(meta); } else if (this.model[meta][1] != null) { if (connectable.connections[0] != null) this.drawStraightCore(meta, ForgeDirection.UP); if (connectable.connections[2] != null) this.drawStraightCore(meta, ForgeDirection.NORTH); if (connectable.connections[4] != null) this.drawStraightCore(meta, ForgeDirection.WEST); } for (int i = 0; i < connectable.connections.length; i++) { if (connectable.connections[i] != null) { if (this.model[meta][3] != null) drawConnection(meta, connectable.connections[i], tile.xCoord, tile.yCoord, tile.zCoord, tile); //Drawing and rendering a new connection model for each connected side specified by the tileentity } } } if (tile instanceof TileEntityPipe) { TileEntityPipe connectable = (TileEntityPipe) tile; for (int i = 0; i < 6; i++) { //System.out.println("Connections " + i + " = " + connectable.connections[i] + " in Cable"); } if (connectable.renderPass == 1) { GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_DEPTH_TEST); //System.out.println("test"); GL11.glDepthMask(true); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.renderTravelingItem(connectable, (float)x, (float)y, (float)z); GL11.glShadeModel(GL11.GL_SMOOTH); if (resource[meta][4] != null) this.bindTexture(resource[meta][4]); if ((!connectable.hasOppositeConnection(connectable.connections))) { if (this.model[meta][0] != null) this.drawCore(meta); } else if (this.model[meta][1] != null) { if (connectable.connections[0] != null) this.drawStraightCore(meta, ForgeDirection.UP); if (connectable.connections[2] != null) this.drawStraightCore(meta, ForgeDirection.NORTH); if (connectable.connections[4] != null) this.drawStraightCore(meta, ForgeDirection.WEST); } for (int i = 0; i < connectable.connections.length; i++) { if (connectable.connections[i] != null) { if (this.model[meta][3] != null) drawConnection(meta, connectable.connections[i], tile.xCoord, tile.yCoord, tile.zCoord, tile); //Drawing and rendering a new connection model for each connected side specified by the tileentity } } GL11.glEnable(GL11.GL_CULL_FACE); GL11.glDepthMask(false); GL11.glDisable(GL11.GL_BLEND); } } //} GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); } Again, relevant code starts from "if (tile instanceof TileEntityPipe)", the rest is for my cables. This is now what it looks like: [/img] So, the water, and other things in the background look fine, they're rendered behind the pipe as they should be. But.... Now there is another problem. You can also see in the screenshot, that the inside of the pipe itself looks slightly strange, there are bits of the inside that are missing, and this is only from certain angles, the missing bits move when looked at from another angle. I think they are getting culled, but I am not sure what by, and disabling culling makes it look weird again. Also, another problem, you can see in my code, I have commented out the line this.renderTravelingItem. This was also causing some of the rendering issues, the item renders fine, without any transparency issues, but is rendered behind the pipe. This is what happens when renderTravelingItem isn't commented out: [/img] The iron ingot is positioned inside the pipe, but is rendered behind the pipe. This is my travelling item method: public void renderTravelingItem(TileEntityPipe pipe, float x, float y, float z) { GL11.glPushMatrix(); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_CULL_FACE); TravelingItem itemToRender1 = new TravelingItem(new ItemStack(Items.iron_ingot, 5), 0.0F, 0.0F, 0.0F, 0.05F); //Testing with an item TravelingItem itemToRender2 = new TravelingItem(new ItemStack(Blocks.stone, 5), 0.0F, 0.0F, 0.0F, 0.05F); //Testing with a block //List<TravelingItem> items = new ArrayList<TravelingItem>(); /*for (ItemStack s : pipe.getStoredItems()) { TravelingItem item = new TravelingItem(s, 0.0F, 0.0F, 0.0F, 0.05F); items.add(item); }*/ float scale = 1.25F; this.renderTravelingItem(itemToRender1, x, y, z, 0.05F, scale); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); } public void renderTravelingItem(TravelingItem item, float x, float y, float z, float speed, float scale) { //TravelingItem item = new TravelingItem(stack, x, y, z, speed); if (item == null || item.getStack() == null) { return; } ItemStack stack = item.getStack(); GL11.glPushMatrix(); GL11.glTranslatef(x, y, z); GL11.glTranslatef(0.5F, 0.9F, 0.5F); GL11.glScalef(scale, scale, scale); fakeItem.setEntityItemStack(stack); renderItem.doRender(fakeItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F); GL11.glPopMatrix(); } And the TravelingItem class just stores the ItemStack, its position, and I will soon make it also store NBT data. So, one major problem is solved, but now there are two annoying problems to solve.
  20. I already have done shouldRenderInPass(int pass) and in the block class, getRnderPass() { return 1; } and it still looks really weird. I think, as suggested above, my best option is to somehow make sure my pipe is rendered last. I only need a way to do this. If needed I'll post my code later, I don't have access to it right now.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.