IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Vous êtes nouveau sur Developpez.com ? Créez votre compte ou connectez-vous afin de pouvoir participer !

Vous devez avoir un compte Developpez.com et être connecté pour pouvoir participer aux discussions.

Vous n'avez pas encore de compte Developpez.com ? Créez-en un en quelques instants, c'est entièrement gratuit !

Si vous disposez déjà d'un compte et qu'il est bien activé, connectez-vous à l'aide du formulaire ci-dessous.

Identifiez-vous
Identifiant
Mot de passe
Mot de passe oublié ?
Créer un compte

L'inscription est gratuite et ne vous prendra que quelques instants !

Je m'inscris !

L'API Scripting de Minecraft, qui permet la création d'add-on, passe en bêta publique
Et n'est disponible que pour les bêta testeurs sur Windows 10

Le , par Stéphane le calme

592PARTAGES

15  0 
L'arrivée du Scripting API s'est accompagnée d'une expérience de modding sur Minecraft. Pour rappel, le modding, dans le monde des jeux vidéo, consiste à ajouter, modifier ou purger du contenu sur un jeu vidéo, en particulier sur un ordinateur. Les mods peuvent être des quêtes, des objets, des maisons pour le joueur, des villes, des magasins, des factions ou des modifications techniques (scripts, textures, mailles). Il existe également des mods de conversion totale, qui sont des mods à un degré bien plus important.


Le moteur de script Minecraft utilise le langage JavaScript. Vous pouvez écrire des scripts JavaScript et les associer à Behavior Packs pour écouter et répondre aux événements du jeu, obtenir et modifier des données dans des composants appartenant à des entités et affecter différentes parties du jeu.

Dans un billet de blog, Tom Stone, assistant de communication créatif chez Mojang AB (la société à l’origine de Minecraft), a expliqué que Scripting API est désormais en bêta publique.

Citation Envoyé par Tom Stone
Avez-vous déjà souhaité que Minecraft ait des combats de type tour par tour ? Ou que vous puissiez jouer aux échecs dans Minecraft ? Ou que je cesserais d'ouvrir ces articles avec des questions rhétoriques et que j'aille à l’essentiel pour une fois ? Toutes ces choses sont possibles et bien plus encore, maintenant que l’API de script est disponible dans la version bêta publique de Minecraft!

Mais qu'est-ce que l'API (Application Programming Interface) de script ? C’est essentiellement l’art d’améliorer l’intérieur d’un jeu - d’écrire de nouvelles commandes dans les entrailles textuelles de Minecraft pour modifier le jeu. Le moteur de script Minecraft utilise le langage JavaScript. Les scripts peuvent être écrits et associés à Behavior Packs pour écouter et répondre aux événements du jeu, obtenir (et modifier) des données dans les composants des entités et affecter différentes parties du jeu.

Ci-dessous, une vidéo qui montre quelques utilisations de cette API.

Citation Envoyé par Tom Stone
Les génies du tout-puissant Wiki de Minecraft possèdent une multitude de guides de référence et d'échantillons. Ils ont également un excellent guide qui explique les scripts dans Minecraft mieux que je ne pourrais jamais (malheureusement, je suis trop bête pour comprendre les scripts, les modding ou même comment activer le mode créatif. C’est pourquoi je ne suis pas autorisé à me situer dans un rayon de 15 mètres des vrais développeurs de Minecraft et que je dois plutôt me contenter d’écrire des bêtises pour ce site charmant, ce qui me convient parfaitement).

Les joueurs de Minecraft: Java Edition modulent le jeu depuis toujours, et c’est notre première étape pour créer une configuration similaire pour les joueurs de Minecraft sur d’autres plateformes !

Actuellement, c’est seulement une fonctionnalité à laquelle les bêta testeurs de Minecraft sur Windows 10 peuvent accéder.

Rappelons que, depuis peu, certaines parties du moteur du jeu vidéo sont disponibles sous licence MIT. Ce choix du studio de développement permet à chaque développeur de s’approprier le code, le modifier et le distribuer, ce, à la seule condition de publier les nouveaux contenus avec la note de copyright initiale. L’équipe Mojang devrait ainsi engranger des contributions de nature à améliorer le moteur de jeu.

