RecipeTELib — различия между версиями

м
м
Строка 179: Строка 179:
 
=== Электрическая(редстоун сигнал) печь ===
 
=== Электрическая(редстоун сигнал) печь ===
  
 +
<div class="mw-parser-output">
 
<div class="mw-parser-output">
 
<div class="mw-parser-output">
 
==== Создание печи ====
 
==== Создание печи ====
Строка 199: Строка 200:
 
Затем создаем наш интерфейс:
 
Затем создаем наш интерфейс:
 
<blockquote>
 
<blockquote>
<span style="font-size:small;">!ВАЖНО!: Слоты, в которые нужно ложить предмет нужна ОБЯЗАТЕЛЬНО называть "inputSlot"+ порядковое число слота, начиная с нуля. Слот результата должен иметь название "outputSlot", так же стоит задавть isValid для outputSlot как RecipeTE.outputSlotValid</span>
+
<span style="font-size:small;">'''!ВАЖНО!:''' Слоты, в которые нужно ложить предмет нужна ОБЯЗАТЕЛЬНО называть ''"'''inputSlot'''"''+ '''порядковое число '''слота, начиная с нуля. Слот результата должен иметь название "'''''outputSlot'''''", так же стоит задавть '''''isValid'''''для outputSlot как '''''RecipeTE.outputSlotValid'''''</span>
 
</blockquote> <syntaxhighlight lang="JavaScript">var Furnace = new UI.StandartWindow({
 
</blockquote> <syntaxhighlight lang="JavaScript">var Furnace = new UI.StandartWindow({
 
    standart: {
 
    standart: {
Строка 230: Строка 231:
 
});</syntaxhighlight>
 
});</syntaxhighlight>
  
Затем регистрируем наш верстак, есть два способа:
+
Затем регистрируем наш верстак(печь), есть два способа:
  
*RecipeTE.registerTimerCraftTable(description);  
+
*'''RecipeTE.registerTimerCraftTable(description);'''
 
<syntaxhighlight lang="JavaScript">RecipeTE.registerTimerCraftTable({
 
<syntaxhighlight lang="JavaScript">RecipeTE.registerTimerCraftTable({
 
    name:"Furnace",
 
    name:"Furnace",
 
    cols:1,
 
    cols:1,
 
    timer:5*20
 
    timer:5*20
});</syntaxhighlight>
+
});
 
+
</syntaxhighlight>
&nbsp;
 
  
*​​RecipeTE.registerTimerCraftTable(name, columns, timer);  
+
*'''​​RecipeTE.registerTimerCraftTable(name, columns, timer);'''
 
<syntaxhighlight lang="JavaScript">RecipeTE.registerTimerCraftTable("Furnace", 1, 5*20);</syntaxhighlight>
 
<syntaxhighlight lang="JavaScript">RecipeTE.registerTimerCraftTable("Furnace", 1, 5*20);</syntaxhighlight>
  
Строка 260: Строка 260:
 
        });
 
        });
 
    }
 
    }
});
+
});</syntaxhighlight>
</syntaxhighlight>
+
<div class="mw-parser-output"><div class="mw-parser-output">&nbsp;</div> </div> </div>
</div>
 
  
<div class="mw-parser-output">
 
<div class="mw-parser-output">
 
 
==== Создание рецептов для печи ====
 
==== Создание рецептов для печи ====
  

Версия 23:16, 21 июня 2019

RecipeTELib - библиотека, упрощающая создание верстаков и печей.

Условия использования

  • Запрещено распространение на сторонних источниках без указания ссылки на официальное сообщество
  • Запрещено изменение кода библиотеки
  • Запрещено явное копирование кода в другие библиотеки или моды 

Используя данный продукт вы автоматически соглашаетесь с этими правилами

Документация

Инициализация

Импортируйте библиотеку.

IMPORT("RecipeTileEntityLib")

Верстак

Создание верстака

Для начала создаем блок:

IDRegistry.genBlockID("Workbench_Grid");
Block.createBlock("Workbench_Grid", [{
    name: "Workbench Grid", 
    texture: [
        ["work_table_bottom", 0], // bottom
        ["work_table_top", 0], // top
        ["work_table_side", 0], // back
        ["work_table_side", 1], // front
        ["work_table_side", 0], // left
        ["work_table_side", 0]  // right
    ], 
    inCreative: true 
}]);

Затем создаем наш интерфейс:

!ВАЖНО!: Слоты, в которые нужно ложить предмет нужна ОБЯЗАТЕЛЬНО называть "inputSlot"+ порядковое число слота, начиная с нуля. Слот результата должен иметь название "outputSlot", так же стоит задавть isValid для outputSlot как RecipeTE.outputSlotValid

var Workbench_Grid = new UI.StandartWindow({
    standart: {
        header: {text: {text: "Workbench Grid 4x4"}},
        inventory: {standart:true},
        background: {standart: true}
    },
    drawing: [{
        type: "bitmap",
        bitmap: "arrow",
        x: 600,
        y: 170, scale: 4
    }],
    elements:{
        "inputSlot0":{x:350, y:80, type:"slot"},
        "inputSlot1":{x:410, y:80, type:"slot"},
        "inputSlot2":{x:470, y:80, type:"slot"},
        "inputSlot3":{x:530, y:80, type:"slot"},

        "inputSlot4":{x:350, y:140, type:"slot"},
        "inputSlot5":{x:410, y:140, type:"slot"},
        "inputSlot6":{x:470, y:140, type:"slot"},
        "inputSlot7":{x:530, y:140, type:"slot"},

        "inputSlot8":{x:350, y:200, type:"slot"},
        "inputSlot9":{x:410, y:200, type:"slot"},
        "inputSlot10":{x:470, y:200, type:"slot"},
        "inputSlot11":{x:530, y:200, type:"slot"},

        "inputSlot12":{x:350, y:260, type:"slot"},
        "inputSlot13":{x:410, y:260, type:"slot"},
        "inputSlot14":{x:470, y:260, type:"slot"},
        "inputSlot15":{x:530, y:260, type:"slot"},

        "outputSlot":{x:698, y:170, type:"slot", isValid:RecipeTE.outputSlotValid }
    }
});

