Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Posts

  • Joined

  • Last visited


  • Gender
  • Personal Text
    I am new!

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

chylex's Achievements

Tree Puncher

Tree Puncher (2/8)



  1. I've been trying to solve this too, very crucial for my mod and can't be done with events (I don't want to use coremods either). Here's something I came up with, it uses nasty amount of reflection so it might and probably will break with updates. I have tested it a bit, and it seems to work fine, so let me know if you have any issues with it. public class BlockReplaceHelper{ public static boolean replaceBlock(Block toReplace, Class<? extends Block> blockClass){ Field modifiersField=null; try{ modifiersField=Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); for(Field field:Blocks.class.getDeclaredFields()){ if (Block.class.isAssignableFrom(field.getType())){ Block block=(Block)field.get(null); if (block==toReplace){ String registryName=Block.blockRegistry.getNameForObject(block); int id=Block.getIdFromBlock(block); ItemBlock item=(ItemBlock)Item.getItemFromBlock(block); System.out.println("Replacing block - "+id+"/"+registryName); Block newBlock=blockClass.newInstance(); FMLControlledNamespacedRegistry<Block> registry=GameData.blockRegistry; registry.putObject(registryName,newBlock); Field map=RegistryNamespaced.class.getDeclaredFields()[0]; map.setAccessible(true); ((ObjectIntIdentityMap)map.get(registry)).func_148746_a(newBlock,id); map=FMLControlledNamespacedRegistry.class.getDeclaredField("namedIds"); map.setAccessible(true); ((BiMap)map.get(registry)).put(registryName,id); field.setAccessible(true); int modifiers=modifiersField.getInt(field); modifiers&=~Modifier.FINAL; modifiersField.setInt(field,modifiers); field.set(null,newBlock); Field itemblock=ItemBlock.class.getDeclaredFields()[0]; itemblock.setAccessible(true); modifiers=modifiersField.getInt(itemblock); modifiers&=~Modifier.FINAL; modifiersField.setInt(itemblock,modifiers); itemblock.set(item,newBlock); System.out.println("Check field: "+field.get(null).getClass()); System.out.println("Check registry: "+Block.blockRegistry.getObjectById(id).getClass()); System.out.println("Check item: "+((ItemBlock)Item.getItemFromBlock(newBlock)).field_150939_a.getClass()); } } } }catch(Exception e){ e.printStackTrace(); return false; } return true; } } Example usage (in preinit): BlockReplaceHelper.replaceBlock(Blocks.dragon_egg,BlockDragonEggCustom.class);
  2. Hey, in 1.6.4, it was possible to access private/protected fields and methods because Forge would make them all public on runtime, but I can't quite get it working in 1.7.2 because it's harder to edit Minecraft sources. Here's what I have got so far - I setup Forge using gradlew.bat setupDecompWorkspace eclipse, extracted the sources from Gradle cache (forge-1.7.2- and put it in Eclipse. Now, it works fine when I run it in Eclipse, but not when I try to build it. I built a jar file with changed Minecraft sources, but I'm not quite sure how to force Gradle to use it instead of the original one - if I replace one of the jars in cache, Gradle notices and replaces it. I've never worked with Gradle before, and the ability to change accessibility is very important, so if anyone has figured out how to get it working, please let me know . Also, don't suggest reflection, that would be the very last resort.
  3. seriously? Oops, somehow I automatically assumed it was supposed to work like that, didn't realize it's just for ModLoader compatibility... Explains many weird things I've encountered, anyways it works now, thanks a lot
  4. Hello, I've been trying to make this working for several hours and it's getting frustrating I'm trying to register an event in @Init (tried @PreInit too) method, but it's never firing. I can register the event in load() or the mod constructor, but it only works in the client, if I put the mod on the server, it throws an error. Source code: The "test" message never shows up, and the event isn't registered. If I register it inside the constructor or load(), client works flawlessly, but this error shows up on the server (started it inside Eclipse, but the same error is thrown if I run the server from .jar and put the mod inside mods folder): I have no idea why it's trying to load the NetClientHandler class on the server, just because I'm trying to register an event, can't find any references to that class in my mod, I'm simply clueless. I have the latest Forge version for 1.5.1 (just to be 100% sure, I redownloaded it about 30 minutes ago). Thanks for help
  • Create New...

Important Information

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