Jump to content

jabelar

Members
  • Posts

    3266
  • Joined

  • Last visited

  • Days Won

    39

Everything posted by jabelar

  1. I admit I'm a bit addicted to events when they're available. For me I find the events often have fairly clean logic to them. But yes, they can be heavy on processing burden if you're not careful. I don't think that entities die that often so don't think it should be a performance issue in this case. But yes it seems "wasteful" to process an event even when the item isn't even in use.
  2. That's an interesting point. Yes i use the registerModEntity() registration method. I had been using tracking frequency of 3. I thought that smaller was better (i.e. that it was number of ticks or something). But I guess you're saying that higher is better? [EDIT]Actually, I was right -- lower is more frequent. 20 was horrible, but a value of 1 was really quite nice. [EDIT#2]Derp! The problem for me is that in my registerModEntity() I had set the tracking to false! I changed it back to value of 10 (suggested by you CoolAlias) and turned it on to true (and I also disabled my manual motion syncing) and it works beautifully now. @Metalbot1, you should ensure that you set the tracking to true when you register the entity. Can you post your code where you register this entity?
  3. Why not use the LivingDeathEvent? I think you can get the player entity by checking for the event.livingEntity.getLastAttacker, and then with that find out if player is holding the soul-stealing sword and then proceed accordingly.
  4. I think that is a complicated way to do it. Why not just handle the PlayerInteractEvent? In that event you can check if the action is RIGHT_CLICK_BLOCK and then check what kind of block it is with the useBlock field. Then just do what you want when you detect that player has right clicked on water.
  5. I haven't played much with this, but why are you testing data == null instead of message.data == null? Shouldn't you be trying to look at the data in the message passed as a parameter to that method?
  6. I was going to ask the same thing -- how do you really know what the attack time is doing in the zombies? You may need to trace it either with debugger tracing or by even going through work to create an entity with copy of the code and add your own console statements or other modifications to figure it out.
  7. I'm a fan of just doing it with good ol' "brute force". Just take some graph paper and draw out what you want. Then create a method that places each block in the location (probably a relative location to some starting point). For any regularly shaped features, like a straight wall, you can use for loops to cut down on the lines of code you need. I actually do it with 2D arrays for each layer, and then loop through the arrays. For example, imagine if you set a int code to represent each type of block you want. Like air/nothing = 0, sandstone = 1, or whatever blocks you are happening to use. Then you can have an int array for first layer that sets the foundation for the walls, something like this for a room: int[][] wallsRoom1 = new int[][] {{1,1,1,1,1,1,1}, {1,0,0,0,0,0,1}, {1,0,0,0,0,0,1}, {1,0,0,0,0,0,1}, {1,0,0,0,0,0,1}, {1,1,1,0,1,1,1}, {0,0,1,0,1,0,0}, {0,0,1,0,1,0,0}}; And then you can loop through that placing the block indicated in the location indicated. You could build up this wall by looping through at multiple heights. I like this method because it is almost like just drawing the structure right in code -- very easy to visualize.
  8. I don't have a solution, but I can say that I recently ran into the exact same problem with a throwable. The entity looked like it was falling from one point on the trajectory then would fall from another, and so on. What I believe was happening was some issue with sync between server and client. Bascially the server knew that it was flying with a trajectory and so ultimately it went where it was supposed to, but the client got occasional syncs from server which put it back on trajectory but in between syncs the client did intermediate processing and thought it was falling. For fast moving objects in client-server games, you usually have to do this -- the client has to do intermediate processing otherwise the movement will be too jerky and laggy waiting for server to update the position. When I was debugging this I found that the server was syncing the position but not the motion. I'm pretty sure that is the problem. I sort of brute forced it by totally rewriting it so that the client took the last two server positions and created motion on the client. But there has to be a cleaner way since there are already projectiles and throwables that work well in Minecraft. I think perhaps vanilla entities have some special sync packet that we're not getting with our custom entity or something? Anyway, hope that gives you some idea.
  9. Is the attacked entity a custom one or are you changing drops for a vanilla entity? Anyway there are several server side methods and fields. I think you should look at the attackEntityFrom method. Alternatively you can handle the living drops event, especially if you're changing vanilla drops.
  10. I have a tutorial on making crops that might be interesting to you: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-creating-custom.html One of the important methods is in the plant block class you need something like this: @Override protected boolean canPlaceBlockOn(Block parBlock) { return parBlock == Blocks.farmland; } Also, in order to ensure that the block can continue to "sustain" on the block you plant in, in your seed item (your class that implements IPlantable) you need something like this: @Override public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z) { return EnumPlantType.Crop; }
  11. Okay, part of the problem in helping you is that you're not using proper naming convention. You should have lower case "C" in "collumStone" otherwise it looks like you're calling a class not a field. But based on the code you just posted, it seems like KimptonCor.CollumStone would be the instance and should work. But you should rename this for proper convention as it can cause a lot of confusion when working with other coders. I just checked some of my own code, and it seems to work fine -- no complaints about static and such. I have, in my main class: public final static Block blockMagicBeanStalk = new BlockMagicBeanStalk(); Then in my tile entity for the block I have: String name = MagicBeans.blockMagicBeanStalk.getUnlocalizedName(); And it has no problem that I could see. Note that I was calling the latter code in a public non-static method of the tile entity. Is the method in your tile entity render class static?
  12. You might want to check out my tutorial on creating custom crops. http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-creating-custom.html
  13. Okay, here's the deal. Blocks are (I suppose) a little bit confusing in Minecraft because there is one class, one instance, but lots of blocks! How does that work? Well, there is some sort of map of the locations of all the places the block should render, and there is record of "metadata" per block that allows some differentiation (like a door can face different directions). But it actually still only one block instance from Java perspective! I suppose this can make the Java confusing. Basically something like the texture and unlocalized name are not static but are the same for all the blocks because there is really only one instance of the block in the game. But because it is an instance it doesn't need to be a static class variable, and in fact as you're experiencing it could create some issues with trying to treat it that way. So you should not be using class variables and methods, but rather you should be using instance methods. They are still unique to the single block instance. If for some reason you want different names or textures for some of your blocks, you need to either use metadata or create an associated TileEntity to contain the unique stuff. So somewhere in your code you should be creating the instance of your block, and you should call your methods and access your fields in that instance. Instead of KimptonCore.CollumStone. (the class) you should be using the instance name you stored somewhere in your main class or proxy.
  14. I think you are doing it backwards. You should set the static block name variable directly with string containing the name you want, and then you should use that to assign the unlocalized name, and then use lang file to do the conversion to localized name. A "static" essentially means you want it to be a constant, but the localized name can theoretically change during the game so it doesn't make sense to do it this way. I think you should question why you need a static variable when you can call the public method at any time you need it? Anyway, I think what you want to do is put the name string directly into that field initialization and then set the unlocalized name based on that. Then everything will match. In other words, the localized name should come from this variable; you should not be assigning this variable from method that looks up localized name.
  15. Um, actually getLocalizedName() is a public method for all blocks. Here is the implementation from the Block class: /** * Gets the localized name of this block. Used for the statistics page. */ public String getLocalizedName() { return StatCollector.translateToLocal(this.getUnlocalizedName() + ".name"); } I have no idea why you are putting that into a private variable, but you can call the method above at any time from anywhere. [EDIT]Also you need to understand that there is difference between localized and unlocalized name, but you can sort of convert between them if necessary. @Kwibble was mentioning how you can strip the "tile." part off with his substring example above.
  16. >> How to reference another mod I made from within a different mod, and how to reference a mod like BuildCraft in my mod. I think this is actually more of a general Java topic. But it depends on a few things. For your own mods, you have the control of the build process so I think you would define part of one or both mods to build as deobfuscated API for those fields and methods you want to access between the mods. Then the other project can reference it (I think as linked library?) within both the development and runtime environment if you put it into your build path. If you're using another person's mod with public API then you can do a similar thing. You should refer to CoolAlias' tutorial on APIs: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571434-tutorial-modding-with-apis#
  17. Kriki, I think the main thing we're questioning is: what do you mean by "not working"? You keep talking about the world object "not being there" but if it really wasn't there then there would be a crash. So I think you're saying that it doesn't crash, but it also doesn't do what you expect. In programming that usually means there is some mistake somewhere, even if you are sure you know what you're doing. I've often made a simple typographical error that is very hard to catch, or a logical error that is subtle. To debug an error, you need to use line-by-line tracing techniques. I usually do this by adding console statements, but of course you can also use your IDE's debugging configuration to watch things you're interested in. It only takes about half an hour to put in enough console statements to confirm every part of your code. My other suggestion is to try something simpler first and then build back up. Maybe just grab the world object and check other methods to confirm that those respond as expected. This will eliminate all the possible errors in the packet handling or the message formation or in any other logic in your code. Anyway, it sounds like you already know Java well, but I don't see evidence in your code that you were really tracing every step of code. Debugging requires that. For example, if you have code to place a block in response to packet received so you should have a statement right before the block placement that says "placing block". If that doesn't show on the console then check to make sure all the parameters for the block placement are what you expect (are the x, y, and z values what you expect, etc) and if that doesn't work then go further up the code to what calls the block placement, like confirm that packet was actually received, and if that doesn't work confirm that packet was actually sent. I'm confident you'll find the error along the way. Anyway, just saying "doesn't work" or "doesn't find world object" doesn't allow us to help you -- it obviously does find some world object if it isn't crashing with null pointer exception. So I think you mean the block placement isn't happening as expected.
  18. Yeah, really good point CoolAlias. My code example above was called after I made the pillar that I was "decorating", so yes it is important to do these in the right order. Furthermore, you should know that the setBlock() methods do a LOT of checking of conditions before allowing placing. One of them is whether there is something to attach to, there is also checking if whatever is there to attach to is considered a valid thing to place on, the block below is checked (I think) to confirm you can place on, and so forth. Because of all this, you need to make sure any custom blocks you create will pass all these checks. For example, in my case I'm attaching the vines to a custom pillar so I had to make sure that the canPlaceBlockOnSide() method in the custom vine class returned true for that pillar block. If you're making custom blocks in your structure you may need to clear out some of those such issues as well.
  19. Hi. I think I just ran into a very similar problem -- I was trying to place vines as part of a structure generation (instead of being placed as an item or during world generation). I'm not sure if your problem has the same cause, but here is how I solved my problem. Basically, there are block types (such as torches, doors, vines, etc.) that have a direction -- they get placed such that they seem to be attached to other blocks around them. I believe in most of these cases (at least it was true with vines) that you need to assign metadata to the block to indicate the direction. If you don't assign metadata then it will default to 0 and won't render (I'm not sure if it is actually placed, but certainly wasn't visible). There are actually two different setBlock() methods. One only takes the position and another takes metadata as well. So for me the solution was to use the right method, and furthermore assign the right metadata. Here is my code for creating vines that surround a pillar. Basically it checks in each direction to ensure the space is free, and then places the vines but does it with different metadata depending on which side I want it to display attached to. // add vines all around if(worldObj.isAirBlock(xCoord+1, yCoord , zCoord)) { worldObj.setBlock(xCoord+1, yCoord, zCoord, MagicBeans.blockMagicBeansVine, 2, 2); } if(worldObj.isAirBlock(xCoord-1, yCoord , zCoord)) { worldObj.setBlock(xCoord-1, yCoord, zCoord, MagicBeans.blockMagicBeansVine, 8, 2); } if(worldObj.isAirBlock(xCoord, yCoord , zCoord+1)) { worldObj.setBlock(xCoord, yCoord, zCoord+1, MagicBeans.blockMagicBeansVine, 4, 2); } if(worldObj.isAirBlock(xCoord, yCoord , zCoord-1)) { worldObj.setBlock(xCoord, yCoord, zCoord-1, MagicBeans.blockMagicBeansVine, 1, 2); } So I'm wondering if you are using the wrong setBlock() method, or maybe you're using right method but setting wrong metadata. If that is not your problem, then I suggest you look at the code for village generation and see how they place the doors in the buildings that are generated.
  20. By the way, you shouldn't have to use G11 rotation to rotate a ModelRenderer. ModelRenderer has its own setRotation() method. And yeah, the rotation axis is the one you rotate around, not the direction you want to rotate. In other words the rotation axis is normally at right angles to the direction you want to rotate. If you want to rotate left or right you rotate around Y, if you want to rotate up and down you rotate around X, if you want to rotate front face clockwise or counterclockwise you rotate around Z. It makes sense once you understand it.
  21. Kriki, what exactly do you mean that worldObj doesn't work? You mean Eclipse doesn't recognize it? You mean that you get a crash during the game that points to problem with it? You mean that your code just doesn't do what you expect?
  22. I have a custom block that will be very lightly used in the game -- only small number created by specific activity, and not on a creative tab. Metadata is working fine for controlling an effect that I want, however I want the effect to change in a predictable pace but have been having trouble with the block's updateTick() method. It seems to be called very infrequently and very irregularly. I noticed that the updates to block seem to be controlled by a queue of sorts and it seems to be possible on the WorldServer class to set an update for a block. So I'm assuming I could try to put my block back on the queue on a regular basis. I realize I can use a tile entity, but it seemed that since metadata generally worked it would be interesting to do it this way. Has anyone got any experience/advice on forcing block updates? I'm thinking about just creating a server tick event handler and every few ticks forcing the update by calling the event on the world server. But I'm worried that there might be some side effect to this, or alternatively maybe there is an easier way to ensure regular, speedy updates to a specific block type.
  23. I think the first thing is to get a good understanding of how placing really works. You might want to just trace the operation with some console statements, or read carefully through the code. But I think (not certain, you'll have to investigate) that there is the action field in the event that has possibility of being value RIGHT_CLICK_AIR. Is it possible that that is the action posted when there is a block place event? It seems to me that RIGHT_CLICK_AIR is the action to look for, as you can see it is posted in the processPlayerBlockPlacement() method of the NethandlerPlayServer. Anyway, just a thought. RIGHT_CLICK_AIR seems to have relationship to the moment of placing a block.
  24. I think there is a MinecartInteractEvent. Not sure if that is useful or not. It seems to contain just the player and minecart entities. The other minecart related events are collision and update. Of course for living entities there is a death event, but not for minecarts (which are entities but not living entities). I don't see any entity events that would be helpful. There is a public field in all entities called isDead. You might be able to check that in some tick handling event perhaps.
×
×
  • Create New...

Important Information

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