Затем регистрируем наш верстак, есть два способа:

  • RecipeTE.registerGridCraftTable(description);
RecipeTE.registerGridCraftTable({
    name:"Workbench_Grid",
    rows:4,
    cols:4
});
  • ​​RecipeTE.registerGridCraftTable(name, columns, rows);
RecipeTE.registerGridCraftTable("Workbench_Grid", 4, 4);

Теперь нам следует зарегистрировать TileEntity. В getGuiScreen мы возвращаем наше окно. В методе тика мы вызываем RecipeTE.getTickResipes(name, TileEntity) :

TileEntity.registerPrototype(BlockID["Workbench_Grid"], {
    getGuiScreen: function(){
        return Workbench_Grid;
    },
    
    tick:function(){
        RecipeTE.getTickResipes("Workbench_Grid", this);
    }  
});

Создание рецептов для верстака

Создание рецептов для верстака с сеткой происходит через метод RecipeTE.addGridRecipe(name_workbench, result, recipe, ingredients), где:

  • name_workbench - имя верстака
  • result - объект результата
    • id - ID предмета
    • count - Кол-во предмета
    • data - Дата предмета
  • recipe - Массив строк крафта
  • ingredients - объект ингредиентов
RecipeTE.addGridRecipe("Workbench_Grid", {
    id:280,
    count:1
},
[   "aa",
    "aa"
], {
    a:{
        id:5
    }
});

RecipeTE.addGridRecipe("Workbench_Grid", {
    id: 281,
    count: 1
},
[   "aaaa",
    "a  a",
    "a  a",
    "aaaa"
], {
    a: {
        id: 1,
        data:0
    }
});

 

Электрическая(редстоун сигнал) печь

Создание печи

Для начала создаем блок:

IDRegistry.genBlockID("Furnace");
Block.createBlockWithRotation("Furnace", [{
    name: "Furnace", 
    texture: [
        ["iron_furnace_bottom", 0], // bottom
        ["iron_furnace_top", 0], // top
        ["iron_furnace_side", 0], // back
        ["iron_furnace_front", 0], // front
        ["iron_furnace_side", 0], // left
        ["iron_furnace_side", 0]  // right
    ], 
    inCreative: true 
}]);

Затем создаем наш интерфейс:

!ВАЖНО!: Слоты, в которые нужно ложить предмет нужна ОБЯЗАТЕЛЬНО называть "inputSlot"+ порядковое число слота, начиная с нуля. Слот результата должен иметь название "outputSlot", так же стоит задавть isValidдля outputSlot как RecipeTE.outputSlotValid

var Furnace = new UI.StandartWindow({
    standart: {
        header: {text: {text: "Furnace"}},
        inventory: {standart:true},
        background: {standart: true}
    },
    drawing: [{
        type: "bitmap",
        bitmap: "arrow",
        x: 600,
        y: 170,
        scale: 4
    }],
    elements:{
        "inputSlot0":{x:530, y:170, type:"slot"},
        
        "outputSlot":{x:698, y:170, type:"slot", isValid:RecipeTE.outputSlotValid },

        "timerScale":{
            type: "scale",
            x: 600,
            y: 170,
            direction:0,
            value: .5,
            bitmap: "arrow_scale",
            scale: 4
        }
    }
});

Затем регистрируем наш верстак(печь), есть два способа:

  • RecipeTE.registerTimerCraftTable(description);
RecipeTE.registerTimerCraftTable({
    name:"Furnace",
    cols:1,
    timer:5*20
});
  • ​​RecipeTE.registerTimerCraftTable(name, columns, timer);
RecipeTE.registerTimerCraftTable("Furnace", 1, 5*20);

Теперь нам следует зарегистрировать TileEntity. В getGuiScreen мы возвращаем наше окно. В методе redstone мы будем проверять, сльный ли редстоун-сигнал и включать машину. В методе тика мы вызываем RecipeTE.getTickResipes(name, TileEntity, condition) с нашим условием:

TileEntity.registerPrototype(BlockID["Furnace"], {
    getGuiScreen: function(){
        return Furnace;
    },
    redstone: function(params){
        if(params.power < 10)
            this.data.power = false;
        else
            this.data.power = true;
    },
    tick:function(){
        RecipeTE.getTickResipes("Furnace", this, function(TE){
            return TE.data.power;
        });
    }
});
 

Создание рецептов для печи

Создание рецептов для верстака(печи) без сетки происходит через метод RecipeTE.addRecipe(name_workbench, result, recipe, ingredients), где:

  • name_workbench - имя верстака
  • result - объект результата
    • id - ID предмета
    • count - Кол-во предмета
    • data - Дата предмета
  • recipe - Строка крафта
  • ingredients - объект ингредиентов
RecipeTE.addRecipe("Furnace", {id:280, count:1}, "a", {a:{id:5}});

Полная документация