[Гайд][Легко][1.6+] Модификация чужого кода при запуске (трансфомеры)

1,015
9
102
Если ты всё сделал правильно, то переустанови gradle. Удали папку C:\Users\ТвойПользователь\.gradle\caches\minecraft\net и передекомпить среду разработки
 
2,505
81
397
Код:
@Hook(returnCondition = ReturnCondition.ALWAYS)
public static String func_77667_c(ItemBlockSponge sp, ItemStack paramItemStack) {
    return "tile.thermalexpansion.sponge.creative";
}
 
808
3
124
Очень странно, но при запуске из eclipse всё отлично хукает, а после компиляции в graddle - как будто не видит класс с хуком... Вот содержимое файла MANIFEST.MF после компиляции в graddle

Код:
Manifest-Version: 1.0
FMLCorePlugin: com.debugme.hooklib.example.ExampleHookLoader
FMLCorePluginContainsFMLMod: true

Может я забыл ещё что то прикрутить? Или нужно както следить за очередью загрузки мода/класса? Если да, то как?

Про methods.bin не забыл?
 
5,018
47
783
Хук в метод, который находится внутри метода - сработает?
 
5,018
47
783
Это как? Скала или Котлин?
java -
Код:
  public static BlockColors init()
    {
        final BlockColors blockcolors = new BlockColors();
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(BlockDoublePlant.VARIANT);
                return worldIn != null && pos != null && (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS || blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN) ? BiomeColorHelper.getGrassColorAtPos(worldIn, state.getValue(BlockDoublePlant.HALF) == BlockDoublePlant.EnumBlockHalf.UPPER ? pos.down() : pos) : -1;
            }
        }, Blocks.DOUBLE_PLANT);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                if (worldIn != null && pos != null)
                {
                    TileEntity tileentity = worldIn.getTileEntity(pos);

                    if (tileentity instanceof TileEntityFlowerPot)
                    {
                        Item item = ((TileEntityFlowerPot)tileentity).getFlowerPotItem();
                        IBlockState iblockstate = Block.getBlockFromItem(item).getDefaultState();
                        return blockcolors.colorMultiplier(iblockstate, worldIn, pos, tintIndex);
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    return -1;
                }
            }
        }, Blocks.FLOWER_POT);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                return worldIn != null && pos != null ? BiomeColorHelper.getGrassColorAtPos(worldIn, pos) : ColorizerGrass.getGrassColor(0.5D, 1.0D);
            }
        }, Blocks.GRASS);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                BlockPlanks.EnumType blockplanks$enumtype = (BlockPlanks.EnumType)state.getValue(BlockOldLeaf.VARIANT);

                if (blockplanks$enumtype == BlockPlanks.EnumType.SPRUCE)
                {
                    return ColorizerFoliage.getFoliageColorPine();
                }
                else if (blockplanks$enumtype == BlockPlanks.EnumType.BIRCH)
                {
                    return ColorizerFoliage.getFoliageColorBirch();
                }
                else
                {
                    return worldIn != null && pos != null ? BiomeColorHelper.getFoliageColorAtPos(worldIn, pos) : ColorizerFoliage.getFoliageColorBasic();
                }
            }
        }, Blocks.LEAVES);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                return worldIn != null && pos != null ? BiomeColorHelper.getFoliageColorAtPos(worldIn, pos) : ColorizerFoliage.getFoliageColorBasic();
            }
        }, Blocks.LEAVES2);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                return worldIn != null && pos != null ? BiomeColorHelper.getWaterColorAtPos(worldIn, pos) : -1;
            }
        }, Blocks.WATER, Blocks.FLOWING_WATER);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                return BlockRedstoneWire.colorMultiplier(((Integer)state.getValue(BlockRedstoneWire.POWER)).intValue());
            }
        }, Blocks.REDSTONE_WIRE);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                return worldIn != null && pos != null ? BiomeColorHelper.getGrassColorAtPos(worldIn, pos) : -1;
            }
        }, Blocks.REEDS);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                int i = ((Integer)state.getValue(BlockStem.AGE)).intValue();
                int j = i * 32;
                int k = 255 - i * 8;
                int l = i * 4;
                return j << 16 | k << 8 | l;
            }
        }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                if (worldIn != null && pos != null)
                {
                    return BiomeColorHelper.getGrassColorAtPos(worldIn, pos);
                }
                else
                {
                    return state.getValue(BlockTallGrass.TYPE) == BlockTallGrass.EnumType.DEAD_BUSH ? 16777215 : ColorizerGrass.getGrassColor(0.5D, 1.0D);
                }
            }
        }, Blocks.TALLGRASS);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                return worldIn != null && pos != null ? BiomeColorHelper.getFoliageColorAtPos(worldIn, pos) : ColorizerFoliage.getFoliageColorBasic();
            }
        }, Blocks.VINE);
        blockcolors.registerBlockColorHandler(new IBlockColor()
        {
            public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
            {
                return worldIn != null && pos != null ? 2129968 : 7455580;
            }
        }, Blocks.WATERLILY);
        net.minecraftforge.client.ForgeHooksClient.onBlockColorsInit(blockcolors);
        return blockcolors;
    }

    public int getColor(IBlockState state, World p_189991_2_, BlockPos p_189991_3_)
    {
        IBlockColor iblockcolor = this.blockColorMap.get(state.getBlock().delegate);

        if (iblockcolor != null)
        {
            return iblockcolor.colorMultiplier(state, (IBlockAccess)null, (BlockPos)null, 0);
        }
        else
        {
            MapColor mapcolor = state.getMapColor(p_189991_2_, p_189991_3_);
            return mapcolor != null ? mapcolor.colorValue : -1;
        }
    }

    public int colorMultiplier(IBlockState state, @Nullable IBlockAccess blockAccess, @Nullable BlockPos pos, int renderPass)
    {
        IBlockColor iblockcolor = this.blockColorMap.get(state.getBlock().delegate);
        return iblockcolor == null ? -1 : iblockcolor.colorMultiplier(state, blockAccess, pos, renderPass);
    }

    public void registerBlockColorHandler(IBlockColor blockColor, Block... blocksIn)
    {
        for (Block block : blocksIn)
        {
            if (block == null) throw new IllegalArgumentException("Block registered to block color handler cannot be null!");
            if (block.getRegistryName() == null) throw new IllegalArgumentException("Block must be registered before assigning color handler.");
            this.blockColorMap.put(block.delegate, blockColor);
        }
    }
}
 

