Java Code Examples for net.minecraftforge.fml.common.ObfuscationReflectionHelper

The following examples show how to use net.minecraftforge.fml.common.ObfuscationReflectionHelper. 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 void updatePingers() {
	for (BleachServerPinger ping: new ArrayList<>(pingers)) {
		if (ping.done) {
			checked++;
			if (!ping.failed && !abort) {
				working++;
				try {
					ServerList list = (ServerList) ObfuscationReflectionHelper.findField(MultiplayerScreen.class, "field_146804_i").get(serverScreen);
					list.addServerData(ping.server);
					list.saveServerList();
				} catch (Exception e) {}
			}
			pingers.remove(ping);
		}
	}
}
 
Example 2
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 3
Source Project: ForgeHax   Source File: FlyMod.java    License: MIT License 6 votes vote down vote up
@SubscribeEvent
public void onOutgoingPacketSent(PacketEvent.Incoming.Pre event) {
  if (event.getPacket() instanceof SPacketPlayerPosLook) {
    SPacketPlayerPosLook packet = event.getPacket();
    try {
      ObfuscationReflectionHelper.setPrivateValue(
          SPacketPlayerPosLook.class,
          packet,
          MC.player.rotationYaw,
          "yaw",
          "field_148936_d",
          "d");
      ObfuscationReflectionHelper.setPrivateValue(
          SPacketPlayerPosLook.class,
          packet,
          MC.player.rotationPitch,
          "pitch",
          "field_148937_e",
          "e");
    } catch (Exception e) {
    }
  }
}
 
Example 4
@SubscribeEvent
public void entityJoinWorld(EntityJoinWorldEvent ev)
{
    if (!ConfigManager.SERVER.enableScraping.get())
        return;
    if (ev.getEntity().world.isRemote)
        return;

    if (ev.getEntity() instanceof PlayerEntity)
    {
        PlayerEntity player = (PlayerEntity) ev.getEntity();

        CombatTrackerIntercept interceptTracker = new CombatTrackerIntercept(player);
        ObfuscationReflectionHelper.setPrivateValue(LivingEntity.class, player, interceptTracker, "field_94063_bt");
    }
}
 
Example 5
Source Project: simpleretrogen   Source File: WorldRetrogen.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 6
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 7
Source Project: TofuCraftReload   Source 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 8
Source Project: CommunityMod   Source File: Foliage.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
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 9
Source Project: bleachhack-1.14   Source File: FastUse.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void onUpdate() {
	if (this.isToggled()) {
		try {
			/* set rightClickDelay to 0 */
			ObfuscationReflectionHelper.findField(Minecraft.class, "field_71467_ac").setInt(mc, 0);
			
			/* call rightClickMouse */
			if (getSettings().get(0).toMode().mode == 1 && mc.gameSettings.keyBindUseItem.isKeyDown()) {
				for (int i = 0; i < (int) getSettings().get(1).toSlider().getValue(); i++) {
					ObfuscationReflectionHelper.findMethod(Minecraft.class, "func_147121_ag").invoke(mc);
				}
			}
		} catch (Exception e) {}
	}
}
 
Example 10
Source Project: GregTech   Source File: ClientProxy.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 11
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 12
Source Project: simpleretrogen   Source File: WorldRetrogen.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 13
protected void initBlockState() {
    BlockStateContainer stateContainer = createStateContainer();
    ObfuscationReflectionHelper.setPrivateValue(Block.class, this, stateContainer, 21); //this.stateContainer
    setDefaultState(stateContainer.getBaseState());
}
 
Example 14
Source Project: GregTech   Source File: BlockOre.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void initBlockState() {
    BlockStateContainer stateContainer = createStateContainer();
    ObfuscationReflectionHelper.setPrivateValue(Block.class, this, stateContainer, 21); //this.stateContainer
    setDefaultState(stateContainer.getBaseState());
}
 
Example 15
Source Project: simpleretrogen   Source File: WorldRetrogen.java    License: GNU General Public License v3.0 4 votes vote down vote up
@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);
            }
        }
    }
}