fixes for 22w11a
This commit is contained in:
1 parent
3e419d1557
commit
302a7b4817
39 files changed
+410
-305
No files matched your search
+1
-1
@@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/use
|
# check these on https://fabricmc.net/use
|
||||||
# or better: https://modmuss50.me/fabric.html
|
# or better: https://modmuss50.me/fabric.html
|
||||||
minecraft_version=1.18.2
|
minecraft_version=22w11a
|
||||||
loader_version=0.13.3
|
loader_version=0.13.3
|
||||||
fabric_version=0.46.4+1.18
|
fabric_version=0.46.4+1.18
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package carpet;
|
|||||||
import carpet.script.CarpetExpression;
|
import carpet.script.CarpetExpression;
|
||||||
import carpet.settings.SettingsManager;
|
import carpet.settings.SettingsManager;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -44,12 +46,32 @@ public interface CarpetExtension
|
|||||||
/**
|
/**
|
||||||
* Register your own commands right after vanilla commands are added
|
* Register your own commands right after vanilla commands are added
|
||||||
* If that matters for you
|
* If that matters for you
|
||||||
|
*
|
||||||
|
* Deprecated, use either this or rather {@link CarpetExtension#registerCommands(CommandDispatcher, CommandBuildContext)}
|
||||||
*
|
*
|
||||||
* @param dispatcher The current {@link CommandSource<ServerCommandSource>} dispatcher
|
* @param dispatcher The current {@link CommandSource<ServerCommandSource>} dispatcher
|
||||||
* where you should register your commands
|
* where you should register your commands
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
default void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher) {}
|
@Deprecated(forRemoval = true)
|
||||||
|
default void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
|
final CommandBuildContext context = new CommandBuildContext(RegistryAccess.BUILTIN.get());
|
||||||
|
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
|
||||||
|
registerCommands(dispatcher, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register your own commands right after vanilla commands are added
|
||||||
|
* If that matters for you
|
||||||
|
*
|
||||||
|
* @param dispatcher The current {@link CommandDispatcher<CommandSourceStack>} dispatcher
|
||||||
|
* where you should register your commands
|
||||||
|
* @param commandBuildContext The current {@link CommandBuildContext} context
|
||||||
|
* * which you can use for registries lookup
|
||||||
|
*/
|
||||||
|
default void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher, final CommandBuildContext commandBuildContext) {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide your own custom settings manager managed in the same way as base /carpet
|
* Provide your own custom settings manager managed in the same way as base /carpet
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.mojang.brigadier.CommandDispatcher;
|
|||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
@@ -117,37 +118,35 @@ public class CarpetServer // static for now - easier to handle all around the co
|
|||||||
extensions.forEach(e -> e.onTick(server));
|
extensions.forEach(e -> e.onTick(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
public static void registerCarpetCommands(CommandDispatcher<CommandSourceStack> dispatcher, Commands.CommandSelection environment, CommandBuildContext commandBuildContext)
|
||||||
public static void registerCarpetCommands(CommandDispatcher<CommandSourceStack> dispatcher) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerCarpetCommands(CommandDispatcher<CommandSourceStack> dispatcher, Commands.CommandSelection environment)
|
|
||||||
{
|
{
|
||||||
if (settingsManager == null) // bootstrap dev initialization check
|
if (settingsManager == null) // bootstrap dev initialization check
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
settingsManager.registerCommand(dispatcher);
|
settingsManager.registerCommand(dispatcher, commandBuildContext);
|
||||||
extensions.forEach(e -> {
|
extensions.forEach(e -> {
|
||||||
SettingsManager sm = e.customSettingsManager();
|
SettingsManager sm = e.customSettingsManager();
|
||||||
if (sm != null) sm.registerCommand(dispatcher);
|
if (sm != null) sm.registerCommand(dispatcher, commandBuildContext);
|
||||||
});
|
});
|
||||||
TickCommand.register(dispatcher);
|
TickCommand.register(dispatcher, commandBuildContext);
|
||||||
ProfileCommand.register(dispatcher);
|
ProfileCommand.register(dispatcher, commandBuildContext);
|
||||||
CounterCommand.register(dispatcher);
|
CounterCommand.register(dispatcher, commandBuildContext);
|
||||||
LogCommand.register(dispatcher);
|
LogCommand.register(dispatcher, commandBuildContext);
|
||||||
SpawnCommand.register(dispatcher);
|
SpawnCommand.register(dispatcher, commandBuildContext);
|
||||||
PlayerCommand.register(dispatcher);
|
PlayerCommand.register(dispatcher, commandBuildContext);
|
||||||
//CameraModeCommand.register(dispatcher);
|
InfoCommand.register(dispatcher, commandBuildContext);
|
||||||
InfoCommand.register(dispatcher);
|
DistanceCommand.register(dispatcher, commandBuildContext);
|
||||||
DistanceCommand.register(dispatcher);
|
PerimeterInfoCommand.register(dispatcher, commandBuildContext);
|
||||||
PerimeterInfoCommand.register(dispatcher);
|
DrawCommand.register(dispatcher, commandBuildContext);
|
||||||
DrawCommand.register(dispatcher);
|
ScriptCommand.register(dispatcher, commandBuildContext);
|
||||||
ScriptCommand.register(dispatcher);
|
MobAICommand.register(dispatcher, commandBuildContext);
|
||||||
MobAICommand.register(dispatcher);
|
|
||||||
// registering command of extensions that has registered before either server is created
|
// registering command of extensions that has registered before either server is created
|
||||||
// for all other, they will have them registered when they add themselves
|
// for all other, they will have them registered when they add themselves
|
||||||
extensions.forEach(e -> e.registerCommands(dispatcher));
|
extensions.forEach(e -> {
|
||||||
|
e.registerCommands(dispatcher, commandBuildContext);
|
||||||
|
e.registerCommands(dispatcher);
|
||||||
|
});
|
||||||
currentCommandDispatcher = dispatcher;
|
currentCommandDispatcher = dispatcher;
|
||||||
|
|
||||||
if (environment != Commands.CommandSelection.DEDICATED)
|
if (environment != Commands.CommandSelection.DEDICATED)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import carpet.helpers.HopperCounter;
|
|||||||
import carpet.utils.Messenger;
|
import carpet.utils.Messenger;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandRuntimeException;
|
import net.minecraft.commands.CommandRuntimeException;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
@@ -20,7 +21,7 @@ public class CounterCommand
|
|||||||
/**
|
/**
|
||||||
* The method used to register the command and make it available for the players to use.
|
* The method used to register the command and make it available for the players to use.
|
||||||
*/
|
*/
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = Commands.literal("counter").executes((context)
|
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = Commands.literal("counter").executes((context)
|
||||||
-> listAllCounters(context.getSource(), false)).requires((player) ->
|
-> listAllCounters(context.getSource(), false)).requires((player) ->
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import carpet.settings.SettingsManager;
|
|||||||
import carpet.utils.DistanceCalculator;
|
import carpet.utils.DistanceCalculator;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
|
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ import static net.minecraft.commands.Commands.literal;
|
|||||||
|
|
||||||
public class DistanceCommand
|
public class DistanceCommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> command = literal("distance").
|
LiteralArgumentBuilder<CommandSourceStack> command = literal("distance").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDistance)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDistance)).
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import com.mojang.brigadier.context.CommandContext;
|
|||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.blocks.BlockInput;
|
import net.minecraft.commands.arguments.blocks.BlockInput;
|
||||||
import net.minecraft.commands.arguments.blocks.BlockPredicateArgument;
|
import net.minecraft.commands.arguments.blocks.BlockPredicateArgument;
|
||||||
@@ -35,48 +37,48 @@ import static net.minecraft.commands.SharedSuggestionProvider.suggest;
|
|||||||
|
|
||||||
public class DrawCommand
|
public class DrawCommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, final CommandBuildContext context)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> command = literal("draw").
|
LiteralArgumentBuilder<CommandSourceStack> command = literal("draw").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)).
|
||||||
then(literal("sphere").
|
then(literal("sphere").
|
||||||
then(argument("center", BlockPosArgument.blockPos()).
|
then(argument("center", BlockPosArgument.blockPos()).
|
||||||
then(argument("radius", IntegerArgumentType.integer(1)).
|
then(argument("radius", IntegerArgumentType.integer(1)).
|
||||||
then(drawShape(c -> DrawCommand.drawSphere(c, false)))))).
|
then(drawShape(c -> DrawCommand.drawSphere(c, false), context))))).
|
||||||
then(literal("ball").
|
then(literal("ball").
|
||||||
then(argument("center", BlockPosArgument.blockPos()).
|
then(argument("center", BlockPosArgument.blockPos()).
|
||||||
then(argument("radius", IntegerArgumentType.integer(1)).
|
then(argument("radius", IntegerArgumentType.integer(1)).
|
||||||
then(drawShape(c -> DrawCommand.drawSphere(c, true)))))).
|
then(drawShape(c -> DrawCommand.drawSphere(c, true), context))))).
|
||||||
then(literal("diamond").
|
then(literal("diamond").
|
||||||
then(argument("center", BlockPosArgument.blockPos()).
|
then(argument("center", BlockPosArgument.blockPos()).
|
||||||
then(argument("radius", IntegerArgumentType.integer(1)).
|
then(argument("radius", IntegerArgumentType.integer(1)).
|
||||||
then(drawShape(c -> DrawCommand.drawDiamond(c, true)))))).
|
then(drawShape(c -> DrawCommand.drawDiamond(c, true), context))))).
|
||||||
then(literal("pyramid").
|
then(literal("pyramid").
|
||||||
then(argument("center", BlockPosArgument.blockPos()).
|
then(argument("center", BlockPosArgument.blockPos()).
|
||||||
then(argument("radius", IntegerArgumentType.integer(1)).
|
then(argument("radius", IntegerArgumentType.integer(1)).
|
||||||
then(argument("height",IntegerArgumentType.integer(1)).
|
then(argument("height",IntegerArgumentType.integer(1)).
|
||||||
then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"up","down"},b)).
|
then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"up","down"},b)).
|
||||||
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b)).
|
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b)).
|
||||||
then(drawShape(c -> DrawCommand.drawPyramid(c, "square", true))))))))).
|
then(drawShape(c -> DrawCommand.drawPyramid(c, "square", true), context)))))))).
|
||||||
then(literal("cone").
|
then(literal("cone").
|
||||||
then(argument("center", BlockPosArgument.blockPos()).
|
then(argument("center", BlockPosArgument.blockPos()).
|
||||||
then(argument("radius", IntegerArgumentType.integer(1)).
|
then(argument("radius", IntegerArgumentType.integer(1)).
|
||||||
then(argument("height",IntegerArgumentType.integer(1)).
|
then(argument("height",IntegerArgumentType.integer(1)).
|
||||||
then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"up","down"},b)).
|
then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"up","down"},b)).
|
||||||
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
|
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
|
||||||
.then(drawShape(c -> DrawCommand.drawPyramid(c, "circle", true))))))))).
|
.then(drawShape(c -> DrawCommand.drawPyramid(c, "circle", true), context)))))))).
|
||||||
then(literal("cylinder").
|
then(literal("cylinder").
|
||||||
then(argument("center", BlockPosArgument.blockPos()).
|
then(argument("center", BlockPosArgument.blockPos()).
|
||||||
then(argument("radius", IntegerArgumentType.integer(1)).
|
then(argument("radius", IntegerArgumentType.integer(1)).
|
||||||
then(argument("height",IntegerArgumentType.integer(1)).
|
then(argument("height",IntegerArgumentType.integer(1)).
|
||||||
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
|
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
|
||||||
.then(drawShape(c -> DrawCommand.drawPrism(c, "circle")))))))).
|
.then(drawShape(c -> DrawCommand.drawPrism(c, "circle"), context))))))).
|
||||||
then(literal("cuboid").
|
then(literal("cuboid").
|
||||||
then(argument("center", BlockPosArgument.blockPos()).
|
then(argument("center", BlockPosArgument.blockPos()).
|
||||||
then(argument("radius", IntegerArgumentType.integer(1)).
|
then(argument("radius", IntegerArgumentType.integer(1)).
|
||||||
then(argument("height",IntegerArgumentType.integer(1)).
|
then(argument("height",IntegerArgumentType.integer(1)).
|
||||||
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
|
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
|
||||||
.then(drawShape(c -> DrawCommand.drawPrism(c, "square"))))))));
|
.then(drawShape(c -> DrawCommand.drawPrism(c, "square"), context)))))));
|
||||||
dispatcher.register(command);
|
dispatcher.register(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,12 +89,12 @@ public class DrawCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static RequiredArgumentBuilder<CommandSourceStack, BlockInput>
|
private static RequiredArgumentBuilder<CommandSourceStack, BlockInput>
|
||||||
drawShape(Command<CommandSourceStack> drawer)
|
drawShape(Command<CommandSourceStack> drawer, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
return argument("block", BlockStateArgument.block()).
|
return argument("block", BlockStateArgument.block(commandBuildContext)).
|
||||||
executes(drawer)
|
executes(drawer)
|
||||||
.then(literal("replace")
|
.then(literal("replace")
|
||||||
.then(argument("filter", BlockPredicateArgument.blockPredicate())
|
.then(argument("filter", BlockPredicateArgument.blockPredicate(commandBuildContext))
|
||||||
.executes(drawer)));
|
.executes(drawer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@@ -21,7 +23,7 @@ import static net.minecraft.commands.Commands.literal;
|
|||||||
|
|
||||||
public class InfoCommand
|
public class InfoCommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> command = literal("info").
|
LiteralArgumentBuilder<CommandSourceStack> command = literal("info").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandInfo)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandInfo)).
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -24,7 +26,7 @@ import static net.minecraft.commands.SharedSuggestionProvider.suggest;
|
|||||||
|
|
||||||
public class LogCommand
|
public class LogCommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = Commands.literal("log").
|
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = Commands.literal("log").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandLog)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandLog)).
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import carpet.utils.MobAI;
|
|||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.EntitySummonArgument;
|
import net.minecraft.commands.arguments.EntitySummonArgument;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
@@ -16,7 +17,7 @@ import static net.minecraft.commands.SharedSuggestionProvider.suggest;
|
|||||||
|
|
||||||
public class MobAICommand
|
public class MobAICommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, final CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> command = literal("track").
|
LiteralArgumentBuilder<CommandSourceStack> command = literal("track").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTrackAI)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTrackAI)).
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import carpet.utils.Messenger;
|
|||||||
import carpet.utils.PerimeterDiagnostics;
|
import carpet.utils.PerimeterDiagnostics;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.EntitySummonArgument;
|
import net.minecraft.commands.arguments.EntitySummonArgument;
|
||||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||||
@@ -21,7 +22,7 @@ import static net.minecraft.commands.Commands.literal;
|
|||||||
|
|
||||||
public class PerimeterInfoCommand
|
public class PerimeterInfoCommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> command = literal("perimeterinfo").
|
LiteralArgumentBuilder<CommandSourceStack> command = literal("perimeterinfo").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPerimeterInfo)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPerimeterInfo)).
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
|||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.DimensionArgument;
|
import net.minecraft.commands.arguments.DimensionArgument;
|
||||||
import net.minecraft.commands.arguments.coordinates.RotationArgument;
|
import net.minecraft.commands.arguments.coordinates.RotationArgument;
|
||||||
@@ -44,7 +45,7 @@ public class PlayerCommand
|
|||||||
{
|
{
|
||||||
|
|
||||||
// TODO: allow any order like execute
|
// TODO: allow any order like execute
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
final String[] gamemodeStrings = Arrays.stream(GameType.values())
|
final String[] gamemodeStrings = Arrays.stream(GameType.values())
|
||||||
.map(GameType::getName)
|
.map(GameType::getName)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import carpet.CarpetSettings;
|
|||||||
import carpet.settings.SettingsManager;
|
import carpet.settings.SettingsManager;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
|
||||||
import static carpet.commands.TickCommand.healthEntities;
|
import static carpet.commands.TickCommand.healthEntities;
|
||||||
@@ -15,7 +16,7 @@ import static net.minecraft.commands.Commands.literal;
|
|||||||
|
|
||||||
public class ProfileCommand
|
public class ProfileCommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("profile").
|
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("profile").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandProfile)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandProfile)).
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.mojang.brigadier.context.CommandContext;
|
|||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -129,7 +130,7 @@ public class ScriptCommand
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, final CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> b = literal("globals").
|
LiteralArgumentBuilder<CommandSourceStack> b = literal("globals").
|
||||||
executes(context -> listGlobals(context, false)).
|
executes(context -> listGlobals(context, false)).
|
||||||
@@ -216,7 +217,7 @@ public class ScriptCommand
|
|||||||
then(argument("from", BlockPosArgument.blockPos()).
|
then(argument("from", BlockPosArgument.blockPos()).
|
||||||
then(argument("to", BlockPosArgument.blockPos()).
|
then(argument("to", BlockPosArgument.blockPos()).
|
||||||
then(argument("expr", StringArgumentType.string()).
|
then(argument("expr", StringArgumentType.string()).
|
||||||
then(argument("block", BlockStateArgument.block()).
|
then(argument("block", BlockStateArgument.block(commandBuildContext)).
|
||||||
executes((cc) -> scriptFill(
|
executes((cc) -> scriptFill(
|
||||||
cc,
|
cc,
|
||||||
BlockPosArgument.getSpawnablePos(cc, "origin"),
|
BlockPosArgument.getSpawnablePos(cc, "origin"),
|
||||||
@@ -227,7 +228,7 @@ public class ScriptCommand
|
|||||||
null, "solid"
|
null, "solid"
|
||||||
)).
|
)).
|
||||||
then(literal("replace").
|
then(literal("replace").
|
||||||
then(argument("filter", BlockPredicateArgument.blockPredicate())
|
then(argument("filter", BlockPredicateArgument.blockPredicate(commandBuildContext))
|
||||||
.executes((cc) -> scriptFill(
|
.executes((cc) -> scriptFill(
|
||||||
cc,
|
cc,
|
||||||
BlockPosArgument.getSpawnablePos(cc, "origin"),
|
BlockPosArgument.getSpawnablePos(cc, "origin"),
|
||||||
@@ -243,7 +244,7 @@ public class ScriptCommand
|
|||||||
then(argument("from", BlockPosArgument.blockPos()).
|
then(argument("from", BlockPosArgument.blockPos()).
|
||||||
then(argument("to", BlockPosArgument.blockPos()).
|
then(argument("to", BlockPosArgument.blockPos()).
|
||||||
then(argument("expr", StringArgumentType.string()).
|
then(argument("expr", StringArgumentType.string()).
|
||||||
then(argument("block", BlockStateArgument.block()).
|
then(argument("block", BlockStateArgument.block(commandBuildContext)).
|
||||||
executes((cc) -> scriptFill(
|
executes((cc) -> scriptFill(
|
||||||
cc,
|
cc,
|
||||||
BlockPosArgument.getSpawnablePos(cc, "origin"),
|
BlockPosArgument.getSpawnablePos(cc, "origin"),
|
||||||
@@ -254,7 +255,7 @@ public class ScriptCommand
|
|||||||
null, "outline"
|
null, "outline"
|
||||||
)).
|
)).
|
||||||
then(literal("replace").
|
then(literal("replace").
|
||||||
then(argument("filter", BlockPredicateArgument.blockPredicate())
|
then(argument("filter", BlockPredicateArgument.blockPredicate(commandBuildContext))
|
||||||
.executes((cc) -> scriptFill(
|
.executes((cc) -> scriptFill(
|
||||||
cc,
|
cc,
|
||||||
BlockPosArgument.getSpawnablePos(cc, "origin"),
|
BlockPosArgument.getSpawnablePos(cc, "origin"),
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.DimensionArgument;
|
import net.minecraft.commands.arguments.DimensionArgument;
|
||||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||||
@@ -36,7 +38,7 @@ import static net.minecraft.commands.SharedSuggestionProvider.suggest;
|
|||||||
|
|
||||||
public class SpawnCommand
|
public class SpawnCommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("spawn").
|
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("spawn").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandSpawn));
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandSpawn));
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import carpet.utils.Messenger;
|
|||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.network.chat.BaseComponent;
|
import net.minecraft.network.chat.BaseComponent;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
@@ -25,7 +26,7 @@ import static net.minecraft.commands.SharedSuggestionProvider.suggest;
|
|||||||
|
|
||||||
public class TickCommand
|
public class TickCommand
|
||||||
{
|
{
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("tick").
|
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("tick").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTick)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTick)).
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package carpet.fakes;
|
package carpet.fakes;
|
||||||
|
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ChunkGeneratorInterface
|
public interface ChunkGeneratorInterface
|
||||||
{
|
{
|
||||||
void initStrongholds();
|
void initStrongholds(final ServerLevel level);
|
||||||
List<StructurePlacement> getPlacementsForFeatureCM(final ConfiguredStructureFeature<?, ?> structure);
|
List<StructurePlacement> getPlacementsForFeatureCM(final ServerLevel level, final Structure structure);
|
||||||
}
|
}
|
||||||
@@ -399,7 +399,7 @@ public class EntityPlayerActionPack
|
|||||||
boolean blockBroken = false;
|
boolean blockBroken = false;
|
||||||
if (player.gameMode.getGameModeForPlayer().isCreative())
|
if (player.gameMode.getGameModeForPlayer().isCreative())
|
||||||
{
|
{
|
||||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
|
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight(), -1);
|
||||||
ap.blockHitDelay = 5;
|
ap.blockHitDelay = 5;
|
||||||
blockBroken = true;
|
blockBroken = true;
|
||||||
}
|
}
|
||||||
@@ -407,9 +407,9 @@ public class EntityPlayerActionPack
|
|||||||
{
|
{
|
||||||
if (ap.currentBlock != null)
|
if (ap.currentBlock != null)
|
||||||
{
|
{
|
||||||
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
|
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight(), -1);
|
||||||
}
|
}
|
||||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
|
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight(), -1);
|
||||||
boolean notAir = !state.isAir();
|
boolean notAir = !state.isAir();
|
||||||
if (notAir && ap.curBlockDamageMP == 0)
|
if (notAir && ap.curBlockDamageMP == 0)
|
||||||
{
|
{
|
||||||
@@ -432,7 +432,7 @@ public class EntityPlayerActionPack
|
|||||||
ap.curBlockDamageMP += state.getDestroyProgress(player, player.level, pos);
|
ap.curBlockDamageMP += state.getDestroyProgress(player, player.level, pos);
|
||||||
if (ap.curBlockDamageMP >= 1)
|
if (ap.curBlockDamageMP >= 1)
|
||||||
{
|
{
|
||||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
|
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight(), -1);
|
||||||
ap.currentBlock = null;
|
ap.currentBlock = null;
|
||||||
ap.blockHitDelay = 5;
|
ap.blockHitDelay = 5;
|
||||||
blockBroken = true;
|
blockBroken = true;
|
||||||
@@ -454,7 +454,7 @@ public class EntityPlayerActionPack
|
|||||||
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
|
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
|
||||||
if (ap.currentBlock == null) return;
|
if (ap.currentBlock == null) return;
|
||||||
player.level.destroyBlockProgress(-1, ap.currentBlock, -1);
|
player.level.destroyBlockProgress(-1, ap.currentBlock, -1);
|
||||||
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getLevel().getMaxBuildHeight());
|
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getLevel().getMaxBuildHeight(), -1);
|
||||||
ap.currentBlock = null;
|
ap.currentBlock = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package carpet.helpers;
|
|||||||
|
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import carpet.fakes.ChunkGeneratorInterface;
|
import carpet.fakes.ChunkGeneratorInterface;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -16,6 +17,7 @@ import net.minecraft.core.Holder;
|
|||||||
import net.minecraft.core.HolderSet;
|
import net.minecraft.core.HolderSet;
|
||||||
import net.minecraft.core.QuartPos;
|
import net.minecraft.core.QuartPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.data.BuiltinRegistries;
|
||||||
import net.minecraft.data.worldgen.ProcessorLists;
|
import net.minecraft.data.worldgen.ProcessorLists;
|
||||||
import net.minecraft.data.worldgen.placement.PlacementUtils;
|
import net.minecraft.data.worldgen.placement.PlacementUtils;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@@ -27,20 +29,22 @@ import net.minecraft.world.level.biome.Biome;
|
|||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
|
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||||
|
import net.minecraft.world.level.levelgen.RandomState;
|
||||||
|
import net.minecraft.world.level.levelgen.VerticalAnchor;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
|
||||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
|
||||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||||
import net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration;
|
|
||||||
import net.minecraft.world.level.levelgen.feature.configurations.SimpleRandomFeatureConfiguration;
|
import net.minecraft.world.level.levelgen.feature.configurations.SimpleRandomFeatureConfiguration;
|
||||||
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
|
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
|
||||||
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
|
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
|
||||||
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
|
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
|
||||||
import net.minecraft.world.level.levelgen.feature.foliageplacers.FancyFoliagePlacer;
|
import net.minecraft.world.level.levelgen.feature.foliageplacers.FancyFoliagePlacer;
|
||||||
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
|
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
|
||||||
|
import net.minecraft.world.level.levelgen.heightproviders.ConstantHeight;
|
||||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.StructureType;
|
||||||
import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement;
|
import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement;
|
||||||
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool;
|
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool;
|
||||||
import net.minecraft.world.level.levelgen.feature.treedecorators.BeehiveDecorator;
|
import net.minecraft.world.level.levelgen.feature.treedecorators.BeehiveDecorator;
|
||||||
@@ -49,6 +53,7 @@ import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlac
|
|||||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure;
|
||||||
|
|
||||||
public class FeatureGenerator
|
public class FeatureGenerator
|
||||||
{
|
{
|
||||||
@@ -61,10 +66,10 @@ public class FeatureGenerator
|
|||||||
return custom.plop(world, pos);
|
return custom.plop(world, pos);
|
||||||
}
|
}
|
||||||
ResourceLocation id = new ResourceLocation(featureName);
|
ResourceLocation id = new ResourceLocation(featureName);
|
||||||
ConfiguredStructureFeature<?, ?> structureFeature = world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(id);
|
Structure structure = world.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(id);
|
||||||
if (structureFeature != null)
|
if (structure != null)
|
||||||
{
|
{
|
||||||
return plopAnywhere( structureFeature, world, pos, world.getChunkSource().getGenerator(), false);
|
return plopAnywhere( structure, world, pos, world.getChunkSource().getGenerator(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfiguredFeature<?, ?> configuredFeature = world.registryAccess().registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).get(id);
|
ConfiguredFeature<?, ?> configuredFeature = world.registryAccess().registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).get(id);
|
||||||
@@ -80,10 +85,10 @@ public class FeatureGenerator
|
|||||||
CarpetSettings.skipGenerationChecks.set(false);
|
CarpetSettings.skipGenerationChecks.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StructureFeature<?> structure = Registry.STRUCTURE_FEATURE.get(id);
|
StructureType<?> structureType = Registry.STRUCTURE_TYPES.get(id);
|
||||||
if (structure != null)
|
if (structure != null)
|
||||||
{
|
{
|
||||||
ConfiguredStructureFeature<?,?> configuredStandard = getDefaultFeature(structure, world, pos);
|
Structure configuredStandard = getDefaultFeature(structureType, world, pos);
|
||||||
if (configuredStandard != null)
|
if (configuredStandard != null)
|
||||||
return plopAnywhere(configuredStandard, world, pos, world.getChunkSource().getGenerator(), false);
|
return plopAnywhere(configuredStandard, world, pos, world.getChunkSource().getGenerator(), false);
|
||||||
}
|
}
|
||||||
@@ -107,17 +112,17 @@ public class FeatureGenerator
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfiguredStructureFeature<?, ?> resolveConfiguredStructure(String name, ServerLevel world, BlockPos pos)
|
public static Structure resolveConfiguredStructure(String name, ServerLevel world, BlockPos pos)
|
||||||
{
|
{
|
||||||
ResourceLocation id = new ResourceLocation(name);
|
ResourceLocation id = new ResourceLocation(name);
|
||||||
ConfiguredStructureFeature<?, ?> configuredStructureFeature = world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(id);
|
Structure configuredStructureFeature = world.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(id);
|
||||||
if (configuredStructureFeature != null) return configuredStructureFeature;
|
if (configuredStructureFeature != null) return configuredStructureFeature;
|
||||||
StructureFeature<?> structureFeature = Registry.STRUCTURE_FEATURE.get(id);
|
StructureType<?> structureFeature = Registry.STRUCTURE_TYPES.get(id);
|
||||||
if (structureFeature == null) return null;
|
if (structureFeature == null) return null;
|
||||||
return getDefaultFeature(structureFeature, world, pos);
|
return getDefaultFeature(structureFeature, world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public static Boolean plopGrid(ConfiguredStructureFeature<?, ?> structureFeature, ServerLevel world, BlockPos pos)
|
synchronized public static Boolean plopGrid(Structure structureFeature, ServerLevel world, BlockPos pos)
|
||||||
{
|
{
|
||||||
return plopAnywhere( structureFeature, world, pos, world.getChunkSource().getGenerator(), true);
|
return plopAnywhere( structureFeature, world, pos, world.getChunkSource().getGenerator(), true);
|
||||||
}
|
}
|
||||||
@@ -153,11 +158,11 @@ public class FeatureGenerator
|
|||||||
return simplePlop(new ConfiguredFeature(Feature.TREE, config));
|
return simplePlop(new ConfiguredFeature(Feature.TREE, config));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Thing spawnCustomStructure(ConfiguredStructureFeature<?,?> structure)
|
private static Thing spawnCustomStructure(Structure structure)
|
||||||
{
|
{
|
||||||
return setupCustomStructure(structure,false);
|
return setupCustomStructure(structure,false);
|
||||||
}
|
}
|
||||||
private static Thing setupCustomStructure(ConfiguredStructureFeature<?,?> structure, boolean wireOnly)
|
private static Thing setupCustomStructure(Structure structure, boolean wireOnly)
|
||||||
{
|
{
|
||||||
return (w, p) -> plopAnywhere(structure, w, p, w.getChunkSource().getGenerator(), wireOnly);
|
return (w, p) -> plopAnywhere(structure, w, p, w.getChunkSource().getGenerator(), wireOnly);
|
||||||
}
|
}
|
||||||
@@ -169,17 +174,17 @@ public class FeatureGenerator
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfiguredStructureFeature<?, ?> getDefaultFeature(StructureFeature<?> structure, ServerLevel world, BlockPos pos)
|
private static Structure getDefaultFeature(StructureType<?> structure, ServerLevel world, BlockPos pos)
|
||||||
{
|
{
|
||||||
// would be nice to have a way to grab structures of this type for position
|
// would be nice to have a way to grab structures of this type for position
|
||||||
|
// TODO allow old types, like vaillage, or bastion
|
||||||
Holder<Biome> existingBiome = world.getBiome(pos);
|
Holder<Biome> existingBiome = world.getBiome(pos);
|
||||||
ConfiguredStructureFeature<?, ?> result = null;
|
Structure result = null;
|
||||||
for (var confstr : world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).entrySet().stream().
|
for (Structure confstr : world.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).entrySet().stream().
|
||||||
filter(cS -> cS.getValue().feature == structure).map(Map.Entry::getValue).toList())
|
filter(cS -> cS.getValue().type() == structure).map(Map.Entry::getValue).toList())
|
||||||
{
|
{
|
||||||
result = confstr;
|
result = confstr;
|
||||||
if (confstr.biomes.contains(existingBiome)) return result;
|
if (confstr.biomes().contains(existingBiome)) return result;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -199,32 +204,33 @@ public class FeatureGenerator
|
|||||||
findFirst().map(Map.Entry::getValue).orElse(null);
|
findFirst().map(Map.Entry::getValue).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends FeatureConfiguration> StructureStart shouldStructureStartAt(ServerLevel world, BlockPos pos, ConfiguredStructureFeature<T, ?> structure, boolean computeBox)
|
public static <T extends FeatureConfiguration> StructureStart shouldStructureStartAt(ServerLevel world, BlockPos pos, Structure structure, boolean computeBox)
|
||||||
{
|
{
|
||||||
long seed = world.getSeed();
|
//long seed = world.getSeed();
|
||||||
|
RandomState seed = world.getChunkSource().randomState();
|
||||||
ChunkGenerator generator = world.getChunkSource().getGenerator();
|
ChunkGenerator generator = world.getChunkSource().getGenerator();
|
||||||
ChunkGeneratorInterface cgi = (ChunkGeneratorInterface) generator;
|
ChunkGeneratorInterface cgi = (ChunkGeneratorInterface) generator;
|
||||||
List<StructurePlacement> structureConfig = cgi.getPlacementsForFeatureCM(structure);
|
List<StructurePlacement> structureConfig = cgi.getPlacementsForFeatureCM(world, structure);
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
ChunkPos chunkPos = new ChunkPos(pos);
|
||||||
boolean couldPlace = structureConfig.stream().anyMatch(p -> p.isFeatureChunk(generator, world.getSeed(), chunkPos.x, chunkPos.z));
|
boolean couldPlace = structureConfig.stream().anyMatch(p -> p.isStructureChunk(generator, seed, world.getSeed(), chunkPos.x, chunkPos.z));
|
||||||
if (!couldPlace) return null;
|
if (!couldPlace) return null;
|
||||||
|
|
||||||
final HolderSet<Biome> structureBiomes = structure.biomes();
|
final HolderSet<Biome> structureBiomes = structure.biomes();
|
||||||
|
|
||||||
if (!computeBox) {
|
if (!computeBox) {
|
||||||
Holder<Biome> genBiome = generator.getNoiseBiome(QuartPos.fromBlock(pos.getX()), QuartPos.fromBlock(pos.getY()), QuartPos.fromBlock(pos.getZ()));
|
Holder<Biome> genBiome = generator.getBiomeSource().getNoiseBiome(QuartPos.fromBlock(pos.getX()), QuartPos.fromBlock(pos.getY()), QuartPos.fromBlock(pos.getZ()), seed.sampler());
|
||||||
if (structureBiomes.contains(genBiome) && structure.feature.canGenerate(
|
if (structureBiomes.contains(genBiome) && structure.findGenerationPoint(new Structure.GenerationContext(
|
||||||
world.registryAccess(), generator, generator.getBiomeSource(), world.getStructureManager(),
|
world.registryAccess(), generator, generator.getBiomeSource(),
|
||||||
seed, chunkPos, structure.config, world, structureBiomes::contains
|
seed, world.getStructureManager(), world.getSeed(), chunkPos, world, structureBiomes::contains
|
||||||
))
|
)).isPresent())
|
||||||
{
|
{
|
||||||
return StructureStart.INVALID_START;
|
return StructureStart.INVALID_START;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final StructureStart filledStructure = structure.generate(
|
final StructureStart filledStructure = structure.generate(
|
||||||
world.registryAccess(), generator, generator.getBiomeSource(), world.getStructureManager(),
|
world.registryAccess(), generator, generator.getBiomeSource(), seed, world.getStructureManager(),
|
||||||
seed, chunkPos, 0, world, structureBiomes::contains);
|
world.getSeed(), chunkPos, 0, world, structureBiomes::contains);
|
||||||
if (filledStructure != null && filledStructure.isValid()) {
|
if (filledStructure != null && filledStructure.isValid()) {
|
||||||
return filledStructure;
|
return filledStructure;
|
||||||
}
|
}
|
||||||
@@ -251,61 +257,93 @@ public class FeatureGenerator
|
|||||||
PlacementUtils.inlinePlaced(Feature.CORAL_CLAW, FeatureConfiguration.NONE),
|
PlacementUtils.inlinePlaced(Feature.CORAL_CLAW, FeatureConfiguration.NONE),
|
||||||
PlacementUtils.inlinePlaced(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE)
|
PlacementUtils.inlinePlaced(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE)
|
||||||
))));
|
))));
|
||||||
put("bastion_remnant_units", spawnCustomStructure(StructureFeature.BASTION_REMNANT.configured(
|
put("bastion_remnant_units", spawnCustomStructure(
|
||||||
new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
|
new JigsawStructure(
|
||||||
new ResourceLocation("bastion/starts"),
|
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
|
||||||
new ResourceLocation("empty"),
|
Map.of(),
|
||||||
List.of(
|
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
||||||
Pair.of(StructurePoolElement.single("bastion/units/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
false,
|
||||||
),
|
Holder.direct(new StructureTemplatePool(
|
||||||
StructureTemplatePool.Projection.RIGID
|
new ResourceLocation("bastion/starts"),
|
||||||
)), 6),
|
new ResourceLocation("empty"),
|
||||||
BiomeTags.HAS_BASTION_REMNANT)
|
ImmutableList.of(
|
||||||
|
Pair.of(StructurePoolElement.single("bastion/units/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||||
|
),
|
||||||
|
StructureTemplatePool.Projection.RIGID
|
||||||
|
)),
|
||||||
|
6,
|
||||||
|
ConstantHeight.of(VerticalAnchor.absolute(33)),
|
||||||
|
false
|
||||||
|
)
|
||||||
));
|
));
|
||||||
put("bastion_remnant_hoglin_stable", spawnCustomStructure(StructureFeature.BASTION_REMNANT.configured(
|
put("bastion_remnant_hoglin_stable", spawnCustomStructure(
|
||||||
new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
|
new JigsawStructure(
|
||||||
new ResourceLocation("bastion/starts"),
|
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
|
||||||
new ResourceLocation("empty"),
|
Map.of(),
|
||||||
List.of(
|
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
||||||
Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
false,
|
||||||
),
|
Holder.direct(new StructureTemplatePool(
|
||||||
StructureTemplatePool.Projection.RIGID
|
new ResourceLocation("bastion/starts"),
|
||||||
)), 6),
|
new ResourceLocation("empty"),
|
||||||
BiomeTags.HAS_BASTION_REMNANT)
|
ImmutableList.of(
|
||||||
|
Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||||
|
),
|
||||||
|
StructureTemplatePool.Projection.RIGID
|
||||||
|
)),
|
||||||
|
6,
|
||||||
|
ConstantHeight.of(VerticalAnchor.absolute(33)),
|
||||||
|
false
|
||||||
|
)
|
||||||
));
|
));
|
||||||
put("bastion_remnant_treasure", spawnCustomStructure(StructureFeature.BASTION_REMNANT.configured(
|
put("bastion_remnant_treasure", spawnCustomStructure(
|
||||||
new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
|
new JigsawStructure(
|
||||||
new ResourceLocation("bastion/starts"),
|
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
|
||||||
new ResourceLocation("empty"),
|
Map.of(),
|
||||||
List.of(
|
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
||||||
Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
false,
|
||||||
),
|
Holder.direct(new StructureTemplatePool(
|
||||||
StructureTemplatePool.Projection.RIGID
|
new ResourceLocation("bastion/starts"),
|
||||||
)), 6),
|
new ResourceLocation("empty"),
|
||||||
BiomeTags.HAS_BASTION_REMNANT)
|
ImmutableList.of(
|
||||||
|
Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||||
|
),
|
||||||
|
StructureTemplatePool.Projection.RIGID
|
||||||
|
)),
|
||||||
|
6,
|
||||||
|
ConstantHeight.of(VerticalAnchor.absolute(33)),
|
||||||
|
false
|
||||||
|
)
|
||||||
));
|
));
|
||||||
put("bastion_remnant_bridge", spawnCustomStructure(StructureFeature.BASTION_REMNANT.configured(
|
put("bastion_remnant_bridge", spawnCustomStructure(
|
||||||
new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
|
new JigsawStructure(
|
||||||
new ResourceLocation("bastion/starts"),
|
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
|
||||||
new ResourceLocation("empty"),
|
Map.of(),
|
||||||
List.of(
|
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
||||||
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
false,
|
||||||
),
|
Holder.direct(new StructureTemplatePool(
|
||||||
StructureTemplatePool.Projection.RIGID
|
new ResourceLocation("bastion/starts"),
|
||||||
)), 6),
|
new ResourceLocation("empty"),
|
||||||
BiomeTags.HAS_BASTION_REMNANT)
|
ImmutableList.of(
|
||||||
|
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||||
|
),
|
||||||
|
StructureTemplatePool.Projection.RIGID
|
||||||
|
)),
|
||||||
|
6,
|
||||||
|
ConstantHeight.of(VerticalAnchor.absolute(33)),
|
||||||
|
false
|
||||||
|
)
|
||||||
));
|
));
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
|
||||||
public static boolean plopAnywhere(ConfiguredStructureFeature<?, ?> structure, ServerLevel world, BlockPos pos, ChunkGenerator generator, boolean wireOnly)
|
public static boolean plopAnywhere(Structure structure, ServerLevel world, BlockPos pos, ChunkGenerator generator, boolean wireOnly)
|
||||||
{
|
{
|
||||||
if (world.isClientSide())
|
if (world.isClientSide())
|
||||||
return false;
|
return false;
|
||||||
CarpetSettings.skipGenerationChecks.set(true);
|
CarpetSettings.skipGenerationChecks.set(true);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StructureStart start = structure.generate(world.registryAccess(), generator, generator.getBiomeSource(), world.getStructureManager(), world.getSeed(), new ChunkPos(pos), 0, world, b -> true );
|
StructureStart start = structure.generate(world.registryAccess(), generator, generator.getBiomeSource(), world.getChunkSource().randomState(), world.getStructureManager(), world.getSeed(), new ChunkPos(pos), 0, world, b -> true );
|
||||||
if (start == StructureStart.INVALID_START)
|
if (start == StructureStart.INVALID_START)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -315,18 +353,18 @@ public class FeatureGenerator
|
|||||||
int k = pos.getZ() >> 4;
|
int k = pos.getZ() >> 4;
|
||||||
long chId = ChunkPos.asLong(j, k);
|
long chId = ChunkPos.asLong(j, k);
|
||||||
|
|
||||||
world.getChunk(j, k).addReferenceForFeature(structure, chId);
|
world.getChunk(j, k).addReferenceForStructure(structure, chId);
|
||||||
|
|
||||||
BoundingBox box = start.getBoundingBox();
|
BoundingBox box = start.getBoundingBox();
|
||||||
|
|
||||||
if (!wireOnly)
|
if (!wireOnly)
|
||||||
{
|
{
|
||||||
Registry<ConfiguredStructureFeature<?, ?>> registry3 = world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
|
Registry<Structure> registry3 = world.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY);
|
||||||
world.setCurrentlyGenerating(() -> {
|
world.setCurrentlyGenerating(() -> {
|
||||||
Objects.requireNonNull(structure);
|
Objects.requireNonNull(structure);
|
||||||
return registry3.getResourceKey(structure).map(Object::toString).orElseGet(structure::toString);
|
return registry3.getResourceKey(structure).map(Object::toString).orElseGet(structure::toString);
|
||||||
});
|
});
|
||||||
start.placeInChunk(world, world.structureFeatureManager(), generator, rand, box, new ChunkPos(j, k));
|
start.placeInChunk(world, world.structureManager(), generator, rand, box, new ChunkPos(j, k));
|
||||||
}
|
}
|
||||||
//structurestart.notifyPostProcessAt(new ChunkPos(j, k));
|
//structurestart.notifyPostProcessAt(new ChunkPos(j, k));
|
||||||
int i = Math.max(box.getXSpan(),box.getZSpan())/16+1;
|
int i = Math.max(box.getXSpan(),box.getZSpan())/16+1;
|
||||||
@@ -339,7 +377,7 @@ public class FeatureGenerator
|
|||||||
if (k1 == j && l1 == k) continue;
|
if (k1 == j && l1 == k) continue;
|
||||||
if (box.intersects(k1<<4, l1<<4, (k1<<4) + 15, (l1<<4) + 15))
|
if (box.intersects(k1<<4, l1<<4, (k1<<4) + 15, (l1<<4) + 15))
|
||||||
{
|
{
|
||||||
world.getChunk(k1, l1).addReferenceForFeature(structure, chId);
|
world.getChunk(k1, l1).addReferenceForStructure(structure, chId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package carpet.mixins;
|
|||||||
import carpet.utils.SpawnOverrides;
|
import carpet.utils.SpawnOverrides;
|
||||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
import net.minecraft.world.level.StructureManager;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
@@ -12,7 +13,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.util.random.WeightedRandomList;
|
import net.minecraft.util.random.WeightedRandomList;
|
||||||
import net.minecraft.world.entity.MobCategory;
|
import net.minecraft.world.entity.MobCategory;
|
||||||
import net.minecraft.world.level.StructureFeatureManager;
|
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
@@ -30,9 +30,9 @@ public abstract class ChunkGenerator_customMobSpawnsMixin
|
|||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Ljava/util/Map$Entry;getKey()Ljava/lang/Object;"
|
target = "Ljava/util/Map$Entry;getKey()Ljava/lang/Object;"
|
||||||
), cancellable = true)
|
), cancellable = true)
|
||||||
private void checkCMSpawns(Holder<Biome> holder, StructureFeatureManager structureFeatureManager, MobCategory mobCategory, BlockPos blockPos,
|
private void checkCMSpawns(Holder<Biome> holder, StructureManager structureFeatureManager, MobCategory mobCategory, BlockPos blockPos,
|
||||||
CallbackInfoReturnable<WeightedRandomList<MobSpawnSettings.SpawnerData>> cir,
|
CallbackInfoReturnable<WeightedRandomList<MobSpawnSettings.SpawnerData>> cir,
|
||||||
Map<ConfiguredStructureFeature<?, ?>, LongSet> map, Iterator<?> var6, Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet> entry)
|
Map<Structure, LongSet> map, Iterator<?> var6, Map.Entry<Structure, LongSet> entry)
|
||||||
{
|
{
|
||||||
WeightedRandomList<MobSpawnSettings.SpawnerData> res = SpawnOverrides.test(structureFeatureManager, entry.getValue(), mobCategory, entry.getKey(), blockPos);
|
WeightedRandomList<MobSpawnSettings.SpawnerData> res = SpawnOverrides.test(structureFeatureManager, entry.getValue(), mobCategory, entry.getKey(), blockPos);
|
||||||
if (res != null)
|
if (res != null)
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package carpet.mixins;
|
|||||||
|
|
||||||
import carpet.fakes.ChunkGeneratorInterface;
|
import carpet.fakes.ChunkGeneratorInterface;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
import net.minecraft.world.level.levelgen.RandomState;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
@@ -14,18 +16,18 @@ import java.util.List;
|
|||||||
public abstract class ChunkGenerator_scarpetMixin implements ChunkGeneratorInterface
|
public abstract class ChunkGenerator_scarpetMixin implements ChunkGeneratorInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
@Shadow protected abstract List<StructurePlacement> getPlacementsForFeature(Holder<ConfiguredStructureFeature<?, ?>> holder);
|
@Shadow public abstract void ensureStructuresGenerated(RandomState randomState);
|
||||||
|
|
||||||
@Shadow public abstract void ensureStructuresGenerated();
|
@Shadow protected abstract List<StructurePlacement> getPlacementsForStructure(Holder<Structure> holder, RandomState randomState);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initStrongholds()
|
public void initStrongholds(final ServerLevel level)
|
||||||
{
|
{
|
||||||
ensureStructuresGenerated();
|
ensureStructuresGenerated(level.getChunkSource().randomState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<StructurePlacement> getPlacementsForFeatureCM(ConfiguredStructureFeature<?, ?> structure) {
|
public List<StructurePlacement> getPlacementsForFeatureCM(final ServerLevel level, Structure structure) {
|
||||||
return getPlacementsForFeature(Holder.direct(structure));
|
return getPlacementsForStructure(Holder.direct(structure), level.getChunkSource().randomState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package carpet.mixins;
|
|||||||
import carpet.CarpetServer;
|
import carpet.CarpetServer;
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -25,9 +26,8 @@ public abstract class Commands_customCommandsMixin
|
|||||||
private CommandDispatcher<CommandSourceStack> dispatcher;
|
private CommandDispatcher<CommandSourceStack> dispatcher;
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
private void onRegister(Commands.CommandSelection arg, CallbackInfo ci) {
|
private void onRegister(Commands.CommandSelection commandSelection, CommandBuildContext commandBuildContext, CallbackInfo ci) {
|
||||||
CarpetServer.registerCarpetCommands(this.dispatcher);
|
CarpetServer.registerCarpetCommands(this.dispatcher, commandSelection, commandBuildContext);
|
||||||
CarpetServer.registerCarpetCommands(this.dispatcher, arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "performCommand", at = @At("HEAD"))
|
@Inject(method = "performCommand", at = @At("HEAD"))
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ public class NaturalSpawnerMixin
|
|||||||
|
|
||||||
@Shadow @Final private static MobCategory[] SPAWNING_CATEGORIES;
|
@Shadow @Final private static MobCategory[] SPAWNING_CATEGORIES;
|
||||||
|
|
||||||
@Redirect(method = "isValidSpawnPostitionForType(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/MobCategory;Lnet/minecraft/world/level/StructureFeatureManager;Lnet/minecraft/world/level/chunk/ChunkGenerator;Lnet/minecraft/world/level/biome/MobSpawnSettings$SpawnerData;Lnet/minecraft/core/BlockPos$MutableBlockPos;D)Z", at = @At(
|
@Redirect(method = "isValidSpawnPostitionForType",
|
||||||
|
at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/level/ServerLevel;noCollision(Lnet/minecraft/world/phys/AABB;)Z"
|
target = "Lnet/minecraft/server/level/ServerLevel;noCollision(Lnet/minecraft/world/phys/AABB;)Z"
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package carpet.mixins;
|
|||||||
|
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import carpet.helpers.BlockSaplingHelper;
|
import carpet.helpers.BlockSaplingHelper;
|
||||||
|
import net.minecraft.tags.BiomeTags;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
@@ -10,7 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.SaplingBlock;
|
import net.minecraft.world.level.block.SaplingBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
@@ -23,7 +23,7 @@ public abstract class SaplingBlock_desertShrubsMixin
|
|||||||
cancellable = true)
|
cancellable = true)
|
||||||
private void onGenerate(ServerLevel serverWorld_1, BlockPos blockPos_1, BlockState blockState_1, Random random_1, CallbackInfo ci)
|
private void onGenerate(ServerLevel serverWorld_1, BlockPos blockPos_1, BlockState blockState_1, Random random_1, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
if(CarpetSettings.desertShrubs && Biome.getBiomeCategory(serverWorld_1.getBiome(blockPos_1)) == Biome.BiomeCategory.DESERT && !BlockSaplingHelper.hasWater(serverWorld_1, blockPos_1))
|
if(CarpetSettings.desertShrubs && serverWorld_1.getBiome(blockPos_1).is(BiomeTags.HAS_DESERT_PYRAMID) && !BlockSaplingHelper.hasWater(serverWorld_1, blockPos_1))
|
||||||
{
|
{
|
||||||
serverWorld_1.setBlock(blockPos_1, Blocks.DEAD_BUSH.defaultBlockState(), 3);
|
serverWorld_1.setBlock(blockPos_1, Blocks.DEAD_BUSH.defaultBlockState(), 3);
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
|||||||
+2
-2
@@ -58,7 +58,7 @@ public class ServerGamePacketListenerImpl_interactionUpdatesMixin
|
|||||||
}
|
}
|
||||||
@Inject(method = "handlePlayerAction", at = @At(
|
@Inject(method = "handlePlayerAction", at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/level/ServerPlayerGameMode;handleBlockBreakAction(Lnet/minecraft/core/BlockPos;Lnet/minecraft/network/protocol/game/ServerboundPlayerActionPacket$Action;Lnet/minecraft/core/Direction;I)V",
|
target = "Lnet/minecraft/server/level/ServerPlayerGameMode;handleBlockBreakAction(Lnet/minecraft/core/BlockPos;Lnet/minecraft/network/protocol/game/ServerboundPlayerActionPacket$Action;Lnet/minecraft/core/Direction;II)V",
|
||||||
shift = At.Shift.BEFORE
|
shift = At.Shift.BEFORE
|
||||||
))
|
))
|
||||||
private void beforeBlockBroken(ServerboundPlayerActionPacket packet, CallbackInfo ci)
|
private void beforeBlockBroken(ServerboundPlayerActionPacket packet, CallbackInfo ci)
|
||||||
@@ -69,7 +69,7 @@ public class ServerGamePacketListenerImpl_interactionUpdatesMixin
|
|||||||
|
|
||||||
@Inject(method = "handlePlayerAction", at = @At(
|
@Inject(method = "handlePlayerAction", at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target ="Lnet/minecraft/server/level/ServerPlayerGameMode;handleBlockBreakAction(Lnet/minecraft/core/BlockPos;Lnet/minecraft/network/protocol/game/ServerboundPlayerActionPacket$Action;Lnet/minecraft/core/Direction;I)V",
|
target ="Lnet/minecraft/server/level/ServerPlayerGameMode;handleBlockBreakAction(Lnet/minecraft/core/BlockPos;Lnet/minecraft/network/protocol/game/ServerboundPlayerActionPacket$Action;Lnet/minecraft/core/Direction;II)V",
|
||||||
shift = At.Shift.AFTER
|
shift = At.Shift.AFTER
|
||||||
))
|
))
|
||||||
private void afterBlockBroken(ServerboundPlayerActionPacket packet, CallbackInfo ci)
|
private void afterBlockBroken(ServerboundPlayerActionPacket packet, CallbackInfo ci)
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
|||||||
|
|
||||||
@Inject(method = "handlePlayerAction", at = @At(
|
@Inject(method = "handlePlayerAction", at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/level/ServerPlayerGameMode;handleBlockBreakAction(Lnet/minecraft/core/BlockPos;Lnet/minecraft/network/protocol/game/ServerboundPlayerActionPacket$Action;Lnet/minecraft/core/Direction;I)V",
|
target = "Lnet/minecraft/server/level/ServerPlayerGameMode;handleBlockBreakAction(Lnet/minecraft/core/BlockPos;Lnet/minecraft/network/protocol/game/ServerboundPlayerActionPacket$Action;Lnet/minecraft/core/Direction;II)V",
|
||||||
shift = At.Shift.BEFORE
|
shift = At.Shift.BEFORE
|
||||||
))
|
))
|
||||||
private void onClicked(ServerboundPlayerActionPacket packet, CallbackInfo ci)
|
private void onClicked(ServerboundPlayerActionPacket packet, CallbackInfo ci)
|
||||||
|
|||||||
@@ -14,58 +14,19 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||||||
@Mixin(value = ServerPlayerGameMode.class, priority = 69420) // not that important for carpet
|
@Mixin(value = ServerPlayerGameMode.class, priority = 69420) // not that important for carpet
|
||||||
public class ServerPlayerGameMode_antiCheatMixin
|
public class ServerPlayerGameMode_antiCheatMixin
|
||||||
{
|
{
|
||||||
// this is how it should be done
|
|
||||||
/*
|
|
||||||
@ModifyConstant(method = "processBlockBreakingAction", require = 0,
|
|
||||||
constant = @Constant(doubleValue = 36D))
|
|
||||||
private double addDistance(double original) {
|
|
||||||
if (CarpetSettings.antiCheatDisabled)
|
|
||||||
return 1024D; // blocks 32 distance
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// that shoudn't've been a constant at the first place
|
// that shoudn't've been a constant at the first place
|
||||||
// resolves problems with mobs using reach entity attributes.
|
// resolves problems with mobs using reach entity attributes.
|
||||||
|
|
||||||
@Redirect(method = "handleBlockBreakAction", at = @At(
|
@Redirect(method = "handleBlockBreakAction", at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/level/ServerPlayer;getX()D"
|
target = "Lnet/minecraft/server/level/ServerPlayer;getEyePosition()Lnet/minecraft/world/phys/Vec3;"
|
||||||
))
|
|
||||||
private double getXX(ServerPlayer player,
|
|
||||||
BlockPos pos, ServerboundPlayerActionPacket.Action action, Direction direction, int worldHeight)
|
|
||||||
{
|
|
||||||
if (CarpetSettings.antiCheatDisabled &&
|
|
||||||
player.position().add(0, 1.5, 0).distanceToSqr(Vec3.atCenterOf(pos)) < 1024
|
|
||||||
) return pos.getX()+0.5;
|
|
||||||
return player.getX();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Redirect(method = "handleBlockBreakAction", at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/server/level/ServerPlayer;getY()D"
|
|
||||||
))
|
))
|
||||||
private double getYY(ServerPlayer player,
|
private Vec3 getEyePos(ServerPlayer instance,
|
||||||
BlockPos pos, ServerboundPlayerActionPacket.Action action, Direction direction, int worldHeight)
|
final BlockPos pos, final ServerboundPlayerActionPacket.Action action, final Direction direction, final int maxBuildHeight, final int sequence)
|
||||||
{
|
{
|
||||||
if (CarpetSettings.antiCheatDisabled &&
|
if (CarpetSettings.antiCheatDisabled &&
|
||||||
player.position().add(0, 1.5, 0).distanceToSqr(Vec3.atCenterOf(pos)) < 1024
|
instance.getEyePosition().distanceToSqr(Vec3.atCenterOf(pos)) < 1024
|
||||||
) return pos.getY()-1.0;
|
) return Vec3.atCenterOf(pos);
|
||||||
return player.getY();
|
return instance.getEyePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "handleBlockBreakAction", at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/server/level/ServerPlayer;getZ()D"
|
|
||||||
))
|
|
||||||
private double getZZ(ServerPlayer player,
|
|
||||||
BlockPos pos, ServerboundPlayerActionPacket.Action action, Direction direction, int worldHeight)
|
|
||||||
{
|
|
||||||
if (CarpetSettings.antiCheatDisabled &&
|
|
||||||
player.position().add(0, 1.5, 0).distanceToSqr(Vec3.atCenterOf(pos)) < 1024
|
|
||||||
) return pos.getZ()+0.5;
|
|
||||||
return player.getZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -775,11 +775,11 @@ public class Auxiliary {
|
|||||||
plopData.put(StringValue.of("configured_features"),
|
plopData.put(StringValue.of("configured_features"),
|
||||||
ListValue.wrap(registryManager.registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
ListValue.wrap(registryManager.registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||||
);
|
);
|
||||||
plopData.put(StringValue.of("structures"),
|
plopData.put(StringValue.of("structure_types"),
|
||||||
ListValue.wrap(Registry.STRUCTURE_FEATURE.keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
ListValue.wrap(Registry.STRUCTURE_TYPES.keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||||
);
|
);
|
||||||
plopData.put(StringValue.of("configured_structures"),
|
plopData.put(StringValue.of("structures"),
|
||||||
ListValue.wrap(registryManager.registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
ListValue.wrap(registryManager.registryOrThrow(Registry.STRUCTURE_REGISTRY).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||||
);
|
);
|
||||||
return MapValue.wrap(plopData);
|
return MapValue.wrap(plopData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ import net.minecraft.core.QuartPos;
|
|||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.StructureType;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -111,13 +113,10 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||||||
import net.minecraft.world.level.block.state.StateDefinition;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.block.state.properties.Property;
|
import net.minecraft.world.level.block.state.properties.Property;
|
||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import net.minecraft.world.level.levelgen.Heightmap;
|
import net.minecraft.world.level.levelgen.Heightmap;
|
||||||
import net.minecraft.world.level.levelgen.WorldgenRandom;
|
import net.minecraft.world.level.levelgen.WorldgenRandom;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
|
||||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
|
||||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||||
import net.minecraft.world.level.pathfinder.PathComputationType;
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
||||||
@@ -237,11 +236,11 @@ public class WorldAccess {
|
|||||||
return (float) num;
|
return (float) num;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BooYah(ChunkGenerator generator)
|
private static void BooYah(final ServerLevel level)
|
||||||
{
|
{
|
||||||
synchronized (generator)
|
synchronized (level)
|
||||||
{
|
{
|
||||||
((ChunkGeneratorInterface)generator).initStrongholds();
|
((ChunkGeneratorInterface)level.getChunkSource().getGenerator()).initStrongholds(level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1285,15 +1284,15 @@ public class WorldAccess {
|
|||||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||||
ServerLevel world = cc.s.getLevel();
|
ServerLevel world = cc.s.getLevel();
|
||||||
BlockPos pos = locator.block.getPos();
|
BlockPos pos = locator.block.getPos();
|
||||||
Map<ConfiguredStructureFeature<?,?>, LongSet> references = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
|
Map<Structure, LongSet> references = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
|
||||||
Registry<ConfiguredStructureFeature<?, ?>> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
|
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY);
|
||||||
if (lv.size() == locator.offset)
|
if (lv.size() == locator.offset)
|
||||||
return ListValue.wrap(references.entrySet().stream().
|
return ListValue.wrap(references.entrySet().stream().
|
||||||
filter(e -> e.getValue()!= null && !e.getValue().isEmpty()).
|
filter(e -> e.getValue()!= null && !e.getValue().isEmpty()).
|
||||||
map(e -> new StringValue(NBTSerializableValue.nameFromRegistryId(reg.getKey(e.getKey())))).collect(Collectors.toList())
|
map(e -> new StringValue(NBTSerializableValue.nameFromRegistryId(reg.getKey(e.getKey())))).collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
String simpleStructureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
|
String simpleStructureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
|
||||||
ConfiguredStructureFeature<?,?> structureName = reg.get(InputValidator.identifierOf(simpleStructureName));
|
Structure structureName = reg.get(InputValidator.identifierOf(simpleStructureName));
|
||||||
if (structureName == null) return Value.NULL;
|
if (structureName == null) return Value.NULL;
|
||||||
LongSet structureReferences = references.get(structureName);
|
LongSet structureReferences = references.get(structureName);
|
||||||
if (structureReferences == null || structureReferences.isEmpty()) return ListValue.of();
|
if (structureReferences == null || structureReferences.isEmpty()) return ListValue.of();
|
||||||
@@ -1311,13 +1310,13 @@ public class WorldAccess {
|
|||||||
ServerLevel world = cc.s.getLevel();
|
ServerLevel world = cc.s.getLevel();
|
||||||
|
|
||||||
// well, because
|
// well, because
|
||||||
BooYah(world.getChunkSource().getGenerator());
|
BooYah(world);
|
||||||
|
|
||||||
BlockPos pos = locator.block.getPos();
|
BlockPos pos = locator.block.getPos();
|
||||||
final List<ConfiguredStructureFeature<?, ?>> structure = new ArrayList<>();
|
final List<Structure> structure = new ArrayList<>();
|
||||||
boolean needSize = false;
|
boolean needSize = false;
|
||||||
boolean singleOutput = false;
|
boolean singleOutput = false;
|
||||||
Registry<ConfiguredStructureFeature<?, ?>> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
|
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY);
|
||||||
if (lv.size() > locator.offset)
|
if (lv.size() > locator.offset)
|
||||||
{
|
{
|
||||||
Value requested = lv.get(locator.offset+0);
|
Value requested = lv.get(locator.offset+0);
|
||||||
@@ -1325,7 +1324,7 @@ public class WorldAccess {
|
|||||||
{
|
{
|
||||||
String reqString = requested.getString();
|
String reqString = requested.getString();
|
||||||
var id = InputValidator.identifierOf(reqString);
|
var id = InputValidator.identifierOf(reqString);
|
||||||
ConfiguredStructureFeature<?, ?> requestedStructure = reg.get(id);
|
Structure requestedStructure = reg.get(id);
|
||||||
if (requestedStructure != null)
|
if (requestedStructure != null)
|
||||||
{
|
{
|
||||||
singleOutput = true;
|
singleOutput = true;
|
||||||
@@ -1333,10 +1332,8 @@ public class WorldAccess {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Registry<StructureFeature<?>> reg1 = cc.s.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_FEATURE_REGISTRY);
|
StructureType<?> sss = Registry.STRUCTURE_TYPES.get(id);
|
||||||
StructureFeature<?> sss = reg1.get(id);
|
reg.entrySet().stream().filter(e -> e.getValue().type() ==sss).forEach(e -> structure.add(e.getValue()));
|
||||||
// bad
|
|
||||||
reg.entrySet().stream().filter(e -> e.getValue().feature==sss).forEach(e -> structure.add(e.getValue()));
|
|
||||||
}
|
}
|
||||||
if (structure.isEmpty())
|
if (structure.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -1365,7 +1362,7 @@ public class WorldAccess {
|
|||||||
return ValueConversions.of(start);
|
return ValueConversions.of(start);
|
||||||
}
|
}
|
||||||
Map<Value, Value> ret = new HashMap<>();
|
Map<Value, Value> ret = new HashMap<>();
|
||||||
for(ConfiguredStructureFeature<?, ?> str: structure)
|
for(Structure str: structure)
|
||||||
{
|
{
|
||||||
StructureStart start;
|
StructureStart start;
|
||||||
try
|
try
|
||||||
@@ -1392,12 +1389,12 @@ public class WorldAccess {
|
|||||||
|
|
||||||
ServerLevel world = cc.s.getLevel();
|
ServerLevel world = cc.s.getLevel();
|
||||||
BlockPos pos = locator.block.getPos();
|
BlockPos pos = locator.block.getPos();
|
||||||
Map<ConfiguredStructureFeature<?,?>, StructureStart> structures = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_STARTS).getAllStarts();
|
Map<Structure, StructureStart> structures = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_STARTS).getAllStarts();
|
||||||
Registry<ConfiguredStructureFeature<?, ?>> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
|
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY);
|
||||||
if (lv.size() == locator.offset)
|
if (lv.size() == locator.offset)
|
||||||
{
|
{
|
||||||
Map<Value, Value> structureList = new HashMap<>();
|
Map<Value, Value> structureList = new HashMap<>();
|
||||||
for (Map.Entry<ConfiguredStructureFeature<?, ?>, StructureStart> entry : structures.entrySet())
|
for (Map.Entry<Structure, StructureStart> entry : structures.entrySet())
|
||||||
{
|
{
|
||||||
StructureStart start = entry.getValue();
|
StructureStart start = entry.getValue();
|
||||||
if (start == StructureStart.INVALID_START)
|
if (start == StructureStart.INVALID_START)
|
||||||
@@ -1425,14 +1422,14 @@ public class WorldAccess {
|
|||||||
if (lv.size() == locator.offset)
|
if (lv.size() == locator.offset)
|
||||||
throw new InternalExpressionException("'set_structure requires at least position and a structure name");
|
throw new InternalExpressionException("'set_structure requires at least position and a structure name");
|
||||||
String structureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
|
String structureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
|
||||||
ConfiguredStructureFeature<?, ?> configuredStructure = FeatureGenerator.resolveConfiguredStructure(structureName, world, pos);
|
Structure configuredStructure = FeatureGenerator.resolveConfiguredStructure(structureName, world, pos);
|
||||||
if (configuredStructure == null) throw new ThrowStatement(structureName, Throwables.UNKNOWN_STRUCTURE);
|
if (configuredStructure == null) throw new ThrowStatement(structureName, Throwables.UNKNOWN_STRUCTURE);
|
||||||
// good 'ol pointer
|
// good 'ol pointer
|
||||||
Value[] result = new Value[]{Value.NULL};
|
Value[] result = new Value[]{Value.NULL};
|
||||||
// technically a world modification. Even if we could let it slide, we will still park it
|
// technically a world modification. Even if we could let it slide, we will still park it
|
||||||
((CarpetContext) c).s.getServer().executeBlocking(() ->
|
((CarpetContext) c).s.getServer().executeBlocking(() ->
|
||||||
{
|
{
|
||||||
Map<ConfiguredStructureFeature<?, ?>, StructureStart> structures = world.getChunk(pos).getAllStarts();
|
Map<Structure, StructureStart> structures = world.getChunk(pos).getAllStarts();
|
||||||
if (lv.size() == locator.offset + 1)
|
if (lv.size() == locator.offset + 1)
|
||||||
{
|
{
|
||||||
Boolean res = FeatureGenerator.plopGrid(configuredStructure, ((CarpetContext) c).s.getLevel(), locator.block.getPos());
|
Boolean res = FeatureGenerator.plopGrid(configuredStructure, ((CarpetContext) c).s.getLevel(), locator.block.getPos());
|
||||||
@@ -1443,7 +1440,7 @@ public class WorldAccess {
|
|||||||
Value newValue = lv.get(locator.offset+1);
|
Value newValue = lv.get(locator.offset+1);
|
||||||
if (newValue.isNull()) // remove structure
|
if (newValue.isNull()) // remove structure
|
||||||
{
|
{
|
||||||
ConfiguredStructureFeature<?,?> structure = configuredStructure;
|
Structure structure = configuredStructure;
|
||||||
if (!structures.containsKey(structure))
|
if (!structures.containsKey(structure))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -1457,7 +1454,7 @@ public class WorldAccess {
|
|||||||
{
|
{
|
||||||
ChunkPos chpos = new ChunkPos(chx, chz);
|
ChunkPos chpos = new ChunkPos(chx, chz);
|
||||||
// getting a chunk will convert it to full, allowing to modify references
|
// getting a chunk will convert it to full, allowing to modify references
|
||||||
Map<ConfiguredStructureFeature<?,?>, LongSet> references =
|
Map<Structure, LongSet> references =
|
||||||
world.getChunk(chpos.getWorldPosition()).getAllReferences();
|
world.getChunk(chpos.getWorldPosition()).getAllReferences();
|
||||||
if (references.containsKey(structure) && references.get(structure) != null)
|
if (references.containsKey(structure) && references.get(structure) != null)
|
||||||
references.get(structure).remove(structureChunkPos.toLong());
|
references.get(structure).remove(structureChunkPos.toLong());
|
||||||
@@ -1469,7 +1466,7 @@ public class WorldAccess {
|
|||||||
});
|
});
|
||||||
return result[0]; // preventing from lazy evaluating of the result in case a future completes later
|
return result[0]; // preventing from lazy evaluating of the result in case a future completes later
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
expression.addContextFunction("custom_dimension", -1, (c, t, lv) ->
|
expression.addContextFunction("custom_dimension", -1, (c, t, lv) ->
|
||||||
{
|
{
|
||||||
if (lv.size() == 0) throw new InternalExpressionException("'custom_dimension' requires at least one argument");
|
if (lv.size() == 0) throw new InternalExpressionException("'custom_dimension' requires at least one argument");
|
||||||
@@ -1496,7 +1493,7 @@ public class WorldAccess {
|
|||||||
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
|
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
|
||||||
return Value.TRUE;
|
return Value.TRUE;
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
// todo maybe enable chunk blending?
|
// todo maybe enable chunk blending?
|
||||||
expression.addContextFunction("reset_chunk", -1, (c, t, lv) ->
|
expression.addContextFunction("reset_chunk", -1, (c, t, lv) ->
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import java.util.stream.Collectors;
|
|||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.advancements.Advancement;
|
import net.minecraft.advancements.Advancement;
|
||||||
import net.minecraft.advancements.critereon.MinMaxBounds;
|
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.SharedSuggestionProvider;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import net.minecraft.commands.arguments.AngleArgument;
|
import net.minecraft.commands.arguments.AngleArgument;
|
||||||
@@ -93,6 +94,7 @@ import net.minecraft.commands.synchronization.SuggestionProviders;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.network.chat.TextComponent;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@@ -266,7 +268,7 @@ public abstract class CommandArgument
|
|||||||
new VanillaUnconfigurableArgument("uuid", UuidArgument::uuid,
|
new VanillaUnconfigurableArgument("uuid", UuidArgument::uuid,
|
||||||
(c, p) -> StringValue.of(UuidArgument.getUuid(c, p).toString()), false
|
(c, p) -> StringValue.of(UuidArgument.getUuid(c, p).toString()), false
|
||||||
),
|
),
|
||||||
new VanillaUnconfigurableArgument("surfacelocation", Vec2Argument::vec2, // vec2
|
new VanillaUnconfigurableArgument("surfacelocation", () -> Vec2Argument.vec2(), // vec2
|
||||||
(c, p) -> {
|
(c, p) -> {
|
||||||
Vec2 res = Vec2Argument.getVec2(c, p);
|
Vec2 res = Vec2Argument.getVec2(c, p);
|
||||||
return ListValue.of(NumericValue.of(res.x), NumericValue.of(res.y));
|
return ListValue.of(NumericValue.of(res.x), NumericValue.of(res.y));
|
||||||
@@ -298,10 +300,10 @@ public abstract class CommandArgument
|
|||||||
public static RequiredArgumentBuilder<CommandSourceStack, ?> argumentNode(String param, CarpetScriptHost host) throws CommandSyntaxException
|
public static RequiredArgumentBuilder<CommandSourceStack, ?> argumentNode(String param, CarpetScriptHost host) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
CommandArgument arg = getTypeForArgument(param, host);
|
CommandArgument arg = getTypeForArgument(param, host);
|
||||||
if (arg.suggestionProvider != null) return argument(param, arg.getArgumentType()).suggests(arg.suggestionProvider);
|
if (arg.suggestionProvider != null) return argument(param, arg.getArgumentType(host)).suggests(arg.suggestionProvider);
|
||||||
if (!arg.needsMatching) return argument(param, arg.getArgumentType());
|
if (!arg.needsMatching) return argument(param, arg.getArgumentType(host));
|
||||||
String hostName = host.getName();
|
String hostName = host.getName();
|
||||||
return argument(param, arg.getArgumentType()).suggests((ctx, b) -> {
|
return argument(param, arg.getArgumentType(host)).suggests((ctx, b) -> {
|
||||||
CarpetScriptHost cHost = CarpetServer.scriptServer.modules.get(hostName).retrieveOwnForExecution(ctx.getSource());
|
CarpetScriptHost cHost = CarpetServer.scriptServer.modules.get(hostName).retrieveOwnForExecution(ctx.getSource());
|
||||||
return arg.suggest(ctx, b, cHost);
|
return arg.suggest(ctx, b, cHost);
|
||||||
});
|
});
|
||||||
@@ -325,7 +327,7 @@ public abstract class CommandArgument
|
|||||||
this.needsMatching = suggestFromExamples;
|
this.needsMatching = suggestFromExamples;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ArgumentType<?> getArgumentType() throws CommandSyntaxException;
|
protected abstract ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException;
|
||||||
|
|
||||||
|
|
||||||
public static Value getValue(CommandContext<CommandSourceStack> context, String param, CarpetScriptHost host) throws CommandSyntaxException
|
public static Value getValue(CommandContext<CommandSourceStack> context, String param, CarpetScriptHost host) throws CommandSyntaxException
|
||||||
@@ -445,7 +447,7 @@ public abstract class CommandArgument
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentType<?> getArgumentType()
|
public ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
return StringArgumentType.string();
|
return StringArgumentType.string();
|
||||||
}
|
}
|
||||||
@@ -490,7 +492,7 @@ public abstract class CommandArgument
|
|||||||
{
|
{
|
||||||
private WordArgument() { super(); suffix = "term"; examples = StringArgumentType.StringType.SINGLE_WORD.getExamples(); }
|
private WordArgument() { super(); suffix = "term"; examples = StringArgumentType.StringType.SINGLE_WORD.getExamples(); }
|
||||||
@Override
|
@Override
|
||||||
public ArgumentType<?> getArgumentType() { return StringArgumentType.word(); }
|
public ArgumentType<?> getArgumentType(CarpetScriptHost host) { return StringArgumentType.word(); }
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<CommandArgument> factory() { return WordArgument::new; }
|
protected Supplier<CommandArgument> factory() { return WordArgument::new; }
|
||||||
}
|
}
|
||||||
@@ -499,7 +501,7 @@ public abstract class CommandArgument
|
|||||||
{
|
{
|
||||||
private GreedyStringArgument() { super();suffix = "text"; examples = StringArgumentType.StringType.GREEDY_PHRASE.getExamples(); }
|
private GreedyStringArgument() { super();suffix = "text"; examples = StringArgumentType.StringType.GREEDY_PHRASE.getExamples(); }
|
||||||
@Override
|
@Override
|
||||||
public ArgumentType<?> getArgumentType() { return StringArgumentType.greedyString(); }
|
public ArgumentType<?> getArgumentType(CarpetScriptHost host) { return StringArgumentType.greedyString(); }
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<CommandArgument> factory() { return GreedyStringArgument::new; }
|
protected Supplier<CommandArgument> factory() { return GreedyStringArgument::new; }
|
||||||
}
|
}
|
||||||
@@ -514,7 +516,7 @@ public abstract class CommandArgument
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentType<?> getArgumentType()
|
public ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
return net.minecraft.commands.arguments.coordinates.BlockPosArgument.blockPos();
|
return net.minecraft.commands.arguments.coordinates.BlockPosArgument.blockPos();
|
||||||
}
|
}
|
||||||
@@ -552,7 +554,7 @@ public abstract class CommandArgument
|
|||||||
blockCentered = true;
|
blockCentered = true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected ArgumentType<?> getArgumentType()
|
protected ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
return Vec3Argument.vec3(blockCentered);
|
return Vec3Argument.vec3(blockCentered);
|
||||||
}
|
}
|
||||||
@@ -589,7 +591,7 @@ public abstract class CommandArgument
|
|||||||
single = false;
|
single = false;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected ArgumentType<?> getArgumentType()
|
protected ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
if (onlyFans)
|
if (onlyFans)
|
||||||
{
|
{
|
||||||
@@ -636,7 +638,7 @@ public abstract class CommandArgument
|
|||||||
single = false;
|
single = false;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected ArgumentType<?> getArgumentType()
|
protected ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
return GameProfileArgument.gameProfile();
|
return GameProfileArgument.gameProfile();
|
||||||
}
|
}
|
||||||
@@ -677,7 +679,7 @@ public abstract class CommandArgument
|
|||||||
suggestionProvider = ScoreHolderArgument.SUGGEST_SCORE_HOLDERS;
|
suggestionProvider = ScoreHolderArgument.SUGGEST_SCORE_HOLDERS;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected ArgumentType<?> getArgumentType()
|
protected ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
return single?ScoreHolderArgument.scoreHolder():ScoreHolderArgument.scoreHolders();
|
return single?ScoreHolderArgument.scoreHolder():ScoreHolderArgument.scoreHolders();
|
||||||
}
|
}
|
||||||
@@ -716,7 +718,7 @@ public abstract class CommandArgument
|
|||||||
mapRequired = true;
|
mapRequired = true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected ArgumentType<?> getArgumentType()
|
protected ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
return mapRequired?CompoundTagArgument.compoundTag(): NbtTagArgument.nbtTag();
|
return mapRequired?CompoundTagArgument.compoundTag(): NbtTagArgument.nbtTag();
|
||||||
}
|
}
|
||||||
@@ -754,7 +756,7 @@ public abstract class CommandArgument
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArgumentType<?> getArgumentType()
|
protected ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
return ResourceLocationArgument.id();
|
return ResourceLocationArgument.id();
|
||||||
}
|
}
|
||||||
@@ -799,7 +801,7 @@ public abstract class CommandArgument
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentType<?> getArgumentType()
|
public ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
if (min != null)
|
if (min != null)
|
||||||
{
|
{
|
||||||
@@ -850,7 +852,7 @@ public abstract class CommandArgument
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentType<?> getArgumentType()
|
public ArgumentType<?> getArgumentType(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
if (min != null)
|
if (min != null)
|
||||||
{
|
{
|
||||||
@@ -944,7 +946,7 @@ public abstract class CommandArgument
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArgumentType<?> getArgumentType() throws CommandSyntaxException
|
protected ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
return net.minecraft.commands.arguments.SlotArgument.slot();
|
return net.minecraft.commands.arguments.SlotArgument.slot();
|
||||||
}
|
}
|
||||||
@@ -998,11 +1000,19 @@ public abstract class CommandArgument
|
|||||||
ArgumentType<?> get() throws CommandSyntaxException;
|
ArgumentType<?> get() throws CommandSyntaxException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
private interface ArgumentProviderEx
|
||||||
|
{
|
||||||
|
ArgumentType<?> get(CommandBuildContext regAccess) throws CommandSyntaxException;
|
||||||
|
}
|
||||||
|
|
||||||
public static class VanillaUnconfigurableArgument extends CommandArgument
|
public static class VanillaUnconfigurableArgument extends CommandArgument
|
||||||
{
|
{
|
||||||
private final ArgumentProvider argumentTypeSupplier;
|
private final ArgumentProvider argumentTypeSupplier;
|
||||||
|
private final ArgumentProviderEx argumentTypeSupplierEx;
|
||||||
private final ValueExtractor valueExtractor;
|
private final ValueExtractor valueExtractor;
|
||||||
private final boolean providesExamples;
|
private final boolean providesExamples;
|
||||||
|
|
||||||
public VanillaUnconfigurableArgument(
|
public VanillaUnconfigurableArgument(
|
||||||
String suffix,
|
String suffix,
|
||||||
ArgumentProvider argumentTypeSupplier,
|
ArgumentProvider argumentTypeSupplier,
|
||||||
@@ -1022,6 +1032,7 @@ public abstract class CommandArgument
|
|||||||
this.providesExamples = suggestFromExamples;
|
this.providesExamples = suggestFromExamples;
|
||||||
this.argumentTypeSupplier = argumentTypeSupplier;
|
this.argumentTypeSupplier = argumentTypeSupplier;
|
||||||
this.valueExtractor = valueExtractor;
|
this.valueExtractor = valueExtractor;
|
||||||
|
this.argumentTypeSupplierEx = null;
|
||||||
}
|
}
|
||||||
public VanillaUnconfigurableArgument(
|
public VanillaUnconfigurableArgument(
|
||||||
String suffix,
|
String suffix,
|
||||||
@@ -1035,12 +1046,38 @@ public abstract class CommandArgument
|
|||||||
this.providesExamples = false;
|
this.providesExamples = false;
|
||||||
this.argumentTypeSupplier = argumentTypeSupplier;
|
this.argumentTypeSupplier = argumentTypeSupplier;
|
||||||
this.valueExtractor = valueExtractor;
|
this.valueExtractor = valueExtractor;
|
||||||
|
this.argumentTypeSupplierEx = null;
|
||||||
|
}
|
||||||
|
public VanillaUnconfigurableArgument(
|
||||||
|
String suffix,
|
||||||
|
ArgumentProviderEx argumentTypeSupplier,
|
||||||
|
ValueExtractor valueExtractor,
|
||||||
|
boolean suggestFromExamples
|
||||||
|
)
|
||||||
|
{
|
||||||
|
super(suffix, null, suggestFromExamples);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final CommandBuildContext context = new CommandBuildContext(RegistryAccess.BUILTIN.get());
|
||||||
|
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
|
||||||
|
this.examples = argumentTypeSupplier.get(context).getExamples();
|
||||||
|
}
|
||||||
|
catch (CommandSyntaxException e)
|
||||||
|
{
|
||||||
|
this.examples = Collections.emptyList();
|
||||||
|
}
|
||||||
|
this.providesExamples = suggestFromExamples;
|
||||||
|
this.argumentTypeSupplierEx = argumentTypeSupplier;
|
||||||
|
this.valueExtractor = valueExtractor;
|
||||||
|
this.argumentTypeSupplier = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArgumentType<?> getArgumentType() throws CommandSyntaxException
|
protected ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
return argumentTypeSupplier.get();
|
if (argumentTypeSupplier != null) return argumentTypeSupplier.get();
|
||||||
|
CommandBuildContext registryAccess = new CommandBuildContext(host.getScriptServer().server.registryAccess());
|
||||||
|
return argumentTypeSupplierEx.get(registryAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1052,7 +1089,8 @@ public abstract class CommandArgument
|
|||||||
@Override
|
@Override
|
||||||
protected Supplier<CommandArgument> factory()
|
protected Supplier<CommandArgument> factory()
|
||||||
{
|
{
|
||||||
return () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplier, valueExtractor, providesExamples);
|
if (argumentTypeSupplier != null) return () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplier, valueExtractor, providesExamples);
|
||||||
|
return () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplierEx, valueExtractor, providesExamples);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,12 +8,11 @@ import carpet.script.value.StringValue;
|
|||||||
import carpet.script.value.Value;
|
import carpet.script.value.Value;
|
||||||
import carpet.script.value.ValueConversions;
|
import carpet.script.value.ValueConversions;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.HolderSet;
|
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
@@ -25,7 +24,12 @@ public class BiomeInfo
|
|||||||
public final static Map<String, BiFunction<ServerLevel, Biome, Value>> biomeFeatures = new HashMap<String, BiFunction<ServerLevel, Biome, Value>>(){{
|
public final static Map<String, BiFunction<ServerLevel, Biome, Value>> biomeFeatures = new HashMap<String, BiFunction<ServerLevel, Biome, Value>>(){{
|
||||||
//put("top_material", (w, b) -> new BlockValue( b.getGenerationSettings(). getSurfaceConfig().getTopMaterial(), null, null));
|
//put("top_material", (w, b) -> new BlockValue( b.getGenerationSettings(). getSurfaceConfig().getTopMaterial(), null, null));
|
||||||
//put("under_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null));
|
//put("under_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null));
|
||||||
put("category", (w, b) -> StringValue.of(Biome.getBiomeCategory(Holder.direct(b)).getName()));
|
//put("category", (w, b) -> StringValue.of(Biome.getBiomeCategory(Holder.direct(b)).getName()));
|
||||||
|
put("biome_tags", (w, b) -> {
|
||||||
|
Holder<Biome> direct = Holder.direct(b);
|
||||||
|
return ListValue.wrap(w.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getTags().filter(p -> p.getSecond().contains(direct)).map(p -> p.getFirst().location()).map(ValueConversions::of).collect(Collectors.toList()));
|
||||||
|
});
|
||||||
|
|
||||||
put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature()));
|
put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature()));
|
||||||
put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor()));
|
put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor()));
|
||||||
put("foliage_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFoliageColorOverride().orElse(4764952))); // client Biome.getDefaultFoliageColor
|
put("foliage_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFoliageColorOverride().orElse(4764952))); // client Biome.getDefaultFoliageColor
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class WorldTools
|
|||||||
catch (IOException ignored) { }
|
catch (IOException ignored) { }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public static boolean createWorld(MinecraftServer server, String worldKey, Long seed)
|
public static boolean createWorld(MinecraftServer server, String worldKey, Long seed)
|
||||||
{
|
{
|
||||||
ResourceLocation worldId = new ResourceLocation(worldKey);
|
ResourceLocation worldId = new ResourceLocation(worldKey);
|
||||||
@@ -137,7 +137,7 @@ public class WorldTools
|
|||||||
overWorld.getWorldBorder().addListener(new BorderChangeListener.DelegateBorderChangeListener(serverWorld.getWorldBorder()));
|
overWorld.getWorldBorder().addListener(new BorderChangeListener.DelegateBorderChangeListener(serverWorld.getWorldBorder()));
|
||||||
((MinecraftServerInterface) server).getCMWorlds().put(customWorld, serverWorld);
|
((MinecraftServerInterface) server).getCMWorlds().put(customWorld, serverWorld);
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public static void forceChunkUpdate(BlockPos pos, ServerLevel world)
|
public static void forceChunkUpdate(BlockPos pos, ServerLevel world)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Direction.Axis;
|
import net.minecraft.core.Direction.Axis;
|
||||||
import net.minecraft.core.GlobalPos;
|
import net.minecraft.core.GlobalPos;
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.StringTag;
|
import net.minecraft.nbt.StringTag;
|
||||||
@@ -59,13 +60,13 @@ public class BlockValue extends Value
|
|||||||
{
|
{
|
||||||
BlockValue bv = bvCache.get(str);
|
BlockValue bv = bvCache.get(str);
|
||||||
if (bv != null) return bv;
|
if (bv != null) return bv;
|
||||||
BlockStateParser blockstateparser = (new BlockStateParser(new StringReader(str), false)).parse(true);
|
BlockStateParser.BlockResult foo = BlockStateParser.parseForBlock(HolderLookup.forRegistry(Registry.BLOCK), new StringReader(str), true );
|
||||||
if (blockstateparser.getState() != null)
|
if (foo.blockState() != null)
|
||||||
{
|
{
|
||||||
CompoundTag bd = blockstateparser.getNbt();
|
CompoundTag bd = foo.nbt();
|
||||||
if (bd == null)
|
if (bd == null)
|
||||||
bd = new CompoundTag();
|
bd = new CompoundTag();
|
||||||
bv = new BlockValue(blockstateparser.getState(), null, null, bd );
|
bv = new BlockValue(foo.blockState(), null, null, bd );
|
||||||
if (bvCache.size()>10000)
|
if (bvCache.size()>10000)
|
||||||
bvCache.clear();
|
bvCache.clear();
|
||||||
bvCache.put(str, bv);
|
bvCache.put(str, bv);
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import net.minecraft.commands.arguments.NbtPathArgument;
|
|||||||
import net.minecraft.commands.arguments.item.ItemInput;
|
import net.minecraft.commands.arguments.item.ItemInput;
|
||||||
import net.minecraft.commands.arguments.item.ItemParser;
|
import net.minecraft.commands.arguments.item.ItemParser;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.nbt.CollectionTag;
|
import net.minecraft.nbt.CollectionTag;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.EndTag;
|
import net.minecraft.nbt.EndTag;
|
||||||
@@ -301,17 +304,17 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
|||||||
if (customTag == null)
|
if (customTag == null)
|
||||||
return res;
|
return res;
|
||||||
else
|
else
|
||||||
return new ItemInput(res.getItem(), customTag);
|
return new ItemInput(Holder.direct(res.getItem()), customTag);
|
||||||
|
ItemParser.ItemResult parser = ItemParser.parseForItem(HolderLookup.forRegistry(Registry.ITEM), new StringReader(itemString));
|
||||||
|
res = new ItemInput(parser.item(), parser.nbt());
|
||||||
|
|
||||||
ItemParser parser = (new ItemParser(new StringReader(itemString), false)).parse();
|
|
||||||
res = new ItemInput(parser.getItem(), parser.getNbt());
|
|
||||||
itemCache.put(itemString, res);
|
itemCache.put(itemString, res);
|
||||||
if (itemCache.size()>64000)
|
if (itemCache.size()>64000)
|
||||||
itemCache.clear();
|
itemCache.clear();
|
||||||
if (customTag == null)
|
if (customTag == null)
|
||||||
return res;
|
return res;
|
||||||
else
|
else
|
||||||
return new ItemInput(res.getItem(), customTag);
|
return new ItemInput(Holder.direct(res.getItem()), customTag);
|
||||||
}
|
}
|
||||||
catch (CommandSyntaxException e)
|
catch (CommandSyntaxException e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,15 +17,16 @@ import com.mojang.brigadier.suggestion.Suggestions;
|
|||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.SharedSuggestionProvider;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.network.chat.BaseComponent;
|
import net.minecraft.network.chat.BaseComponent;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.TickTask;
|
import net.minecraft.server.TickTask;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.storage.LevelResource;
|
import net.minecraft.world.level.storage.LevelResource;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
import org.apache.logging.log4j.util.TriConsumer;
|
import org.apache.logging.log4j.util.TriConsumer;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -574,12 +575,21 @@ public class SettingsManager
|
|||||||
return suggestionsBuilder.buildFuture();
|
return suggestionsBuilder.buildFuture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
|
public void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||||
|
{
|
||||||
|
final CommandBuildContext context = new CommandBuildContext(RegistryAccess.BUILTIN.get());
|
||||||
|
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
|
||||||
|
registerCommand(dispatcher, context);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the the settings command for this {@link SettingsManager}.<br>
|
* Registers the settings command for this {@link SettingsManager}.<br>
|
||||||
* It is handled automatically by Carpet.
|
* It is handled automatically by Carpet.
|
||||||
* @param dispatcher The current {@link CommandDispatcher}
|
* @param dispatcher The current {@link CommandDispatcher}
|
||||||
|
* @param commandBuildContext The current {@link CommandBuildContext}
|
||||||
*/
|
*/
|
||||||
public void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher)
|
public void registerCommand(final CommandDispatcher<CommandSourceStack> dispatcher, final CommandBuildContext commandBuildContext)
|
||||||
{
|
{
|
||||||
if (dispatcher.getRoot().getChildren().stream().anyMatch(node -> node.getName().equalsIgnoreCase(identifier)))
|
if (dispatcher.getRoot().getChildren().stream().anyMatch(node -> node.getName().equalsIgnoreCase(identifier)))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -159,10 +159,10 @@ public class PerimeterDiagnostics
|
|||||||
|
|
||||||
private boolean check_entity_spawn(BlockPos pos)
|
private boolean check_entity_spawn(BlockPos pos)
|
||||||
{
|
{
|
||||||
if (sle == null || !worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureFeatureManager(), ctype, pos).unwrap().contains(sle))
|
if (sle == null || !worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureManager(), ctype, pos).unwrap().contains(sle))
|
||||||
{
|
{
|
||||||
sle = null;
|
sle = null;
|
||||||
for (MobSpawnSettings.SpawnerData sle: worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureFeatureManager(), ctype, pos).unwrap())
|
for (MobSpawnSettings.SpawnerData sle: worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureManager(), ctype, pos).unwrap())
|
||||||
{
|
{
|
||||||
if (el.getType() == sle.type)
|
if (el.getType() == sle.type)
|
||||||
{
|
{
|
||||||
@@ -170,7 +170,7 @@ public class PerimeterDiagnostics
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sle == null || !worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureFeatureManager(), ctype, pos).unwrap().contains(sle))
|
if (sle == null || !worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureManager(), ctype, pos).unwrap().contains(sle))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,22 +3,22 @@ package carpet.utils;
|
|||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Holder;
|
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.SectionPos;
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.data.worldgen.StructureFeatures;
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.util.random.WeightedRandomList;
|
import net.minecraft.util.random.WeightedRandomList;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.MobCategory;
|
import net.minecraft.world.entity.MobCategory;
|
||||||
import net.minecraft.world.level.StructureFeatureManager;
|
import net.minecraft.world.level.StructureManager;
|
||||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
|
||||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureSpawnOverride;
|
import net.minecraft.world.level.levelgen.structure.StructureSpawnOverride;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.StructureType;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -28,16 +28,16 @@ import java.util.Map;
|
|||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
|
|
||||||
public class SpawnOverrides {
|
public class SpawnOverrides {
|
||||||
final private static Map<Pair<MobCategory, StructureFeature<?>>, Pair<BooleanSupplier, StructureSpawnOverride>> carpetOverrides = new HashMap<>();
|
final private static Map<Pair<MobCategory, ResourceKey<Structure>>, Pair<BooleanSupplier, StructureSpawnOverride>> carpetOverrides = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
addOverride(() -> CarpetSettings.huskSpawningInTemples, MobCategory.MONSTER, StructureFeatures.DESERT_PYRAMID, StructureSpawnOverride.BoundingBoxType.STRUCTURE,
|
addOverride(() -> CarpetSettings.huskSpawningInTemples, MobCategory.MONSTER, BuiltinStructures.DESERT_PYRAMID, StructureSpawnOverride.BoundingBoxType.STRUCTURE,
|
||||||
WeightedRandomList.create(new MobSpawnSettings.SpawnerData(EntityType.HUSK, 1, 1, 1))
|
WeightedRandomList.create(new MobSpawnSettings.SpawnerData(EntityType.HUSK, 1, 1, 1))
|
||||||
);
|
);
|
||||||
addOverride(() -> CarpetSettings.shulkerSpawningInEndCities, MobCategory.MONSTER, StructureFeatures.END_CITY, StructureSpawnOverride.BoundingBoxType.PIECE,
|
addOverride(() -> CarpetSettings.shulkerSpawningInEndCities, MobCategory.MONSTER, BuiltinStructures.END_CITY, StructureSpawnOverride.BoundingBoxType.PIECE,
|
||||||
WeightedRandomList.create(new MobSpawnSettings.SpawnerData(EntityType.SHULKER, 10, 4, 4))
|
WeightedRandomList.create(new MobSpawnSettings.SpawnerData(EntityType.SHULKER, 10, 4, 4))
|
||||||
);
|
);
|
||||||
addOverride(() -> CarpetSettings.piglinsSpawningInBastions, MobCategory.MONSTER, StructureFeatures.BASTION_REMNANT, StructureSpawnOverride.BoundingBoxType.PIECE,
|
addOverride(() -> CarpetSettings.piglinsSpawningInBastions, MobCategory.MONSTER, BuiltinStructures.BASTION_REMNANT, StructureSpawnOverride.BoundingBoxType.PIECE,
|
||||||
WeightedRandomList.create(
|
WeightedRandomList.create(
|
||||||
new MobSpawnSettings.SpawnerData(EntityType.PIGLIN_BRUTE, 5, 1, 2),
|
new MobSpawnSettings.SpawnerData(EntityType.PIGLIN_BRUTE, 5, 1, 2),
|
||||||
new MobSpawnSettings.SpawnerData(EntityType.PIGLIN, 10, 2, 4),
|
new MobSpawnSettings.SpawnerData(EntityType.PIGLIN, 10, 2, 4),
|
||||||
@@ -47,14 +47,16 @@ public class SpawnOverrides {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addOverride(BooleanSupplier when, MobCategory cat, Holder<ConfiguredStructureFeature<?, ?>> poo,
|
public static void addOverride(BooleanSupplier when, MobCategory cat, ResourceKey<Structure> poo,
|
||||||
StructureSpawnOverride.BoundingBoxType type, WeightedRandomList<MobSpawnSettings.SpawnerData> spawns) {
|
StructureSpawnOverride.BoundingBoxType type, WeightedRandomList<MobSpawnSettings.SpawnerData> spawns) {
|
||||||
carpetOverrides.put(Pair.of(cat, poo.value().feature), Pair.of(when, new StructureSpawnOverride(type, spawns)));
|
carpetOverrides.put(Pair.of(cat, poo), Pair.of(when, new StructureSpawnOverride(type, spawns)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WeightedRandomList<MobSpawnSettings.SpawnerData> test(StructureFeatureManager structureFeatureManager, LongSet foo,
|
public static WeightedRandomList<MobSpawnSettings.SpawnerData> test(StructureManager structureFeatureManager, LongSet foo,
|
||||||
MobCategory cat, ConfiguredStructureFeature<?, ?> confExisting, BlockPos where) {
|
MobCategory cat, Structure confExisting, BlockPos where) {
|
||||||
final Pair<BooleanSupplier, StructureSpawnOverride> spawnData = carpetOverrides.get(Pair.of(cat, confExisting.feature));
|
ResourceLocation resource = structureFeatureManager.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).getKey(confExisting);
|
||||||
|
ResourceKey<Structure> key = ResourceKey.create(Registry.STRUCTURE_REGISTRY, resource);
|
||||||
|
final Pair<BooleanSupplier, StructureSpawnOverride> spawnData = carpetOverrides.get(Pair.of(cat, key));
|
||||||
if (spawnData == null || !spawnData.getKey().getAsBoolean()) return null;
|
if (spawnData == null || !spawnData.getKey().getAsBoolean()) return null;
|
||||||
StructureSpawnOverride override = spawnData.getRight();
|
StructureSpawnOverride override = spawnData.getRight();
|
||||||
if (override.boundingBox() == StructureSpawnOverride.BoundingBoxType.STRUCTURE) {
|
if (override.boundingBox() == StructureSpawnOverride.BoundingBoxType.STRUCTURE) {
|
||||||
@@ -62,7 +64,7 @@ public class SpawnOverrides {
|
|||||||
return override.spawns();
|
return override.spawns();
|
||||||
} else {
|
} else {
|
||||||
List<StructureStart> starts = new ArrayList<>(1);
|
List<StructureStart> starts = new ArrayList<>(1);
|
||||||
structureFeatureManager.fillStartsForFeature(confExisting, foo, starts::add);
|
structureFeatureManager.fillStartsForStructure(confExisting, foo, starts::add);
|
||||||
for (StructureStart start : starts) {
|
for (StructureStart start : starts) {
|
||||||
if (start != null && start.isValid() && structureFeatureManager.structureHasPieceAt(where, start)) {
|
if (start != null && start.isValid() && structureFeatureManager.structureHasPieceAt(where, start)) {
|
||||||
return override.spawns();
|
return override.spawns();
|
||||||
@@ -72,16 +74,16 @@ public class SpawnOverrides {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isStructureAtPosition(ServerLevel level, ResourceKey<ConfiguredStructureFeature<?, ?>> structureKey, BlockPos pos)
|
public static boolean isStructureAtPosition(ServerLevel level, ResourceKey<Structure> structureKey, BlockPos pos)
|
||||||
{
|
{
|
||||||
final ConfiguredStructureFeature<?, ?> fortressFeature = level.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(structureKey);
|
final Structure fortressFeature = level.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(structureKey);
|
||||||
if (fortressFeature == null) {
|
if (fortressFeature == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return level.structureFeatureManager().getStructureAt(pos, fortressFeature).isValid();
|
return level.structureManager().getStructureAt(pos, fortressFeature).isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isStructureAtPosition(ServerLevel level, StructureFeature<?> structure, BlockPos pos)
|
public static boolean isStructureAtPosition(ServerLevel level, StructureType<?> structure, BlockPos pos)
|
||||||
{
|
{
|
||||||
for(StructureStart structureStart : startsForFeature(level, SectionPos.of(pos), structure)) {
|
for(StructureStart structureStart : startsForFeature(level, SectionPos.of(pos), structure)) {
|
||||||
if (structureStart.getBoundingBox().isInside(pos) && structureStart.isValid()) {
|
if (structureStart.getBoundingBox().isInside(pos) && structureStart.isValid()) {
|
||||||
@@ -91,15 +93,15 @@ public class SpawnOverrides {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<StructureStart> startsForFeature(ServerLevel level, SectionPos sectionPos, StructureFeature<?> structure) {
|
public static List<StructureStart> startsForFeature(ServerLevel level, SectionPos sectionPos, StructureType<?> structure) {
|
||||||
Map<ConfiguredStructureFeature<?, ?>, LongSet> allrefs = level.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
|
Map<Structure, LongSet> allrefs = level.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
|
||||||
List<StructureStart> result = new ArrayList<>();
|
List<StructureStart> result = new ArrayList<>();
|
||||||
for (var entry: allrefs.entrySet())
|
for (var entry: allrefs.entrySet())
|
||||||
{
|
{
|
||||||
ConfiguredStructureFeature<?, ?> existing = entry.getKey();
|
Structure existing = entry.getKey();
|
||||||
if (existing.feature == structure)
|
if (existing.type() == structure)
|
||||||
{
|
{
|
||||||
level.structureFeatureManager().fillStartsForFeature(existing, entry.getValue(), result::add);
|
level.structureManager().fillStartsForStructure(existing, entry.getValue(), result::add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import it.unimi.dsi.fastutil.objects.Object2LongMap;
|
|||||||
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.network.chat.BaseComponent;
|
import net.minecraft.network.chat.BaseComponent;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
@@ -23,7 +24,7 @@ import net.minecraft.world.entity.animal.Ocelot;
|
|||||||
import net.minecraft.world.item.DyeColor;
|
import net.minecraft.world.item.DyeColor;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.NaturalSpawner;
|
import net.minecraft.world.level.NaturalSpawner;
|
||||||
import net.minecraft.world.level.StructureFeatureManager;
|
import net.minecraft.world.level.StructureManager;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
@@ -32,8 +33,11 @@ import net.minecraft.world.level.chunk.ChunkAccess;
|
|||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.entity.EntityTypeTest;
|
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||||
import net.minecraft.world.level.levelgen.Heightmap;
|
import net.minecraft.world.level.levelgen.Heightmap;
|
||||||
import net.minecraft.world.level.levelgen.feature.NetherFortressFeature;
|
import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.structures.NetherFortressStructure;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -422,11 +426,17 @@ public class SpawnReporter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// yeeted from NaturalSpawner - temporary access fix
|
// yeeted from NaturalSpawner - temporary access fix
|
||||||
private static List<MobSpawnSettings.SpawnerData> getSpawnEntries(final ServerLevel level, final StructureFeatureManager structureFeatureManager, final ChunkGenerator generator, final MobCategory mobCategory, final BlockPos pos, final Holder<Biome> biome) {
|
private static List<MobSpawnSettings.SpawnerData> getSpawnEntries(ServerLevel serverLevel, StructureManager structureManager, ChunkGenerator chunkGenerator, MobCategory mobCategory, BlockPos blockPos, @Nullable Holder<Biome> holder) {
|
||||||
if (NaturalSpawner.isInNetherFortressBounds (pos, level, mobCategory, structureFeatureManager)) {
|
return isInNetherFortressBounds(blockPos, serverLevel, mobCategory, structureManager) ? NetherFortressStructure.FORTRESS_ENEMIES.unwrap() : chunkGenerator.getMobsAt(holder != null ? holder : serverLevel.getBiome(blockPos), structureManager, mobCategory, blockPos).unwrap();
|
||||||
return NetherFortressFeature.FORTRESS_ENEMIES.unwrap();
|
}
|
||||||
|
|
||||||
|
public static boolean isInNetherFortressBounds(BlockPos blockPos, ServerLevel serverLevel, MobCategory mobCategory, StructureManager structureManager) {
|
||||||
|
if (mobCategory == MobCategory.MONSTER && serverLevel.getBlockState(blockPos.below()).is(Blocks.NETHER_BRICKS)) {
|
||||||
|
Structure structure = (Structure)structureManager.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(BuiltinStructures.FORTRESS);
|
||||||
|
return structure == null ? false : structureManager.getStructureAt(blockPos, structure).isValid();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return generator.getMobsAt(biome != null ? biome : level.getBiome(pos), structureFeatureManager, mobCategory, pos).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BaseComponent> report(BlockPos pos, ServerLevel worldIn)
|
public static List<BaseComponent> report(BlockPos pos, ServerLevel worldIn)
|
||||||
@@ -442,7 +452,7 @@ public class SpawnReporter
|
|||||||
for (MobCategory enumcreaturetype : MobCategory.values())
|
for (MobCategory enumcreaturetype : MobCategory.values())
|
||||||
{
|
{
|
||||||
String type_code = String.format("%s", enumcreaturetype).substring(0, 3);
|
String type_code = String.format("%s", enumcreaturetype).substring(0, 3);
|
||||||
List<MobSpawnSettings.SpawnerData> lst = getSpawnEntries(worldIn, worldIn.structureFeatureManager(), worldIn.getChunkSource().getGenerator(), enumcreaturetype, pos, worldIn.getBiome(pos) );// ((ChunkGenerator)worldIn.getChunkManager().getChunkGenerator()).getEntitySpawnList(, worldIn.getStructureAccessor(), enumcreaturetype, pos);
|
List<MobSpawnSettings.SpawnerData> lst = getSpawnEntries(worldIn, worldIn.structureManager(), worldIn.getChunkSource().getGenerator(), enumcreaturetype, pos, worldIn.getBiome(pos) );// ((ChunkGenerator)worldIn.getChunkManager().getChunkGenerator()).getEntitySpawnList(, worldIn.getStructureAccessor(), enumcreaturetype, pos);
|
||||||
if (lst != null && !lst.isEmpty())
|
if (lst != null && !lst.isEmpty())
|
||||||
{
|
{
|
||||||
for (MobSpawnSettings.SpawnerData spawnEntry : lst)
|
for (MobSpawnSettings.SpawnerData spawnEntry : lst)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ __config() ->
|
|||||||
'clear' -> 'clear',
|
'clear' -> 'clear',
|
||||||
},
|
},
|
||||||
'arguments' -> {
|
'arguments' -> {
|
||||||
'structure' -> {'type' -> 'term', 'suggest' -> plop():'configured_structures' },
|
'structure' -> {'type' -> 'term', 'suggest' -> plop():'structures' },
|
||||||
'radius' -> {'type' -> 'int', 'min' -> 0, 'max' -> 1024, 'suggest' -> [128, 24, 32]},
|
'radius' -> {'type' -> 'int', 'min' -> 0, 'max' -> 1024, 'suggest' -> [128, 24, 32]},
|
||||||
'shape' -> {'type' -> 'term', 'options' -> keys(global_shapes) },
|
'shape' -> {'type' -> 'term', 'options' -> keys(global_shapes) },
|
||||||
'color' -> {'type' -> 'teamcolor'}
|
'color' -> {'type' -> 'teamcolor'}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
"accessWidener" : "carpet.accesswidener",
|
"accessWidener" : "carpet.accesswidener",
|
||||||
|
|
||||||
"depends": {
|
"depends": {
|
||||||
"minecraft": "1.18.x",
|
"minecraft": "1.19.*",
|
||||||
"fabricloader": ">=0.12.8",
|
"fabricloader": ">=0.12.8",
|
||||||
"java": ">=17"
|
"java": ">=17"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user