Skip to content

Commit

Permalink
feat: updated to 1.21.2/3
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHillcox committed Dec 31, 2024
1 parent 1bbd12d commit a93e553
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 283 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 89.0.0

### Changed

- Updated to 1.21.2/1.21.3
- The `/tk clear` command now supports custom input filters as well as optionally being able to remove bedrock from the world
- This technically replaces existing functionality where a tag or blockstate would be read from the input but due to poor auto-complete, this is basically an unknown feature so we've changed it to one that's much more clear
- The new syntax is `/tk clear <size> [filter] [removeBedrock]`

## 87.0.1

### Changed
Expand All @@ -22,7 +31,6 @@

- Updated to 1.21


## 85.0.0

### Changed
Expand Down
51 changes: 49 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import groovy.json.JsonSlurper

plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.7.1"
}

architectury {
Expand Down Expand Up @@ -88,12 +90,14 @@ publishMods {
accessToken = providers.environmentVariable("CURSE_TOKEN")
projectId = "${curseforge_id}"
minecraftVersions.add("${minecraft_version}")
minecraftVersions.add("1.21.2")
}

def modrinthOptions = modrinthOptions {
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
projectId = "${modrinth_id}"
minecraftVersions.add("${minecraft_version}")
minecraftVersions.add("1.21.2")
}

curseforge("curseforgeFabric") {
Expand Down Expand Up @@ -146,3 +150,46 @@ publishMods {
}
}
}

tasks.register("updateModVersion") {
doLast {
def gradleFile = file("gradle.properties")
def text = gradleFile.text

def minecraftVersion = getModPrefixVersion()
def modVersion = text.find("mod_version=(.*)")

if (modVersion == null) {
throw new IllegalStateException("Could not find mod_version in gradle.properties")
}

modVersion = modVersion.split("=")[1]
def remainingVersion = modVersion.tokenize(".").drop(1).join(".")
def newVersion = "${minecraftVersion}.${remainingVersion}"

text = text.replace("mod_version=${modVersion}", "mod_version=${newVersion}")
gradleFile.text = text

println "Updated mod version to ${newVersion} from ${modVersion}"
}
}

