Редактирование:Пример создания моба

Внимание! Вы не авторизовались на сайте. Ваш IP-адрес будет публично видимым, если вы будете вносить любые правки. Если вы войдёте или создадите учётную запись, правки вместо этого будут связаны с вашим именем пользователя, а также у вас появятся другие преимущества.

Правка может быть отменена. Пожалуйста, просмотрите сравнение версий, чтобы убедиться, что это именно те изменения, которые вас интересуют, и нажмите «Записать страницу», чтобы изменения вступили в силу.
Текущая версия Ваш текст
Строка 1: Строка 1:
<syntaxhighlight lang="Javascript">MobSpawnRegistry.registerSpawn("bird-blue", .2); // относительно редкий спавн птицы
 
var blue_bird_texture = new Texture("bird_blue.png"); // создадим объект текстуры
 
blue_bird_texture.setResolution(128, 64); // зададим разрешение
 
blue_bird_texture.setPixelScale(2); // установим масштабирование
 
/* Так же этот код можно записать короче, в таком формате: var blue_bird_texture = new Texture("bird_blue.png").setResolution(128, 64).setPixelScale(2);*/
 
var blue_bird_texture = new Texture("bird_blue.png").setResolution(128, 64).setPixelScale(2);// загружаем текстуру и задаем ей разрешение и масштабирование.
 
var blue_bird_model = new EntityModel(); // создаем модель нашей птицы
 
blue_bird_model.setTexture(blue_bird_texture);// устанавливаем ей текстуру // создаем анимацию модели: она будет содержать 16 кадров, каждый из которых будет занимать 0.5 тика (1 цикл = 1 взмах крыльев = 8 тиков)
 
