Skip to content

Commit

Permalink
Big ForgeRegistries -> Registry pass
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 29, 2023
1 parent 51c6a86 commit ff25918
Show file tree
Hide file tree
Showing 37 changed files with 84 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.common.collect.Lists;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -39,7 +40,6 @@
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.zeta.util.ItemNBTHelper;
import vazkii.quark.addons.oddities.inventory.EnchantmentMatrix;
import vazkii.quark.addons.oddities.inventory.EnchantmentMatrix.Piece;
Expand Down Expand Up @@ -294,9 +294,9 @@ private float getEnchantPowerAt(Level world, BlockPos pos) {
if(influencer != null) {
int count = influencer.getInfluenceStack(world, pos, state);

List<Enchantment> influencedEnchants = ForgeRegistries.ENCHANTMENTS.getValues().stream()
List<Enchantment> influencedEnchants = Registry.ENCHANTMENT.stream()
.filter((it) -> influencer.influencesEnchantment(world, pos, state, it)).toList();
List<Enchantment> dampenedEnchants = ForgeRegistries.ENCHANTMENTS.getValues().stream()
List<Enchantment> dampenedEnchants = Registry.ENCHANTMENT.stream()
.filter((it) -> influencer.dampensEnchantment(world, pos, state, it)).toList();
if(!influencedEnchants.isEmpty() || !dampenedEnchants.isEmpty()) {
for(Enchantment e : influencedEnchants) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentInstance;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.addons.oddities.module.MatrixEnchantingModule;
import vazkii.quark.content.experimental.module.EnchantmentsBegoneModule;

Expand Down Expand Up @@ -144,8 +143,8 @@ private EnchantmentDataWrapper generateRandomEnchantment(Map<Enchantment, Intege
List<Piece> marked = pieces.values().stream().filter(p -> p.marked).collect(Collectors.toList());

List<EnchantmentDataWrapper> validEnchants = new ArrayList<>();
ForgeRegistries.ENCHANTMENTS.forEach(enchantment -> {
String id = ForgeRegistries.ENCHANTMENTS.getKey(enchantment).toString();
Registry.ENCHANTMENT.forEach(enchantment -> {
String id = Registry.ENCHANTMENT.getKey(enchantment).toString();
boolean isValid = true;
if(enchantment.isTreasureOnly()){
isValid = MatrixEnchantingModule.allowTreasures ||
Expand Down Expand Up @@ -472,7 +471,7 @@ public void writeToNBT(CompoundTag cmp) {
public void readFromNBT(CompoundTag cmp) {
color = cmp.getInt(TAG_COLOR);
type = cmp.getInt(TAG_TYPE);
enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(cmp.getString(TAG_ENCHANTMENT)));
enchant = Registry.ENCHANTMENT.get(new ResourceLocation(cmp.getString(TAG_ENCHANTMENT)));
level = cmp.getInt(TAG_LEVEL);
x = cmp.getInt(TAG_X);
y = cmp.getInt(TAG_Y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.zeta.event.ZConfigChanged;
import vazkii.zeta.event.ZGatherHints;
import vazkii.zeta.event.ZRegister;
Expand Down Expand Up @@ -232,7 +231,7 @@ private Influence parseEnchantmentList(String enchantmentList) {
if (damp)
enchStr = enchStr.substring(1);

Enchantment ench = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchStr));
Enchantment ench = Registry.ENCHANTMENT.get(new ResourceLocation(enchStr));
if (ench != null) {
if (damp)
dampen.add(ench);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/vazkii/quark/base/handler/FuelHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.minecraft.world.level.material.Material;
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.base.Quark;
import vazkii.quark.content.building.block.VerticalSlabBlock;
import vazkii.zeta.event.ZLoadComplete;
Expand Down Expand Up @@ -42,7 +41,7 @@ public static void addWood(Block block) {

@LoadEvent
public static void addAllWoods(ZLoadComplete event) {
for(Block block : ForgeRegistries.BLOCKS) {
for(Block block : Registry.BLOCK) {
ResourceLocation regname = Quark.ZETA.registry.getRegistryName(block, Registry.BLOCK);
if(block != null && regname.getNamespace().equals(Quark.MOD_ID) && block.defaultBlockState().getMaterial() == Material.WOOD)
addWood(block);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/vazkii/quark/base/handler/MiscUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.base.Quark;
import vazkii.zeta.client.config.screen.ZetaScreen;
import vazkii.quark.content.experimental.module.EnchantmentsBegoneModule;
Expand Down Expand Up @@ -155,7 +154,7 @@ public static void damageStack(Player player, InteractionHand hand, ItemStack st
public static void initializeEnchantmentList(Iterable<String> enchantNames, List<Enchantment> enchants) {
enchants.clear();
for(String s : enchantNames) {
Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(s));
Enchantment enchant = Registry.ENCHANTMENT.get(new ResourceLocation(s));
if (enchant != null && !EnchantmentsBegoneModule.shouldBegone(enchant))
enchants.add(enchant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraftforge.event.TagsUpdatedEvent;
import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.api.event.RecipeCrawlEvent;
import vazkii.quark.api.event.RecipeCrawlEvent.Visit;
import vazkii.quark.base.Quark;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/vazkii/quark/base/handler/SortingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.addons.oddities.inventory.BackpackMenu;
import vazkii.quark.addons.oddities.inventory.slot.CachedItemHandlerSlot;
import vazkii.quark.api.ICustomSorting;
Expand Down Expand Up @@ -342,8 +341,8 @@ else if (o instanceof Block block)
else if (o instanceof ItemStack stack)
itemList.add(stack.getItem());
else if (o instanceof String s) {
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(s));
if (item != null)
Item item = Registry.ITEM.get(new ResourceLocation(s));
if (item != Items.AIR)
itemList.add(item);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.google.common.collect.ImmutableSet;
import net.minecraft.advancements.Criterion;
import net.minecraft.advancements.critereon.PlacedBlockTrigger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.api.IMutableAdvancement;
import vazkii.quark.base.handler.advancement.AdvancementModifier;
import vazkii.zeta.module.ZetaModule;
Expand Down Expand Up @@ -34,7 +34,7 @@ public boolean apply(ResourceLocation res, IMutableAdvancement adv) {
for(var block : seeds) {
Criterion criterion = new Criterion(PlacedBlockTrigger.TriggerInstance.placedBlock(block));

String name = ForgeRegistries.BLOCKS.getKey(block).toString();
String name = Registry.BLOCK.getKey(block).toString();
adv.addOrCriterion(name, criterion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import net.minecraft.advancements.Criterion;
import net.minecraft.advancements.critereon.ConsumeItemTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.api.IMutableAdvancement;
import vazkii.quark.base.handler.advancement.AdvancementModifier;
import vazkii.zeta.module.ZetaModule;
Expand Down Expand Up @@ -39,7 +39,7 @@ public boolean apply(ResourceLocation res, IMutableAdvancement adv) {
Criterion criterion = new Criterion(ConsumeItemTrigger.TriggerInstance.usedItem(
ItemPredicate.Builder.item().of(array).build()));

String name = ForgeRegistries.ITEMS.getKey(array[0].asItem()).toString();
String name = Registry.ITEM.getKey(array[0].asItem()).toString();

adv.addRequiredCriterion(name, criterion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.FishingRodHookedTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.api.IMutableAdvancement;
import vazkii.quark.base.handler.advancement.AdvancementModifier;
import vazkii.zeta.module.ZetaModule;
Expand Down Expand Up @@ -42,7 +42,7 @@ public boolean apply(ResourceLocation res, IMutableAdvancement adv) {
EntityPredicate.ANY,
ItemPredicate.Builder.item().of(array).build()));

String name = ForgeRegistries.ITEMS.getKey(array[0].asItem()).toString();
String name = Registry.ITEM.getKey(array[0].asItem()).toString();
adv.addOrCriterion(name, criterion);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import net.minecraft.advancements.critereon.ItemInteractWithBlockTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.LocationPredicate;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.api.IMutableAdvancement;
import vazkii.quark.base.handler.advancement.AdvancementModifier;
import vazkii.zeta.module.ZetaModule;
Expand Down Expand Up @@ -45,7 +45,7 @@ public boolean apply(ResourceLocation res, IMutableAdvancement adv) {
.of(array).build()),
ItemPredicate.Builder.item().of(Items.GLOW_INK_SAC)));

String name = ForgeRegistries.BLOCKS.getKey(array[0]).toString();
String name = Registry.BLOCK.getKey(array[0]).toString();
adv.addOrCriterion(name, criterion);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.EntityTypePredicate;
import net.minecraft.advancements.critereon.KilledTrigger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.api.IMutableAdvancement;
import vazkii.quark.base.handler.advancement.AdvancementModifier;
import vazkii.zeta.module.ZetaModule;
Expand Down Expand Up @@ -40,7 +40,7 @@ public boolean apply(ResourceLocation res, IMutableAdvancement adv) {
for(EntityType<?> type : entityTypes) {
Criterion criterion = new Criterion(KilledTrigger.TriggerInstance.playerKilledEntity(EntityPredicate.Builder.entity().entityType(EntityTypePredicate.of(type))));

String name = ForgeRegistries.ENTITY_TYPES.getKey(type).toString();
String name = Registry.ENTITY_TYPE.getKey(type).toString();
if(all)
adv.addRequiredCriterion(name, criterion);
else adv.addOrCriterion(name, criterion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import net.minecraft.advancements.Criterion;
import net.minecraft.advancements.critereon.FilledBucketTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.api.IMutableAdvancement;
import vazkii.quark.base.handler.advancement.AdvancementModifier;
import vazkii.zeta.module.ZetaModule;
Expand Down Expand Up @@ -40,7 +40,7 @@ public boolean apply(ResourceLocation res, IMutableAdvancement adv) {
TriggerInstance.filledBucket(ItemPredicate.Builder.item()
.of(array).build()));

String name = ForgeRegistries.ITEMS.getKey(array[0].asItem()).toString();
String name = Registry.ITEM.getKey(array[0].asItem()).toString();
adv.addOrCriterion(name, criterion);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import net.minecraft.advancements.critereon.BredAnimalsTrigger;
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.EntityTypePredicate;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.api.IMutableAdvancement;
import vazkii.quark.base.handler.advancement.AdvancementModifier;
import vazkii.zeta.module.ZetaModule;
Expand Down Expand Up @@ -41,7 +41,7 @@ public boolean apply(ResourceLocation res, IMutableAdvancement adv) {
Criterion criterion = new Criterion(BredAnimalsTrigger.TriggerInstance
.bredAnimals(EntityPredicate.Builder.entity().entityType(EntityTypePredicate.of(type))));

String name = ForgeRegistries.ENTITY_TYPES.getKey(type).toString();
String name = Registry.ENTITY_TYPE.getKey(type).toString();
adv.addRequiredCriterion(name, criterion);
}

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/vazkii/quark/base/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vazkii.quark.base.proxy;

import net.minecraft.core.Registry;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
Expand All @@ -11,7 +12,6 @@
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.base.Quark;
import vazkii.quark.base.capability.CapabilityHandler;
import vazkii.quark.base.handler.*;
Expand All @@ -24,6 +24,7 @@
import vazkii.quark.base.module.LegacyQuarkModuleFinder;
import vazkii.zeta.event.ZCommonSetup;
import vazkii.zeta.event.ZConfigChanged;
import vazkii.zeta.event.ZRegister;
import vazkii.zeta.event.bus.LoadEvent;
import vazkii.zeta.module.ZetaCategory;
import vazkii.zetaimplforge.module.ModFileScanDataModuleFinder;
Expand All @@ -39,8 +40,6 @@ public class CommonProxy {
private boolean configGuiSaving = false;

public void start() {
ForgeRegistries.RECIPE_SERIALIZERS.register(Quark.MOD_ID + ":exclusion", ExclusionRecipe.SERIALIZER);

Quark.ZETA.loadBus
.subscribe(ContributorRewardHandler.class)
.subscribe(CreativeTabHandler.class)
Expand Down Expand Up @@ -95,6 +94,12 @@ public void setup(ZCommonSetup event) {
handleQuarkConfigChange();
}

//TODO find a better place for this little one-off thing, lol
@LoadEvent
public void recipe(ZRegister event) {
event.getRegistry().register(ExclusionRecipe.SERIALIZER, "exclusion", Registry.RECIPE_SERIALIZER_REGISTRY);
}

//forge event
public void configChanged(ModConfigEvent event) {
if(event.getConfig().getModId().equals(Quark.MOD_ID)
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/vazkii/quark/base/recipe/ExclusionRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.crafting.IShapedRecipe;
import net.minecraftforge.registries.ForgeRegistries;

/**
* @author WireSegal
Expand Down Expand Up @@ -160,7 +159,7 @@ public ExclusionRecipe fromJson(@Nonnull ResourceLocation recipeId, @Nonnull Jso
excludedRecipes.add(loc);
}

RecipeSerializer<?> serializer = ForgeRegistries.RECIPE_SERIALIZERS.getValue(new ResourceLocation(trueType));
RecipeSerializer<?> serializer = Registry.RECIPE_SERIALIZER.get(new ResourceLocation(trueType));
if (serializer == null)
throw new JsonSyntaxException("Invalid or unsupported recipe type '" + trueType + "'");
Recipe<?> parent = serializer.fromJson(recipeId, json);
Expand All @@ -184,7 +183,7 @@ public ExclusionRecipe fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull
}
String trueType = buffer.readUtf(32767);

RecipeSerializer<?> serializer = ForgeRegistries.RECIPE_SERIALIZERS.getValue(new ResourceLocation(trueType));
RecipeSerializer<?> serializer = Registry.RECIPE_SERIALIZER.get(new ResourceLocation(trueType));
if (serializer == null)
throw new IllegalArgumentException("Invalid or unsupported recipe type '" + trueType + "'");
Recipe<?> parent = serializer.fromNetwork(recipeId, buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vazkii/quark/base/world/WorldGenHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void modify(Holder<Biome> biome, Phase phase, Builder builder) {

@Override
public Codec<? extends BiomeModifier> codec() {
return (Codec<? extends BiomeModifier>) SERIALIZER.get();
return SERIALIZER.get();
}

public static Codec<QuarkBiomeModifier> makeCodec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.base.Quark;
import vazkii.quark.content.automation.module.PistonsMoveTileEntitiesModule;

Expand All @@ -37,7 +35,7 @@ public static boolean renderPistonBlock(PistonMovingBlockEntity piston, float pa
BlockEntity tile = eb.newBlockEntity(truePos, state);
if (tile == null) return false;
CompoundTag tileTag = PistonsMoveTileEntitiesModule.getMovingBlockEntityData(piston.getLevel(), truePos);
if (tileTag != null && tile.getType() == ForgeRegistries.BLOCK_ENTITY_TYPES.getValue(new ResourceLocation(tileTag.getString("id"))))
if (tileTag != null && tile.getType() == Registry.BLOCK_ENTITY_TYPE.get(new ResourceLocation(tileTag.getString("id"))))
tile.load(tileTag);
Vec3 offset = new Vec3(piston.getXOff(partialTicks), piston.getYOff(partialTicks), piston.getZOff(partialTicks));
return renderTESafely(piston.getLevel(), truePos, state, tile, piston, partialTicks, offset, matrix, bufferIn, combinedLightIn, combinedOverlayIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.StairBlock;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.quark.base.module.LoadModule;
import vazkii.zeta.module.ZetaModule;
import vazkii.quark.base.module.config.Config;
Expand Down Expand Up @@ -53,7 +52,7 @@ public void setup(ZCommonSetup e) {
e.enqueueWork(() -> {
Map<Item, DispenseItemBehavior> registry = DispenserBlock.DISPENSER_REGISTRY;

for(Block b : ForgeRegistries.BLOCKS) {
for(Block b : Registry.BLOCK) {
ResourceLocation res = Registry.BLOCK.getKey(b);
if(!blacklist.contains(Objects.toString(res))) {
Item item = b.asItem();
Expand Down
Loading

0 comments on commit ff25918

Please sign in to comment.