Jump to content

ClubPT

Members
  • Posts

    4
  • Joined

  • Last visited

ClubPT's Achievements

Tree Puncher

Tree Puncher (2/8)

1

Reputation

  1. So I have a collection of data that I want to change per-world. It's a simple Map<ResourceLocation, int>. But the ints should be calculated once and shared across the world (savegame). I have all the code to create the ints for new ResourceLocations as I find them, my question is what would be the best place to store this data? I thought of the following options: Custom NBT data on Chunk 0,0,0 Custom file saved in the savegame directory (alongside level.dat) Custom file, saved in the "data" directory in the savegame directory Config file save in "serverconfig" Option #1 has the bonus of being hard for the average player to see, as the data is akin to passcodes, but it feels kludgy to me. Is the a recommended place to store this type of data? Something that MC or forge has functions/serializers already written for? Thanks -pete
  2. If you've created your own tag Then you can use the is() function on the ItemStack. public static final TagKey<Item> myItemTag = ItemTags.create(new ResourceLocation("mymod", "my_tag_name")); //later... stack.is(myItemTag); If you want to use a vanilla tag, they are all defined for you... stack.is(ItemTags.LOGS) I'm not sure this results in O(1) complexity, as it may use something like contains() under the hood, but at least your code is simple and if an optimization is made, you will take advantage of it.
  3. Thank you, that clears it up for me. I ended up with this setup: public static final DeferredRegister<GeneType> GENE_TYPES = DeferredRegister.create(GeneticsRebirthAPI.GENE_TYPE_REGISTRY_NAME, GeneticsRebirth.MODID); public static final Supplier<IForgeRegistry<GeneType>> GENE_TYPE_REGISTRY = GENE_TYPES.makeRegistry(RegistryBuilder::new); public static final RegistryObject<GeneType> DROP = GENE_TYPES.register("drop", DropGeneType::new); public static final Supplier<Codec<Gene>> GENE_CODEC = () -> GENE_TYPE_REGISTRY.get().getCodec().dispatch("gene", Gene::type, GeneType::codec); public static final DeferredRegister<Gene> GENES = DeferredRegister.create(GeneticsRebirthAPI.GENE_REGISTRY_NAME, GeneticsRebirth.MODID); public static final Supplier<IForgeRegistry<Gene>> GENE_REGISTRY = GENES.makeRegistry(() -> new RegistryBuilder<Gene>().disableSaving().dataPackRegistry(GENE_CODEC.get()));
  4. I know I'm almost there, but I'm just not grasping something in the way custom registries work. I'm following the steps outlined in the gemwire wiki: I have a collection of classes that implement "GeneType" that can be instantiated multiple times as instances that extend the class "Gene". I've created the DeferredRegister of GeneTypes, I need the datapack directory of gene configurations read in and an entry placed in the Gene registry for each file in the directory. The end goal is to create my own GeneType and Genes and allow other modders to create GeneTypes and datapack designers to create their own Genes. I'm stuck on #3 in the wiki instructions. I've looked at the Forge BiomeModifiers registry, and the RecipeManger (both similar in concept to what I'm trying to do) but they don't implement exactly what I need. Here's what I have so far, Registry definitions: public static final DeferredRegister<GeneType> GENE_TYPES = DeferredRegister.create(GeneticsRebirthAPI.GENE_TYPE_REGISTRY_NAME, GeneticsRebirth.MODID); public static final Supplier<IForgeRegistry<GeneType>> GENE_TYPE_REGISTRY = GENE_TYPES.makeRegistry(RegistryBuilder::new); public static final RegistryObject<GeneType> DROP = GENE_TYPES.register("drop", DropGeneType::new); public static final DeferredRegister<Gene> GENES = DeferredRegister.create(GeneticsRebirthAPI.GENE_REGISTRY_NAME, GeneticsRebirth.MODID); public static final Supplier<IForgeRegistry<Gene>> GENE_REGISTRY = GENES.makeRegistry(() -> new RegistryBuilder<Gene>().disableSaving().dataPackRegistry(/*something needs to go here*/)); First GeneType: public class DropGeneType implements GeneType { public static final Codec<DropGene> CODEC = RecordCodecBuilder.create((in) -> in.group( BlockState.CODEC.fieldOf("source").forGetter(DropGene::source) ).apply(in, DropGene::new)); @Override public List<GeneEvents> needsEvents() { return List.of(GeneEvents.LOOT_DROP); } @Override public Codec<? extends Gene> codec() { return CODEC; } public record DropGeneLevel() implements GeneLevel { } public record DropGene(BlockState source) implements Gene { @Override public Supplier<GeneType> type() { return GeneRegistry.DROP; } } } Can someone guide me on coding steps 3 and 4? Specifically: How do I have the GeneType registry implement Codec? What codec do I pass to dataPackRegistry() Since DataPacks can be reloaded do I need to do anything special? or does the forge registry system handle all the reloading? I found two examples of using dispatch().. and they are vastly different, and I'm not sure when I need the "Lazy protections" and when I don't. public static final Codec<ParticleOptions> CODEC = Registry.PARTICLE_TYPE.byNameCodec().dispatch("type", ParticleOptions::getType, ParticleType::codec); Codec<BiomeModifier> DIRECT_CODEC = ExtraCodecs.lazyInitializedCodec(() -> ForgeRegistries.BIOME_MODIFIER_SERIALIZERS.get().getCodec()) .dispatch(BiomeModifier::codec, Function.identity()); Thanks for your help. -pete
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.