CumingSoon

Местный стендапер
1,634
12
269
Не вижу метода в методе. Вижу метод в анонимном классе. Собственно, при компиляции всё это развернётся в отдельный класс. Проверь
 

deleted.user

Мошенник
321
43
Код:
Can not find target method of hook AsmHook: net.minecraft.client.gui.inventory.GuiContainer#handleMouseClick(Lnet/minecraft/inventory/Slot;III) -> ua.agravaine.advancediteminfo.asm.AdvancedItemInfoHooks#handleMouseClick(Lnet/minecraft/client/gui/inventory/GuiContainer;Lnet/minecraft/inventory/Slot;III)Z, ReturnCondition=ON_TRUE, ReturnValue=HOOK_RETURN_VALUE, InjectorFactory: ua.agravaine.hooklib.asm.HookInjectorFactory$MethodEnter, CreateMethod = false

А у меня вот такая вот ересь вылезает. Хотя и в моде и в хуклибе лежит методс.бин, который я генерировал с mcp 908, для 1.7.10.

Ну и сам класс, собственно.
Java:
public class AdvancedItemInfoHooks {

    @Hook(returnCondition = ReturnCondition.ON_TRUE)
    public static boolean handleMouseClick(GuiContainer gui, Slot slot, int slotIndex, int mouseButton, int clickType) {
        if (slot != null && mouseButton == 1 && !isSplitKeyDown()) {
            ItemStack stack = slot.getStack();
            ItemInfo info = AdvancedItemInfoMod.getInfoFromItem(stack);
            if (stack != null && info != null && Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) {
                ContextMenu menu = ContextMenu.getInstance();
                int mouseX = Mouse.getEventX() * gui.width / gui.mc.displayWidth;
                int mouseY = gui.height - Mouse.getEventY() * gui.height / gui.mc.displayHeight - 1;
                menu.setX(mouseX);
                menu.setY(mouseY);
                menu.setTarget(slot);

                MenuItem item = menu.getItem(ContextMenu.MENU_ITEM_INSURE_ID);
                if (ArrayUtils.isEmpty(info.getInsure()) || AdvancedItemInfoMod.isItemHas(stack, AdvancedItemInfoMod.NBT_NO_DROP_KEY)) {
                    item.hide();
                }

                menu.show();
                return true;
            }
        }
        return false;
    }

    @Hook(returnCondition = ReturnCondition.ON_TRUE)
    public static boolean mouseClicked(GuiContainer gui, int mouseX, int mouseY, int mouseButton) {
        ContextMenu menu = ContextMenu.getInstance();
        boolean clicked = menu.mouseClicked(mouseX, mouseY, mouseButton);
        if (!clicked) {
            menu.close();
        }
        return clicked;
    }

    @Hook(injectOnExit = true)
    public static void drawScreen(GuiContainer gui, int mouseX, int mouseY, float ticks) {
        RenderHelper.disableStandardItemLighting();
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_DEPTH_TEST);

        ContextMenu menu = ContextMenu.getInstance();
        menu.draw(mouseX, mouseY);

        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        RenderHelper.enableStandardItemLighting();
    }

    @Hook
    public static void onGuiClosed(GuiContainer gui) {
        ContextMenu.getInstance().close();
    }

    public static boolean isSplitKeyDown() {
        return Minecraft.isRunningOnMac ? Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220) : Keyboard.isKeyDown(Keyboard.KEY_Z) || Keyboard.isKeyDown(Keyboard.KEY_Z);
    }
}
 
