Skip to content

Commit 449cdcb

Browse files
committed
chore: move to mojmap
1 parent a0af1a1 commit 449cdcb

13 files changed

Lines changed: 110 additions & 111 deletions

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repositories {
1919
dependencies {
2020
// To change the versions see the gradle.properties file
2121
minecraft "com.mojang:minecraft:${project.minecraft_version}"
22-
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
22+
mappings loom.officialMojangMappings()
2323
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
2424

2525
// Fabric API. This is technically optional, but you probably want it anyway.

gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ org.gradle.jvmargs=-Xmx1G
44
# Fabric Properties
55
# check these on https://modmuss50.me/fabric.html
66
minecraft_version=1.21.11
7-
yarn_mappings=1.21.11+build.2
87
loader_version=0.18.2
98

109
# Mod Properties

src/main/java/dev/keesmand/magnetcommand/MagnetCommandMod.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import net.fabricmc.loader.api.FabricLoader;
1212
import net.fabricmc.loader.api.ModContainer;
1313
import net.fabricmc.loader.api.metadata.ModMetadata;
14-
import net.minecraft.nbt.NbtCompound;
15-
import net.minecraft.server.network.ServerPlayerEntity;
16-
import net.minecraft.util.math.BlockPos;
14+
import net.minecraft.nbt.CompoundTag;
15+
import net.minecraft.server.level.ServerPlayer;
16+
import net.minecraft.core.BlockPos;
1717
import org.slf4j.Logger;
1818
import org.slf4j.LoggerFactory;
1919

@@ -27,8 +27,8 @@ public class MagnetCommandMod implements ModInitializer {
2727
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
2828
private static final String logPrefix = "[" + MOD_METADATA.getName() + "] ";
2929
public static MagnetCommandConfig CONFIG;
30-
public static Map<BlockPos, ServerPlayerEntity> BLOCKS_BROKEN_BY;
31-
public static final PlayerDataStorage<NbtCompound> DATA_STORAGE = new NbtDataStorage("magnet_command");
30+
public static Map<BlockPos, ServerPlayer> BLOCKS_BROKEN_BY;
31+
public static final PlayerDataStorage<CompoundTag> DATA_STORAGE = new NbtDataStorage("magnet_command");
3232

3333
static {
3434
PlayerDataApi.register(DATA_STORAGE);

src/main/java/dev/keesmand/magnetcommand/commands/MagnetCommand.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,52 @@
66
import dev.keesmand.magnetcommand.enums.MagnetMode;
77
import dev.keesmand.magnetcommand.util.MagnetModeData;
88
import me.lucko.fabric.api.permissions.v0.Permissions;
9-
import net.minecraft.server.command.CommandManager;
10-
import net.minecraft.server.command.ServerCommandSource;
11-
import net.minecraft.text.Text;
9+
import net.minecraft.commands.Commands;
10+
import net.minecraft.commands.CommandSourceStack;
11+
import net.minecraft.network.chat.Component;
1212

1313
import static dev.keesmand.magnetcommand.MagnetCommandMod.MOD_METADATA;
1414

1515
public class MagnetCommand {
16-
public static LiteralArgumentBuilder<ServerCommandSource> register() {
17-
LiteralArgumentBuilder<ServerCommandSource> node = CommandManager.literal("magnet")
18-
.then(CommandManager.literal("info")
16+
public static LiteralArgumentBuilder<CommandSourceStack> register() {
17+
LiteralArgumentBuilder<CommandSourceStack> node = Commands.literal("magnet")
18+
.then(Commands.literal("info")
1919
.executes(ctx -> provideInfo(ctx.getSource())));
2020

2121
MagnetCommandConfig config = MagnetCommandMod.CONFIG;
2222

2323
if (config.rangeEnabled || config.onBreakEnabled) {
24-
node.then(CommandManager.literal("Off").executes(ctx -> setMode(ctx.getSource(), MagnetMode.Off)));
24+
node.then(Commands.literal("Off").executes(ctx -> setMode(ctx.getSource(), MagnetMode.Off)));
2525
}
2626

2727
if (config.rangeEnabled) {
28-
node.then(CommandManager.literal("Range")
28+
node.then(Commands.literal("Range")
2929
.requires(ctx -> Permissions.check(ctx, "magnet.mode.range", config.permissionLevel))
3030
.executes(ctx -> setMode(ctx.getSource(), MagnetMode.Range)));
3131
}
3232

3333
if (config.onBreakEnabled) {
34-
node.then(CommandManager.literal("OnBreak")
34+
node.then(Commands.literal("OnBreak")
3535
.requires(ctx -> Permissions.check(ctx, "magnet.mode.break", config.permissionLevel))
3636
.executes(ctx -> setMode(ctx.getSource(), MagnetMode.OnBreak)));
3737
}
3838

3939
return node;
4040
}
4141

42-
public static int setMode(ServerCommandSource source, MagnetMode mode) {
43-
if (!source.isExecutedByPlayer()) {
44-
source.sendFeedback(() -> Text.literal("This command can only be used by players"), false);
42+
public static int setMode(CommandSourceStack source, MagnetMode mode) {
43+
if (!source.isPlayer()) {
44+
source.sendSuccess(() -> Component.literal("This command can only be used by players"), false);
4545
return 0;
4646
}
4747
MagnetModeData.setMagnetMode(source.getPlayer(), mode);
48-
source.sendFeedback(() -> Text.literal("Set magnet mode to " + mode.name()), false);
48+
source.sendSuccess(() -> Component.literal("Set magnet mode to " + mode.name()), false);
4949

5050
return 0;
5151
}
5252

53-
public static int provideInfo(ServerCommandSource source) {
54-
source.sendFeedback(() -> Text.literal(MOD_METADATA.getName() + " " + MOD_METADATA.getVersion().getFriendlyString()), false);
53+
public static int provideInfo(CommandSourceStack source) {
54+
source.sendSuccess(() -> Component.literal(MOD_METADATA.getName() + " " + MOD_METADATA.getVersion().getFriendlyString()), false);
5555
return 0;
5656
}
5757
}

src/main/java/dev/keesmand/magnetcommand/mixin/BlockMixin.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import dev.keesmand.magnetcommand.enums.DropMode;
66
import dev.keesmand.magnetcommand.enums.MagnetMode;
77
import dev.keesmand.magnetcommand.util.MagnetModeData;
8-
import net.minecraft.block.Block;
9-
import net.minecraft.block.BlockState;
10-
import net.minecraft.block.entity.BlockEntity;
11-
import net.minecraft.entity.Entity;
12-
import net.minecraft.item.ItemStack;
13-
import net.minecraft.server.network.ServerPlayerEntity;
14-
import net.minecraft.server.world.ServerWorld;
15-
import net.minecraft.util.math.BlockPos;
8+
import net.minecraft.world.level.block.Block;
9+
import net.minecraft.world.level.block.state.BlockState;
10+
import net.minecraft.world.level.block.entity.BlockEntity;
11+
import net.minecraft.world.entity.Entity;
12+
import net.minecraft.world.item.ItemStack;
13+
import net.minecraft.server.level.ServerPlayer;
14+
import net.minecraft.server.level.ServerLevel;
15+
import net.minecraft.core.BlockPos;
1616
import org.spongepowered.asm.mixin.Mixin;
1717
import org.spongepowered.asm.mixin.injection.At;
1818
import org.spongepowered.asm.mixin.injection.Redirect;
@@ -21,26 +21,26 @@
2121
import java.util.List;
2222

2323
import static dev.keesmand.magnetcommand.util.Magnet.InjectStack;
24-
import static net.minecraft.block.Block.getDroppedStacks;
24+
import static net.minecraft.world.level.block.Block.getDrops;
2525

2626
@Mixin(Block.class)
2727
public class BlockMixin {
2828
@Redirect(
29-
method = "dropStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/item/ItemStack;)V",
30-
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getDroppedStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/item/ItemStack;)Ljava/util/List;")
29+
method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V",
30+
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;getDrops(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)Ljava/util/List;")
3131
)
32-
private static List<ItemStack> onDropStacks(BlockState state, ServerWorld world, BlockPos pos, BlockEntity blockEntity, Entity entity, ItemStack tool) {
33-
List<ItemStack> droppedStacks = getDroppedStacks(state, world, pos, blockEntity, entity, tool);
32+
private static List<ItemStack> onDropStacks(BlockState state, ServerLevel world, BlockPos pos, BlockEntity blockEntity, Entity entity, ItemStack tool) {
33+
List<ItemStack> droppedStacks = getDrops(state, world, pos, blockEntity, entity, tool);
3434

3535
MagnetCommandConfig config = MagnetCommandMod.CONFIG;
3636
if (config == null) return droppedStacks;
3737

38-
if (entity instanceof ServerPlayerEntity player) {
38+
if (entity instanceof ServerPlayer player) {
3939
MagnetMode mode = MagnetModeData.getMagnetMode(player);
4040
if (mode != MagnetMode.OnBreak) return droppedStacks;
4141

4242
droppedStacks.forEach(dropStack -> InjectStack(world,
43-
config.dropLocation == DropMode.Block ? pos : player.getBlockPos(),
43+
config.dropLocation == DropMode.Block ? pos : player.blockPosition(),
4444
player, dropStack));
4545

4646
// return an empty list as we've already given out the drops

src/main/java/dev/keesmand/magnetcommand/mixin/ItemScattererMixin.java renamed to src/main/java/dev/keesmand/magnetcommand/mixin/ContainersMixin.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@
55
import dev.keesmand.magnetcommand.enums.DropMode;
66
import dev.keesmand.magnetcommand.enums.MagnetMode;
77
import dev.keesmand.magnetcommand.util.MagnetModeData;
8-
import net.minecraft.inventory.Inventory;
9-
import net.minecraft.server.network.ServerPlayerEntity;
10-
import net.minecraft.util.ItemScatterer;
11-
import net.minecraft.util.math.BlockPos;
12-
import net.minecraft.world.World;
8+
import net.minecraft.world.Container;
9+
import net.minecraft.server.level.ServerPlayer;
10+
import net.minecraft.world.Containers;
11+
import net.minecraft.core.BlockPos;
12+
import net.minecraft.world.level.Level;
1313
import org.spongepowered.asm.mixin.Mixin;
1414
import org.spongepowered.asm.mixin.injection.At;
1515
import org.spongepowered.asm.mixin.injection.Inject;
1616
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1717

1818
import static dev.keesmand.magnetcommand.util.Magnet.InjectStack;
1919

20-
@Mixin(ItemScatterer.class)
21-
public class ItemScattererMixin {
22-
@Inject(method = "spawn(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/inventory/Inventory;)V", at = @At("HEAD"), cancellable = true)
23-
private static void inject(World world, BlockPos pos, Inventory inventory, CallbackInfo ci) {
20+
@Mixin(Containers.class)
21+
public class ContainersMixin {
22+
@Inject(method = "dropContents(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/Container;)V", at = @At("HEAD"), cancellable = true)
23+
private static void inject(Level world, BlockPos pos, Container inventory, CallbackInfo ci) {
2424
MagnetCommandConfig config = MagnetCommandMod.CONFIG;
2525
if (config == null || !config.includeContainerItems) return;
2626

27-
ServerPlayerEntity player = MagnetCommandMod.BLOCKS_BROKEN_BY.getOrDefault(pos, null);
27+
ServerPlayer player = MagnetCommandMod.BLOCKS_BROKEN_BY.getOrDefault(pos, null);
2828
if (player == null) return;
2929

3030
if (MagnetModeData.getMagnetMode(player) != MagnetMode.OnBreak) return;
3131

32-
for (int i = 0; i < inventory.size(); ++i) {
32+
for (int i = 0; i < inventory.getContainerSize(); ++i) {
3333
InjectStack(world,
34-
config.dropLocation == DropMode.Block ? pos : player.getBlockPos(),
35-
player, inventory.getStack(i));
34+
config.dropLocation == DropMode.Block ? pos : player.blockPosition(),
35+
player, inventory.getItem(i));
3636
}
3737

3838
ci.cancel();

src/main/java/dev/keesmand/magnetcommand/mixin/PlayerManagerMixin.java renamed to src/main/java/dev/keesmand/magnetcommand/mixin/PlayerListMixin.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
import dev.keesmand.magnetcommand.enums.MagnetMode;
44
import dev.keesmand.magnetcommand.util.MagnetModeData;
5-
import net.minecraft.entity.Entity;
6-
import net.minecraft.server.PlayerManager;
7-
import net.minecraft.server.network.ServerPlayerEntity;
8-
import net.minecraft.server.world.ServerWorld;
9-
import net.minecraft.world.TeleportTarget;
5+
import net.minecraft.world.entity.Entity;
6+
import net.minecraft.server.players.PlayerList;
7+
import net.minecraft.server.level.ServerPlayer;
8+
import net.minecraft.server.level.ServerLevel;
9+
import net.minecraft.world.level.portal.TeleportTransition;
1010
import org.spongepowered.asm.mixin.Mixin;
1111
import org.spongepowered.asm.mixin.injection.At;
1212
import org.spongepowered.asm.mixin.injection.Inject;
1313
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1414
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
1515

16-
@Mixin(PlayerManager.class)
17-
public class PlayerManagerMixin {
16+
@Mixin(PlayerList.class)
17+
public class PlayerListMixin {
1818
@Inject(
19-
method = "respawnPlayer",
20-
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;copyFrom(Lnet/minecraft/server/network/ServerPlayerEntity;Z)V"),
19+
method = "respawn",
20+
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;restoreFrom(Lnet/minecraft/server/level/ServerPlayer;Z)V"),
2121
locals = LocalCapture.CAPTURE_FAILHARD)
22-
void handlePlayerRespawn(ServerPlayerEntity oldPlayer, boolean alive, Entity.RemovalReason removalReason, CallbackInfoReturnable<ServerPlayerEntity> cir, TeleportTarget teleportTarget, ServerWorld serverWorld, ServerPlayerEntity newPlayer) {
22+
void handlePlayerRespawn(ServerPlayer oldPlayer, boolean alive, Entity.RemovalReason removalReason, CallbackInfoReturnable<ServerPlayer> cir, TeleportTransition teleportTarget, ServerLevel serverWorld, ServerPlayer newPlayer) {
2323
MagnetMode mode = MagnetModeData.getMagnetMode(oldPlayer);
2424
MagnetModeData.setMagnetMode(newPlayer, mode);
2525
}

src/main/java/dev/keesmand/magnetcommand/mixin/ServerWorldMixin.java renamed to src/main/java/dev/keesmand/magnetcommand/mixin/ServerLevelMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package dev.keesmand.magnetcommand.mixin;
22

33
import dev.keesmand.magnetcommand.MagnetCommandMod;
4-
import net.minecraft.server.world.ServerWorld;
4+
import net.minecraft.server.level.ServerLevel;
55
import org.spongepowered.asm.mixin.Mixin;
66
import org.spongepowered.asm.mixin.injection.At;
77
import org.spongepowered.asm.mixin.injection.Inject;
88
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
99

1010
import java.util.function.BooleanSupplier;
1111

12-
@Mixin(ServerWorld.class)
13-
public class ServerWorldMixin {
12+
@Mixin(ServerLevel.class)
13+
public class ServerLevelMixin {
1414
@Inject(method = "tick", at = @At("HEAD"))
1515
void clearBreakingAuthors(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
1616
MagnetCommandMod.BLOCKS_BROKEN_BY.clear();

src/main/java/dev/keesmand/magnetcommand/mixin/ServerPlayerInteractionManagerMixin.java renamed to src/main/java/dev/keesmand/magnetcommand/mixin/ServerPlayerGameModeMixin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package dev.keesmand.magnetcommand.mixin;
22

33
import dev.keesmand.magnetcommand.MagnetCommandMod;
4-
import net.minecraft.server.network.ServerPlayerEntity;
5-
import net.minecraft.server.network.ServerPlayerInteractionManager;
6-
import net.minecraft.util.math.BlockPos;
4+
import net.minecraft.server.level.ServerPlayer;
5+
import net.minecraft.server.level.ServerPlayerGameMode;
6+
import net.minecraft.core.BlockPos;
77
import org.spongepowered.asm.mixin.Final;
88
import org.spongepowered.asm.mixin.Mixin;
99
import org.spongepowered.asm.mixin.Shadow;
@@ -12,15 +12,15 @@
1212
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1313
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
1414

15-
@Mixin(ServerPlayerInteractionManager.class)
16-
public class ServerPlayerInteractionManagerMixin {
15+
@Mixin(ServerPlayerGameMode.class)
16+
public class ServerPlayerGameModeMixin {
1717
@Shadow
1818
@Final
19-
protected ServerPlayerEntity player;
19+
protected ServerPlayer player;
2020

2121
@Inject(
22-
method = "tryBreakBlock",
23-
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/block/BlockState;"),
22+
method = "destroyBlock",
23+
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;playerWillDestroy(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/player/Player;)Lnet/minecraft/world/level/block/state/BlockState;"),
2424
locals = LocalCapture.CAPTURE_FAILHARD)
2525
void storeBreakingAuthor(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
2626
MagnetCommandMod.BLOCKS_BROKEN_BY.put(pos, player);

src/main/java/dev/keesmand/magnetcommand/mixin/ServerPlayerEntityMixin.java renamed to src/main/java/dev/keesmand/magnetcommand/mixin/ServerPlayerMixin.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import dev.keesmand.magnetcommand.enums.MagnetMode;
66
import dev.keesmand.magnetcommand.enums.MoveMode;
77
import dev.keesmand.magnetcommand.util.Magnet;
8-
import net.minecraft.entity.EntityType;
9-
import net.minecraft.entity.ItemEntity;
10-
import net.minecraft.server.network.ServerPlayerEntity;
11-
import net.minecraft.util.math.Box;
12-
import net.minecraft.util.math.Vec3d;
8+
import net.minecraft.world.entity.EntityType;
9+
import net.minecraft.world.entity.item.ItemEntity;
10+
import net.minecraft.server.level.ServerPlayer;
11+
import net.minecraft.world.phys.AABB;
12+
import net.minecraft.world.phys.Vec3;
1313
import org.spongepowered.asm.mixin.Mixin;
1414
import org.spongepowered.asm.mixin.injection.At;
1515
import org.spongepowered.asm.mixin.injection.Inject;
@@ -21,14 +21,14 @@
2121
import static dev.keesmand.magnetcommand.util.Magnet.TeleportItem;
2222
import static dev.keesmand.magnetcommand.util.MagnetModeData.getMagnetMode;
2323

24-
@Mixin(ServerPlayerEntity.class)
25-
public abstract class ServerPlayerEntityMixin {
24+
@Mixin(ServerPlayer.class)
25+
public abstract class ServerPlayerMixin {
2626
@SuppressWarnings("UnreachableCode")
2727
@Inject(method = "tick", at = @At("HEAD"))
2828
private void magnetRangeMode(CallbackInfo callbackInfo) {
2929
// well this sure is a nice trick, thanks u/tom_the_geek
3030
// https://www.reddit.com/r/fabricmc/comments/nw3rs8/comment/h17daen
31-
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
31+
ServerPlayer player = (ServerPlayer) (Object) this;
3232

3333
MagnetCommandConfig config = MagnetCommandMod.CONFIG;
3434
if (config == null) return;
@@ -39,11 +39,11 @@ private void magnetRangeMode(CallbackInfo callbackInfo) {
3939
double range = config.range;
4040

4141
// get items within range
42-
Vec3d playerPos = player.getEntityPos();
43-
Box box = new Box(
42+
Vec3 playerPos = player.position();
43+
AABB box = new AABB(
4444
playerPos.x + range, playerPos.y + range, playerPos.z + range,
4545
playerPos.x - range, playerPos.y - range, playerPos.z - range);
46-
List<ItemEntity> items = player.getEntityWorld().getEntitiesByType(EntityType.ITEM, box, Magnet::TestItemEntity);
46+
List<ItemEntity> items = player.level().getEntities(EntityType.ITEM, box, Magnet::TestItemEntity);
4747

4848
items.forEach(item -> {
4949
if (config.moveMode == MoveMode.Pull) PullItem(playerPos, item, range);

0 commit comments

Comments
 (0)