Java Code Examples for net.minecraftforge.fml.common.ObfuscationReflectionHelper#getPrivateValue()

The following examples show how to use net.minecraftforge.fml.common.ObfuscationReflectionHelper#getPrivateValue() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void fixResourcePackLocation(ModContainer selfContainer) {
    File sourceFile = selfContainer.getSource();
    if (sourceFile.isDirectory()) {
        AbstractResourcePack resourcePack = getModResourcePack(selfContainer.getModId());
        File actualPackRoot = ObfuscationReflectionHelper.getPrivateValue(AbstractResourcePack.class, resourcePack, "field_110597_b");
        File expectedPackRoot = getGTCEResourcePackRoot();

        if (!expectedPackRoot.getAbsolutePath().equals(actualPackRoot.getAbsolutePath())) {
            System.out.println("[GTCE] Found unexpected resource pack path in dev environment");
            System.out.println("[GTCE] Expected path: " + expectedPackRoot.getAbsolutePath());
            System.out.println("[GTCE] Actual path: " + actualPackRoot.getAbsolutePath());
            System.out.println("[GTCE] Fixed resource pack patch automatically.");
            ObfuscationReflectionHelper.setPrivateValue(AbstractResourcePack.class, resourcePack, expectedPackRoot, "field_110597_b");
            setModResourcePack(selfContainer.getModId(), resourcePack);
        }
    }
}
 
Example 2
@EventHandler
public void serverStopped(FMLServerStoppedEvent evt)
{
    Set<IWorldGenerator> worldGens = ObfuscationReflectionHelper.getPrivateValue(GameRegistry.class, null, "worldGenerators");
    Map<IWorldGenerator,Integer> worldGenIdx = ObfuscationReflectionHelper.getPrivateValue(GameRegistry.class, null, "worldGeneratorIndex");

    for (TargetWorldWrapper tww : delegates.values())
    {
        worldGens.remove(tww);
        Integer idx = worldGenIdx.remove(tww);
        worldGens.add(tww.delegate);
        worldGenIdx.put(tww.delegate,idx);
    }

    delegates.clear();
}
 
Example 3
private static void removeDragonBossBarHack(EntityPlayerMP player, WorldProviderEnd provider)
{
    // Somewhat ugly way to clear the Boss Info stuff when teleporting FROM The End
    DragonFightManager manager = provider.getDragonFightManager();

    if (manager != null)
    {
        try
        {
            BossInfoServer bossInfo = ObfuscationReflectionHelper.getPrivateValue(DragonFightManager.class, manager, "field_186109_c");

            if (bossInfo != null)
            {
                bossInfo.removePlayer(player);
            }
        }
        catch (Exception e)
        {
            EnderUtilities.logger.warn("TP: Failed to get DragonFightManager#bossInfo");
        }
    }
}
 
Example 4
Source Project: TofuCraftReload   File: WorldProviderTofu.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
   public void resetRainAndThunder() {

       super.resetRainAndThunder();

       if(this.world.getGameRules().getBoolean("doDaylightCycle"))
       {
           WorldInfo worldInfo = ObfuscationReflectionHelper.getPrivateValue(DerivedWorldInfo.class, (DerivedWorldInfo) world.getWorldInfo(), "theWorldInfo", "field_76115_a");
           long i = worldInfo.getWorldTime() + 24000L;
           worldInfo.setWorldTime(i - i % 24000L);
       }
   }
 
Example 5
private static void registerExtendedBlockColor(BlockColors bc, IExtendedBlockColor extColor, Block... blocks) {
	Map<IRegistryDelegate<Block>, IBlockColor> internalMap = ObfuscationReflectionHelper.getPrivateValue(BlockColors.class, bc, "blockColorMap"); //forge-added field in 1.12, no srg name available
	//TODO someone test this in obf lol
	
	for(Block b : blocks) {
		IRegistryDelegate<Block> delegate = b.delegate;
		IBlockColor regularColor = internalMap.get(delegate);
		
		bc.registerBlockColorHandler(((state, world, pos, tintIndex) -> extColor.colorMultiplierExt(regularColor, state, world, pos, tintIndex)), b);
	}
}
 
