mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-26 17:46:25 -05:00
Custom advancement criterion registry (#1091)
* Custom advancement criterion registry Fixes #20 Signed-off-by: liach <liach@users.noreply.github.com> * Update fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/advancement/FabricCriterionRegistry.java * Update fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/advancement/FabricCriterionRegistry.java * Rename fabric criterion registry -> criterion registry Signed-off-by: liach <liach@users.noreply.github.com> * Remove unnecessary build.gradle parts Will add manually when I run tests Signed-off-by: liach <liach@users.noreply.github.com> * Fine I give up Hope my github editing skill suffices * Code style Co-authored-by: liach <liach@users.noreply.github.com> Co-authored-by: liach <7806504+liach@users.noreply.github.com>
This commit is contained in:
parent
74685c149c
commit
b17f382b19
9 changed files with 210 additions and 0 deletions
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.api.object.builder.v1.advancement;
|
||||
|
||||
import net.minecraft.advancement.criterion.Criterion;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.mixin.object.builder.CriteriaAccessor;
|
||||
|
||||
/**
|
||||
* Allows registering advancement criteria for triggers.
|
||||
*
|
||||
* <p>A registered criterion (trigger) can be retrieved through
|
||||
* {@link net.minecraft.advancement.criterion.Criteria#getById(Identifier)}.</p>
|
||||
*
|
||||
* @see net.minecraft.advancement.criterion.Criteria
|
||||
*/
|
||||
public final class CriterionRegistry {
|
||||
/**
|
||||
* Registers a criterion for a trigger for advancements.
|
||||
*
|
||||
* @param <T> the criterion's type
|
||||
* @param criterion the criterion registered
|
||||
* @return the criterion registered, for chaining
|
||||
* @throws IllegalArgumentException if a criterion with the same {@link
|
||||
* Criterion#getId() id} exists
|
||||
*/
|
||||
public static <T extends Criterion<?>> T register(T criterion) {
|
||||
CriteriaAccessor.callRegister(criterion);
|
||||
return criterion;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.object.builder;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import net.minecraft.advancement.criterion.Criteria;
|
||||
import net.minecraft.advancement.criterion.Criterion;
|
||||
|
||||
@Mixin(Criteria.class)
|
||||
public interface CriteriaAccessor {
|
||||
@Invoker
|
||||
static <T extends Criterion<?>> T callRegister(T object) {
|
||||
throw new AssertionError("Mixin dummy");
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
@ -6,6 +6,7 @@
|
|||
"AbstractBlockAccessor",
|
||||
"AbstractBlockSettingsAccessor",
|
||||
"AbstractBlockSettingsMixin",
|
||||
"CriteriaAccessor",
|
||||
"DefaultAttributeRegistryAccessor",
|
||||
"DefaultAttributeRegistryMixin",
|
||||
"MaterialBuilderAccessor",
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.test.object.builder;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.advancement.criterion.ImpossibleCriterion;
|
||||
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.advancement.CriterionRegistry;
|
||||
|
||||
public final class CriterionRegistryTest {
|
||||
public static void init() {
|
||||
CriterionRegistry.register(new CustomCriterion());
|
||||
}
|
||||
|
||||
static class CustomCriterion extends ImpossibleCriterion {
|
||||
static final Identifier ID = ObjectBuilderTestConstants.id("custom");
|
||||
|
||||
@Override
|
||||
public Identifier getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Conditions conditionsFromJson(JsonObject jsonObject, AdvancementEntityPredicateDeserializer advancementEntityPredicateDeserializer) {
|
||||
ObjectBuilderTestConstants.LOGGER.info("Loading custom criterion in advancement!");
|
||||
return super.conditionsFromJson(jsonObject, advancementEntityPredicateDeserializer);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.test.object.builder;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public final class ObjectBuilderTestConstants {
|
||||
public static final String MOD_ID = "fabric-object-builder-api-v1-testmod";
|
||||
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
|
||||
|
||||
public static Identifier id(String name) {
|
||||
return new Identifier(MOD_ID, name);
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"display": {
|
||||
"icon": {
|
||||
"item": "minecraft:command_block_minecart"
|
||||
},
|
||||
"title": {
|
||||
"text": "Criterion registry test advancement"
|
||||
},
|
||||
"description": {
|
||||
"text": "Criterion registry test advancement description"
|
||||
},
|
||||
"frame": "task",
|
||||
"show_toast": false,
|
||||
"announce_to_chat": false,
|
||||
"hidden": false,
|
||||
"background": "minecraft:textures/gui/advancements/backgrounds/stone.png"
|
||||
},
|
||||
"criteria": {
|
||||
"custom": {
|
||||
"trigger": "fabric-object-builder-api-v1-testmod:custom"
|
||||
}
|
||||
},
|
||||
"requirements": [
|
||||
[
|
||||
"custom"
|
||||
]
|
||||
]
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "fabric-object-builder-api-v1-testmod",
|
||||
"name": "Fabric Object Builder API (v1) Test Mod",
|
||||
"version": "${version}",
|
||||
"environment": "*",
|
||||
"license": "Apache-2.0",
|
||||
"icon": "assets/fabric-object-builder-api-v1-testmod/icon.png",
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net",
|
||||
"irc": "irc://irc.esper.net:6667/fabric",
|
||||
"issues": "https://github.com/FabricMC/fabric/issues",
|
||||
"sources": "https://github.com/FabricMC/fabric"
|
||||
},
|
||||
"authors": [
|
||||
"FabricMC"
|
||||
],
|
||||
"depends": {
|
||||
"fabric-object-builder-api-v1": "*"
|
||||
},
|
||||
"description": "Test mod for fabric object builder API v1.",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"net.fabricmc.fabric.test.object.builder.CriterionRegistryTest::init"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue