Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunekaer committed Jun 19, 2024
1 parent 2545d1d commit 0c15128
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 87.0.0

### Changed

- Updated to 1.21


## 85.0.0

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ private static int enchant(CommandContext<CommandSourceStack> context, Holder.Re
throw ERROR_MISSING_PLAYER.create();
}

if (!enchantment.canEnchant(mainHandItem) || !EnchantmentHelper.isEnchantmentCompatible(EnchantmentHelper.getEnchantmentsForCrafting(mainHandItem).keySet(), enchantment)) {
if (!enchantment.canEnchant(mainHandItem) || !EnchantmentHelper.isEnchantmentCompatible(EnchantmentHelper.getEnchantmentsForCrafting(mainHandItem).keySet(), arg2)) {
throw ERROR_INCOMPATIBLE.create(mainHandItem.getItem().getName(mainHandItem).getString());
}

EnchantmentHacks.enchantItem(mainHandItem, enchantment, (short) level);
source.sendSuccess(() -> Component.translatable("commands.toolkit.enchant.success", mainHandItem.getItem().getName(mainHandItem).getString(), enchantment.getFullname(level).getString()), false);
EnchantmentHacks.enchantItem(mainHandItem, arg2, (short) level);
source.sendSuccess(() -> Component.translatable("commands.toolkit.enchant.success", mainHandItem.getItem().getName(mainHandItem).getString(), Enchantment.getFullname(arg2, level).getString()), false);
return 1;
}

