Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
mschae23 committed Jun 13, 2024
1 parent 50fef7a commit 1e2fa74
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
minecraft_version=1.21-rc1
yarn_mappings=1.21-rc1+build.1
loader_version=0.15.11

# Mod Properties
mod_version = 3.2.1
mod_version = 3.2.2
maven_group = de.mschae23.minecraft.mod
archives_base_name = grind-enchantments

# Dependencies
fabric_api_version=0.98.0+1.20.6
fabric_api_version=0.100.1+1.21
codec_config_api_version=2.0.0+1.20.5-rc3
tax_free_levels_version=loom-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ public static void log(Level level, Object message) {
}

public static Identifier id(String path) {
return new Identifier(MODID, path);
return Identifier.of(MODID, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.entry.RegistryEntryList;
import net.minecraft.registry.tag.EnchantmentTags;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

Expand All @@ -48,7 +49,7 @@ public ItemEnchantmentsComponent filter(ItemEnchantmentsComponent enchantments)

if (this.curses == FilterAction.DENY) {
for (RegistryEntry<Enchantment> entry : builder.getEnchantments()) {
if (entry.value().isCursed()) {
if (entry.isIn(EnchantmentTags.CURSE)) {
return ItemEnchantmentsComponent.DEFAULT;
}
}
Expand All @@ -63,7 +64,7 @@ public ItemEnchantmentsComponent filter(ItemEnchantmentsComponent enchantments)
}

builder.remove(enchantment ->
((this.curses == FilterAction.IGNORE) && enchantment.value().isCursed())
((this.curses == FilterAction.IGNORE) && enchantment.isIn(EnchantmentTags.CURSE))
|| ((this.enchantment.action == FilterAction.IGNORE) == this.enchantment.enchantments.contains(enchantment)));

return builder.build();
Expand All @@ -78,7 +79,7 @@ public ItemEnchantmentsComponent filterReversed(ItemEnchantmentsComponent enchan

if (this.curses == FilterAction.DENY) {
for (RegistryEntry<Enchantment> entry : builder.getEnchantments()) {
if (entry.value().isCursed()) {
if (entry.isIn(EnchantmentTags.CURSE)) {
return ItemEnchantmentsComponent.DEFAULT;
}
}
Expand All @@ -93,7 +94,7 @@ public ItemEnchantmentsComponent filterReversed(ItemEnchantmentsComponent enchan
}

builder.remove(enchantment ->
((this.curses == FilterAction.ALLOW) || !enchantment.value().isCursed())
((this.curses == FilterAction.ALLOW) || !enchantment.isIn(EnchantmentTags.CURSE))
&& ((this.enchantment.action == FilterAction.ALLOW) == this.enchantment.enchantments.contains(enchantment)));

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import net.minecraft.component.type.ItemEnchantmentsComponent;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.EnchantmentTags;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
Expand All @@ -34,8 +35,8 @@ public record CountLevelsCostFunction(double normalFactor, double treasureFactor

@Override
public double getCost(ItemEnchantmentsComponent enchantments, FilterConfig filter, RegistryWrapper.WrapperLookup wrapperLookup) {
return enchantments.getEnchantmentsMap().stream()
.mapToDouble(entry -> (double) entry.getIntValue() * (entry.getKey().value().isTreasure() ? this.treasureFactor : this.normalFactor))
return enchantments.getEnchantmentEntries().stream()
.mapToDouble(entry -> (double) entry.getIntValue() * (entry.getKey().isIn(EnchantmentTags.TREASURE) ? this.treasureFactor : this.normalFactor))
.sum();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CountMinPowerCostFunction implements CostFunction {

@Override
public double getCost(ItemEnchantmentsComponent enchantments, FilterConfig filter, RegistryWrapper.WrapperLookup wrapperLookup) {
return enchantments.getEnchantmentsMap().stream()
return enchantments.getEnchantmentEntries().stream()
.mapToDouble(entry -> entry.getKey().value().getMinPower(entry.getIntValue()))
.sum();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public double getCost(ItemEnchantmentsComponent enchantments, FilterConfig filte
return 1.0;
} else {
ItemEnchantmentsComponent.Builder builder = new ItemEnchantmentsComponent.Builder(ItemEnchantmentsComponent.DEFAULT);
builder.add(firstEnchantment.left().value(), firstEnchantment.rightInt());
builder.add(firstEnchantment.left(), firstEnchantment.rightInt());

return this.delegate.getCost(builder.build(), filter, wrapperLookup);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public boolean canInsert(ItemStack stack, ItemStack other, int slotId) {

ItemStack result = input2.copy();
ItemEnchantmentsComponent.Builder builder = new ItemEnchantmentsComponent.Builder(result.getOrDefault(DataComponentTypes.STORED_ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT));
int targetLevel = builder.getLevel(firstEnchantment.left().value());
int targetLevel = builder.getLevel(firstEnchantment.left());

if (targetLevel > 0) {
if (targetLevel != firstEnchantment.rightInt() || firstEnchantment.rightInt() == firstEnchantment.left().value().getMaxLevel()) {
Expand All @@ -86,7 +86,7 @@ public boolean canInsert(ItemStack stack, ItemStack other, int slotId) {
targetLevel = firstEnchantment.rightInt();
}

builder.add(firstEnchantment.left().value(), targetLevel);
builder.add(firstEnchantment.left(), targetLevel);

if (result.getItem() == Items.BOOK) {
result = result.copyComponentsToNewStack(Items.ENCHANTED_BOOK, 1);
Expand Down Expand Up @@ -201,7 +201,7 @@ public static ObjectIntPair<RegistryEntry<Enchantment>> getFirstEnchantment(Item
}
}

for (Object2IntMap.Entry<RegistryEntry<Enchantment>> entry : enchantments.getEnchantmentsMap()) {
for (Object2IntMap.Entry<RegistryEntry<Enchantment>> entry : enchantments.getEnchantmentEntries()) {
if (firstEnchantment == null && !tooltipOrder.contains(entry.getKey())) {
firstEnchantment = ObjectIntPair.of(entry.getKey(), entry.getIntValue());
break;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/grindenchantments.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ accessible field net/minecraft/screen/GrindstoneScreenHandler result Lnet/minecr

accessible field net/minecraft/component/type/ItemEnchantmentsComponent enchantments Lit/unimi/dsi/fastutil/objects/Object2IntOpenHashMap;
accessible method net/minecraft/component/type/ItemEnchantmentsComponent getTooltipOrderList (Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/tag/TagKey;)Lnet/minecraft/registry/entry/RegistryEntryList;
accessible method net/minecraft/enchantment/EnchantmentHelper getEnchantmentsComponentType (Lnet/minecraft/item/ItemStack;)Lnet/minecraft/component/DataComponentType;
accessible method net/minecraft/enchantment/EnchantmentHelper getEnchantmentsComponentType (Lnet/minecraft/item/ItemStack;)Lnet/minecraft/component/ComponentType;

0 comments on commit 1e2fa74

Please sign in to comment.