diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/Extras.java b/src/main/java/land/chipmunk/kaboomfabric/extras/Extras.java index 8dc78f0..3b90e3b 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/Extras.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/Extras.java @@ -3,7 +3,6 @@ package land.chipmunk.kaboomfabric.extras; import net.fabricmc.api.ModInitializer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import net.minecraft.util.Formatting; import com.mojang.brigadier.CommandDispatcher; import land.chipmunk.kaboomfabric.extras.commands.*; @@ -41,7 +40,7 @@ public class Extras implements ModInitializer { for (int i = 0; i < string.length(); i++) { char character = string.charAt(i); - if (character == '&' && string.length() > (i + 1) && validateEscapeCode(string.charAt(i + 1))) sb.append(Formatting.FORMATTING_CODE_PREFIX); + if (character == '&' && string.length() > (i + 1) && validateEscapeCode(string.charAt(i + 1))) sb.append((char) 0xa7); else sb.append(character); } diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandClearChat.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandClearChat.java index 677c24b..4fb1b94 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandClearChat.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandClearChat.java @@ -27,7 +27,7 @@ public interface CommandClearChat { for (int i = 0; i < 100; i++) text.append(new LiteralText("\n")); text.append(new LiteralText("The chat has been cleared").formatted(Formatting.DARK_GREEN)); - for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) { + for (ServerPlayerEntity player : context.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { player.sendMessage(text); } diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandConsole.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandConsole.java index 54f5739..0412af5 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandConsole.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandConsole.java @@ -27,13 +27,13 @@ public interface CommandConsole { static int consoleCommand (CommandContext context) { // ? Should I optimize this to manually create a ParseResults object, or just not wrap the say command in the first place? final ServerCommandSource source = context.getSource(); - final MinecraftServer server = source.getServer(); + final MinecraftServer server = source.getMinecraftServer(); final ServerCommandSource console = server.getCommandSource(); final String command = "say " + Extras.parseEscapeSequences(getString(context, "message")); final CommandManager commandManager = server.getCommandManager(); - commandManager.execute(commandManager.getDispatcher().parse(command, source), command); + commandManager.execute(console, command); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandDestroyEntities.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandDestroyEntities.java index 96bd7ee..ff112d2 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandDestroyEntities.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandDestroyEntities.java @@ -12,6 +12,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.MinecraftServer; import net.minecraft.text.LiteralText; +import land.chipmunk.kaboomfabric.extras.mixin.ServerWorldAccessor; +import land.chipmunk.kaboomfabric.extras.mixin.EntityAccessor; // Currently broken public interface CommandDestroyEntities { @@ -19,7 +21,7 @@ public interface CommandDestroyEntities { final LiteralCommandNode node = dispatcher.register( literal("destroyentities") .requires(source -> source.hasPermissionLevel(2)) - // .executes(CommandDestroyEntities::destroyEntitiesCommand) + //.executes(CommandDestroyEntities::destroyEntitiesCommand) ); dispatcher.register(literal("de").redirect(node)); @@ -27,15 +29,15 @@ public interface CommandDestroyEntities { static int destroyEntitiesCommand (CommandContext context) { final ServerCommandSource source = context.getSource(); - final MinecraftServer server = source.getServer(); + final MinecraftServer server = source.getMinecraftServer(); int entityCount = 0; int worldCount = 0; for (ServerWorld world : server.getWorlds()) { - for (Entity entity : world.iterateEntities()) { + for (Entity entity : ((ServerWorldAccessor)(Object)world).entitiesById().values()) { if (entity instanceof PlayerEntity) continue; try { - entity.discard(); + ((EntityAccessor)(Object)entity).destroy(); entityCount++; } catch (Exception ignored) { } diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandEnchantAll.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandEnchantAll.java index 4c16107..27e251a 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandEnchantAll.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandEnchantAll.java @@ -10,7 +10,7 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; -import net.minecraft.item.Items; +import net.minecraft.util.registry.Registry; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; @@ -31,8 +31,8 @@ public abstract class CommandEnchantAll { public static int enchantAllCommand (CommandContext context) throws CommandSyntaxException { final ServerCommandSource source = context.getSource(); - final ServerPlayerEntity player = source.getPlayerOrThrow(); - final PlayerInventory inventory = player.getInventory(); + final ServerPlayerEntity player = source.getPlayer(); + final PlayerInventory inventory = player.inventory; final ListTag enchantments = new ListTag(); for (Identifier identifier : Registry.ENCHANTMENT.getIds()) { @@ -45,12 +45,12 @@ public abstract class CommandEnchantAll { final ItemStack stack = inventory.getStack(inventory.selectedSlot).copy(); if (stack.isEmpty()) throw EMPTY_ITEM_EXCEPTION.create(); - CompoundTag nbt = stack.getNbt(); + CompoundTag nbt = stack.getTag(); if (nbt == null) { nbt = new CompoundTag(); - stack.setNbt(nbt); + stack.setTag(nbt); } - stack.getNbt().put("Enchantments", enchantments); + stack.getTag().put("Enchantments", enchantments); inventory.setStack(inventory.selectedSlot, stack); source.sendFeedback(new LiteralText("I killed Martin."), false); diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandJumpscare.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandJumpscare.java index 171956b..2af63f4 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandJumpscare.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandJumpscare.java @@ -12,7 +12,7 @@ import static net.minecraft.command.arguments.EntityArgumentType.getPlayers; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.item.Items; +import net.minecraft.util.registry.Registry; import net.minecraft.util.Identifier; import net.minecraft.particle.ParticleEffect; import net.minecraft.sound.SoundEvent; @@ -42,7 +42,7 @@ public interface CommandJumpscare { final SoundEvent soundEvent = Registry.SOUND_EVENT.get(new Identifier("minecraft", "entity.enderman.scream")); for (ServerPlayerEntity player : players) { - final ServerWorld world = player.getWorld(); + final ServerWorld world = player.getServerWorld(); final Vec3d position = player.getPos(); world.spawnParticles(player, particle, false, position.getX(), position.getY(), position.getZ(), 4, 0, 0, 0, 1); diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandKaboom.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandKaboom.java index 7c74908..02321a7 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandKaboom.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandKaboom.java @@ -6,17 +6,18 @@ import com.mojang.brigadier.context.CommandContext; import static net.minecraft.server.command.CommandManager.literal; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.world.World; import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.explosion.Explosion.DestructionType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.Items; +import net.minecraft.util.registry.Registry; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import net.minecraft.block.BlockState; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.BlockPos; -import net.minecraft.text.Text; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Clearable; import java.util.concurrent.ThreadLocalRandom; public interface CommandKaboom { @@ -29,16 +30,16 @@ public interface CommandKaboom { } static int kaboomCommand (CommandContext context) throws CommandSyntaxException { - final ServerPlayerEntity player = context.getSource().getPlayerOrThrow(); + final ServerPlayerEntity player = context.getSource().getPlayer(); boolean explode = ThreadLocalRandom.current().nextBoolean(); if (explode) { final Vec3d position = player.getPos(); - final ServerWorld world = player.getWorld(); + final ServerWorld world = player.getServerWorld(); final int explosionCount = 20; final int power = 8; - world.createExplosion(player, position.getX(), position.getY(), position.getZ(), power, true, World.ExplosionSourceType.MOB); + world.createExplosion(player, position.getX(), position.getY(), position.getZ(), power, true, DestructionType.DESTROY); final int power2 = 4; final BlockState lava = Registry.BLOCK.get(new Identifier("minecraft", "lava")).getDefaultState(); @@ -48,11 +49,11 @@ public interface CommandKaboom { final double posY = position.getY() + ThreadLocalRandom.current().nextInt(-6, 6); final double posZ = position.getZ() + ThreadLocalRandom.current().nextInt(-15, 15); - world.createExplosion(player, posX, posY, posZ, power2, true, World.ExplosionSourceType.MOB); + world.createExplosion(player, posX, posY, posZ, power2, true, DestructionType.DESTROY); final BlockPos blockPos = new BlockPos((int) posX, (int) posY, (int) posZ); if (!world.canSetBlock(blockPos)) continue; - if (world.getBlockState(blockPos).hasBlockEntity()) world.removeBlockEntity(blockPos); + Clearable.clear(world.getBlockEntity(blockPos)); world.setBlockState(blockPos, lava); } @@ -60,8 +61,8 @@ public interface CommandKaboom { return Command.SINGLE_SUCCESS; } - final PlayerInventory inventory = player.getInventory(); - inventory.setStack(inventory.selectedSlot, new ItemStack(Items.get(new Identifier("minecraft", "cake")))); + final PlayerInventory inventory = player.inventory; + inventory.setStack(inventory.selectedSlot, new ItemStack(Registry.ITEM.get(new Identifier("minecraft", "cake")))); player.sendMessage(new LiteralText("Have a nice day :)")); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandPing.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandPing.java index 9aa4e7e..9d6a6c3 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandPing.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandPing.java @@ -32,7 +32,7 @@ public abstract class CommandPing { public static int pingCommand (CommandContext context) throws CommandSyntaxException { final ServerCommandSource source = context.getSource(); - final ServerPlayerEntity player = source.getPlayerOrThrow(); + final ServerPlayerEntity player = source.getPlayer(); final int ping = player.pingMilliseconds; final Formatting highlighting = getHighlighting(ping); diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandPumpkin.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandPumpkin.java index fb31ee3..1281791 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandPumpkin.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandPumpkin.java @@ -11,7 +11,7 @@ import static net.minecraft.command.arguments.EntityArgumentType.getPlayers; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.Items; +import net.minecraft.util.registry.Registry; import net.minecraft.util.Identifier; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -34,11 +34,11 @@ public interface CommandPumpkin { static int pumpkinCommand (CommandContext context) throws CommandSyntaxException { final ServerCommandSource source = context.getSource(); final Collection players = getPlayers(context, "targets"); - final Item pumpkin = Items.get(new Identifier("minecraft", "pumpkin")); + final Item pumpkin = Registry.ITEM.get(new Identifier("minecraft", "pumpkin")); for (ServerPlayerEntity player : players) { - final PlayerInventory inventory = player.getInventory(); - inventory.setStack(PlayerInventory.ARMOR_SLOTS[3], new ItemStack(pumpkin)); + final PlayerInventory inventory = player.inventory; + inventory.setStack(3, new ItemStack(pumpkin)); } if (players.size() == 1) { diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandSpawn.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandSpawn.java index 74c4b8b..2016efa 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandSpawn.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandSpawn.java @@ -8,6 +8,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import static net.minecraft.server.command.CommandManager.literal; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.level.LevelProperties; +import net.minecraft.world.dimension.DimensionType; import net.minecraft.entity.Entity; import net.minecraft.util.math.Vec3d; import net.minecraft.text.LiteralText; @@ -26,12 +28,11 @@ public interface CommandSpawn { static int spawnCommand (CommandContext context) throws CommandSyntaxException { final ServerCommandSource source = context.getSource(); final Entity entity = source.getEntityOrThrow(); - final ServerWorld world = source.getServer().getOverworld(); + final ServerWorld world = source.getMinecraftServer().getWorld(DimensionType.OVERWORLD); + final LevelProperties properties = world.getLevelProperties(); - final Vec3d spawn = Vec3d.ofCenter(world.getSpawnPos()); - final float spawnAngle = world.getSpawnAngle(); - - entity.teleport(world, spawn.getX(), spawn.getY(), spawn.getZ(), positionFlags, spawnAngle, 0); + entity.setWorld(world); + entity.teleport(properties.getSpawnX() + 0.5, properties.getSpawnY(), properties.getSpawnZ() + 0.5); source.sendFeedback(new LiteralText("Successfully moved to spawn"), false); diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandSpidey.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandSpidey.java index a9e7667..67f0c4e 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandSpidey.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandSpidey.java @@ -9,11 +9,12 @@ import static net.minecraft.server.command.CommandManager.argument; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.entity.Entity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.item.Items; +import net.minecraft.util.registry.Registry; import net.minecraft.util.Identifier; import net.minecraft.block.BlockState; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.Clearable; import land.chipmunk.kaboomfabric.extras.modules.block.BlockIterator; public abstract class CommandSpidey { @@ -29,7 +30,7 @@ public abstract class CommandSpidey { final ServerCommandSource source = context.getSource(); final Entity entity = source.getEntityOrThrow(); final ServerWorld world = source.getWorld(); - + /* final Vec3d start = entity.getEyePos(); final Vec3d direction = Vec3d.fromPolar(entity.getYaw(), entity.getPitch()); final int yOffset = 0; @@ -41,11 +42,12 @@ public abstract class CommandSpidey { while (iterator.hasNext()) { BlockPos pos = iterator.next(); - if (!world.isInBuildLimit(pos) || !world.getBlockState(pos).isAir()) break; + if ((pos.getY() >= 0 && pos.getY() <= 255) || !world.getBlockState(pos).isAir()) break; - if (world.getBlockState(pos).hasBlockEntity()) world.removeBlockEntity(pos); + Clearable.clear(world.getBlockEntity(pos)); world.setBlockState(pos, cobweb); } + */ return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/EntityAccessor.java b/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/EntityAccessor.java new file mode 100644 index 0000000..facad77 --- /dev/null +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/EntityAccessor.java @@ -0,0 +1,9 @@ +package land.chipmunk.kaboomfabric.extras.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(net.minecraft.entity.Entity.class) +public interface EntityAccessor { + @Invoker("destroy") void destroy (); +} diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/ReloadCommandMixin.java b/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/ReloadCommandMixin.java index b311410..ce433f2 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/ReloadCommandMixin.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/ReloadCommandMixin.java @@ -3,14 +3,15 @@ package land.chipmunk.kaboomfabric.extras.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import com.mojang.brigadier.context.CommandContext; import net.minecraft.server.command.ServerCommandSource; import java.util.Collection; @Mixin(net.minecraft.server.command.ReloadCommand.class) public abstract class ReloadCommandMixin { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;reload()V"), method = "method_13530", cancellable = true) - private static void reload (Collection datapacks, ServerCommandSource source, CallbackInfo info) { + private static void reload (CommandContext context, CallbackInfoReturnable info) { info.cancel(); } } diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/ServerWorldAccessor.java b/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/ServerWorldAccessor.java new file mode 100644 index 0000000..1667868 --- /dev/null +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/mixin/ServerWorldAccessor.java @@ -0,0 +1,11 @@ +package land.chipmunk.kaboomfabric.extras.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import net.minecraft.entity.Entity; + +@Mixin(net.minecraft.server.world.ServerWorld.class) +public interface ServerWorldAccessor { + @Accessor("entitiesById") Int2ObjectMap entitiesById (); +} diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/modules/block/BlockIterator.java b/src/main/java/land/chipmunk/kaboomfabric/extras/modules/block/BlockIterator.java index fe3a234..154704c 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/modules/block/BlockIterator.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/modules/block/BlockIterator.java @@ -219,9 +219,12 @@ public class BlockIterator implements Iterator { return getPosition(direction.getZ(), position.getZ(), block.getZ()); } + // TODO: Backport + /* public BlockIterator(Entity entity, int maxDistance) { this(entity.getPos(), Vec3d.fromPolar(entity.getYaw(), entity.getPitch()), entity.getEyeHeight(entity.getPose()), maxDistance); } + */ /** * Constructs the BlockIterator. @@ -231,9 +234,11 @@ public class BlockIterator implements Iterator { * @param entity Information from the entity is used to set up the trace */ + /* public BlockIterator(Entity entity) { this(entity, 0); } + */ /** * Returns true if the iteration has more elements diff --git a/src/main/resources/extras.mixins.json b/src/main/resources/extras.mixins.json index 69cf16a..eb8e23c 100644 --- a/src/main/resources/extras.mixins.json +++ b/src/main/resources/extras.mixins.json @@ -10,7 +10,9 @@ "StopCommandMixin", "ReloadCommandMixin", "OpCommandMixin", - "EntitySelectorMixin" + "EntitySelectorMixin", + "ServerWorldAccessor", + "EntityAccessor" ], "injectors": { "defaultRequire": 1