Remove hacks around RegistryEntry (#144)

This commit is contained in:
shedaniel
2021-12-11 19:05:13 +08:00
parent 7857615bfc
commit ebbc2a6490
6 changed files with 97 additions and 55 deletions

View File

@@ -0,0 +1,53 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.test.recipes;
import com.google.gson.JsonObject;
import dev.architectury.core.RegistryEntry;
import dev.architectury.platform.Platform;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.FireworkRocketRecipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import java.util.Objects;
public class TestRecipeSerializer extends RegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<CustomRecipe> {
public TestRecipeSerializer() {
if (Platform.isForge() && !Objects.equals(getRegistryType(), RecipeSerializer.class)) {
throw new IllegalStateException("getRegistryType() must be of type " + RecipeSerializer.class.getName());
}
}
@Override
public CustomRecipe fromJson(ResourceLocation id, JsonObject json) {
return new FireworkRocketRecipe(id);
}
@Override
public CustomRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
return new FireworkRocketRecipe(id);
}
@Override
public void toNetwork(FriendlyByteBuf buf, CustomRecipe recipe) {
}
}

View File

@@ -26,6 +26,7 @@ import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrySupplier;
import dev.architectury.test.TestMod;
import dev.architectury.test.entity.TestEntity;
import dev.architectury.test.recipes.TestRecipeSerializer;
import dev.architectury.test.registry.objects.EquippableTickingItem;
import dev.architectury.test.tab.TestCreativeTabs;
import net.minecraft.core.BlockPos;
@@ -37,6 +38,8 @@ import net.minecraft.world.entity.EntityType;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@@ -51,9 +54,11 @@ public class TestRegistries {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(TestMod.MOD_ID, Registry.BLOCK_REGISTRY);
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(TestMod.MOD_ID, Registry.ENTITY_TYPE_REGISTRY);
public static final DeferredRegister<MobEffect> MOB_EFFECTS = DeferredRegister.create(TestMod.MOD_ID, Registry.MOB_EFFECT_REGISTRY);
public static final DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS = DeferredRegister.create(TestMod.MOD_ID, Registry.RECIPE_SERIALIZER_REGISTRY);
public static final RegistrySupplier<MobEffect> TEST_EFFECT = MOB_EFFECTS.register("test_effect", () ->
new MobEffect(MobEffectCategory.NEUTRAL, 0x123456) {});
new MobEffect(MobEffectCategory.NEUTRAL, 0x123456) {
});
public static final RegistrySupplier<Item> TEST_ITEM = ITEMS.register("test_item", () ->
new Item(new Item.Properties().tab(TestCreativeTabs.TEST_TAB)));
@@ -83,10 +88,13 @@ public class TestRegistries {
public static final RegistrySupplier<EntityType<TestEntity>> TEST_ENTITY = ENTITY_TYPES.register("test_entity", () -> TestEntity.TYPE);
public static final RegistrySupplier<RecipeSerializer<CustomRecipe>> TEST_SERIALIZER = RECIPE_SERIALIZERS.register("test_serializer", TestRecipeSerializer::new);
public static void initialize() {
MOB_EFFECTS.register();
BLOCKS.register();
ITEMS.register();
ENTITY_TYPES.register();
RECIPE_SERIALIZERS.register();
}
}