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 !

Microsoft ouvre certaines parties du code source de Minecraft édition Java :
Deux bibliothèques disponibles sous licence MIT

Le , par Patrick Ruiz

458PARTAGES

13  0 

Microsoft ouvre certaines parties du code source de Minecraft édition Java :
Deux bibliothèques disponibles sous licence MIT

Le studio de développement Mojang (propriété de Microsoft) ouvre la cuisine interne de Minecraft aux programmeurs. L’équipe a passé l’annonce via son compte Twitter.

417866

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.

Le studio de développement Mojang ouvre 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));
}
}
}


417863
Le jeu génère une liste de suggestions pour chaque commande (ci-dessus, un exemple avec /give)


DataFixerUpper est la deuxième bibliothèque que Mojang a décidé d’ouvrir et 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 schemas;
private final List globalList;
private final IntSortedSet fixerVersions;
private final Long2ObjectMap rules = new Long2ObjectOpenHashMap<>();

protected DataFixerUpper(final Int2ObjectSortedMap schemas, final List globalList, final IntSortedSet fixerVersions) {
this.schemas = schemas;
this.globalList = globalList;
this.fixerVersions = fixerVersions;
}

@Override
public Dynamic update(final DSL.TypeReference type, final Dynamic input, final int version, final int newVersion) {
try {
if (version < newVersion) {
final Type dataType = getType(type, version);
final Optional read = dataType.readAndWrite(input.getOps(), getType(type, newVersion), getRule(version, newVersion), OPTIMIZATION_RULE, input.getValue());
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 schemas, final int versionKey) {
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 rules = Lists.newArrayList();
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;
}
}

L’intérêt pour un développeur tiers est de pouvoir s’inspirer d’un travail de ce type pour le réutiliser dans des projets qui n’ont rien à voir avec le gaming. C’est en cela que l’open source est magique. De façon officielle, le jeu était jusqu’ici distribué sous licence propriétaire. La donne a changé et ce n’est qu’un début puisque l’équipe Mojang promet d’ouvrir d’autres pans du code source.

Source : Minecraft.net

Et vous ?

:fleche: Que pensez-vous de cette initiative du studio de développement Mojang ?

:fleche: Qu’avez-vous déniché de bon dans les packages mis à votre disposition ? Comment comptez-vous le réutiliser ?

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é ?

Vous avez lu gratuitement 8 092 articles depuis plus d'un an.
Soutenez le club developpez.com en souscrivant un abonnement pour que nous puissions continuer à vous proposer des publications.

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