Expand All @@ -74,17 +74,17 @@ private static int removeEnchantment(CommandContext<CommandSourceStack> context,
Enchantment enchantment = arg2.value();

var enchantments = EnchantmentHelper.getEnchantmentsForCrafting(mainHandItem);
var hasEnchantment = enchantments.getLevel(enchantment) > 0;
var hasEnchantment = enchantments.getLevel(arg2) > 0;

if (!hasEnchantment) {
throw ERROR_MISSING_ENCHANTMENT.create(mainHandItem.getItem().getName(mainHandItem).getString(), enchantment.getFullname(1));
throw ERROR_MISSING_ENCHANTMENT.create(mainHandItem.getItem().getName(mainHandItem).getString(), Enchantment.getFullname(arg2, 1));
}

boolean success = EnchantmentHacks.removeEnchantment(mainHandItem, enchantment);
boolean success = EnchantmentHacks.removeEnchantment(mainHandItem, arg2);
if (success) {
source.sendSuccess(() -> Component.translatable("commands.toolkit.remove_enchant.success", mainHandItem.getItem().getName(mainHandItem).getString(), enchantment.getFullname(1).getString()), false);
source.sendSuccess(() -> Component.translatable("commands.toolkit.remove_enchant.success", mainHandItem.getItem().getName(mainHandItem).getString(), Enchantment.getFullname(arg2, 1).getString()), false);
} else {
source.sendFailure(Component.translatable("commands.toolkit.remove_enchant.failed", mainHandItem.getItem().getName(mainHandItem).getString(), enchantment.getFullname(1).getString()));
source.sendFailure(Component.translatable("commands.toolkit.remove_enchant.failed", mainHandItem.getItem().getName(mainHandItem).getString(), Enchantment.getFullname(arg2, 1).getString()));
}
return success ? 1 : 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import com.mojang.brigadier.builder.ArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.enchantment.ItemEnchantments;

Expand All @@ -35,7 +38,8 @@ private static int giveItem(ServerPlayer player) {

var enchants = itemstack.get(DataComponents.ENCHANTMENTS);
var mutableEnchants = new ItemEnchantments.Mutable(enchants);
enchantments.forEach(e -> mutableEnchants.set(e, Short.MAX_VALUE));
Registry<Enchantment> enchantmentRegistry = player.server.registryAccess().registryOrThrow(Registries.ENCHANTMENT);
enchantments.forEach(e -> mutableEnchants.set(enchantmentRegistry.getHolderOrThrow(e), Short.MAX_VALUE));
itemstack.set(DataComponents.ENCHANTMENTS, mutableEnchants.toImmutable());

boolean added = player.getInventory().add(itemstack.copy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static int remove(CommandSourceStack source, int size, String filter) th
var removalCheck = RemovalPredicate.getFromName(filter).orElse(RemovalPredicate.JUST_ORES);
Predicate<BlockState> customCheck = null;
if (filter.startsWith("#")) {
customCheck = state -> state.is(TagKey.create(Registries.BLOCK, new ResourceLocation(filter.replace("#", ""))));
customCheck = state -> state.is(TagKey.create(Registries.BLOCK, ResourceLocation.withDefaultNamespace(filter.replace("#", ""))));
} else if(filter.contains(":")) {
customCheck = state -> BuiltInRegistries.BLOCK.getKey(state.getBlock()).toString().equalsIgnoreCase(filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand All @@ -21,6 +23,7 @@
import net.minecraft.world.item.crafting.AbstractCookingRecipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SmeltingRecipe;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -49,8 +52,10 @@ public class MineAreaCommand {
private static int mine(CommandSourceStack source, int size, String filter) throws CommandSyntaxException {
try {
ItemStack breaker = new ItemStack(Items.NETHERITE_PICKAXE);

Registry<Enchantment> enchantmentRegistry = source.getLevel().registryAccess().registryOrThrow(Registries.ENCHANTMENT);
// breaker.enchant(Enchantments.BLOCK_FORTUNE, 3);
breaker.enchant(Enchantments.SILK_TOUCH, 1);
breaker.enchant(enchantmentRegistry.getHolderOrThrow(Enchantments.SILK_TOUCH), 1);

MinecraftServer server = source.getServer();
ServerLevel level = source.getLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.resources.ResourceLocation;

public class Handler {
public static final NetworkChannel CHANNEL = NetworkChannel.create(new ResourceLocation(Toolkit.MOD_ID, "networking_channel"));
public static final NetworkChannel CHANNEL = NetworkChannel.create(ResourceLocation.fromNamespaceAndPath(Toolkit.MOD_ID, "networking_channel"));

public static void init() {
CHANNEL.register(SetCopy.class, SetCopy::encode, SetCopy::new, SetCopy::apply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
import java.util.Objects;

public class EnchantmentHacks {
public static void enchantItem(ItemStack stack, Enchantment enchantment, short level) {
public static void enchantItem(ItemStack stack, Holder.Reference<Enchantment> enchantment, short level) {
var enchantments = stack.get(DataComponents.ENCHANTMENTS);
var mutableEnchants = new ItemEnchantments.Mutable(Objects.requireNonNullElse(enchantments, ItemEnchantments.EMPTY));

mutableEnchants.set(enchantment, level);
stack.set(DataComponents.ENCHANTMENTS, mutableEnchants.toImmutable());
}

public static boolean removeEnchantment(ItemStack stack, Enchantment enchantment) {
public static boolean removeEnchantment(ItemStack stack, Holder.Reference<Enchantment> enchantment) {
var enchantments = stack.get(DataComponents.ENCHANTMENTS);
if (enchantments == null) {
return false;
}

var mutableEnchants = new ItemEnchantments.Mutable(enchantments);
for (Holder<Enchantment> enchant : mutableEnchants.keySet()) {
if (enchant.value().equals(enchantment)) {
if (enchant.value().equals(enchantment.value())) {
mutableEnchants.set(enchantment, 0);
stack.set(DataComponents.ENCHANTMENTS, mutableEnchants.toImmutable());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ToolkitFabric implements ModInitializer {
public void onInitialize() {
Toolkit.init();
ArgumentTypeRegistry.registerArgumentType(
new ResourceLocation(Toolkit.MOD_ID, "kill_type"),
ResourceLocation.fromNamespaceAndPath(Toolkit.MOD_ID, "kill_type"),
KillEntitiesCommand.KillTypeArgument.class,
SingletonArgumentInfo.contextFree(KillEntitiesCommand.KillTypeArgument::killType)
);
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
org.gradle.jvmargs=-Xmx2048M

minecraft_version=1.20.6
minecraft_version=1.21
#enabled_platforms=fabric,forge,neoforge
enabled_platforms=fabric,neoforge

archives_base_name=ToolKit
mod_version=86.0.0
mod_version=87.0.0
maven_group=com.sunekaer.mods

architectury_version=12.0.28
architectury_version=13.0.1

fabric_loader_version=0.15.11
fabric_api_version=0.98.0+1.20.6
fabric_api_version=0.100.3+1.21

forge_version=50.0.9
forge_gradle_version=6.0.20

neoforge_version=20.6.48-beta
neoforge_gradle_version=7.0.83
neoforge_version=21.0.19-beta
neoforge_gradle_version=7.0.145

curseforge_id=324888
modrinth_id=fWj0tJp5
8 changes: 4 additions & 4 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modLoader = "javafml"
loaderVersion="[2,)" #mandatory
loaderVersion="[4,)" #mandatory
license = "All Rights Reserved"

[[mods]]
Expand All @@ -14,20 +14,20 @@ This mod adds bunch of useful commands
[[dependencies.toolkit]]
modId = "neoforge"
required = true
versionRange = "[20.5,)"
versionRange = "[21,)"
ordering = "NONE"
side = "BOTH"

[[dependencies.toolkit]]
modId = "minecraft"
required = true
versionRange = "[1.20.5,)"
versionRange = "[1.21,)"
ordering = "NONE"
side = "BOTH"

[[dependencies.toolkit]]
modId = "architectury"
required = true
versionRange = "[12.0.28,)"
versionRange = "[13.0.1,)"
ordering = "AFTER"
side = "BOTH"

0 comments on commit 0c15128

Please sign in to comment.