808
3
124
Код:
Can not find target method of hook AsmHook: net.minecraft.client.gui.inventory.GuiContainer#handleMouseClick(Lnet/minecraft/inventory/Slot;III) -> ua.agravaine.advancediteminfo.asm.AdvancedItemInfoHooks#handleMouseClick(Lnet/minecraft/client/gui/inventory/GuiContainer;Lnet/minecraft/inventory/Slot;III)Z, ReturnCondition=ON_TRUE, ReturnValue=HOOK_RETURN_VALUE, InjectorFactory: ua.agravaine.hooklib.asm.HookInjectorFactory$MethodEnter, CreateMethod = false

А у меня вот такая вот ересь вылезает. Хотя и в моде и в хуклибе лежит методс.бин, который я генерировал с mcp 908, для 1.7.10.

Ну и сам класс, собственно.
Java:
public class AdvancedItemInfoHooks {

    @Hook(returnCondition = ReturnCondition.ON_TRUE)
    public static boolean handleMouseClick(GuiContainer gui, Slot slot, int slotIndex, int mouseButton, int clickType) {
        if (slot != null && mouseButton == 1 && !isSplitKeyDown()) {
            ItemStack stack = slot.getStack();
            ItemInfo info = AdvancedItemInfoMod.getInfoFromItem(stack);
            if (stack != null && info != null && Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) {
                ContextMenu menu = ContextMenu.getInstance();
                int mouseX = Mouse.getEventX() * gui.width / gui.mc.displayWidth;
                int mouseY = gui.height - Mouse.getEventY() * gui.height / gui.mc.displayHeight - 1;
                menu.setX(mouseX);
                menu.setY(mouseY);
                menu.setTarget(slot);

                MenuItem item = menu.getItem(ContextMenu.MENU_ITEM_INSURE_ID);
                if (ArrayUtils.isEmpty(info.getInsure()) || AdvancedItemInfoMod.isItemHas(stack, AdvancedItemInfoMod.NBT_NO_DROP_KEY)) {
                    item.hide();
                }

                menu.show();
                return true;
            }
        }
        return false;
    }

    @Hook(returnCondition = ReturnCondition.ON_TRUE)
    public static boolean mouseClicked(GuiContainer gui, int mouseX, int mouseY, int mouseButton) {
        ContextMenu menu = ContextMenu.getInstance();
        boolean clicked = menu.mouseClicked(mouseX, mouseY, mouseButton);
        if (!clicked) {
            menu.close();
        }
        return clicked;
    }

    @Hook(injectOnExit = true)
    public static void drawScreen(GuiContainer gui, int mouseX, int mouseY, float ticks) {
        RenderHelper.disableStandardItemLighting();
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_DEPTH_TEST);

        ContextMenu menu = ContextMenu.getInstance();
        menu.draw(mouseX, mouseY);

        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        RenderHelper.enableStandardItemLighting();
    }

    @Hook
    public static void onGuiClosed(GuiContainer gui) {
        ContextMenu.getInstance().close();
    }

    public static boolean isSplitKeyDown() {
        return Minecraft.isRunningOnMac ? Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220) : Keyboard.isKeyDown(Keyboard.KEY_Z) || Keyboard.isKeyDown(Keyboard.KEY_Z);
    }
}

Только в собранном виде не работает? Точно-точно уверен что с methods.bin всё в порядке?
 
808
3
124
Чекнул mcp908. В methods.csv там нет метода handleMouseClick. Твой воркспейс сгенерирован на базе какого-то другого mcp. В качестве костыля можешь завести второй хук-метод с srg названием (вида func_12345_X), но лучше разберись, из чего сделан твой воркспейс.
 

deleted.user

Мошенник
321
43
Чекнул mcp908. В methods.csv там нет метода handleMouseClick. Твой воркспейс сгенерирован на базе какого-то другого mcp. В качестве костыля можешь завести второй хук-метод с srg названием (вида func_12345_X), но лучше разберись, из чего сделан твой воркспейс.

В общем даже выдернув methods.csv из среды - ничего не вышло. Попробую второй хук метод завести, может и поможет.
 

deleted.user

Мошенник
321
43
Java:
[DEBUG] Injecting hooks into class net.minecraft.client.gui.inventory.GuiContainer
[DEBUG] Patching method net.minecraft.client.gui.inventory.GuiContainer#drawScreen(IIF)
[DEBUG] Patching method net.minecraft.client.gui.inventory.GuiContainer#mouseClicked(III)
[DEBUG] Patching method net.minecraft.client.gui.inventory.GuiContainer#func_146984_a(Lnet/minecraft/inventory/Slot;III)
[DEBUG] Patching method net.minecraft.client.gui.inventory.GuiContainer#handleMouseClick(Lnet/minecraft/inventory/Slot;III)
[DEBUG] Patching method net.minecraft.client.gui.inventory.GuiContainer#onGuiClosed()

На левом клиенте все вроде бы даже патчится, но так вышло, что я юзаю паленого второго сашка и в нем гемороно, в плане изменения клиента. Но это не суть. Суть в том, что даже после того как все пропатчилось - в игре нет никакого результата. С чем это может быть связано? Хотя все тоже самое ИДЕАЛЬНО работает в IDE.
 
Сверху