com.mojang.datafixers.schemas.Schema Java Examples

The following examples show how to use com.mojang.datafixers.schemas.Schema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataFixerBuilder.java    From DataFixerUpper with MIT License 6 votes vote down vote up
public DataFixer build(final Executor executor) {
    final DataFixerUpper fixerUpper = new DataFixerUpper(new Int2ObjectAVLTreeMap<>(schemas), new ArrayList<>(globalList), new IntAVLTreeSet(fixerVersions));

    final IntBidirectionalIterator iterator = fixerUpper.fixerVersions().iterator();
    while (iterator.hasNext()) {
        final int versionKey = iterator.nextInt();
        final Schema schema = schemas.get(versionKey);
        for (final String typeName : schema.types()) {
            CompletableFuture.runAsync(() -> {
                final Type<?> dataType = schema.getType(() -> typeName);
                final TypeRewriteRule rule = fixerUpper.getRule(DataFixUtils.getVersion(versionKey), dataVersion);
                dataType.rewrite(rule, DataFixerUpper.OPTIMIZATION_RULE);
            }, executor).exceptionally(e -> {
                LOGGER.error("Unable to build datafixers", e);
                Runtime.getRuntime().exit(1);
                return null;
            });
        }
    }

    return fixerUpper;
}
 
Example #2
Source File: MixinEntityTypeBuilder.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Fixes MC-170128: Cannot build an EntityType without a datafixer due to an IllegalArgumentException.
 */
@Redirect(method = "build", at = @At(value = "INVOKE", target = "Lcom/mojang/datafixers/schemas/Schema;getChoiceType(Lcom/mojang/datafixers/DSL$TypeReference;Ljava/lang/String;)Lcom/mojang/datafixers/types/Type;", remap = false))
public Type catchIllegalArgumentExceptionForDataFixers(Schema schema, DSL.TypeReference type, String choiceName) {
	try {
		return schema.getChoiceType(type, choiceName);
	} catch (IllegalArgumentException ex) {
		LOGGER.warn("No data fixer registered for entity {}", choiceName);
	}

	// This return result is ignored
	return null;
}
 
Example #3
Source File: DataFixerBuilder.java    From DataFixerUpper with MIT License 5 votes vote down vote up
public Schema addSchema(final int version, final int subVersion, final BiFunction<Integer, Schema, Schema> factory) {
    final int key = DataFixUtils.makeKey(version, subVersion);
    final Schema parent = schemas.isEmpty() ? null : schemas.get(DataFixerUpper.getLowestSchemaSameVersion(schemas, key - 1));
    final Schema schema = factory.apply(DataFixUtils.makeKey(version, subVersion), parent);
    addSchema(schema);
    return schema;
}
 
Example #4
Source File: DataFixerUpper.java    From DataFixerUpper with MIT License 5 votes vote down vote up
protected static int getLowestSchemaSameVersion(final Int2ObjectSortedMap<Schema> 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();
}
 
Example #5
Source File: DataConverters_1_13_R2_2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Schema getSchema(int i) {
    return realFixer.getSchema(i);
}
 
Example #6
Source File: DataConverters_1_14_R4.java    From worldedit-adapters with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Schema getSchema(int i) {
    return realFixer.getSchema(i);
}
 
Example #7
Source File: DataConverters_1_15_R2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Schema getSchema(int i) {
    return realFixer.getSchema(i);
}
 
Example #8
Source File: DataConverters_1_16_R1.java    From worldedit-adapters with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Schema getSchema(int i) {
    return realFixer.getSchema(i);
}
 
Example #9
Source File: DSL.java    From DataFixerUpper with MIT License 4 votes vote down vote up
default TypeTemplate in(final Schema schema) {
    return schema.id(typeName());
}
 
Example #10
Source File: DataFixerUpper.java    From DataFixerUpper with MIT License 4 votes vote down vote up
@Override
public Schema getSchema(final int key) {
    return schemas.get(getLowestSchemaSameVersion(schemas, key));
}
 
Example #11
Source File: DataFixerUpper.java    From DataFixerUpper with MIT License 4 votes vote down vote up
protected DataFixerUpper(final Int2ObjectSortedMap<Schema> schemas, final List<DataFix> globalList, final IntSortedSet fixerVersions) {
    this.schemas = schemas;
    this.globalList = globalList;
    this.fixerVersions = fixerVersions;
}
 
Example #12
Source File: DataFixerBuilder.java    From DataFixerUpper with MIT License 4 votes vote down vote up
public void addSchema(final Schema schema) {
    schemas.put(schema.getVersionKey(), schema);
}
 
Example #13
Source File: DataFixerBuilder.java    From DataFixerUpper with MIT License 4 votes vote down vote up
public Schema addSchema(final int version, final BiFunction<Integer, Schema, Schema> factory) {
    return addSchema(version, 0, factory);
}
 
Example #14
Source File: DataFix.java    From DataFixerUpper with MIT License 4 votes vote down vote up
protected Schema getOutputSchema() {
    return outputSchema;
}
 
Example #15
Source File: DataFix.java    From DataFixerUpper with MIT License 4 votes vote down vote up
protected Schema getInputSchema() {
    if (changesType) {
        return outputSchema.getParent();
    }
    return getOutputSchema();
}
 
Example #16
Source File: DataFix.java    From DataFixerUpper with MIT License 4 votes vote down vote up
public DataFix(final Schema outputSchema, final boolean changesType) {
    this.outputSchema = outputSchema;
    this.changesType = changesType;
}
 
Example #17
Source File: DataFixer.java    From DataFixerUpper with MIT License votes vote down vote up
Schema getSchema(int key);