blue_bird_model.createAnimation(16, function(frame) { // создание кадра
 
    var render = new Render(); // создаем рендер
 
    var partObj = [ // создаем объект, описывающий часть body, в нашем случае это вся модель
 
        {
 
            type: "box",
 
            coords: {
 
                x: 0,
 
                y: 16,
 
                z: 0
 
            },
 
            size: {
 
                x: 5,
 
                y: 4,
 
                z: 9
 
            },
 
            uv: {
 
                x: 20,
 
                y: 0
 
            }
 
        },// тело
 
        {
 
            type: "box",
 
            coords: {
 
                x: 0,
 
                y: 14,
 
                z: -4
 
            },
 
            size: {
 
                x: 4,
 
                y: 4,
 
                z: 6
 
            },
 
            uv: {
 
                x: 0,
 
                y: 0
 
            }
 
        }, // голова
 
        {
 
            type: "box",
 
            coords: {
 
                x: 0,
 
                y: 14,
 
                z: -6.5
 
            },
 
            size: {
 
                x: 1,
 
                y: 1,
 
                z: 3
 
            },
 
            uv: {
 
                x: 0,
 
                y: 16
 
            }
 
        }, // клюв
 
        {
 
            type: "box",
 
            coords: {
 
                x: 0,
 
                y: 14,
 
                z: 6
 
            },
 
            size: {
 
                x: 3,
 
                y: 1,
 
                z: 8
 
            },
 
            uv: {
 
                x: 20,
 
                y: 0
 
            }
 
        }, // хвост
 
        {
 
            type: "box",
 
            coords: {
 
                x: 0,
 
                y: 20,
 
                z: 0
 
            },
 
            size: {
 
                x: 3,
 
                y: 4,
 
                z: 1
 
            },
 
            uv: {
 
                x: 0,
 
                y: 11
 
            }
 
        }, // ноги
 
    ]; // крылья - более сложная структура и она генерируется в цикле, при том именно крылья меняют свое положение каждый кадр.
 
    var position = Math.sin(frame / 16 * Math.PI * 2); // рассчитываем позицию крыльев - синус здесь принимает значения от 0 до 2 * pi и поэтому проходит 1 период, принимая значения от -1 до 1, что нам и нужно (взмахи)
 
    for (var i = 0; i < 5; i++) { // каждое крыло состоит из 5 частей, чем дальше от тела часть, тем сильнее изменение позиции и тем меньше эта часть по длине
 
        partObj.push({
 
            type: "box",
 
            size: {
 
                x: 1,
 
                y: 1,
 
                z: 8 - i
 
            },
 
            uv: {
 
                x: 20,
 
                y: 0
 
            },
 
            coords: {
 
                x: 2.5 + i,
 
                y: position * i + 15,
 
                z: 0
 
            }
 
        }); // правое крыло
 
        partObj.push({
 
            type: "box",
 
            size: {
 
                x: 1,
 
                y: 1,
 
                z: 8 - i
 
            },
 
            uv: {
 
                x: 20,
 
                y: 0
 
            },
 
            coords: {
 
                x: -2.5 - i,
 
                y: position * i + 15,
 
                z: 0
 
            }
 
        }); // левое крыло
 
    }
 
    render.setPart("head", partObj, {});// устанавливаем наше описание части в рендер
 
    return render;// возвращаем рендер для данного кадра
 
}, 0.5);
 
  
var entityTypeBird = MobRegistry.registerEntity("bird-blue"); // создаем тип моба - птицу  
+
MobSpawnRegistry.registerSpawn("bird-blue", .2); ''// относительно редкий спавн птицы''<br/> var blue_bird_texture = new Texture("bird_blue.png"); ''// создадим объект текстуры''<br/> blue_bird_texture.setResolution(128, 64); ''// зададим разрешение&nbsp;''<br/> blue_bird_texture.setPixelScale(2); ''// установим масштабирование&nbsp;''<br/> ''/* Так же этот код можно записать короче, в таком формате: ''var blue_bird_texture = new Texture("bird_blue.png").setResolution(128, 64).setPixelScale(2);''*/''<br/> var blue_bird_texture = new Texture("bird_blue.png").setResolution(128, 64).setPixelScale(2);''// загружаем текстуру и задаем ей разрешение и масштабирование. ''<br/> var blue_bird_model = new EntityModel(); ''// создаем модель нашей птицы&nbsp;''<br/> blue_bird_model.setTexture(blue_bird_texture);''// устанавливаем ей текстуру // создаем анимацию модели: она будет содержать 16 кадров, каждый из которых будет занимать 0.5 тика (1 цикл = 1 взмах крыльев = 8 тиков)&nbsp;''<br/> blue_bird_model.createAnimation(16, function(frame) { ''// создание кадра&nbsp;''<br/> &nbsp; &nbsp; var render = new Render(); ''// создаем рендер&nbsp;''<br/> &nbsp; &nbsp; var partObj = [ ''// создаем объект, описывающий часть body, в нашем случае это вся модель''<br/> &nbsp; &nbsp; &nbsp; &nbsp; {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "box",<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coords: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 0,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 16,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 5,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 4,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 9<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uv: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 20,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp; &nbsp; &nbsp; },''// тело&nbsp;''<br/> &nbsp; &nbsp; &nbsp; &nbsp; {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "box",<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coords: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 0,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 14,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: -4<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 4,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 4,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 6<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uv: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 0,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp; &nbsp; &nbsp; }, ''// голова&nbsp;''<br/> &nbsp; &nbsp; &nbsp; &nbsp; {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "box",<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coords: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 0,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 14,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: -6.5<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 1,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 1,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 3<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uv: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 0,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 16<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp; &nbsp; &nbsp; }, ''// клюв''<br/> &nbsp; &nbsp; &nbsp; &nbsp; {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "box",<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coords: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 0,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 14,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 6<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 3,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 1,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 8<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uv: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 20,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp; &nbsp; &nbsp; }, ''// хвост''&nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "box",<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coords: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 0,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 20,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 3,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 4,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 1<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uv: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 0,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 11<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp; &nbsp; &nbsp; }, ''// ноги&nbsp;''<br/> &nbsp; &nbsp; ]; ''// крылья - более сложная структура и она генерируется в цикле, при том именно крылья меняют свое положение каждый кадр.&nbsp;''<br/> &nbsp; &nbsp; var position = Math.sin(frame / 16 * Math.PI * 2); ''// рассчитываем позицию крыльев - синус здесь принимает значения от 0 до 2 * pi и поэтому проходит 1 период, принимая значения от -1 до 1, что нам и нужно (взмахи)&nbsp;''<br/> &nbsp; &nbsp; for (var i = 0; i < 5; i++) { ''// каждое крыло состоит из 5 частей, чем дальше от тела часть, тем сильнее изменение позиции и тем меньше эта часть по длине&nbsp;''<br/> &nbsp; &nbsp; &nbsp; &nbsp; partObj.push({<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "box",<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 1,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 1,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 8 - i<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uv: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 20,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coords: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 2.5 + i,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: position * i + 15,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp; &nbsp; &nbsp; }); ''// правое крыло&nbsp;''<br/> &nbsp; &nbsp; &nbsp; &nbsp; partObj.push({<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "box",<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 1,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 1,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 8 - i<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uv: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: 20,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coords: {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: -2.5 - i,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: position * i + 15,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z: 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp; &nbsp; &nbsp; }); ''// левое крыло&nbsp;''<br/> &nbsp; &nbsp; }<br/> &nbsp; &nbsp; render.setPart("head", partObj, {});''// устанавливаем наше описание части в рендер''&nbsp;<br/> &nbsp; &nbsp; return render;''// возвращаем рендер для данного кадра''<br/> }, 0.5);
entityTypeBird.customizeVisual({ // задаем нашу модель как основную (будет установлена при старте)  
+
 
    getModels: function() {
+
var entityTypeBird = MobRegistry.registerEntity("bird-blue"); ''// создаем тип моба - птицу&nbsp;''<br/> entityTypeBird.customizeVisual({ ''// задаем нашу модель как основную (будет установлена при старте)&nbsp;''<br/> &nbsp; &nbsp; getModels: function() {<br/> &nbsp; &nbsp; &nbsp; &nbsp; return {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "main": blue_bird_model<br/> &nbsp; &nbsp; &nbsp; &nbsp; };<br/> &nbsp; &nbsp; }<br/> });<br/> entityTypeBird.customizeDescription({''// кроме этого задаем размер хитбокса птице, чтобы он был поменьше&nbsp;''<br/> &nbsp; &nbsp; getHitbox: function() {<br/> &nbsp; &nbsp; &nbsp; &nbsp; return {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w: 0.3,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h: 0.3<br/> &nbsp; &nbsp; &nbsp; &nbsp; };<br/> &nbsp; &nbsp; }<br/> });<br/> Item.registerUseFunctionForID(280, function(coords, item, block) {<br/> &nbsp; &nbsp; coords = coords.relative;<br/> &nbsp; &nbsp; Entity.spawnCustom("bird-blue", coords.x + .5, coords.y + .5, coords.z + .5);<br/> });
        return {
 
            "main": blue_bird_model
 
        };
 
    }
 
});
 
entityTypeBird.customizeDescription({// кроме этого задаем размер хитбокса птице, чтобы он был поменьше  
 
    getHitbox: function() {
 
        return {
 
            w: 0.3,
 
            h: 0.3
 
        };
 
    }
 
});
 
Item.registerUseFunctionForID(280, function(coords, item, block) {
 
    coords = coords.relative;
 
    Entity.spawnCustom("bird-blue", coords.x + .5, coords.y + .5, coords.z + .5);
 
});</syntaxhighlight>
 

Обратите внимание, что все добавления и изменения текста статьи рассматриваются как выпущенные на условиях лицензии GNU Free Documentation License 1.3 или более поздняя (см. Mineprogramming wiki:Авторские права). Если вы не хотите, чтобы ваши тексты свободно распространялись и редактировались любым желающим, не помещайте их сюда.
Вы также подтверждаете, что являетесь автором вносимых дополнений или скопировали их из источника, допускающего свободное распространение и изменение своего содержимого.
НЕ РАЗМЕЩАЙТЕ БЕЗ РАЗРЕШЕНИЯ МАТЕРИАЛЫ, ОХРАНЯЕМЫЕ АВТОРСКИМ ПРАВОМ!