Skip to content

Commit

Permalink
Backport Key Method
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph T. McQuigg <[email protected]>
  • Loading branch information
JT122406 committed Dec 9, 2024
1 parent b85ac09 commit bb2441e
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.potionstudios.biomeswevegone;

import com.mojang.logging.LogUtils;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.potionstudios.biomeswevegone.sounds.BWGSounds;
Expand Down Expand Up @@ -97,4 +99,14 @@ public static void serverStart(MinecraftServer server) {
public static ResourceLocation id(String name) {
return new ResourceLocation(MOD_ID, name);
}

/**
* Creates a new resource key for Oh The Biomes We've Gone.
* @param registryKey the registry key for the resource
* @param name the name of the resource
* @return the new resource key with the Biomes We've Gone location
*/
public static <T> ResourceKey<T> key(ResourceKey<? extends Registry<T>> registryKey, String name) {
return ResourceKey.create(registryKey, id(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface BWGDamageTypes {
ResourceKey<DamageType> CATTAIL_EXPLOSION = register("cattail_explosion", (damageTypeBootstapContext -> new DamageType(BiomesWeveGone.MOD_ID + ".cattailExplosion", DamageScaling.ALWAYS, 0.1F)));

private static ResourceKey<DamageType> register(String id, DamageTypeFactory factory) {
ResourceKey<DamageType> key = ResourceKey.create(Registries.DAMAGE_TYPE, BiomesWeveGone.id(id));
ResourceKey<DamageType> key = BiomesWeveGone.key(Registries.DAMAGE_TYPE, id);
DAMAGE_TYPE_FACTORIES.put(key, factory);
return key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BWGPoiTypes {

private static ResourceKey<PoiType> register(String id, Supplier<Block> block, int maxTickets, int validRange) {
PlatformHandler.PLATFORM_HANDLER.registerPOIType(id, block, maxTickets, validRange);
return ResourceKey.create(Registries.POINT_OF_INTEREST_TYPE, BiomesWeveGone.id(id));
return BiomesWeveGone.key(Registries.POINT_OF_INTEREST_TYPE, id);
}

public static void poiTypes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BWGCreativeTabs {
@SafeVarargs
private static ResourceKey<CreativeModeTab> createCreativeTab(String name, Supplier<ItemStack> icon, ArrayList<Supplier<? extends Item>>... items) {
PlatformHandler.PLATFORM_HANDLER.createCreativeTab(name, icon, items);
return ResourceKey.create(Registries.CREATIVE_MODE_TAB, BiomesWeveGone.id(name));
return BiomesWeveGone.key(Registries.CREATIVE_MODE_TAB, name);
}

public static void tabs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public BWGDirtPathBlock(Supplier<? extends Block> dirtBlock) {
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
public @NotNull BlockState getStateForPlacement(BlockPlaceContext context) {
return !this.defaultBlockState().canSurvive(context.getLevel(), context.getClickedPos())
? Block.pushEntitiesUp(this.defaultBlockState(), dirtBlock.get().defaultBlockState(), context.getLevel(), context.getClickedPos())
: super.getStateForPlacement(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BWGFarmLandBlock(Supplier<Block> dirt) {
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
public @NotNull BlockState getStateForPlacement(BlockPlaceContext context) {
return !this.defaultBlockState().canSurvive(context.getLevel(), context.getClickedPos())
? dirt.get().defaultBlockState() : super.getStateForPlacement(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class BWGBiomes {

@SafeVarargs
public static ResourceKey<Biome> createBiome(String id, BiomeFactory biomeFactory, TagKey<Biome>... tags) {
ResourceKey<Biome> biomeResourceKey = ResourceKey.create(Registries.BIOME, BiomesWeveGone.id(id));
ResourceKey<Biome> biomeResourceKey = BiomesWeveGone.key(Registries.BIOME, id);
BIOME_FACTORIES.put(biomeResourceKey, biomeFactory);

for (TagKey<Biome> tag : tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static RandomFeatureConfiguration createRandomWeightedConfiguredFeature(H
}

private static ResourceKey<ConfiguredFeature<?, ?>> registerKey(String name) {
return ResourceKey.create(Registries.CONFIGURED_FEATURE, BiomesWeveGone.id(name));
return BiomesWeveGone.key(Registries.CONFIGURED_FEATURE, name);
}

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected static <FC extends FeatureConfiguration> ResourceKey<PlacedFeature> cr
}

private static ResourceKey<PlacedFeature> registerKey(String name) {
return ResourceKey.create(Registries.PLACED_FEATURE, BiomesWeveGone.id(name));
return BiomesWeveGone.key(Registries.PLACED_FEATURE, name);
}

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class BWGStructureSets {


private static ResourceKey<StructureSet> register(String id, StructureSetFactory factory) {
ResourceKey<StructureSet> structureSetResourceKey = ResourceKey.create(Registries.STRUCTURE_SET, BiomesWeveGone.id(id));
ResourceKey<StructureSet> structureSetResourceKey = BiomesWeveGone.key(Registries.STRUCTURE_SET, id);
STRUCTURE_SET_FACTORIES.put(structureSetResourceKey, factory);
return structureSetResourceKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public class BWGStructures {
)));

private static ResourceKey<Structure> register(String id, StructureFactory factory) {
ResourceKey<Structure> structureSetResourceKey = ResourceKey.create(Registries.STRUCTURE, BiomesWeveGone.id(id));
ResourceKey<Structure> structureSetResourceKey = BiomesWeveGone.key(Registries.STRUCTURE, id);
STRUCTURE_FACTORIES.put(structureSetResourceKey, factory);
return structureSetResourceKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static Holder.Reference<StructureProcessorList> getProcessor(BootstapCon
}

private static ResourceKey<StructureTemplatePool> register(String id, TemplatePoolFactory factory) {
ResourceKey<StructureTemplatePool> templatePoolResourceKey = ResourceKey.create(Registries.TEMPLATE_POOL, BiomesWeveGone.id(id));
ResourceKey<StructureTemplatePool> templatePoolResourceKey = BiomesWeveGone.key(Registries.TEMPLATE_POOL, id);
TEMPLATE_POOL_FACTORIES.put(templatePoolResourceKey, factory);
return templatePoolResourceKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private static ResourceKey<StructureTemplatePool> createTerminatorPool(String id
}

private static ResourceKey<StructureTemplatePool> register(String id, BWGTemplatePools.TemplatePoolFactory factory) {
ResourceKey<StructureTemplatePool> templatePoolResourceKey = ResourceKey.create(Registries.TEMPLATE_POOL, BiomesWeveGone.id("village/" + id));
ResourceKey<StructureTemplatePool> templatePoolResourceKey = BiomesWeveGone.key(Registries.TEMPLATE_POOL, "village/" + id);
BWGTemplatePools.TEMPLATE_POOL_FACTORIES.put(templatePoolResourceKey, factory);
return templatePoolResourceKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public class BWGStructureProcessorLists {
));

private static ResourceKey<StructureProcessorList> register(String id, StructureProcessorListFactory factory) {
ResourceKey<StructureProcessorList> structureProcessorListResourceKey = ResourceKey.create(Registries.PROCESSOR_LIST, BiomesWeveGone.id(id));
ResourceKey<StructureProcessorList> structureProcessorListResourceKey = BiomesWeveGone.key(Registries.PROCESSOR_LIST, id);
STRUCTURE_PROCESSOR_LIST_FACTORIES.put(structureProcessorListResourceKey, factory);
return structureProcessorListResourceKey;
}
Expand Down

0 comments on commit bb2441e

Please sign in to comment.