make it compile

This commit is contained in:
chipmunk 2024-06-16 23:26:33 -04:00
parent 7449a5bb46
commit 6740cf9d4b
16 changed files with 77 additions and 44 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -27,13 +27,13 @@ public interface CommandConsole {
static int consoleCommand (CommandContext<ServerCommandSource> 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;
}

View file

@ -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<ServerCommandSource> 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) {
}

View file

@ -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<ServerCommandSource> 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);

View file

@ -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.<ParticleEffect>spawnParticles(player, particle, false, position.getX(), position.getY(), position.getZ(), 4, 0, 0, 0, 1);

View file

@ -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<ServerCommandSource> 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;
}

View file

@ -32,7 +32,7 @@ public abstract class CommandPing {
public static int pingCommand (CommandContext<ServerCommandSource> 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);

View file

@ -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<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final Collection<ServerPlayerEntity> 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) {

View file

@ -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<ServerCommandSource> 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);

View file

@ -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;
}

View file

@ -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 ();
}

View file

@ -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<ServerCommandSource> context, CallbackInfoReturnable<Integer> info) {
info.cancel();
}
}

View file

@ -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<Entity> entitiesById ();
}

View file

@ -219,9 +219,12 @@ public class BlockIterator implements Iterator<BlockPos> {
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<BlockPos> {
* @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

View file

@ -10,7 +10,9 @@
"StopCommandMixin",
"ReloadCommandMixin",
"OpCommandMixin",
"EntitySelectorMixin"
"EntitySelectorMixin",
"ServerWorldAccessor",
"EntityAccessor"
],
"injectors": {
"defaultRequire": 1