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
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.
433334
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.
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.
https://www.youtube.com/watch?v=PUMeS8C0IRk&feature=youtu.be
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.
// 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()));
assertThat(ex.getCursor(), is(0));
}
}
@Test
public void readBoolean_correct() throws Exception {
final StringReader reader = new StringReader("true");
assertThat(reader.readBoolean(), is(true));
assertThat(reader.getRead(), equalTo("true"));
}
@Test
public void readBoolean_incorrect() throws Exception {
final StringReader reader = new StringReader("tuesday");
try {
reader.readBoolean();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidBool()));
assertThat(ex.getCursor(), is(0));
}
}
@Test
public void readBoolean_none() throws Exception {
final StringReader reader = new StringReader("");
try {
reader.readBoolean();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedBool()));
assertThat(ex.getCursor(), is(0));
}
}
}
DataFixerUpper est la deuxième bibliothèque que Mojang a décidé d’ouvrir en octobre dernier. Il est également l’une des parties les plus importantes du moteur du jeu. De façon brossée, il s’agit d’une bibliothèque de conversion des données (dont le jeu fait usage) au format requis pour que l’apparence des différents niveaux reste en phase avec les modifications introduites par l’équipe de développement. « Pour faire simple, avant que Minecraft ne charge les différents blocs, il fait appel à DataFixerUpper qui assure la mise à jour visuelle », explique l’équipe de développement.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package com.mojang.datafixers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap;
import it.unimi.dsi.fastutil.ints.IntSortedSet;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import com.mojang.datafixers.functions.PointFreeRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
/*
* Optimizing functions
* Cunha, A., & Pinto, J. S. (2005). Point-free program transformation
* Lämmel, R., Visser, E., & Visser, J. (2002). The essence of strategic programming
*
* How to handle recursive types
* Cunha, A., & Pacheco, H. (2011). Algebraic specialization of generic functions for recursive types
* Yakushev, A. R., Holdermans, S., Löh, A., & Jeuring, J. (2009, August). Generic programming with fixed points for mutually recursive datatypes
* Magalhães, J. P., & Löh, A. (2012). A formal comparison of approaches to datatype-generic programming
*
* Optics
* Pickering, M., Gibbons, J., & Wu, N. (2017). Profunctor Optics: Modular Data Accessors
* Pacheco, H., & Cunha, A. (2010, June). Generic point-free lenses
*
* Tying it together
* Cunha, A., Oliveira, J. N., & Visser, J. (2006, August). Type-safe two-level data transformation
* Cunha, A., & Visser, J. (2011). Transformation of structure-shy programs with application to XPath queries and strategic functions
* Pacheco, H., & Cunha, A. (2011, January). Calculating with lenses: optimising bidirectional transformations
*/
public class DataFixerUpper implements DataFixer {
public static boolean ERRORS_ARE_FATAL = false;
private static final Logger LOGGER = LogManager.getLogger();
protected static final PointFreeRule OPTIMIZATION_RULE = DataFixUtils.make(() -> {
final PointFreeRule opSimple = PointFreeRule.orElse(
PointFreeRule.orElse(
PointFreeRule.CataFuseSame.INSTANCE,
PointFreeRule.orElse(
PointFreeRule.CataFuseDifferent.INSTANCE,
PointFreeRule.LensAppId.INSTANCE
)
),
PointFreeRule.orElse(
PointFreeRule.LensComp.INSTANCE,
PointFreeRule.orElse(
PointFreeRule.AppNest.INSTANCE,
PointFreeRule.LensCompFunc.INSTANCE
)
)
);
final PointFreeRule opLeft = PointFreeRule.many(PointFreeRule.once(PointFreeRule.orElse(opSimple, PointFreeRule.CompAssocLeft.INSTANCE)));
final PointFreeRule opComp = PointFreeRule.many(PointFreeRule.once(PointFreeRule.orElse(PointFreeRule.SortInj.INSTANCE, PointFreeRule.SortProj.INSTANCE)));
final PointFreeRule opRight = PointFreeRule.many(PointFreeRule.once(PointFreeRule.orElse(opSimple, PointFreeRule.CompAssocRight.INSTANCE)));
return PointFreeRule.seq(ImmutableList.of(() -> opLeft, () -> opComp, () -> opRight, () -> opLeft, () -> opRight));
});
private final Int2ObjectSortedMap
private final List
private final IntSortedSet fixerVersions;
private final Long2ObjectMap
protected DataFixerUpper(final Int2ObjectSortedMap
this.schemas = schemas;
this.globalList = globalList;
this.fixerVersions = fixerVersions;
}
@Override
public
try {
if (version < newVersion) {
final Type> dataType = getType(type, version);
final Optional
if (!read.isPresent()) {
throw new IllegalStateException("Could not parse for fixing " + dataType);
}
return new Dynamic<>(input.getOps(), read.get());
}
} catch (final Throwable t) {
LOGGER.error("Something went wrong upgrading!", t);
}
return input;
}
@Override
public Schema getSchema(final int key) {
return schemas.get(getLowestSchemaSameVersion(schemas, key));
}
protected Type> getType(final DSL.TypeReference type, final int version) {
return getSchema(DataFixUtils.makeKey(version)).getType(type);
}
protected static int getLowestSchemaSameVersion(final Int2ObjectSortedMap
if (versionKey < schemas.firstIntKey()) {
// can't have a data type before anything else
return schemas.firstIntKey();
}
return schemas.subMap(0, versionKey + 1).lastIntKey();
}
private int getLowestFixSameVersion(final int versionKey) {
if (versionKey < fixerVersions.firstInt()) {
// can have a version before everything else
return fixerVersions.firstInt() - 1;
}
return fixerVersions.subSet(0, versionKey + 1).lastInt();
}
protected TypeRewriteRule getRule(final int version, final int dataVersion) {
if (version >= dataVersion) {
return TypeRewriteRule.nop();
}
final int expandedVersion = getLowestFixSameVersion(DataFixUtils.makeKey(version));
final int expandedDataVersion = DataFixUtils.makeKey(dataVersion);
final long key = (long) expandedVersion << 32 | expandedDataVersion;
if (!rules.containsKey(key)) {
final List
for (final DataFix fix : globalList) {
final int fixVersion = fix.getVersionKey();
if (fixVersion > expandedVersion && fixVersion <= expandedDataVersion) {
final TypeRewriteRule fixRule = fix.getRule();
if (fixRule == TypeRewriteRule.nop()) {
continue;
}
rules.add(fixRule);
}
}
this.rules.put(key, TypeRewriteRule.seq(rules));
}
return rules.get(key);
}
protected IntSortedSet fixerVersions() {
return fixerVersions;
}
}
Source : Minecraft
Voir aussi :
:fleche: Microsoft confirme le rachat de Minecraft pour 2,5 milliards de dollars
:fleche: Microsoft utilise le jeu Minecraft comme espace d'apprentissage pour son logiciel d'intelligence artificielle qui sera disponible cet été
:fleche: Microsoft mise sur C++ plutôt que Java pour écrire la nouvelle version de Minecraft Education Edition, gage de plus de rapidité ?
:fleche: Microsoft ouvre certaines parties du code source de Minecraft édition Java : deux bibliothèques disponibles sous licence MIT
Soutenez le club developpez.com en souscrivant un abonnement pour que nous puissions continuer à vous proposer des publications.