Example 6
@SubscribeEvent
public static void onPlayerRender(RenderPlayerEvent.Pre event) {
    AbstractClientPlayer clientPlayer = (AbstractClientPlayer) event.getEntityPlayer();
    if (capeHoldersUUIDs.contains(clientPlayer.getUniqueID()) && clientPlayer.hasPlayerInfo() && clientPlayer.getLocationCape() == null) {
        NetworkPlayerInfo playerInfo = ObfuscationReflectionHelper.getPrivateValue(AbstractClientPlayer.class, clientPlayer, 0);
        Map<Type, ResourceLocation> playerTextures = ObfuscationReflectionHelper.getPrivateValue(NetworkPlayerInfo.class, playerInfo, 1);
        playerTextures.put(Type.CAPE, GREGTECH_CAPE_TEXTURE);
    }
}
 
Example 7
private static void setModResourcePack(String modid, AbstractResourcePack newPack) {
    FMLClientHandler clientHandler = FMLClientHandler.instance();
    IResourcePack oldPack = clientHandler.getResourcePackFor(modid);
    Map<String, IResourcePack> resourcePackMap = ObfuscationReflectionHelper.getPrivateValue(FMLClientHandler.class, clientHandler, "resourcePackMap");
    resourcePackMap.put(modid, newPack);
    List<IResourcePack> resourcePackList = ObfuscationReflectionHelper.getPrivateValue(FMLClientHandler.class, clientHandler, "resourcePackList");
    resourcePackList.remove(oldPack);
    resourcePackList.add(newPack);
}
 
Example 8
private void runRetrogen(WorldServer world, ChunkPos chunkCoords, String retroClass)
{
    long worldSeed = world.getSeed();
    Random fmlRandom = new Random(worldSeed);
    long xSeed = fmlRandom.nextLong() >> 2 + 1L;
    long zSeed = fmlRandom.nextLong() >> 2 + 1L;
    long chunkSeed = (xSeed * chunkCoords.chunkXPos + zSeed * chunkCoords.chunkZPos) ^ worldSeed;

    fmlRandom.setSeed(chunkSeed);
    ChunkProviderServer providerServer = world.getChunkProvider();
    IChunkGenerator generator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, providerServer, "field_186029_c", "chunkGenerator");
    delegates.get(retroClass).delegate.generate(fmlRandom, chunkCoords.chunkXPos, chunkCoords.chunkZPos, world, generator, providerServer);
    FMLLog.fine("Retrogenerated chunk for %s", retroClass);
    completeRetrogen(chunkCoords, world, retroClass);
}
 
Example 9
@EventHandler
public void serverAboutToStart(FMLServerAboutToStartEvent evt)
{
    this.pendingWork = new MapMaker().weakKeys().makeMap();
    this.completedWork = new MapMaker().weakKeys().makeMap();
    this.completedWorkLocks = new MapMaker().weakKeys().makeMap();

    Set<IWorldGenerator> worldGens = ObfuscationReflectionHelper.getPrivateValue(GameRegistry.class, null, "worldGenerators");
    Map<IWorldGenerator,Integer> worldGenIdx = ObfuscationReflectionHelper.getPrivateValue(GameRegistry.class, null, "worldGeneratorIndex");

    for (String retro : ImmutableSet.copyOf(retros.keySet()))
    {
        if (!delegates.containsKey(retro))
        {
            FMLLog.info("Substituting worldgenerator %s with delegate", retro);
            for (Iterator<IWorldGenerator> iterator = worldGens.iterator(); iterator.hasNext();)
            {
                IWorldGenerator wg = iterator.next();
                if (wg.getClass().getName().equals(retro))
                {
                    iterator.remove();
                    TargetWorldWrapper tww = new TargetWorldWrapper();
                    tww.delegate = wg;
                    tww.tag = retro;
                    worldGens.add(tww);
                    Integer idx = worldGenIdx.remove(wg);
                    worldGenIdx.put(tww, idx);
                    FMLLog.info("Successfully substituted %s with delegate", retro);
                    delegates.put(retro, tww);
                    break;
                }
            }

            if (!delegates.containsKey(retro))
            {
                FMLLog.warning("WorldRetrogen was not able to locate world generator class %s, it will be skipped, found %s", retro, worldGens);
                retros.remove(retro);
            }
        }
    }
}