Skip to content

Commit

Permalink
[1.21.3] Fix ToolMaterial and ArmorMaterial causing crashes when …
Browse files Browse the repository at this point in the history
…unique tags are used (#1651)
  • Loading branch information
dhyces authored Nov 1, 2024
1 parent 62eb61a commit fcffb21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public static void unfreezeData() {

public static void freezeData() {
LOGGER.debug(REGISTRIES, "Freezing registries");
BuiltInRegistries.REGISTRY.stream().filter(r -> r instanceof MappedRegistry).forEach(r -> ((MappedRegistry<?>) r).freeze());
BuiltInRegistries.REGISTRY.stream().filter(r -> r instanceof MappedRegistry).forEach(r -> {
// HolderSet.Named may be used for registry objects, vanilla binds these tags so freeze won't throw for unbound tags
((MappedRegistry<?>) r).bindAllTagsToEmpty();
((MappedRegistry<?>) r).freeze();
});

RegistryManager.takeFrozenSnapshot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
Expand All @@ -33,7 +35,9 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.MobBucketItem;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.equipment.ArmorMaterials;
import net.minecraft.world.item.equipment.ArmorType;
Expand Down Expand Up @@ -194,4 +198,10 @@ public boolean canWalkOnPowderedSnow(ItemStack stack, LivingEntity wearer) {
.thenWaitUntil(() -> helper.assertEntityPresent(EntityType.PIG, 1, 1, 1))
.thenSucceed());
}

@TestHolder(description = "Adds a stone-pickaxe-like item that cannot mine bamboo blocks and is repaired with beds. Tests that registries can correctly handle named holder set references.")
static void toolItem(final DynamicTest test, final RegistrationHelper reg) {
var material = new ToolMaterial(BlockTags.BAMBOO_BLOCKS, 160, 5.0F, 0.5F, 10, ItemTags.BEDS);
reg.items().registerItem("neo_pickaxe", properties -> new PickaxeItem(material, 1.0F, -2.8F, properties));
}
}

0 comments on commit fcffb21

Please sign in to comment.