C'est dans ce contexte qu'en octobre dernier, le studio de développement Mojang a ouvert Brigadier et DataFixerUpper. Sous Minecraft, le gamer dispose d’une ligne de commandes – des instructions sous forme de texte qui débutent avec le caractère /. Brigadier est la bibliothèque qui assure la conversion de ce texte en une fonction que le jeu va exécuter. « Beaucoup de personnes pensent qu’il s’agit d’une fonctionnalité aisée à implémenter, mais il n’en est rien », expliquent les développeurs. Le code de la portion chargée de lire la chaîne de caractère illustre l’ardeur de la tâche.

[CODE=Java]// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

package com.mojang.brigadier;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.junit.Test;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

public class StringReaderTest {
@Test
public void canRead() throws Exception {
final StringReader reader = new StringReader("abc");
assertThat(reader.canRead(), is(true));
reader.skip(); // 'a'
assertThat(reader.canRead(), is(true));
reader.skip(); // 'b'
assertThat(reader.canRead(), is(true));
reader.skip(); // 'c'
assertThat(reader.canRead(), is(false));
}

@Test
public void getRemainingLength() throws Exception {
final StringReader reader = new StringReader("abc");
assertThat(reader.getRemainingLength(), is(3));
reader.setCursor(1);
assertThat(reader.getRemainingLength(), is(2));
reader.setCursor(2);
assertThat(reader.getRemainingLength(), is(1));
reader.setCursor(3);
assertThat(reader.getRemainingLength(), is(0));
}

@Test
public void canRead_length() throws Exception {
final StringReader reader = new StringReader("abc");
assertThat(reader.canRead(1), is(true));
assertThat(reader.canRead(2), is(true));
assertThat(reader.canRead(3), is(true));
assertThat(reader.canRead(4), is(false));
assertThat(reader.canRead(5), is(false));
}

@Test
public void peek() throws Exception {
final StringReader reader = new StringReader("abc");
assertThat(reader.peek(), is('a'));
assertThat(reader.getCursor(), is(0));
reader.setCursor(2);
assertThat(reader.peek(), is('c'));
assertThat(reader.getCursor(), is(2));
}

@Test
public void peek_length() throws Exception {
final StringReader reader = new StringReader("abc");
assertThat(reader.peek(0), is('a'));
assertThat(reader.peek(2), is('c'));
assertThat(reader.getCursor(), is(0));
reader.setCursor(1);
assertThat(reader.peek(1), is('c'));
assertThat(reader.getCursor(), is(1));
}

@Test
public void read() throws Exception {
final StringReader reader = new StringReader("abc");
assertThat(reader.read(), is('a'));
assertThat(reader.read(), is('b'));
assertThat(reader.read(), is('c'));
assertThat(reader.getCursor(), is(3));
}

@Test
public void skip() throws Exception {
final StringReader reader = new StringReader("abc");
reader.skip();
assertThat(reader.getCursor(), is(1));
}

@Test
public void getRemaining() throws Exception {
final StringReader reader = new StringReader("Hello!");
assertThat(reader.getRemaining(), equalTo("Hello!"));
reader.setCursor(3);
assertThat(reader.getRemaining(), equalTo("lo!"));
reader.setCursor(6);
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void getRead() throws Exception {
final StringReader reader = new StringReader("Hello!");
assertThat(reader.getRead(), equalTo(""));
reader.setCursor(3);
assertThat(reader.getRead(), equalTo("Hel"));
reader.setCursor(6);
assertThat(reader.getRead(), equalTo("Hello!"));
}

@Test
public void skipWhitespace_none() throws Exception {
final StringReader reader = new StringReader("Hello!");
reader.skipWhitespace();
assertThat(reader.getCursor(), is(0));
}

@Test
public void skipWhitespace_mixed() throws Exception {
final StringReader reader = new StringReader(" \t \t\nHello!");
reader.skipWhitespace();
assertThat(reader.getCursor(), is(5));
}

@Test
public void skipWhitespace_empty() throws Exception {
final StringReader reader = new StringReader("");
reader.skipWhitespace();
assertThat(reader.getCursor(), is(0));
}

@Test
public void readUnquotedString() throws Exception {
final StringReader reader = new StringReader("hello world");
assertThat(reader.readUnquotedString(), equalTo("hello"));
assertThat(reader.getRead(), equalTo("hello"));
assertThat(reader.getRemaining(), equalTo(" world"));
}

@Test
public void readUnquotedString_empty() throws Exception {
final StringReader reader = new StringReader("");
assertThat(reader.readUnquotedString(), equalTo(""));
assertThat(reader.getRead(), equalTo(""));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readUnquotedString_empty_withRemaining() throws Exception {
final StringReader reader = new StringReader(" hello world");
assertThat(reader.readUnquotedString(), equalTo(""));
assertThat(reader.getRead(), equalTo(""));
assertThat(reader.getRemaining(), equalTo(" hello world"));
}

@Test
public void readQuotedString() throws Exception {
final StringReader reader = new StringReader("\"hello world\"");
assertThat(reader.readQuotedString(), equalTo("hello world"));
assertThat(reader.getRead(), equalTo("\"hello world\""));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readQuotedString_empty() throws Exception {
final StringReader reader = new StringReader("");
assertThat(reader.readQuotedString(), equalTo(""));
assertThat(reader.getRead(), equalTo(""));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readQuotedString_emptyQuoted() throws Exception {
final StringReader reader = new StringReader("\"\"");
assertThat(reader.readQuotedString(), equalTo(""));
assertThat(reader.getRead(), equalTo("\"\""));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readQuotedString_emptyQuoted_withRemaining() throws Exception {
final StringReader reader = new StringReader("\"\" hello world");
assertThat(reader.readQuotedString(), equalTo(""));
assertThat(reader.getRead(), equalTo("\"\""));
assertThat(reader.getRemaining(), equalTo(" hello world"));
}

@Test
public void readQuotedString_withEscapedQuote() throws Exception {
final StringReader reader = new StringReader("\"hello \\\"world\\\"\"");
assertThat(reader.readQuotedString(), equalTo("hello \"world\""));
assertThat(reader.getRead(), equalTo("\"hello \\\"world\\\"\""));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readQuotedString_withEscapedEscapes() throws Exception {
final StringReader reader = new StringReader("\"\\\\o/\"");
assertThat(reader.readQuotedString(), equalTo("\\o/"));
assertThat(reader.getRead(), equalTo("\"\\\\o/\""));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readQuotedString_withRemaining() throws Exception {
final StringReader reader = new StringReader("\"hello world\" foo bar");
assertThat(reader.readQuotedString(), equalTo("hello world"));
assertThat(reader.getRead(), equalTo("\"hello world\""));
assertThat(reader.getRemaining(), equalTo(" foo bar"));
}

@Test
public void readQuotedString_withImmediateRemaining() throws Exception {
final StringReader reader = new StringReader("\"hello world\"foo bar");
assertThat(reader.readQuotedString(), equalTo("hello world"));
assertThat(reader.getRead(), equalTo("\"hello world\""));
assertThat(reader.getRemaining(), equalTo("foo bar"));
}

@Test
public void readQuotedString_noOpen() throws Exception {
try {
new StringReader("hello world\"").readQuotedString();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedStartOfQuote()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readQuotedString_noClose() throws Exception {
try {
new StringReader("\"hello world").readQuotedString();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedEndOfQuote()));
assertThat(ex.getCursor(), is(12));
}
}

@Test
public void readQuotedString_invalidEscape() throws Exception {
try {
new StringReader("\"hello\\nworld\"").readQuotedString();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidEscape()));
assertThat(ex.getCursor(), is(7));
}
}

@Test
public void readInt() throws Exception {
final StringReader reader = new StringReader("1234567890");
assertThat(reader.readInt(), is(1234567890));
assertThat(reader.getRead(), equalTo("1234567890"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readInt_negative() throws Exception {
final StringReader reader = new StringReader("-1234567890");
assertThat(reader.readInt(), is(-1234567890));
assertThat(reader.getRead(), equalTo("-1234567890"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readInt_invalid() throws Exception {
try {
new StringReader("12.34").readInt();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidInt()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readInt_none() throws Exception {
try {
new StringReader("").readInt();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedInt()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readInt_withRemaining() throws Exception {
final StringReader reader = new StringReader("1234567890 foo bar");
assertThat(reader.readInt(), is(1234567890));
assertThat(reader.getRead(), equalTo("1234567890"));
assertThat(reader.getRemaining(), equalTo(" foo bar"));
}

@Test
public void readInt_withRemainingImmediate() throws Exception {
final StringReader reader = new StringReader("1234567890foo bar");
assertThat(reader.readInt(), is(1234567890));
assertThat(reader.getRead(), equalTo("1234567890"));
assertThat(reader.getRemaining(), equalTo("foo bar"));
}

@Test
public void readLong() throws Exception {
final StringReader reader = new StringReader("1234567890");
assertThat(reader.readLong(), is(1234567890L));
assertThat(reader.getRead(), equalTo("1234567890"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readLong_negative() throws Exception {
final StringReader reader = new StringReader("-1234567890");
assertThat(reader.readLong(), is(-1234567890L));
assertThat(reader.getRead(), equalTo("-1234567890"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readLong_invalid() throws Exception {
try {
new StringReader("12.34").readLong();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidLong()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readLong_none() throws Exception {
try {
new StringReader("").readLong();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedLong()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readLong_withRemaining() throws Exception {
final StringReader reader = new StringReader("1234567890 foo bar");
assertThat(reader.readLong(), is(1234567890L));
assertThat(reader.getRead(), equalTo("1234567890"));
assertThat(reader.getRemaining(), equalTo(" foo bar"));
}

@Test
public void readLong_withRemainingImmediate() throws Exception {
final StringReader reader = new StringReader("1234567890foo bar");
assertThat(reader.readLong(), is(1234567890L));
assertThat(reader.getRead(), equalTo("1234567890"));
assertThat(reader.getRemaining(), equalTo("foo bar"));
}

@Test
public void readDouble() throws Exception {
final StringReader reader = new StringReader("123");
assertThat(reader.readDouble(), is(123.0));
assertThat(reader.getRead(), equalTo("123"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readDouble_withDecimal() throws Exception {
final StringReader reader = new StringReader("12.34");
assertThat(reader.readDouble(), is(12.34));
assertThat(reader.getRead(), equalTo("12.34"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readDouble_negative() throws Exception {
final StringReader reader = new StringReader("-123");
assertThat(reader.readDouble(), is(-123.0));
assertThat(reader.getRead(), equalTo("-123"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readDouble_invalid() throws Exception {
try {
new StringReader("12.34.56").readDouble();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidDouble()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readDouble_none() throws Exception {
try {
new StringReader("").readDouble();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedDouble()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readDouble_withRemaining() throws Exception {
final StringReader reader = new StringReader("12.34 foo bar");
assertThat(reader.readDouble(), is(12.34));
assertThat(reader.getRead(), equalTo("12.34"));
assertThat(reader.getRemaining(), equalTo(" foo bar"));
}

@Test
public void readDouble_withRemainingImmediate() throws Exception {
final StringReader reader = new StringReader("12.34foo bar");
assertThat(reader.readDouble(), is(12.34));
assertThat(reader.getRead(), equalTo("12.34"));
assertThat(reader.getRemaining(), equalTo("foo bar"));
}

@Test
public void readFloat() throws Exception {
final StringReader reader = new StringReader("123");
assertThat(reader.readFloat(), is(123.0f));
assertThat(reader.getRead(), equalTo("123"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readFloat_withDecimal() throws Exception {
final StringReader reader = new StringReader("12.34");
assertThat(reader.readFloat(), is(12.34f));
assertThat(reader.getRead(), equalTo("12.34"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readFloat_negative() throws Exception {
final StringReader reader = new StringReader("-123");
assertThat(reader.readFloat(), is(-123.0f));
assertThat(reader.getRead(), equalTo("-123"));
assertThat(reader.getRemaining(), equalTo(""));
}

@Test
public void readFloat_invalid() throws Exception {
try {
new StringReader("12.34.56").readFloat();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidFloat()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readFloat_none() throws Exception {
try {
new StringReader("").readFloat();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedFloat()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void readFloat_withRemaining() throws Exception {
final StringReader reader = new StringReader("12.34 foo bar");
assertThat(reader.readFloat(), is(12.34f));
assertThat(reader.getRead(), equalTo("12.34"));
assertThat(reader.getRemaining(), equalTo(" foo bar"));
}

@Test
public void readFloat_withRemainingImmediate() throws Exception {
final StringReader reader = new StringReader("12.34foo bar");
assertThat(reader.readFloat(), is(12.34f));
assertThat(reader.getRead(), equalTo("12.34"));
assertThat(reader.getRemaining(), equalTo("foo bar"));
}

@Test
public void expect_correct() throws Exception {
final StringReader reader = new StringReader("abc");
reader.expect('a');
assertThat(reader.getCursor(), is(1));
}

@Test
public void expect_incorrect() throws Exception {
final StringReader reader = new StringReader("bcd");
try {
reader.expect('a');
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedSymbol()));
assertThat(ex.getCursor(), is(0));
}
}

@Test
public void expect_none() throws Exception {
final StringReader reader = new StringReader("");
try {
reader.expect('a');
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedSymbol()));[/code=java]...
La fin de cet article est réservée aux abonnés. Soutenez le Club Developpez.com en prenant un abonnement pour que nous puissions continuer à vous proposer des publications.

Une erreur dans cette actualité ? Signalez-nous-la !