Example usage for net.minecraftforge.fml.common ObfuscationReflectionHelper getPrivateValue

List of usage examples for net.minecraftforge.fml.common ObfuscationReflectionHelper getPrivateValue

Introduction

In this page you can find the example usage for net.minecraftforge.fml.common ObfuscationReflectionHelper getPrivateValue.

Prototype

@Nullable
public static <T, E> T getPrivateValue(Class<? super E> classToAccess, E instance, String fieldName) 

Source Link

Document

Gets the value a field with the specified name in the given class.

Usage

From source file:blusunrize.immersiveengineering.common.blocks.cloth.TileEntityBalloon.java

@Override
public boolean interact(EnumFacing side, EntityPlayer player, EnumHand hand, ItemStack heldItem, float hitX,
        float hitY, float hitZ) {
    if (!heldItem.isEmpty() && heldItem.getItem() instanceof IShaderItem) {
        if (this.shader == null)
            this.shader = new ShaderWrapper_Direct("immersiveengineering:balloon");
        this.shader.setShaderItem(Utils.copyStackWithAmount(heldItem, 1));
        markContainingBlockForUpdate(null);
        return true;
    }/*from   w w  w. ja va 2  s  .c  o m*/
    int target = 0;
    if (side.getAxis() == Axis.Y && style == 0)
        target = (hitX < .375 || hitX > .625) && (hitZ < .375 || hitZ > .625) ? 1 : 0;
    else if (side.getAxis() == Axis.Z) {
        if (style == 0)
            target = (hitX < .375 || hitX > .625) ? 1 : 0;
        else
            target = (hitY > .5625 && hitY < .75) ? 1 : 0;
    } else if (side.getAxis() == Axis.X) {
        if (style == 0)
            target = (hitZ < .375 || hitZ > .625) ? 1 : 0;
        else
            target = (hitY > .5625 && hitY < .75) ? 1 : 0;
    }
    int heldDye = Utils.getDye(heldItem);
    if (heldDye == -1)
        return false;
    int color = ObfuscationReflectionHelper.getPrivateValue(EnumDyeColor.class,
            EnumDyeColor.byMetadata(15 - heldDye), "field_193351_w");
    if (target == 0) {
        if (colour0 == color)
            return false;
        colour0 = color;
    } else {
        if (colour1 == color)
            return false;
        colour1 = color;
    }
    markContainingBlockForUpdate(null);
    return true;
}

From source file:com.crowsofwar.gorecore.chat.ChatSender.java

License:Open Source License

private Object[] getFormatArgs(TextComponentTranslation message) {
    return ObfuscationReflectionHelper.getPrivateValue(TextComponentTranslation.class, message, 1);
}

From source file:com.crowsofwar.gorecore.chat.ChatSender.java

License:Open Source License

private String getKey(TextComponentTranslation message) {
    return ObfuscationReflectionHelper.getPrivateValue(TextComponentTranslation.class, message, 0);
}

From source file:com.teambrmodding.assistedprogression.managers.RecipeHelper.java

License:Creative Commons License

/**
 * This method lets you get all of the recipe data for a given recipe type. The existing
 * methods for this require an IInventory, and this allows you to skip that overhead. This
 * method uses reflection to get the recipes map, but an access transformer would also
 * work.//from   w w w  . j av  a2 s.  c o m
 *
 * Credit to Darkhax
 * @author https://github.com/Minecraft-Forge-Tutorials/Custom-Json-Recipes/blob/master/src/main/java/net/darkhax/customrecipeexample/CustomRecipesMod.java
 *
 * @param recipeType The type of recipe to grab.
 * @param manager The recipe manager. This is generally taken from a World.
 * @return A map containing all recipes for the passed recipe type. This map is immutable
 *         and can not be modified.
 */
public static Map<ResourceLocation, IRecipe<?>> getRecipes(IRecipeType<?> recipeType, RecipeManager manager) {
    final Map<IRecipeType<?>, Map<ResourceLocation, IRecipe<?>>> recipesMap = ObfuscationReflectionHelper
            .getPrivateValue(RecipeManager.class, manager, "field_199522_d");
    return recipesMap.get(recipeType);
}

From source file:cpw.mods.ironchest.ItemChestChanger.java

License:Open Source License

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side,
        float hitX, float hitY, float hitZ) {
    if (world.isRemote)
        return false;
    TileEntity te = world.getTileEntity(pos);
    TileEntityIronChest newchest;/*from  w  w  w .  j  av  a2 s  .  com*/
    if (te != null && te instanceof TileEntityIronChest) {
        TileEntityIronChest ironchest = (TileEntityIronChest) te;
        newchest = ironchest.applyUpgradeItem(this);
        if (newchest == null) {
            return false;
        }
    } else if (te != null && te instanceof TileEntityChest) {
        TileEntityChest tec = (TileEntityChest) te;
        if (tec.numPlayersUsing > 0) {
            return false;
        }
        if (!getType().canUpgrade(IronChestType.WOOD)) {
            return false;
        }
        // Force old TE out of the world so that adjacent chests can update
        newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal()));
        int newSize = newchest.chestContents.length;
        ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0);
        System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length));
        BlockIronChest block = IronChest.ironChestBlock;
        block.dropContent(newSize, tec, world, tec.getPos());
        newchest.setFacing((byte) tec.getBlockMetadata());
        newchest.sortTopStacks();
        for (int i = 0; i < Math.min(newSize, chestContents.length); i++) {
            chestContents[i] = null;
        }
        // Clear the old block out
        world.setBlockState(pos, Blocks.air.getDefaultState(), 3);
        // Force the Chest TE to reset it's knowledge of neighbouring blocks
        tec.updateContainingBlockInfo();
        // Force the Chest TE to update any neighbours so they update next
        // tick
        tec.checkForAdjacentChests();
        // And put in our block instead
        world.setBlockState(pos, block.getStateFromMeta(newchest.getType().ordinal()), 3);
    } else {
        return false;
    }
    world.setTileEntity(pos, newchest);
    world.setBlockState(pos, IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal()), 3);
    stack.stackSize = 0;
    return true;
}

From source file:katrix.mouseyEars.client.ClientProxy.java

License:Open Source License

@Override
public void unregisterLayers() {
    RenderPlayer defaultModel = Minecraft.getMinecraft().getRenderManager().getSkinMap().get("default");
    RenderPlayer slimModel = Minecraft.getMinecraft().getRenderManager().getSkinMap().get("slim");
    List<?> layersDefualt = ObfuscationReflectionHelper.getPrivateValue(RendererLivingEntity.class,
            defaultModel, "layerRenderers");
    List<?> layersSlim = ObfuscationReflectionHelper.getPrivateValue(RendererLivingEntity.class, slimModel,
            "layerRenderers");
    layersDefualt.remove(defaultModelLayer);
    layersSlim.remove(slimModelLayer);/*from w w  w . j a  va 2 s  .  com*/
}