mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-04 06:44:40 +01:00
mind if I intrude?
This commit is contained in:
parent
37c075c117
commit
5bb4f9a0ac
5 changed files with 63 additions and 28 deletions
|
@ -4,8 +4,6 @@ import java.util.function.Supplier;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
import com.simibubi.create.AllContraptionTypes;
|
||||
import com.simibubi.create.api.registry.CreateBuiltInRegistries;
|
||||
import com.simibubi.create.content.contraptions.Contraption;
|
||||
|
@ -16,18 +14,12 @@ import net.minecraft.tags.TagKey;
|
|||
|
||||
public final class ContraptionType {
|
||||
public final Supplier<? extends Contraption> factory;
|
||||
@Internal
|
||||
public Holder.Reference<ContraptionType> holder;
|
||||
public final Holder.Reference<ContraptionType> holder = CreateBuiltInRegistries.CONTRAPTION_TYPE.createIntrusiveHolder(this);
|
||||
|
||||
public ContraptionType(Supplier<? extends Contraption> factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Internal
|
||||
public void bind() {
|
||||
this.holder = (Holder.Reference<ContraptionType>) CreateBuiltInRegistries.CONTRAPTION_TYPE.wrapAsHolder(this);
|
||||
}
|
||||
|
||||
public boolean is(TagKey<ContraptionType> tag) {
|
||||
return this.holder.is(tag);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.simibubi.create.api.contraption.storage.item;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
|
@ -31,18 +30,12 @@ public abstract class MountedItemStorageType<T extends MountedItemStorage> {
|
|||
});
|
||||
|
||||
public final MapCodec<? extends T> codec;
|
||||
@Internal
|
||||
public Holder<MountedItemStorageType<?>> holder;
|
||||
public final Holder<MountedItemStorageType<?>> holder = CreateBuiltInRegistries.MOUNTED_ITEM_STORAGE_TYPE.createIntrusiveHolder(this);
|
||||
|
||||
protected MountedItemStorageType(MapCodec<? extends T> codec) {
|
||||
this.codec = codec;
|
||||
}
|
||||
|
||||
@Internal
|
||||
public void bind() {
|
||||
this.holder = CreateBuiltInRegistries.MOUNTED_ITEM_STORAGE_TYPE.wrapAsHolder(this);
|
||||
}
|
||||
|
||||
public final boolean is(TagKey<MountedItemStorageType<?>> tag) {
|
||||
return this.holder.is(tag);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ package com.simibubi.create.api.registry;
|
|||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
import com.simibubi.create.api.behaviour.display.DisplaySource;
|
||||
import com.simibubi.create.api.behaviour.display.DisplayTarget;
|
||||
|
@ -30,16 +31,18 @@ import net.neoforged.neoforge.registries.RegistryBuilder;
|
|||
*/
|
||||
@EventBusSubscriber(bus = Bus.MOD)
|
||||
public class CreateBuiltInRegistries {
|
||||
public static final Set<Registry<?>> REGISTRIES = new HashSet<>();
|
||||
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);
|
||||
public static final Registry<DisplaySource> DISPLAY_SOURCE = simple(CreateRegistries.DISPLAY_SOURCE);
|
||||
public static final Registry<DisplayTarget> DISPLAY_TARGET = simple(CreateRegistries.DISPLAY_TARGET);
|
||||
public static final Registry<MountedItemStorageType<?>> MOUNTED_ITEM_STORAGE_TYPE = withCallback(CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE, MountedItemStorageType::bind);
|
||||
public static final Registry<MountedItemStorageType<?>> MOUNTED_ITEM_STORAGE_TYPE = withIntrusiveHolders(CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE);
|
||||
public static final Registry<MountedFluidStorageType<?>> MOUNTED_FLUID_STORAGE_TYPE = simple(CreateRegistries.MOUNTED_FLUID_STORAGE_TYPE);
|
||||
public static final Registry<ContraptionType> CONTRAPTION_TYPE = withCallback(CreateRegistries.CONTRAPTION_TYPE, ContraptionType::bind);
|
||||
public static final Registry<ContraptionType> CONTRAPTION_TYPE = withIntrusiveHolders(CreateRegistries.CONTRAPTION_TYPE);
|
||||
public static final Registry<PackagePortTargetType> PACKAGE_PORT_TARGET_TYPE = simple(CreateRegistries.PACKAGE_PORT_TARGET_TYPE);
|
||||
|
||||
private static <T> Registry<T> simple(ResourceKey<Registry<T>> key) {
|
||||
|
@ -49,12 +52,9 @@ public class CreateBuiltInRegistries {
|
|||
return register(registry);
|
||||
}
|
||||
|
||||
private static <T> Registry<T> withCallback(ResourceKey<Registry<T>> key, Consumer<T> callback) {
|
||||
Registry<T> registry = new RegistryBuilder<>(key)
|
||||
.onBake(r -> r.forEach(callback))
|
||||
.sync(true)
|
||||
.create();
|
||||
return register(registry);
|
||||
private static <T> Registry<T> withIntrusiveHolders(ResourceKey<Registry<T>> key) {
|
||||
HAS_INTRUSIVE_HOLDERS.add(key);
|
||||
return simple(key);
|
||||
}
|
||||
|
||||
private static <T> Registry<T> register(Registry<T> registry) {
|
||||
|
@ -62,6 +62,11 @@ public class CreateBuiltInRegistries {
|
|||
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)
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -47,7 +47,8 @@
|
|||
"compat.journeymap.MapRendererAccessor",
|
||||
"datafixer.BlockPosFormatAndRenamesFixMixin",
|
||||
"datafixer.ItemStackComponentizationFixMixin",
|
||||
"datafixer.V1460Mixin"
|
||||
"datafixer.V1460Mixin",
|
||||
"forge.RegistryBuilderMixin"
|
||||
],
|
||||
"client": [
|
||||
"accessor.AgeableListModelAccessor",
|
||||
|
|
Loading…
Add table
Reference in a new issue