fabric cloud impl

This commit is contained in:
dfsek
2021-09-06 14:31:40 -07:00
parent bdb486188e
commit c9f19937c9
16 changed files with 64 additions and 120 deletions

View File

@@ -9,6 +9,8 @@ plugins {
id("com.modrinth.minotaur").version("1.1.0")
}
val fabricApi = "0.31.0+1.16"
addonDir(project.rootProject.file("./run/config/Terra/addons"), tasks.named("runClient").get())
addonDir(project.rootProject.file("./run/config/Terra/addons"), tasks.named("runServer").get())
@@ -32,6 +34,8 @@ dependencies {
exclude(group = "org.apache.logging.log4j", module = "log4j-api")
exclude(group = "org.apache.logging.log4j", module = "log4j-core")
}
"modImplementation"("cloud.commandframework", "cloud-fabric", "1.5.0")
}
tasks.named<ShadowJar>("shadowJar") {

View File

@@ -1,6 +1,14 @@
package com.dfsek.terra.fabric;
package com.dfsek.terra.fabric.entry;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricServerCommandManager;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
import com.dfsek.terra.fabric.TerraPluginImpl;
import net.fabricmc.api.ModInitializer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
@@ -16,7 +24,7 @@ import com.dfsek.terra.fabric.generation.PopulatorFeature;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
public class FabricEntryPoint implements ModInitializer {
public class CommonEntryPoint implements ModInitializer {
public static final PopulatorFeature POPULATOR_FEATURE = new PopulatorFeature(DefaultFeatureConfig.CODEC);
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(
Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
@@ -36,5 +44,12 @@ public class FabricEntryPoint implements ModInitializer {
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
FabricServerCommandManager<CommandSender> commandManager = new FabricServerCommandManager<>(
CommandExecutionCoordinator.simpleCoordinator(),
fabricClientCommandSource -> (CommandSender) fabricClientCommandSource,
commandSender -> (ServerCommandSource) commandSender);
TERRA_PLUGIN.getEventManager().callEvent(new CommandRegistrationEvent(commandManager));
}
}

View File

@@ -35,7 +35,7 @@ import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.api.world.generator.Chunkified;
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
import com.dfsek.terra.util.FastRandom;
@@ -46,7 +46,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
config -> config.group(
Codec.STRING.fieldOf("pack")
.forGetter(ConfigPack::getID)
).apply(config, config.stable(FabricEntryPoint.getTerraPlugin().getConfigRegistry()::get)));
).apply(config, config.stable(CommonEntryPoint.getTerraPlugin().getConfigRegistry()::get)));
public static final Codec<FabricChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(
instance -> instance.group(

View File

@@ -14,7 +14,7 @@ import java.util.stream.Collectors;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
import com.dfsek.terra.fabric.util.FabricUtil;
@@ -23,7 +23,7 @@ public class TerraBiomeSource extends BiomeSource {
Codec.STRING.fieldOf("pack").forGetter(ConfigPack::getID)
)
.apply(config, config.stable(
FabricEntryPoint.getTerraPlugin()
CommonEntryPoint.getTerraPlugin()
.getConfigRegistry()::get))));
public static final Codec<TerraBiomeSource> CODEC = RecordCodecBuilder.create(instance -> instance.group(
RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter(source -> source.biomeRegistry),

View File

@@ -11,7 +11,7 @@ import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
@@ -28,7 +28,7 @@ public class TerraGeneratorType extends GeneratorType {
public GeneratorOptions createDefaultOptions(DynamicRegistryManager.Impl registryManager, long seed, boolean generateStructures,
boolean bonusChest) {
GeneratorOptions options = super.createDefaultOptions(registryManager, seed, generateStructures, bonusChest);
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(new BiomeRegistrationEvent(registryManager)); // register biomes
CommonEntryPoint.getTerraPlugin().getEventManager().callEvent(new BiomeRegistrationEvent(registryManager)); // register biomes
return options;
}

View File

@@ -1,92 +0,0 @@
package com.dfsek.terra.fabric.mixin;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.dfsek.terra.api.command.exception.CommandException;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.fabric.FabricEntryPoint;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
@Mixin(CommandManager.class)
public abstract class CommandManagerMixin {
@Shadow
@Final
private CommandDispatcher<ServerCommandSource> dispatcher;
@Inject(method = "<init>",
at = @At(value = "INVOKE",
target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V",
remap = false))
private void injectTerraCommands(CommandManager.RegistrationEnvironment environment, CallbackInfo ci) {
com.dfsek.terra.api.command.CommandManager manager = FabricEntryPoint.getTerraPlugin().getManager();
int max = manager.getMaxArgumentDepth();
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
for(int i = 0; i < max; i++) {
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
arg = next.then(assemble(arg, manager));
}
dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager)));
dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager)));
}
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in,
com.dfsek.terra.api.command.CommandManager manager) {
return in.suggests((context, builder) -> {
List<String> args = parseCommand(context.getInput());
CommandSender sender = (CommandSender) context.getSource();
try {
sender = (Entity) context.getSource().getEntityOrThrow();
} catch(CommandSyntaxException ignore) {
}
try {
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
} catch(CommandException e) {
sender.sendMessage(e.getMessage());
}
return builder.buildFuture();
}).executes(context -> {
List<String> args = parseCommand(context.getInput());
CommandSender sender = (CommandSender) context.getSource();
try {
sender = (Entity) context.getSource().getEntityOrThrow();
} catch(CommandSyntaxException ignore) {
}
try {
manager.execute(args.remove(0), sender, args);
} catch(CommandException e) {
context.getSource().sendError(new LiteralText(e.getMessage()));
}
return 1;
});
}
private List<String> parseCommand(String command) {
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
if(command.endsWith(" ")) c.add("");
return c;
}
}

