Non-Plural registries

This commit is contained in:
IThundxr 2025-02-15 11:53:23 -05:00
parent 312f5a2929
commit 150ef3e497
Failed to generate hash of commit
12 changed files with 48 additions and 46 deletions

View file

@ -1,29 +1,30 @@
package com.simibubi.create;
import java.util.function.Supplier;
import com.simibubi.create.content.kinetics.fan.processing.FanProcessingType;
import com.simibubi.create.content.kinetics.mechanicalArm.ArmInteractionPointType;
import com.simibubi.create.content.logistics.item.filter.attribute.ItemAttributeType;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.NewRegistryEvent;
import net.minecraftforge.registries.RegistryBuilder;
import java.util.function.Supplier;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class AllRegistries {
public static Supplier<IForgeRegistry<ArmInteractionPointType>> ARM_INTERACTION_POINT_TYPES;
public static Supplier<IForgeRegistry<FanProcessingType>> FAN_PROCESSING_TYPES;
public static Supplier<IForgeRegistry<ItemAttributeType>> ITEM_ATTRIBUTE_TYPES;
public static Supplier<IForgeRegistry<ArmInteractionPointType>> ARM_INTERACTION_POINT_TYPE;
public static Supplier<IForgeRegistry<FanProcessingType>> FAN_PROCESSING_TYPE;
public static Supplier<IForgeRegistry<ItemAttributeType>> ITEM_ATTRIBUTE_TYPE;
public static final class Keys {
public static final ResourceKey<Registry<ArmInteractionPointType>> ARM_INTERACTION_POINT_TYPES = key("arm_interaction_point_types");
public static final ResourceKey<Registry<FanProcessingType>> FAN_PROCESSING_TYPES = key("fan_processing_types");
public static final ResourceKey<Registry<ItemAttributeType>> ITEM_ATTRIBUTE_TYPES = key("item_attribute_types");
public static final ResourceKey<Registry<ArmInteractionPointType>> ARM_INTERACTION_POINT_TYPE = key("arm_interaction_point_type");
public static final ResourceKey<Registry<FanProcessingType>> FAN_PROCESSING_TYPE = key("fan_processing_type");
public static final ResourceKey<Registry<ItemAttributeType>> ITEM_ATTRIBUTE_TYPE = key("item_attribute_type");
private static <T> ResourceKey<Registry<T>> key(String name) {
return ResourceKey.createRegistryKey(Create.asResource(name));
@ -32,16 +33,16 @@ public class AllRegistries {
@SubscribeEvent
public static void registerRegistries(NewRegistryEvent event) {
ARM_INTERACTION_POINT_TYPES = event.create(new RegistryBuilder<ArmInteractionPointType>()
.setName(Keys.ARM_INTERACTION_POINT_TYPES.location())
ARM_INTERACTION_POINT_TYPE = event.create(new RegistryBuilder<ArmInteractionPointType>()
.setName(Keys.ARM_INTERACTION_POINT_TYPE.location())
.disableSaving());
FAN_PROCESSING_TYPES = event.create(new RegistryBuilder<FanProcessingType>()
.setName(Keys.FAN_PROCESSING_TYPES.location())
FAN_PROCESSING_TYPE = event.create(new RegistryBuilder<FanProcessingType>()
.setName(Keys.FAN_PROCESSING_TYPE.location())
.disableSaving());
ITEM_ATTRIBUTE_TYPES = event.create(new RegistryBuilder<ItemAttributeType>()
.setName(Keys.ITEM_ATTRIBUTE_TYPES.location())
ITEM_ATTRIBUTE_TYPE = event.create(new RegistryBuilder<ItemAttributeType>()
.setName(Keys.ITEM_ATTRIBUTE_TYPE.location())
.disableSaving());
}
}

View file

@ -82,7 +82,7 @@ public class TransportedItemStack implements Comparable<TransportedItemStack> {
nbt.putInt("InDirection", insertedFrom.get3DDataValue());
if (processedBy != null && processedBy != AllFanProcessingTypes.NONE) {
ResourceLocation key = AllRegistries.FAN_PROCESSING_TYPES.get().getKey(processedBy);
ResourceLocation key = AllRegistries.FAN_PROCESSING_TYPE.get().getKey(processedBy);
if (key == null)
throw new IllegalArgumentException("Could not get id for FanProcessingType " + processedBy + "!");

View file

@ -60,7 +60,7 @@ import net.minecraftforge.items.wrapper.RecipeWrapper;
import net.minecraftforge.registries.DeferredRegister;
public class AllFanProcessingTypes {
private static final DeferredRegister<FanProcessingType> REGISTER = DeferredRegister.create(AllRegistries.Keys.FAN_PROCESSING_TYPES, Create.ID);
private static final DeferredRegister<FanProcessingType> REGISTER = DeferredRegister.create(AllRegistries.Keys.FAN_PROCESSING_TYPE, Create.ID);
public static final NoneType NONE = register("none", new NoneType());
public static final BlastingType BLASTING = register("blasting", new BlastingType());

View file

@ -95,7 +95,7 @@ public class FanProcessing {
CompoundTag processing = createData.getCompound("Processing");
if (!processing.contains("Type") || AllFanProcessingTypes.parseLegacy(processing.getString("Type")) != type) {
ResourceLocation key = AllRegistries.FAN_PROCESSING_TYPES.get().getKey(type);
ResourceLocation key = AllRegistries.FAN_PROCESSING_TYPE.get().getKey(type);
if (key == null)
throw new IllegalArgumentException("Could not get id for FanProcessingType " + type + "!");

View file

@ -36,7 +36,7 @@ public interface FanProcessingType {
if (id == null) {
return AllFanProcessingTypes.NONE;
}
FanProcessingType type = AllRegistries.FAN_PROCESSING_TYPES.get().getValue(id);
FanProcessingType type = AllRegistries.FAN_PROCESSING_TYPE.get().getValue(id);
if (type == null) {
return AllFanProcessingTypes.NONE;
}

View file

@ -3,12 +3,12 @@ package com.simibubi.create.content.kinetics.fan.processing;
import java.util.Collections;
import java.util.List;
import org.jetbrains.annotations.UnmodifiableView;
import com.simibubi.create.AllRegistries;
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
import org.jetbrains.annotations.UnmodifiableView;
public class FanProcessingTypeRegistry {
private static List<FanProcessingType> sortedTypes = null;
@UnmodifiableView
@ -19,7 +19,7 @@ public class FanProcessingTypeRegistry {
if (sortedTypes == null) {
sortedTypes = new ReferenceArrayList<>();
sortedTypes.addAll(AllRegistries.FAN_PROCESSING_TYPES.get().getValues());
sortedTypes.addAll(AllRegistries.FAN_PROCESSING_TYPE.get().getValues());
sortedTypes.sort((t1, t2) -> t2.getPriority() - t1.getPriority());
sortedTypesView = Collections.unmodifiableList(sortedTypes);

View file

@ -64,7 +64,7 @@ import net.minecraftforge.items.wrapper.SidedInvWrapper;
import net.minecraftforge.registries.DeferredRegister;
public class AllArmInteractionPointTypes {
private static final DeferredRegister<ArmInteractionPointType> REGISTER = DeferredRegister.create(AllRegistries.Keys.ARM_INTERACTION_POINT_TYPES, Create.ID);
private static final DeferredRegister<ArmInteractionPointType> REGISTER = DeferredRegister.create(AllRegistries.Keys.ARM_INTERACTION_POINT_TYPE, Create.ID);
static {
register("basin", new BasinType());

View file

@ -5,8 +5,8 @@ import javax.annotation.Nullable;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.content.contraptions.StructureTransform;
import net.createmod.catnip.nbt.NBTHelper;
import net.createmod.catnip.math.VecHelper;
import net.createmod.catnip.nbt.NBTHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
@ -17,6 +17,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
@ -89,7 +90,8 @@ public class ArmInteractionPoint {
return type.canCreatePoint(level, pos, cachedState);
}
public void keepAlive() {}
public void keepAlive() {
}
@Nullable
protected IItemHandler getHandler() {
@ -136,7 +138,7 @@ public class ArmInteractionPoint {
}
public final CompoundTag serialize(BlockPos anchor) {
ResourceLocation key = AllRegistries.ARM_INTERACTION_POINT_TYPES.get().getKey(type);
ResourceLocation key = AllRegistries.ARM_INTERACTION_POINT_TYPE.get().getKey(type);
if (key == null)
throw new IllegalArgumentException("Could not get id for ArmInteractionPointType " + type + "!");
@ -152,7 +154,7 @@ public class ArmInteractionPoint {
ResourceLocation id = ResourceLocation.tryParse(nbt.getString("Type"));
if (id == null)
return null;
ArmInteractionPointType type = AllRegistries.ARM_INTERACTION_POINT_TYPES.get().getValue(id);
ArmInteractionPointType type = AllRegistries.ARM_INTERACTION_POINT_TYPE.get().getValue(id);
if (type == null)
return null;
BlockPos pos = NbtUtils.readBlockPos(nbt.getCompound("Pos")).offset(anchor);

View file

@ -6,6 +6,8 @@ import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.jetbrains.annotations.UnmodifiableView;
import com.simibubi.create.AllRegistries;
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
@ -13,8 +15,6 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.UnmodifiableView;
public abstract class ArmInteractionPointType {
private static List<ArmInteractionPointType> sortedTypes = null;
@UnmodifiableView
@ -29,7 +29,7 @@ public abstract class ArmInteractionPointType {
if (sortedTypes == null) {
sortedTypes = new ReferenceArrayList<>();
sortedTypes.addAll(AllRegistries.ARM_INTERACTION_POINT_TYPES.get().getValues());
sortedTypes.addAll(AllRegistries.ARM_INTERACTION_POINT_TYPE.get().getValues());
sortedTypes.sort((t1, t2) -> t2.getPriority() - t1.getPriority());
sortedTypesView = Collections.unmodifiableList(sortedTypes);

View file

@ -146,7 +146,7 @@ public class AttributeFilterScreen extends AbstractFilterScreen<AttributeFilterM
.plainCopy()
.append("..."));
attributesOfItem.clear();
for (ItemAttributeType type : AllRegistries.ITEM_ATTRIBUTE_TYPES.get())
for (ItemAttributeType type : AllRegistries.ITEM_ATTRIBUTE_TYPE.get())
attributesOfItem.addAll(type.getAllAttributes(stack, minecraft.level));
List<Component> options = attributesOfItem.stream()
.map(a -> a.format(false))

View file

@ -2,7 +2,6 @@ package com.simibubi.create.content.logistics.item.filter.attribute;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.jetbrains.annotations.ApiStatus;
@ -46,7 +45,7 @@ import net.minecraftforge.registries.DeferredRegister;
// TODO - Documentation
public class AllItemAttributeTypes {
private static final DeferredRegister<ItemAttributeType> REGISTER = DeferredRegister.create(AllRegistries.Keys.ITEM_ATTRIBUTE_TYPES, Create.ID);
private static final DeferredRegister<ItemAttributeType> REGISTER = DeferredRegister.create(AllRegistries.Keys.ITEM_ATTRIBUTE_TYPE, Create.ID);
private static final RecipeWrapper RECIPE_WRAPPER = new RecipeWrapper(new ItemStackHandler(1));
public static final ItemAttributeType

View file

@ -20,7 +20,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public interface ItemAttribute {
static CompoundTag saveStatic(ItemAttribute attribute) {
CompoundTag nbt = new CompoundTag();
ResourceLocation id = AllRegistries.ITEM_ATTRIBUTE_TYPES.get().getKey(attribute.getType());
ResourceLocation id = AllRegistries.ITEM_ATTRIBUTE_TYPE.get().getKey(attribute.getType());
if (id == null)
throw new IllegalArgumentException("Cannot get " + attribute.getType() + "as it does not exist in AllRegistries.ITEM_ATTRIBUTE_TYPES");
@ -42,7 +42,7 @@ public interface ItemAttribute {
if (id == null)
return null;
ItemAttributeType type = AllRegistries.ITEM_ATTRIBUTE_TYPES.get().getValue(id);
ItemAttributeType type = AllRegistries.ITEM_ATTRIBUTE_TYPE.get().getValue(id);
if (type == null)
return null;
@ -53,7 +53,7 @@ public interface ItemAttribute {
static List<ItemAttribute> getAllAttributes(ItemStack stack, Level level) {
List<ItemAttribute> attributes = new ArrayList<>();
for (ItemAttributeType type : AllRegistries.ITEM_ATTRIBUTE_TYPES.get()) {
for (ItemAttributeType type : AllRegistries.ITEM_ATTRIBUTE_TYPE.get()) {
attributes.addAll(type.getAllAttributes(stack, level));
}
return attributes;