Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Quilt DataFixerUpper API with Fabric Data Fixer API #48

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ tasks {

license {
if (licenseChecks) {
rule(file("codeformat/FABRIC_QUILT_MODIFIED_HEADER"))
rule(file("codeformat/QUILT_MODIFIED_HEADER"))
rule(file("codeformat/HEADER"))

Expand Down
28 changes: 28 additions & 0 deletions codeformat/FABRIC_QUILT_MODIFIED_HEADER
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright (c) ${YEAR} FabricMC
Copyright (c) ${YEAR} FrozenBlock
Modified to use Mojang's Official Mappings

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

This file is a modified version of Quilt Standard Libraries,
authored by QuiltMC.

;;match_from: \/\*\r?\n \* Copyright (\(c\) )?2016-2022 FabricMC
;;match_from: \/\*\r?\n \* Copyright (\(c\) )?2016, 2017, 2018, 2019 FabricMC
;;match_from: \/\*\r?\n \* Copyright (\(c\) )?2022 FabricMC
;;match_from: \/\*\r?\n \* Copyright (\(c\) )?2021-2022 FabricMC
;;match_from: \/\*\r?\n \* Copyright (\(c\) )?2023 FabricMC
;;match_from: \/\*\r?\n \* Copyright (\(c\) )?2021-2023 FabricMC
;;match_from: \/\*\r?\n \* Copyright (\(c\) )?2022-2023 FabricMC
;;match_from: \/\*\r?\n \* Copyright (\(c\) )?2024 FabricMC
;;year_display: lenient_range
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 FabricMC
* Copyright (c) 2024 FrozenBlock
* Modified to use Mojang's Official Mappings
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is a modified version of Quilt Standard Libraries,
* authored by QuiltMC.
*/

package net.fabricmc.frozenblock.datafixer.api;

import com.mojang.datafixers.schemas.Schema;

public interface DataFixerEntrypoint {
void onRegisterBlockEntities(SchemaRegistry registry, Schema schema);

void onRegisterEntities(SchemaRegistry registry, Schema schema);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2024 The Quilt Project
* Copyright 2024 FrozenBlock
* Modified to work on Fabric
* Copyright (c) 2024 FabricMC
* Copyright (c) 2024 FrozenBlock
* Modified to use Mojang's Official Mappings
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,9 +14,12 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is a modified version of Quilt Standard Libraries,
* authored by QuiltMC.
*/

package org.quiltmc.qsl.frozenblock.misc.datafixerupper.api;
package net.fabricmc.frozenblock.datafixer.api;

import com.mojang.datafixers.DSL;
import com.mojang.datafixers.schemas.Schema;
Expand All @@ -29,27 +32,27 @@

/**
* Represents an empty {@link Schema}, having no parent and containing no type definitions.
* <p>
* Modified to work on Fabric
*/
public final class EmptySchema extends FirstSchema {
/**
* Constructs an empty schema.
*
* @param versionKey the data version key
*/
public EmptySchema(@Range(from = 0, to = Integer.MAX_VALUE) int versionKey) {
super(versionKey);
}
// From QSL.

/**
* Constructs an empty schema.
*
* @param versionKey the data version key
*/
public EmptySchema(@Range(from = 0, to = Integer.MAX_VALUE) int versionKey) {
super(versionKey);
}

// Ensure the schema stays empty.
@Override
public void registerType(boolean recursive, DSL.TypeReference type, Supplier<TypeTemplate> template) {
throw new UnsupportedOperationException();
}
// Ensure the schema stays empty.
@Override
public void registerType(boolean recursive, DSL.TypeReference type, Supplier<TypeTemplate> template) {
throw new UnsupportedOperationException();
}

@Override
protected Map<String, Type<?>> buildTypes() {
return Object2ObjectMaps.emptyMap();
}
@Override
protected Map<String, Type<?>> buildTypes() {
return Object2ObjectMaps.emptyMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2024 FabricMC
* Copyright (c) 2024 FrozenBlock
* Modified to use Mojang's Official Mappings
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is a modified version of Quilt Standard Libraries,
* authored by QuiltMC.
*/

package net.fabricmc.frozenblock.datafixer.api;

import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.DataFixerUpper;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.function.Supplier;
import net.fabricmc.frozenblock.datafixer.impl.FabricDataFixesInternals;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.Util;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Range;

/**
* An extended variant of the {@link DataFixerBuilder} class, which provides an extra method.
*/
public class FabricDataFixerBuilder extends DataFixerBuilder {
// From QSL.
protected final int dataVersion;

/**
* Creates a new {@code FabricDataFixerBuilder}.
*
* @param dataVersion the current data version
*/
public FabricDataFixerBuilder(@Range(from = 0, to = Integer.MAX_VALUE) int dataVersion) {
super(dataVersion);
this.dataVersion = dataVersion;
}

/**
* Creates a new {@code FabricDataFixerBuilder}. This method gets the current version from
* the {@code fabric-data-fixer-api-v1:version} field in the {@code custom} object of
* the {@code fabric.mod.json} file of {@code mod}. To specify the version
* manually, use the other overload.
*
* @param mod the mod container
* @return the data fixer builder
* @throws RuntimeException if the version field does not exist or is not a number
*/
public static FabricDataFixerBuilder create(ModContainer mod) {
Objects.requireNonNull(mod, "mod cannot be null");
int dataVersion = FabricDataFixesInternals.getDataVersionFromMetadata(mod);
return new FabricDataFixerBuilder(dataVersion);
}

/**
* @return the current data version
*/
@Range(from = 0, to = Integer.MAX_VALUE)
public int getDataVersion() {
return this.dataVersion;
}

/**
* Builds the final {@code DataFixer}.
*
* <p>This will build either an {@linkplain #build() unoptimized fixer} or an
* optimized fixer, depending on the vanilla game's settings.
*
* @param types the set of required {@link DSL.TypeReference}s, only used if the game is using optimized data fixers
* @param executorGetter the executor supplier, only invoked if the game is using optimized data fixers
* @return the newly built data fixer
*/
@Contract(value = "_, _ -> new")
public DataFixerUpper build(Set<DSL.TypeReference> types, Supplier<Executor> executorGetter) {
Objects.requireNonNull(executorGetter, "executorGetter cannot be null");
return (DataFixerUpper) (types.isEmpty() ? this.build().fixer() : Util.make(() -> {
Result result = this.build();
result.optimize(types, executorGetter.get()).join();
return result.fixer();
}));
}
}
Loading
Loading