Skip to content

Commit

Permalink
Adapt to registry overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
glowredman committed Nov 25, 2023
1 parent d8ff7a9 commit 855e9a2
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 51 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ minecraft_version=1.20.2
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.2,1.21)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=20.2.53-beta
neo_version=20.2.64-beta
# The Neo version range can use any version of Neo as bounds or match the loader version range
neo_version_range=[20.2,)
neo_version_range=[20.2.59,)
# The loader version range can only use the major version of Neo/FML as bounds
loader_version_range=[1,)
# The mapping channel to use for mappings.
Expand Down Expand Up @@ -48,7 +48,7 @@ mod_name=Modular Materials
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=LGPL-3.0
# The mod version. See https://semver.org/
mod_version=0.14-beta
mod_version=0.14.1-beta
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/glowredman/modularmaterials/MM_Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
Expand All @@ -46,8 +48,6 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.ForgeRegistries;
import net.neoforged.neoforge.registries.ForgeRegistries.Keys;

public class MM_Commands {

Expand All @@ -68,13 +68,13 @@ public void register(RegisterCommandsEvent event) {
stack = commandSourceStack.getPlayerOrException().getMainHandItem();
} catch (Exception e) {}

if (stack == null || ForgeRegistries.ITEMS.getKey(stack.getItem()).equals(ForgeRegistries.ITEMS.getKey(Blocks.AIR.asItem()))) {
if (stack == null || BuiltInRegistries.ITEM.getKey(stack.getItem()).equals(BuiltInRegistries.ITEM.getKey(Blocks.AIR.asItem()))) {

commandSourceStack.sendFailure(Component.literal("Your main hand is empty!").withStyle(style -> style.withColor(ChatFormatting.RED).withItalic(true)));

} else {
final Item item = stack.getItem();
commandSourceStack.sendSuccess(() -> copyable(ForgeRegistries.ITEMS.getKey(item).toString()).withStyle(ChatFormatting.GREEN), false);
commandSourceStack.sendSuccess(() -> copyable(BuiltInRegistries.ITEM.getKey(item).toString()).withStyle(ChatFormatting.GREEN), false);
stack.getTags().forEach(rl -> commandSourceStack.sendSuccess(() -> Component.literal(" > ").append(copyable(rl.location().toString())), false));
}
return 0;
Expand Down Expand Up @@ -106,15 +106,15 @@ private static int getInfo(CommandSourceStack commandSourceStack, BlockPos pos)

BlockState blockstate = level.getBlockState(pos);
Block block = blockstate.getBlock();
Registry<Block> blockRegistry = level.registryAccess().registryOrThrow(Keys.BLOCKS);
Registry<Block> blockRegistry = level.registryAccess().registryOrThrow(Registries.BLOCK);
ResourceLocation blockRegName = blockRegistry.getKey(block);
List<TagKey<Block>> blockTags = blockRegistry.getHolderOrThrow(ResourceKey.create(Keys.BLOCKS, blockRegName)).tags().toList();
List<TagKey<Block>> blockTags = blockRegistry.getHolderOrThrow(ResourceKey.create(Registries.BLOCK, blockRegName)).tags().toList();

FluidState fluidstate = level.getFluidState(pos);
Fluid fluid = fluidstate.getType();
Registry<Fluid> fluidRegistry = level.registryAccess().registryOrThrow(Keys.FLUIDS);
Registry<Fluid> fluidRegistry = level.registryAccess().registryOrThrow(Registries.FLUID);
ResourceLocation fluidRegName = fluidRegistry.getKey(fluid);
List<TagKey<Fluid>> fluidTags = fluidRegistry.getHolderOrThrow(ResourceKey.create(Keys.FLUIDS, fluidRegName)).tags().toList();
List<TagKey<Fluid>> fluidTags = fluidRegistry.getHolderOrThrow(ResourceKey.create(Registries.FLUID, fluidRegName)).tags().toList();
FluidType fluidType = fluid.getFluidType();

commandSourceStack.sendSuccess(() -> Component.literal("Information for ").withStyle(ChatFormatting.GOLD)
Expand All @@ -124,7 +124,7 @@ private static int getInfo(CommandSourceStack commandSourceStack, BlockPos pos)
.append(Component.literal(":")).withStyle(ChatFormatting.GOLD), false);

commandSourceStack.sendSuccess(() -> Component.literal("Biome: ").withStyle(ChatFormatting.BLUE)
.append(copyable(level.registryAccess().registryOrThrow(Keys.BIOMES).getKey(biome.value()).toString())), false);
.append(copyable(level.registryAccess().registryOrThrow(Registries.BIOME).getKey(biome.value()).toString())), false);

if(!biomeTags.isEmpty()) commandSourceStack.sendSuccess(() -> Component.literal(" Tags: ").withStyle(ChatFormatting.AQUA), false);
biomeTags.forEach(rl -> commandSourceStack.sendSuccess(() -> Component.literal(" > ").append(copyable(rl.location().toString())), false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
import glowredman.modularmaterials.data.object.sub.Category;
import glowredman.modularmaterials.data.object.sub.ColorProperties;
import glowredman.modularmaterials.worldgen.FeatureVeinLayer;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.MapColor;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.registries.ForgeRegistries;
import net.neoforged.neoforge.registries.RegisterEvent;

public class BlockHandler {
Expand All @@ -29,7 +31,7 @@ public class BlockHandler {

@SubscribeEvent
public void registerBlocks(RegisterEvent event) {
if(!event.getRegistryKey().equals(ForgeRegistries.BLOCKS.getRegistryKey())) {
if(!event.getRegistryKey().equals(Registries.BLOCK)) {
return;
}

Expand All @@ -46,7 +48,7 @@ public void registerBlocks(RegisterEvent event) {
MM_Material material = eMaterial.getValue();
if((material.enabled && material.enabledTypes.contains(typeName)) || MM_Reference.CONFIG.enableAll) {
ResourceLocation regName = new ResourceLocation(MM_Reference.MODID, typeName + "." + materialName);
event.getForgeRegistry().register(regName, new MetaBlock(material, type, materialName, regName));
Registry.register(BuiltInRegistries.BLOCK, regName, new MetaBlock(material, type, materialName, regName));
}
}
}
Expand All @@ -62,9 +64,9 @@ public void registerBlocks(RegisterEvent event) {
if(variant.enabled || MM_Reference.CONFIG.enableAll) {
ResourceLocation regName = new ResourceLocation(MM_Reference.MODID, "ore." + eVariant.getKey() + "." + materialName);
if(variant.falling) {
event.getForgeRegistry().register(regName, new MetaFallingOreBlock(material, variant, materialName, regName));
Registry.register(BuiltInRegistries.BLOCK, regName, new MetaFallingOreBlock(material, variant, materialName, regName));
} else {
event.getForgeRegistry().register(regName, new MetaOreBlock(material, variant, materialName, regName));
Registry.register(BuiltInRegistries.BLOCK, regName, new MetaOreBlock(material, variant, materialName, regName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import glowredman.modularmaterials.MM_Reference;
import glowredman.modularmaterials.data.object.MM_Material;
import glowredman.modularmaterials.data.object.MM_OreVariant;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FallingBlock;
import net.neoforged.neoforge.registries.ForgeRegistries;

public class MetaFallingOreBlock extends FallingBlock implements IMetaOre {

Expand All @@ -23,11 +23,11 @@ public class MetaFallingOreBlock extends FallingBlock implements IMetaOre {
private final ResourceLocation registryName;

public MetaFallingOreBlock(MM_Material material, MM_OreVariant ore, String uniqueMM_MaterialName, ResourceLocation registryName) {
super(BlockHandler.getOreBlockProperties(material, ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ore.baseBlock)), uniqueMM_MaterialName));
super(BlockHandler.getOreBlockProperties(material, BuiltInRegistries.BLOCK.get(new ResourceLocation(ore.baseBlock)), uniqueMM_MaterialName));
this.material = material;
this.variant = ore;
this.registryName = registryName;
MM_Reference.ORES.put(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ore.baseBlock)), uniqueMM_MaterialName, this);
MM_Reference.ORES.put(BuiltInRegistries.BLOCK.get(new ResourceLocation(ore.baseBlock)), uniqueMM_MaterialName, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import glowredman.modularmaterials.MM_Reference;
import glowredman.modularmaterials.data.object.MM_Material;
import glowredman.modularmaterials.data.object.MM_OreVariant;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.neoforged.neoforge.registries.ForgeRegistries;

public class MetaOreBlock extends Block implements IMetaOre {

Expand All @@ -22,11 +22,11 @@ public class MetaOreBlock extends Block implements IMetaOre {
private final ResourceLocation registryName;

public MetaOreBlock(MM_Material material, MM_OreVariant ore, String uniqueMM_MaterialName, ResourceLocation registryName) {
super(BlockHandler.getOreBlockProperties(material, ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ore.baseBlock)), uniqueMM_MaterialName));
super(BlockHandler.getOreBlockProperties(material, BuiltInRegistries.BLOCK.get(new ResourceLocation(ore.baseBlock)), uniqueMM_MaterialName));
this.material = material;
this.variant = ore;
this.registryName = registryName;
MM_Reference.ORES.put(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ore.baseBlock)), uniqueMM_MaterialName, this);
MM_Reference.ORES.put(BuiltInRegistries.BLOCK.get(new ResourceLocation(ore.baseBlock)), uniqueMM_MaterialName, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.registries.ForgeRegistries.Keys;

public class MM_OreVein {

Expand Down Expand Up @@ -153,7 +153,7 @@ private boolean testDimension(WorldGenLevel world) {
private boolean testBiome(WorldGenLevel world, int x, int y, int z) {
Holder<Biome> biomeHolder = world.getBiome(new BlockPos(x + 8, y, z + 8));
Biome biome = biomeHolder.value();
Registry<Biome> registry = world.getLevel().registryAccess().registryOrThrow(Keys.BIOMES);
Registry<Biome> registry = world.getLevel().registryAccess().registryOrThrow(Registries.BIOME);
String biomeName = registry.getKey(biome).toString();
if(invertBiomes) {
for(TagKey<Biome> tagKey : biomeHolder.tags().toList()) {
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/glowredman/modularmaterials/fluid/FluidHandler.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package glowredman.modularmaterials.fluid;

import java.util.Map.Entry;
import java.util.function.Supplier;

import glowredman.modularmaterials.MM_Reference;
import glowredman.modularmaterials.ModularMaterials;
import glowredman.modularmaterials.data.object.MM_Material;
import glowredman.modularmaterials.data.object.MM_Type;
import glowredman.modularmaterials.data.object.sub.Category;
import glowredman.modularmaterials.item.MetaBucketItem;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext;
import net.neoforged.neoforge.fluids.BaseFlowingFluid;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.ForgeRegistries;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import net.neoforged.neoforge.registries.RegisterEvent;
import net.neoforged.neoforge.registries.RegistryObject;

public class FluidHandler {

private static final DeferredRegister<FluidType> FLUID_TYPES = DeferredRegister.create(ForgeRegistries.Keys.FLUID_TYPES, MM_Reference.MODID);
private static final DeferredRegister<FluidType> FLUID_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.FLUID_TYPES, MM_Reference.MODID);


public FluidHandler() {
Expand All @@ -30,7 +35,7 @@ public FluidHandler() {

@SubscribeEvent
public void registerBlocks(RegisterEvent event) {
if(!event.getRegistryKey().equals(ForgeRegistries.FLUIDS.getRegistryKey())) {
if(!event.getRegistryKey().equals(Registries.FLUID)) {
return;
}

Expand All @@ -46,20 +51,20 @@ public void registerBlocks(RegisterEvent event) {
String materialName = eMaterial.getKey();
MM_Material material = eMaterial.getValue();
if((material.enabled && material.enabledTypes.contains(typeName)) || MM_Reference.CONFIG.enableAll) {
RegistryObject<MetaFluid> fluidS = RegistryObject.create(new ResourceLocation(MM_Reference.MODID, typeName + "." + materialName), ForgeRegistries.FLUIDS);
RegistryObject<MetaFluid> fluidF = RegistryObject.create(new ResourceLocation(MM_Reference.MODID, "flowing_" + typeName + "." + materialName), ForgeRegistries.FLUIDS);
RegistryObject<MetaFluidType> fluidType = FLUID_TYPES.register(typeName + "." + materialName, () -> new MetaFluidType(material, type, typeName));
DeferredHolder<Fluid, MetaFluid> fluidS = DeferredHolder.create(Registries.FLUID, new ResourceLocation(MM_Reference.MODID, typeName + "." + materialName));
DeferredHolder<Fluid, MetaFluid> fluidF = DeferredHolder.create(Registries.FLUID, new ResourceLocation(MM_Reference.MODID, "flowing_" + typeName + "." + materialName));
Supplier<MetaFluidType> fluidType = FLUID_TYPES.register(typeName + "." + materialName, () -> new MetaFluidType(material, type, typeName));
BaseFlowingFluid.Properties p = new BaseFlowingFluid.Properties(fluidType, fluidS, fluidF);

if(MM_Reference.CONFIG.enableBuckets) {
ResourceLocation regName = new ResourceLocation(MM_Reference.MODID, "bucket." + fluidS.getId().getPath());
Item bucket = new MetaBucketItem(fluidS, material, regName);
p.bucket(() -> bucket);
ForgeRegistries.ITEMS.register(regName, bucket);
Registry.register(BuiltInRegistries.ITEM, regName, bucket);
}
ForgeRegistries.FLUIDS.register(fluidS.getId(), new MetaFluid(material, type, p, fluidS.getId()));
ForgeRegistries.FLUIDS.register(fluidF.getId(), new MetaFlowingFluid(material, type, p, fluidF.getId()));

Registry.register(BuiltInRegistries.FLUID, fluidS.getId(), new MetaFluid(material, type, p, fluidS.getId()));
Registry.register(BuiltInRegistries.FLUID, fluidF.getId(), new MetaFlowingFluid(material, type, p, fluidF.getId()));

//TODO
//MetaFluidBlock block = new MetaFluidBlock(fluidS, material, type, materialName);
Expand Down
Loading

0 comments on commit 855e9a2

Please sign in to comment.