mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-04 06:44:40 +01:00
Held registries
This commit is contained in:
parent
881cda5bb6
commit
653d17e09c
7 changed files with 37 additions and 110 deletions
|
@ -269,7 +269,6 @@ import com.simibubi.create.foundation.data.ModelGen;
|
|||
import com.simibubi.create.foundation.data.SharedProperties;
|
||||
import com.simibubi.create.foundation.item.ItemDescription;
|
||||
import com.simibubi.create.foundation.item.UncontainableBlockItem;
|
||||
import com.simibubi.create.foundation.mixin.accessor.BlockLootSubProviderAccessor;
|
||||
import com.simibubi.create.foundation.utility.DyeHelper;
|
||||
import com.simibubi.create.infrastructure.config.CStress;
|
||||
import com.tterrag.registrate.providers.RegistrateRecipeProvider;
|
||||
|
@ -2488,7 +2487,7 @@ public class AllBlocks {
|
|||
.sound(SoundType.STONE))
|
||||
.transform(pickaxeOnly())
|
||||
.loot((lt, b) -> {
|
||||
HolderLookup.RegistryLookup<Enchantment> enchantmentRegistryLookup = ((BlockLootSubProviderAccessor) lt).create$getRegistries().lookupOrThrow(Registries.ENCHANTMENT);
|
||||
HolderLookup.RegistryLookup<Enchantment> enchantmentRegistryLookup = lt.getRegistries().lookupOrThrow(Registries.ENCHANTMENT);
|
||||
|
||||
lt.add(b,
|
||||
lt.createSilkTouchDispatchTable(b,
|
||||
|
@ -2509,8 +2508,7 @@ public class AllBlocks {
|
|||
.sound(SoundType.DEEPSLATE))
|
||||
.transform(pickaxeOnly())
|
||||
.loot((lt, b) -> {
|
||||
HolderLookup.RegistryLookup<Enchantment> enchantmentRegistryLookup = ((BlockLootSubProviderAccessor) lt).create$getRegistries().lookupOrThrow(Registries.ENCHANTMENT);
|
||||
|
||||
HolderLookup.RegistryLookup<Enchantment> enchantmentRegistryLookup = lt.getRegistries().lookupOrThrow(Registries.ENCHANTMENT);
|
||||
|
||||
lt.add(b,
|
||||
lt.createSilkTouchDispatchTable(b,
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.simibubi.create.api.registry;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.simibubi.create.api.behaviour.display.DisplaySource;
|
||||
import com.simibubi.create.api.behaviour.display.DisplayTarget;
|
||||
|
@ -20,13 +16,12 @@ import com.simibubi.create.content.kinetics.mechanicalArm.ArmInteractionPointTyp
|
|||
import com.simibubi.create.content.logistics.item.filter.attribute.ItemAttributeType;
|
||||
import com.simibubi.create.content.logistics.packagePort.PackagePortTargetType;
|
||||
|
||||
import net.minecraft.core.RegistrationInfo;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.EventBusSubscriber.Bus;
|
||||
import net.neoforged.neoforge.registries.NewRegistryEvent;
|
||||
import net.neoforged.neoforge.registries.RegistryBuilder;
|
||||
|
||||
/**
|
||||
|
@ -34,12 +29,7 @@ import net.neoforged.neoforge.registries.RegistryBuilder;
|
|||
*
|
||||
* @see CreateRegistries
|
||||
*/
|
||||
@EventBusSubscriber(bus = Bus.MOD)
|
||||
public class CreateBuiltInRegistries {
|
||||
private static final Set<Registry<?>> REGISTRIES = new HashSet<>();
|
||||
// specifying Registry<?> here makes generics upset later
|
||||
private static final Set<ResourceKey<?>> HAS_INTRUSIVE_HOLDERS = new HashSet<>();
|
||||
|
||||
public static final Registry<ArmInteractionPointType> ARM_INTERACTION_POINT_TYPE = simple(CreateRegistries.ARM_INTERACTION_POINT_TYPE);
|
||||
public static final Registry<FanProcessingType> FAN_PROCESSING_TYPE = simple(CreateRegistries.FAN_PROCESSING_TYPE);
|
||||
public static final Registry<ItemAttributeType> ITEM_ATTRIBUTE_TYPE = simple(CreateRegistries.ITEM_ATTRIBUTE_TYPE);
|
||||
|
@ -54,31 +44,30 @@ public class CreateBuiltInRegistries {
|
|||
public static final Registry<MapCodec<? extends PotatoProjectileBlockHitAction>> POTATO_PROJECTILE_BLOCK_HIT_ACTION = simple(CreateRegistries.POTATO_PROJECTILE_BLOCK_HIT_ACTION);
|
||||
|
||||
private static <T> Registry<T> simple(ResourceKey<Registry<T>> key) {
|
||||
Registry<T> registry = new RegistryBuilder<>(key)
|
||||
.sync(true)
|
||||
.create();
|
||||
return register(registry);
|
||||
return register(key, false);
|
||||
}
|
||||
|
||||
private static <T> Registry<T> withIntrusiveHolders(ResourceKey<Registry<T>> key) {
|
||||
HAS_INTRUSIVE_HOLDERS.add(key);
|
||||
return simple(key);
|
||||
return register(key, true);
|
||||
}
|
||||
|
||||
private static <T> Registry<T> register(Registry<T> registry) {
|
||||
REGISTRIES.add(registry);
|
||||
@SuppressWarnings({"deprecation", "unchecked", "rawtypes"})
|
||||
private static <T> Registry<T> register(ResourceKey<Registry<T>> key, boolean hasIntrusiveHolders) {
|
||||
RegistryBuilder<T> builder = new RegistryBuilder<>(key)
|
||||
.sync(true);
|
||||
|
||||
if (hasIntrusiveHolders)
|
||||
builder.withIntrusiveHolders();
|
||||
|
||||
Registry<T> registry = builder.create();
|
||||
((WritableRegistry) BuiltInRegistries.REGISTRY)
|
||||
.register(key, registry, RegistrationInfo.BUILT_IN);
|
||||
return registry;
|
||||
}
|
||||
|
||||
@Internal
|
||||
public static boolean hasIntrusiveHolders(ResourceKey<?> key) {
|
||||
return HAS_INTRUSIVE_HOLDERS.contains(key);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onNewRegistryEvent(NewRegistryEvent event) {
|
||||
for (Registry<?> registry : REGISTRIES)
|
||||
event.register(registry);
|
||||
REGISTRIES.clear();
|
||||
public static void init() {
|
||||
// make sure the class is loaded.
|
||||
// this method is called at the tail of BuiltInRegistries, injected by BuiltInRegistriesMixin.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.simibubi.create.foundation.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.simibubi.create.api.registry.CreateBuiltInRegistries;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
|
||||
@Mixin(BuiltInRegistries.class)
|
||||
public class BuiltInRegistriesMixin {
|
||||
static {
|
||||
CreateBuiltInRegistries.init();
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.simibubi.create.foundation.mixin.accessor;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.data.loot.BlockLootSubProvider;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(BlockLootSubProvider.class)
|
||||
public interface BlockLootSubProviderAccessor {
|
||||
@Accessor("registries")
|
||||
HolderLookup.Provider create$getRegistries();
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.simibubi.create.foundation.mixin.accessor;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
|
||||
@Mixin(BuiltInRegistries.class)
|
||||
public interface BuiltInRegistriesAccessor {
|
||||
@Accessor("WRITABLE_REGISTRY")
|
||||
static WritableRegistry<WritableRegistry<?>> create$getWRITABLE_REGISTRY() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package com.simibubi.create.foundation.mixin.forge;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import com.simibubi.create.api.registry.CreateBuiltInRegistries;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
import net.neoforged.neoforge.registries.RegistryBuilder;
|
||||
|
||||
@Mixin(RegistryBuilder.class)
|
||||
public class RegistryBuilderMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private ResourceKey<?> registryKey;
|
||||
|
||||
// only a single At is supported by ModifyArg for some reason.
|
||||
|
||||
@ModifyArg(
|
||||
method = "create",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/core/DefaultedMappedRegistry;<init>(Ljava/lang/String;Lnet/minecraft/resources/ResourceKey;Lcom/mojang/serialization/Lifecycle;Z)V"
|
||||
)
|
||||
)
|
||||
private boolean allowIntrusiveHoldersDefaulted(boolean hasIntrusiveHolders) {
|
||||
return hasIntrusiveHolders || CreateBuiltInRegistries.hasIntrusiveHolders(this.registryKey);
|
||||
}
|
||||
|
||||
@ModifyArg(
|
||||
method = "create",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/core/MappedRegistry;<init>(Lnet/minecraft/resources/ResourceKey;Lcom/mojang/serialization/Lifecycle;Z)V"
|
||||
)
|
||||
)
|
||||
private boolean allowIntrusiveHolders(boolean hasIntrusiveHolders) {
|
||||
return hasIntrusiveHolders || CreateBuiltInRegistries.hasIntrusiveHolders(this.registryKey);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
"mixins": [
|
||||
"ArmorTrimMixin",
|
||||
"BlockItemMixin",
|
||||
"BuiltInRegistriesMixin",
|
||||
"CustomItemUseEffectsMixin",
|
||||
"EnchantedCountIncreaseFunctionMixin",
|
||||
"EntityMixin",
|
||||
|
@ -24,8 +25,6 @@
|
|||
"WaterWheelFluidSpreadMixin",
|
||||
"accessor.AbstractRegistrateAccessor",
|
||||
"accessor.BlockBehaviourAccessor",
|
||||
"accessor.BlockLootSubProviderAccessor",
|
||||
"accessor.BuiltInRegistriesAccessor",
|
||||
"accessor.DispenserBlockAccessor",
|
||||
"accessor.FallingBlockEntityAccessor",
|
||||
"accessor.FlowingFluidAccessor",
|
||||
|
@ -48,8 +47,7 @@
|
|||
"compat.journeymap.MapRendererAccessor",
|
||||
"datafixer.BlockPosFormatAndRenamesFixMixin",
|
||||
"datafixer.ItemStackComponentizationFixMixin",
|
||||
"datafixer.V1460Mixin",
|
||||
"forge.RegistryBuilderMixin"
|
||||
"datafixer.V1460Mixin"
|
||||
],
|
||||
"client": [
|
||||
"accessor.AgeableListModelAccessor",
|
||||
|
|
Loading…
Add table
Reference in a new issue