Skip to content

Commit

Permalink
[Fabric] 1.20.2-rc2, remove many mixins in favor of AW
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Sep 19, 2023
1 parent 2afc11c commit c4c5a6c
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 243 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ version=7.2.16-SNAPSHOT
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true

loom.version=1.2.7
loom.version=1.3.9
mixin.version=0.12.5+mixin.0.8.5
45 changes: 7 additions & 38 deletions worldedit-fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.configuration.FabricApiExtension
import net.fabricmc.loom.task.RemapJarTask

buildscript {
Expand All @@ -21,7 +22,7 @@ applyShadowConfiguration()
apply(plugin = "fabric-loom")
apply(plugin = "java-library")

val minecraftVersion = "1.20.2-rc1"
val minecraftVersion = "1.20.2-rc2"
val loaderVersion = "0.14.22"

val fabricApiConfiguration: Configuration = configurations.create("fabricApi")
Expand Down Expand Up @@ -52,52 +53,20 @@ dependencies {
"mappings"(project.the<LoomGradleExtensionAPI>().officialMojangMappings())
"modImplementation"("net.fabricmc:fabric-loader:$loaderVersion")

// [1] declare fabric-api dependency...
"fabricApi"("net.fabricmc.fabric-api:fabric-api:0.88.5+1.20.2")

// [2] Load the API dependencies from the fabric mod json...
// [1] Load the API dependencies from the fabric mod json...
@Suppress("UNCHECKED_CAST")
val fabricModJson = file("src/main/resources/fabric.mod.json").bufferedReader().use {
groovy.json.JsonSlurper().parse(it) as Map<String, Map<String, *>>
}
val wantedDependencies = (fabricModJson["depends"] ?: error("no depends in fabric.mod.json")).keys
.filter { it == "fabric-api-base" || it.contains(Regex("v\\d$")) }
.map { "net.fabricmc.fabric-api:$it" }
.toSet()
logger.lifecycle("Looking for these dependencies:")
// [2] Request the matching dependency from fabric-loom
for (wantedDependency in wantedDependencies) {
logger.lifecycle(wantedDependency)
}
// [3] and now we resolve it to pick out what we want :D
val fabricApiDependencies = fabricApiConfiguration.incoming.resolutionResult.allDependencies
.onEach {
if (it is UnresolvedDependencyResult) {
throw kotlin.IllegalStateException("Failed to resolve Fabric API", it.failure)
}
}
.filterIsInstance<ResolvedDependencyResult>()
// pick out transitive dependencies
.flatMap {
it.selected.dependencies
}
// grab the requested versions
.map { it.requested }
.filterIsInstance<ModuleComponentSelector>()
// map to standard notation
.associateByTo(
mutableMapOf(),
keySelector = { "${it.group}:${it.module}" },
valueTransform = { "${it.group}:${it.module}:${it.version}" }
)
fabricApiDependencies.keys.retainAll(wantedDependencies)
// sanity check
for (wantedDep in wantedDependencies) {
check(wantedDep in fabricApiDependencies) { "Fabric API library $wantedDep is missing!" }
}

fabricApiDependencies.values.forEach {
"include"(it)
"modImplementation"(it)
val dep = project.the<FabricApiExtension>().module(wantedDependency, "0.89.0+1.20.2")
"include"(dep)
"modImplementation"(dep)
}

// No need for this at runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.fabric.internal.NBTConverter;
import com.sk89q.worldedit.fabric.mixin.AccessorClientboundBlockEntityDataPacket;
import com.sk89q.worldedit.fabric.net.handler.WECUIPacketHandler;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.math.BlockVector3;
Expand All @@ -48,6 +47,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -243,10 +243,10 @@ public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B bl
if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
final CompoundTag nbtData = ((BaseBlock) block).getNbtData();
if (nbtData != null) {
player.connection.send(AccessorClientboundBlockEntityDataPacket.construct(
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
BlockEntityType.STRUCTURE_BLOCK,
NBTConverter.toNative(nbtData))
player.connection.send(new ClientboundBlockEntityDataPacket(
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
BlockEntityType.STRUCTURE_BLOCK,
NBTConverter.toNative(nbtData))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
import com.sk89q.worldedit.fabric.internal.ExtendedMinecraftServer;
import com.sk89q.worldedit.fabric.internal.FabricWorldNativeAccess;
import com.sk89q.worldedit.fabric.internal.NBTConverter;
import com.sk89q.worldedit.fabric.mixin.AccessorDerivedLevelData;
import com.sk89q.worldedit.fabric.mixin.AccessorPrimaryLevelData;
import com.sk89q.worldedit.fabric.mixin.AccessorServerChunkCache;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Mask2D;
Expand Down Expand Up @@ -96,8 +93,10 @@
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.storage.DerivedLevelData;
import net.minecraft.world.level.storage.LevelData;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.PrimaryLevelData;
import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
Expand Down Expand Up @@ -323,20 +322,14 @@ private void doRegen(Region region, Extent extent, RegenOptions options) throws
LevelStorageSource levelStorage = LevelStorageSource.createDefault(tempDir);
try (LevelStorageSource.LevelStorageAccess session = levelStorage.createAccess("WorldEditTempGen")) {
ServerLevel originalWorld = (ServerLevel) getWorld();
AccessorPrimaryLevelData levelProperties;
if (originalWorld.getLevelData() instanceof AccessorDerivedLevelData derivedLevelData) {
levelProperties = (AccessorPrimaryLevelData) derivedLevelData.getWrapped();
} else {
levelProperties = (AccessorPrimaryLevelData) originalWorld.getLevelData();
}
PrimaryLevelData levelProperties = getPrimaryLevelData(originalWorld.getLevelData());
WorldOptions originalOpts = levelProperties.worldGenOptions();

long seed = options.getSeed().orElse(originalWorld.getSeed());
WorldOptions newOpts = options.getSeed().isPresent()
levelProperties.worldOptions = options.getSeed().isPresent()
? originalOpts.withSeed(OptionalLong.of(seed))
: originalOpts;

levelProperties.setWorldOptions(newOpts);
ResourceKey<Level> worldRegKey = originalWorld.dimension();
try (ServerLevel serverWorld = new ServerLevel(
originalWorld.getServer(), Util.backgroundExecutor(), session,
Expand All @@ -362,19 +355,29 @@ private void doRegen(Region region, Extent extent, RegenOptions options) throws
Thread.yield();
}
} finally {
levelProperties.setWorldOptions(originalOpts);
levelProperties.worldOptions = originalOpts;
}
} finally {
SafeFiles.tryHardToDeleteDir(tempDir);
}
}

private static PrimaryLevelData getPrimaryLevelData(LevelData levelData) {
if (levelData instanceof DerivedLevelData derivedLevelData) {
return getPrimaryLevelData(derivedLevelData.wrapped);
} else if (levelData instanceof PrimaryLevelData primaryLevelData) {
return primaryLevelData;
} else {
throw new IllegalStateException("Unknown level data type: " + levelData.getClass());
}
}

private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld,
RegenOptions options) throws WorldEditException {
List<CompletableFuture<ChunkAccess>> chunkLoadings = submitChunkLoadTasks(region, serverWorld);

// drive executor until loading finishes
((AccessorServerChunkCache) serverWorld.getChunkSource()).getMainThreadProcessor()
serverWorld.getChunkSource().mainThreadProcessor
.managedBlock(() -> {
// bail out early if a future fails
if (chunkLoadings.stream().anyMatch(ftr ->
Expand Down Expand Up @@ -411,12 +414,11 @@ private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld
}

private List<CompletableFuture<ChunkAccess>> submitChunkLoadTasks(Region region, ServerLevel world) {
AccessorServerChunkCache chunkManager = (AccessorServerChunkCache) world.getChunkSource();
List<CompletableFuture<ChunkAccess>> chunkLoadings = new ArrayList<>();
// Pre-gen all the chunks
for (BlockVector2 chunk : region.getChunks()) {
chunkLoadings.add(
chunkManager.callGetChunkFuture(chunk.getX(), chunk.getZ(), ChunkStatus.FEATURES, true)
world.getChunkSource().getChunkFuture(chunk.getX(), chunk.getZ(), ChunkStatus.FEATURES, true)
.thenApply(either -> either.left().orElse(null))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@

public class WorldEditFakePlayer extends ServerPlayer {
private static final GameProfile FAKE_WORLDEDIT_PROFILE = new GameProfile(UUID.nameUUIDFromBytes("worldedit".getBytes()), "[WorldEdit]");
private static final ClientInformation FAKE_CLIENT_INFO = new ClientInformation(
"en_US", 16, ChatVisiblity.FULL, true, 0, HumanoidArm.LEFT, false, false
);

public WorldEditFakePlayer(ServerLevel world) {
super(world.getServer(), world, FAKE_WORLDEDIT_PROFILE, new ClientInformation("", 0, ChatVisiblity.FULL, false, 0, HumanoidArm.RIGHT, false, false));
super(world.getServer(), world, FAKE_WORLDEDIT_PROFILE, FAKE_CLIENT_INFO);
}

@Override
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c4c5a6c

Please sign in to comment.