def getModPrefixVersion() {
def url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
def json = new JsonSlurper().parseText(url.toURL().text)

def versions = json.versions
versions = versions.reverse() // We want the oldest version first
versions = versions.findAll { it.type == "release" } // We only want releases

def incrementalVersion = 0
for (version in versions) {
if (version.id == minecraft_version) {
break
}

incrementalVersion++
}

return incrementalVersion
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
.then(SlayerCommand.register())
.then(EnchantCommand.register(context))
.then(BlockDistributionCommand.register())
.then(ClearCommand.register())
.then(ClearCommand.register(context))
.then(KillEntitiesCommand.register(context))
.then(HealCommand.register())
.then(RepairItemCommand.register())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ private static int giveItem(ServerPlayer player) {

var enchants = itemstack.get(DataComponents.ENCHANTMENTS);
var mutableEnchants = new ItemEnchantments.Mutable(enchants);
Registry<Enchantment> enchantmentRegistry = player.server.registryAccess().registryOrThrow(Registries.ENCHANTMENT);
enchantments.forEach(e -> mutableEnchants.set(enchantmentRegistry.getHolderOrThrow(e), Short.MAX_VALUE));
Registry<Enchantment> enchantmentRegistry = player.server.registryAccess().lookupOrThrow(Registries.ENCHANTMENT);
enchantments.forEach(e -> mutableEnchants.set(enchantmentRegistry.get(e).orElseThrow(), 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
@@ -1,27 +1,27 @@
package com.sunekaer.toolkit.commands.level;

import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.sunekaer.toolkit.ToolkitPlatform;
import com.sunekaer.toolkit.jobs.ServerTickJobRunner;
import com.sunekaer.toolkit.utils.ChunkRangeIterator;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.blocks.BlockPredicateArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.pattern.BlockInWorld;

import java.util.*;
import java.util.concurrent.ExecutorService;
Expand All @@ -33,43 +33,73 @@ public class ClearCommand {
private static final AtomicBoolean COMPLETED = new AtomicBoolean(true);
public static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();

public static ArgumentBuilder<CommandSourceStack, ?> register() {
public static ArgumentBuilder<CommandSourceStack, ?> register(CommandBuildContext commandBuildContext) {
return (Commands.literal("clear")
.requires(cs -> cs.hasPermission(2))
.executes(context -> remove(context.getSource(), 1, RemovalPredicate.NAMES[0]))
.then(Commands.argument("range", IntegerArgumentType.integer()).executes(ctx -> remove(ctx.getSource(), IntegerArgumentType.getInteger(ctx, "range"), RemovalPredicate.NAMES[0]))
.then(Commands.argument("filter", StringArgumentType.string()).suggests((commandContext, suggestionsBuilder) -> SharedSuggestionProvider.suggest(RemovalPredicate.NAMES, suggestionsBuilder)).executes(ctx -> remove(ctx.getSource(), IntegerArgumentType.getInteger(ctx, "range"), StringArgumentType.getString(ctx, "filter"))))));
.executes(context -> remove(context.getSource(), 1, RemovalPredicate.NAMES[0], false))
.then(Commands.argument("range", IntegerArgumentType.integer())
.executes(ctx -> remove(ctx.getSource(), IntegerArgumentType.getInteger(ctx, "range"), RemovalPredicate.NAMES[0], false))
.then(Commands.argument("filter", StringArgumentType.string())
.suggests((commandContext, suggestionsBuilder) -> SharedSuggestionProvider.suggest(RemovalPredicate.NAMES, suggestionsBuilder))
.executes(ctx -> remove(ctx.getSource(), IntegerArgumentType.getInteger(ctx, "range"), StringArgumentType.getString(ctx, "filter"), false))
.then(Commands.argument("removes_bedrock", BoolArgumentType.bool())
.executes(ctx -> remove(ctx.getSource(), IntegerArgumentType.getInteger(ctx, "range"), StringArgumentType.getString(ctx, "filter"), BoolArgumentType.getBool(ctx, "removes_bedrock")))
)
)
.then(Commands.literal("custom_filter")
.then(Commands.argument("block", BlockPredicateArgument.blockPredicate(commandBuildContext))
.executes(ctx -> remove(ctx.getSource(), IntegerArgumentType.getInteger(ctx, "range"), BlockPredicateArgument.getBlockPredicate(ctx, "block")))
)
)
)
);
}

private static int remove(CommandSourceStack source, int size, String filter) throws CommandSyntaxException {
private static int remove(CommandSourceStack source, int size, String filter, boolean removesBedrock) throws CommandSyntaxException {
_remove(new RemoveContext(
source,
size,
RemovalPredicate.getFromName(filter).orElse(RemovalPredicate.JUST_ORES).stateCheck,
removesBedrock
));

return 1;
}

private static int remove(CommandSourceStack source, int size, Predicate<BlockInWorld> blockCheck) throws CommandSyntaxException {
_remove(new RemoveContext(
source,
size,
blockCheck,
false
));

return 1;
}

private static void _remove(RemoveContext context) throws CommandSyntaxException {
var source = context.commandStack;

// Block running
if (!COMPLETED.get()) {
source.sendFailure(Component.literal("Already running, give it a second."));
return 1;
return;
}

COMPLETED.set(false);
var player = source.getPlayerOrException();

// Resolve the predicate check, we're lazy, so we'll get the enum regardless but if the filter looks like a
// tag then lets try a tag instead
var removalCheck = RemovalPredicate.getFromName(filter).orElse(RemovalPredicate.JUST_ORES);
Predicate<BlockState> customCheck = null;
if (filter.startsWith("#")) {
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);
}
var removalCheck = context.filter;

ServerLevel level = source.getLevel();
source.sendSuccess(() -> Component.translatable("commands.toolkit.remove.lagwarring"), true);

// We're removing 1 to make it so 1 = 0, 2 - 1, etc, this means we'll have correct radius 0 = 1x1, 1 = 3x3, 2 = 5x5
var range = size - 1;
var range = context.size - 1;
var chunkPos = player.chunkPosition();

// Compute the max height for the wall and queue the chunk removal
Predicate<BlockState> finalCustomCheck = customCheck;
COMPLETED.set(false);

for (int x = chunkPos.x - range; x <= chunkPos.x + range; x++) {
Expand All @@ -79,7 +109,7 @@ private static int remove(CommandSourceStack source, int size, String filter) th
final boolean shouldComplete = x == chunkPos.x + range && z == chunkPos.z + range;

ServerTickJobRunner.get().add(() -> {
removeChunk(level, currentChunkPos, finalCustomCheck != null ? finalCustomCheck : removalCheck.stateCheck);
removeChunk(level, currentChunkPos, removalCheck, context.removesBedrock);

// If this is the last chunk, then we're done
if (shouldComplete) {
Expand All @@ -88,8 +118,6 @@ private static int remove(CommandSourceStack source, int size, String filter) th
});
}
}

return 1;
}

/**
Expand All @@ -99,29 +127,29 @@ private static int remove(CommandSourceStack source, int size, String filter) th
* @param chunkPos the chunk to remove
* @param blockCheck the predicate that defines what blocks are removed
*/
private static void removeChunk(ServerLevel level, ChunkPos chunkPos, Predicate<BlockState> blockCheck) {
private static void removeChunk(ServerLevel level, ChunkPos chunkPos, Predicate<BlockInWorld> blockCheck, boolean removeBedrock) {
BlockState airState = Blocks.AIR.defaultBlockState();

ChunkRangeIterator iterator = new ChunkRangeIterator(level, chunkPos, 1, true);
List<BlockPos> updatedBlocks = new ArrayList<>();

int maxHeight = level.dimension() == ServerLevel.NETHER ? 127 : level.getMaxBuildHeight();

int maxHeight = level.dimension() == ServerLevel.NETHER ? 127 : level.getMaxY();
while (iterator.hasNext()) {
BlockPos pos = iterator.next();
final BlockState state = level.getBlockState(pos);

// Don't remove bedrock and skip air, it's a waste of computation
if (state.isAir() || state.getBlock() == Blocks.BEDROCK) {
if (!state.isAir() && pos.getY() > level.getMinBuildHeight() && pos.getY() < maxHeight) {
if (state.isAir() || (!removeBedrock && state.getBlock() == Blocks.BEDROCK)) {
if (!state.isAir() && pos.getY() > level.getMinY() && pos.getY() < maxHeight) {
level.setBlock(pos, airState, Block.UPDATE_CLIENTS);
updatedBlocks.add(pos);
}

continue;
}

if (blockCheck.test(state)) {
var blockInWorld = new BlockInWorld(level, pos, true);
if (!blockCheck.test(blockInWorld)) {
continue;
}

Expand All @@ -135,20 +163,27 @@ private static void removeChunk(ServerLevel level, ChunkPos chunkPos, Predicate<
}

private enum RemovalPredicate {
JUST_ORES(state -> state.is(ToolkitPlatform.getOresTag())),
ORES_AND_MODDED(state -> state.is(ToolkitPlatform.getOresTag()) && BuiltInRegistries.BLOCK.getKey(state.getBlock()).getNamespace().equals("minecraft"));
JUST_ORES(state -> !state.getState().is(ToolkitPlatform.getOresTag())),
ORES_AND_MODDED(state -> !state.getState().is(ToolkitPlatform.getOresTag()) || !BuiltInRegistries.BLOCK.getKey(state.getState().getBlock()).getNamespace().equals("minecraft"));

public static final List<RemovalPredicate> VALUES = Arrays.asList(values());
public static final String[] NAMES = VALUES.stream().map(e -> e.toString().toLowerCase()).toArray(String[]::new);

final Predicate<BlockState> stateCheck;
RemovalPredicate(Predicate<BlockState> stateCheck) {
final Predicate<BlockInWorld> stateCheck;
RemovalPredicate(Predicate<BlockInWorld> stateCheck) {
this.stateCheck = stateCheck;
}

public static Optional<RemovalPredicate> getFromName(String name) {
return VALUES.stream().filter(e -> e.toString().toLowerCase().equals(name)).findFirst();
}
}

private record RemoveContext(
CommandSourceStack commandStack,
int size,
Predicate<BlockInWorld> filter,
boolean removesBedrock
) {}
}

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static int kill(KillType type, CommandSourceStack source) throws Command

if (type == KillType.me || type == KillType.players) {
for (Player player : level.getPlayers(e -> type.checker.test(e, e))) {
player.kill();
player.kill(source.getLevel());
entitiesKilled++;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ private static int mine(CommandSourceStack source, int size, String filter) thro
try {
ItemStack breaker = new ItemStack(Items.NETHERITE_PICKAXE);

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

MinecraftServer server = source.getServer();
ServerLevel level = source.getLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Relative;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
Expand Down Expand Up @@ -45,7 +46,7 @@ private static int teleport(CommandSourceStack source, MinecraftServer server, C

if (entity instanceof ServerPlayer serverPlayer) {
playerXp = serverPlayer.experienceLevel;
serverPlayer.teleportTo(level, pos.getX(), pos.getY(), pos.getZ(), entity.getYRot(), entity.getXRot());
serverPlayer.teleportTo(level, pos.getX(), pos.getY(), pos.getZ(), Relative.ALL, entity.getYRot(), entity.getXRot(), true);
serverPlayer.setExperienceLevels(playerXp);
} else {
entity.teleportTo(pos.getX(), pos.getY(), pos.getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public ChunkRangeIterator(Level level, ChunkPos startPos, int size, boolean reve
this.currentX = minX;
this.currentZ = minZ;
this.reverseY = reverseY;
this.currentY = reverseY ? level.getMaxBuildHeight() : level.getMinBuildHeight();
this.currentY = reverseY ? level.getMaxY() : level.getMinY();
}

@Override
public boolean hasNext() {
return (this.reverseY ? currentY > level.getMinBuildHeight() : currentY < level.getMaxBuildHeight())
return (this.reverseY ? currentY >= level.getMinY() : currentY <= level.getMaxY())
&& currentZ < maxZ
&& currentX < maxX;
}
Expand All @@ -70,6 +70,6 @@ public BlockPos next() {
}
}

return pos;
return pos;
}
}
4 changes: 2 additions & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ processResources {

filesMatching("fabric.mod.json") {
expand "version": project.version,
"mcversion": rootProject.minecraft_version,
"mcversion": rootProject.lowest_minecraft_version,
"archversion": rootProject.architectury_version
}
}
Expand Down Expand Up @@ -88,4 +88,4 @@ publishing {
from components.java
}
}
}
}
Loading

0 comments on commit a93e553

Please sign in to comment.