View File

@@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
import java.util.concurrent.Executor;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
@@ -31,7 +31,7 @@ public abstract class ServerWorldMixin {
boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((ServerWorld) (Object) this);
FabricEntryPoint.getTerraPlugin().logger().info("Registered world " + this);
CommonEntryPoint.getTerraPlugin().logger().info("Registered world " + this);
}
}
}

View File

@@ -21,7 +21,7 @@ import com.dfsek.terra.api.util.collection.MaterialSet;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
@Mixin(ConfiguredFeature.class)
@@ -33,7 +33,7 @@ public abstract class ConfiguredFeatureMixin {
@SuppressWarnings({ "ConstantConditions", "try" })
public boolean terra$plant(Vector3 l, World world, Random r) {
String id = BuiltinRegistries.CONFIGURED_FEATURE.getId((ConfiguredFeature<?, ?>) (Object) this).toString();
try(ProfileFrame ignore = FabricEntryPoint.getTerraPlugin().getProfiler().profile("fabric_tree:" + id.toLowerCase(Locale.ROOT))) {
try(ProfileFrame ignore = CommonEntryPoint.getTerraPlugin().getProfiler().profile("fabric_tree:" + id.toLowerCase(Locale.ROOT))) {
StructureWorldAccess fabricWorldAccess = ((StructureWorldAccess) world);
ChunkGenerator generatorWrapper = ((ServerWorldAccess) world).toServerWorld().getChunkManager().getChunkGenerator();
return generate(fabricWorldAccess, generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
@@ -41,8 +41,8 @@ public abstract class ConfiguredFeatureMixin {
}
public Set<BlockType> terra$getSpawnable() {
return MaterialSet.get(FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:grass_block"),
FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:podzol"),
FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:mycelium"));
return MaterialSet.get(CommonEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:grass_block"),
CommonEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:podzol"),
CommonEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:mycelium"));
}
}

View File

@@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.Shadow;
import com.dfsek.terra.api.block.entity.MobSpawner;
import com.dfsek.terra.api.block.entity.SerialState;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
import com.dfsek.terra.fabric.mixin.access.MobSpawnerLogicAccessor;
@@ -98,7 +98,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
SerialState.parse(state).forEach((k, v) -> {
switch(k) {
case "type":
terra$setSpawnedType(FabricEntryPoint.getTerraPlugin().getWorldHandle().getEntity(v));
terra$setSpawnedType(CommonEntryPoint.getTerraPlugin().getWorldHandle().getEntity(v));
return;
case "delay":
terra$setDelay(Integer.parseInt(v));

View File

@@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
import com.dfsek.terra.fabric.generation.TerraGeneratorType;
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
@@ -24,8 +24,8 @@ public class MinecraftClientMixin {
// sorta arbitrary position, after mod init, before window opens
shift = At.Shift.BEFORE))
public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) {
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(new PlatformInitializationEvent());
FabricEntryPoint.getTerraPlugin().getConfigRegistry().forEach(pack -> {
CommonEntryPoint.getTerraPlugin().getEventManager().callEvent(new PlatformInitializationEvent());
CommonEntryPoint.getTerraPlugin().getConfigRegistry().forEach(pack -> {
final GeneratorType generatorType = new TerraGeneratorType(pack);
//noinspection ConstantConditions
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getID()));

View File

@@ -18,7 +18,7 @@ import java.util.Properties;
import java.util.Random;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
import com.dfsek.terra.fabric.TerraPluginImpl;
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
@@ -37,7 +37,7 @@ public abstract class GeneratorOptionsMixin {
return;
}
TerraPluginImpl main = FabricEntryPoint.getTerraPlugin();
TerraPluginImpl main = CommonEntryPoint.getTerraPlugin();
String prop = properties.get("level-type").toString().trim();
if(prop.startsWith("Terra")) {

View File

@@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
@Mixin(Main.class)
@@ -17,7 +17,7 @@ public class ServerMainMixin {
target = "Lnet/minecraft/util/registry/DynamicRegistryManager;create()" +
"Lnet/minecraft/util/registry/DynamicRegistryManager$Impl;"))
private static void injectConstructor(String[] args, CallbackInfo ci) {
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(
CommonEntryPoint.getTerraPlugin().getEventManager().callEvent(
new PlatformInitializationEvent()); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
}
}

View File

@@ -1,9 +1,16 @@
package com.dfsek.terra.fabric.util;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Entity;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.WallShape;
import net.minecraft.block.enums.WireConnection;
import net.minecraft.client.network.ClientCommandSource;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
@@ -214,4 +221,13 @@ public final class FabricAdapter {
throw new IllegalStateException();
}
}
public static CommandSender adapt(ServerCommandSource source) {
try {
return (Entity) source.getEntityOrThrow();
} catch(CommandSyntaxException e) {
e.printStackTrace();
}
return (CommandSender) source;
}
}

View File

@@ -1,5 +1,7 @@
package com.dfsek.terra.fabric.util;
import com.dfsek.terra.api.entity.CommandSender;
import com.mojang.serialization.Lifecycle;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.block.entity.MobSpawnerBlockEntity;
@@ -29,7 +31,7 @@ import com.dfsek.terra.api.block.entity.MobSpawner;
import com.dfsek.terra.api.block.entity.Sign;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.entry.CommonEntryPoint;
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
@@ -60,7 +62,7 @@ public final class FabricUtil {
generationSettings.surfaceBuilder(
vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, FabricEntryPoint.POPULATOR_CONFIGURED_FEATURE);
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, CommonEntryPoint.POPULATOR_CONFIGURED_FEATURE);
if(pack.vanillaCaves()) {
for(GenerationStep.Carver carver : GenerationStep.Carver.values()) {

View File

@@ -17,7 +17,7 @@
"environment": "*",
"entrypoints": {
"main": [
"com.dfsek.terra.fabric.FabricEntryPoint"
"com.dfsek.terra.fabric.entry.CommonEntryPoint"
]
},
"mixins": [

View File

@@ -4,7 +4,6 @@
"package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"CommandManagerMixin",
"ServerWorldMixin",
"StructureAccessorAccessor",
"access.BiomeEffectsAccessor",