Skip to content

Commit 8afc79e

Browse files
committed
fix: update API calls for 26.1.2 compatibility
1 parent b757866 commit 8afc79e

4 files changed

Lines changed: 10 additions & 18 deletions

File tree

src/main/java/com/example/customcmd/CustomCommand.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void register() {
1616
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
1717
dispatcher.register(
1818
Commands.literal("mycommand")
19-
.requires(source -> source.hasPermission(2))
19+
.requires(source -> source.isPlayer() && source.getServer() != null)
2020
.then(Commands.argument("oyuncu", EntityArgument.players())
2121
.then(Commands.argument("miktar", IntegerArgumentType.integer(1, 9999))
2222
.executes(ctx -> execute(
@@ -39,12 +39,6 @@ private static int execute(CommandSourceStack source, Collection<ServerPlayer> t
3939
() -> Component.literal(player.getName().getString() + " -> " + amount + " birim"),
4040
true
4141
);
42-
CustomCmdMod.LOGGER.info(
43-
"[mycommand] {} -> {} birim (çalıştıran: {})",
44-
player.getName().getString(),
45-
amount,
46-
source.getTextName()
47-
);
4842
}
4943
return targets.size();
5044
}

src/main/java/com/example/customcmd/component/ModComponents.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
import net.minecraft.core.Registry;
66
import net.minecraft.core.component.DataComponentType;
77
import net.minecraft.core.registries.BuiltInRegistries;
8+
import net.minecraft.resources.ResourceKey;
89
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.core.registries.Registries;
911

1012
public class ModComponents {
1113

12-
// Boolean component: item'da "aktif" bayrağı
1314
public static final DataComponentType<Boolean> TITLE_TRIGGER =
1415
Registry.register(
1516
BuiltInRegistries.DATA_COMPONENT_TYPE,
16-
ResourceLocation.fromNamespaceAndPath(CustomCmdMod.MOD_ID, "title_trigger"),
17+
ResourceKey.create(Registries.DATA_COMPONENT_TYPE,
18+
ResourceLocation.fromNamespaceAndPath(CustomCmdMod.MOD_ID, "title_trigger")),
1719
DataComponentType.<Boolean>builder()
1820
.persistent(Codec.BOOL)
1921
.build()

src/main/java/com/example/customcmd/item/ModItems.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import com.example.customcmd.component.ModComponents;
55
import net.minecraft.core.Registry;
66
import net.minecraft.core.registries.BuiltInRegistries;
7+
import net.minecraft.core.registries.Registries;
78
import net.minecraft.resources.ResourceKey;
89
import net.minecraft.resources.ResourceLocation;
9-
import net.minecraft.core.registries.Registries;
1010
import net.minecraft.world.item.Item;
1111

1212
import java.util.function.Function;
@@ -17,7 +17,6 @@ public class ModItems {
1717
"title_item",
1818
TitleItem::new,
1919
new Item.Properties()
20-
// Varsayılan: component true (her yeni item aktif gelir)
2120
.component(ModComponents.TITLE_TRIGGER, true)
2221
);
2322

src/main/java/com/example/customcmd/item/TitleItem.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,26 @@ public TitleItem(Properties properties) {
2121
public InteractionResult use(Level level, Player player, InteractionHand hand) {
2222
ItemStack stack = player.getItemInHand(hand);
2323

24-
// Client-side'da bir şey yapma
2524
if (level.isClientSide()) {
2625
return InteractionResult.SUCCESS;
2726
}
2827

29-
// Component var mı ve true mu?
3028
Boolean active = stack.get(ModComponents.TITLE_TRIGGER);
3129
if (active == null || !active) {
3230
player.sendSystemMessage(
33-
Component.literal("[TitleItem] Component yok veya false — title çalışmıyor.")
31+
Component.literal("[TitleItem] Component yok veya false.")
3432
);
3533
return InteractionResult.FAIL;
3634
}
3735

38-
// /title @s title {"text":"test123"} komutunu çalıştır
3936
if (player instanceof ServerPlayer serverPlayer) {
4037
CommandSourceStack source = serverPlayer.createCommandSourceStack()
41-
.withPermission(4) // op yetkisi ver (komut için)
42-
.withSuppressedOutput(); // log'a yazma
38+
.withPermission(2)
39+
.withSuppressedOutput();
4340

4441
level.getServer().getCommands().performPrefixedCommand(
4542
source,
46-
"title " + serverPlayer.getGameProfile().getName() + " title {\"text\":\"test123\"}"
43+
"title " + serverPlayer.getName().getString() + " title {\"text\":\"test123\"}"
4744
);
4845
}
4946

0 commit comments

Comments
 (0)