Jump to content

kauan99

Members
  • Posts

    210
  • Joined

  • Last visited

Everything posted by kauan99

  1. Oh this was a name mixup on my part then. I called forge names the deobfuscated names we see when coding for Forge. and I called mcp names the func_xxx_xx stuff.
  2. This is what I did, according to the teachings of diesieben07 /* in my actual code, the methods here span 3 classes that contain other methods and stuff, I simplified the code for clarity * (hopefully) putting all relevant methods to this use case together here and changing the names of some identifiers for * readability. Because of that, something may have broke, because I'm doing theses edits directly in the textArea of this reply. */ private final static MethodHandle myFieldGetter = createGetterForField(PotionEffect.class, "gw_myField", "gw_myField"); private final static MethodHandle myFieldSetter = createSetterForField(PotionEffect.class, "gw_myField", "gw_myField"); public static MethodHandle createGetterForField(Class c, String forgeFieldName, String srgFieldName) { String fieldName = isDeobfEnvironment() ? forgeFieldName: srgFieldName; Field field = null; try { field = c.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { // TODO this is unlikely to happen; } catch (SecurityException e) { // TODO this is unlikely to happen; } field.setAccessible(true); try { return MethodHandles.publicLookup().unreflectGetter(field); } catch (IllegalAccessException e) { return null; } public static MethodHandle createSetterForField(Class c, String forgeFieldName, String srgFieldName) { Field field = null; String fieldName = FMLHelper.isDeobfEnvironment() ? forgeFieldName: srgFieldName; try { field = c.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { } catch (SecurityException e) { } field.setAccessible(true); try { return MethodHandles.publicLookup().unreflectSetter(field); } catch (IllegalAccessException e) { return null; } } public static void setMyField(PotionEffect instance, boolean value) throws Throwable { myFieldSetter.invokeExact((PotionEffect)instance, value); } public static boolean getMyField(PotionEffect instance) throws Throwable { return (boolean) myFieldGetter.invokeExact((PotionEffect)instance); } public static boolean isDeobfEnvironment() { return (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); }
  3. I've been delaying this issue since I started using ASM, but now my project is close to a test release and I need to know. These are the doubts: 1) Do minecraft classes and packages change names at runtime? 2) for fields and methods, always use Forge names when deobfuscated and mcp names when obfuscated? Notch names are never used in mod code? 3) mod stuff (names of fields, methods, classes) also get obfuscated? 4) IClassTransformer.transform has 2 String parameters. What's up with that? that's all. thank you.
  4. Both solutions sound good. when you say reflection you mean that unreflected getter/setter thing you taught me using MethodHandle and invokeExact, right?
  5. I add a public boolean field to PotionEffect via ASM and I wanted to know how can I access that field while writing my code. Do I need reflection?
  6. I didn't know there was such interface. then your lambda seems fine. maybe it's the java version you're targeting? I don't know the language used in build.gradle, but maybe there's something wrong there? for instance, I was told I should choose java version for building using these lines: sourceCompatibility = 1.8 targetCompatibility = 1.8 but you do something different.
  7. I heard making all methods public using an * may not work for most classes.
  8. java thinks you're invoking an interface method without implementation though. well if only I knew more about that model stuff...
  9. I don't know much about 1.8 or models, but that lambda seems weird... Are you sure that's what you meant to write?
  10. This is the line that interests me: public static final String[] ICONNAMES = new String[] {"modid:pulling_0", "modid:pulling_1", "modid:pulling_2"}; I imagine I need to have (inside assets\textures\items\) textures with the names <bow>_pulling_0.png , <bow>_pulling_1.png , <bow>_pulling_2.png and <bow>_standby.png , where <bow> is the name of my Bow's class?
  11. the fields are static. each field is only set once during preInit. The JIT probably can't optimize the fields because they are static and are not set during type construction. But it's ok. I'm just trying hard to squeeze every bit of performace optimization I can, because the server is already too slow as it is. It was a lot better when I ran Cauldron instead of pure Forge, but I couldn't make my event handling code work properly for Cauldron. Anyway, thanks for the code example, that may come in handy some other time.
  12. the class that holds my mod's items. My mod adds a lot of item sets (armor, trinkets (currently rings and necklace from baubles. I plan to write my own custom inventory to optimize trinkets later) and weapons (either swords or bows). every tool/armor material can be customized by the user via config file, every potion effect given by wearing the set. but because of this customizations, a lot of stuff can't be final , otherwise it would have to be hardcoded instead. I feel the JIT would do a better job if I was able to dynamically define that class. I'm also avoiding static stuff that I will need only during initialization, to allow the GC to be able to dispose of things as soon as they are out of scope.
  13. I see, so if I just extend ItemBow all I have to override is what, onPlayerStoppedUsing, and change the code where it sets be arrow damage? what about the icons? this is the hardest part for me, I have a hard time understanding everything that's related to graphics or art in general.
  14. I need it because the host environment where I will run this mod has low performance and already has a lot of mods. I would create the class at runtime in an attempt to optimize it, creating only what is necessary and marking everything I can as final to allow JIT optimizations. this may sound as pre-optimization, but it really isn't. the server is already having a bad performance. I have to do anything I can to maybe avoid making it worse.
  15. cool . It would be harder and more vulnerable to erros to dynamically write the whole class via asm. it's possible, just not an approach I wish to take if I have a choice. Is there a way to add the compiler as a dependency (an external jar)? and if yes, will it take up memory after I'm done with it?
  16. I was wondering if I can use the compiler API to compile one of my mod's classes during one of the initialization events (pre, init, post) and then tell the class loader to load that class as one of my mod's.
  17. I noticed I have to implement getIcon and getIconForUseDuration and registerIcons, and also probably onItemRightClick if I want to change the damage my bow causes to entities. I read a (very old) tutorial about bows, but I was hoping someone could either link me to a more recent and clearer one, or give me a quick explanation of how this is done. I don't really like just copy-pasting stuff, I prefer to actually undestand what I'm doing, so, a link to a plain coded example, while appreciated, is not exactly what I'm looking for. thanks.
  18. I can't locate those files on disk.
  19. I used bytecode viewer, the problem is I don't know where to find the .class files. they're not inside .minecraft\versions\1.7.10.jar because that's where I got that .class file from. it seems only vanilla classes are in there? maybe forge uses ASM to transform the classes into what we see in the source code? All I want is access to the .class files the way they actually are when we play modded minecraft. I want to know where they are, that's all.
  20. please I'd really like to know how to see the bytecode for minecraft classes. maybe the source displays the class after forge patches it. I want to see the source of the class after all patching has been done. could anybody help me with that? thanks.
  21. yeah, thanks! I'm aware of that and I use eclipse and I can't install it for my life.... eclipse always displays and error.
  22. how do I get the bytecode for that method? I checked the joined.srg file to find the method and the class, and picked the class from my .minecraft\versions\1.7.10.jar file (yz.class, method c(ILadd;)V). am I supposed to get the class file from somewhere else? also, if someone would be so kind to check my interpretation of the bytecode for correctness that would be really apreciated.
  23. there are still those 10% of the cases though. we don't need to wear seat belts most of the time, but the one time we need it is the one that counts, isn't it.
  24. I'm trying to experiement with ASM, but I'm facing a weird problem. I'm looking into what was supposed to be the bytecode of EntityPlayer.setCurrentItemOrArmor(int, ItemStack). I'm really bad at reading bytecode, but this doesn't seem right even to me: java source: public void setCurrentItemOrArmor(int p_70062_1_, ItemStack p_70062_2_) { if (p_70062_1_ == 0) { this.inventory.mainInventory[this.inventory.currentItem] = p_70062_2_; } else { this.inventory.armorInventory[p_70062_1_ - 1] = p_70062_2_; } } bytecode: aload_0 getfield yz/bm Lyx; getfield yx/b [Ladd; iload_1 aload_2 aastore return let me see if I inderstand this correctly: aload_0 puts a pointer to this on the stack getfield yz/bm Lyx; gets the field from the pointer on top of the stack ( this ) identified as bm in the constants pool ( inventory ), which is of type Lyx ( pointer to InventoryPlayer ), pops the pointer on top the stack and puts the pointer to the field we just got onto the stack getfield yx/b [Ladd; same operation above, now resulting in we having a pointer to this.inventory.armorInventory (type: array of pointers to ItemStack ) on the stack iload_1 stacks the int value param 1 on top of the stack aload_2 stacks the ItemStack pointer param 2 on top of the stack aastore probably reads the pointer on top of the stack to some register A and pops it from the stack, then reads an int from the stack to some register B and pops it too, then stores the pointer at register A at the address obtained by performing pointer arithmetic on the pointer now on top of the stack (to this.inventory.armorInventory ), and finally pops this last pointer out of the stack return we all know that one where is the code that checks if the index is 0? if this method was used it would put a sword at your helmet slot. where is the subtraction param1 - 1?
×
×
  • Create New...

Important Information

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