Skip to content

Commit

Permalink
Fixed the botched iterator access.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vatuu committed Nov 25, 2019
1 parent 3428df1 commit 58850c4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ minecraft {}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}"
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-events-lifecycle-v0:${project.cmd_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api-base:${project.base_version}"
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx2G

# Fabric Properties
minecraft_version=19w46b
yarn_build=1:v2
loader_version=0.6.4+build.169
minecraft_version=1.15-pre1
yarn_build=3
loader_version=0.7.1+build.173

# Mod Properties
mod_version = 0.3
Expand Down
23 changes: 4 additions & 19 deletions src/main/java/dev/vatuu/tesseract/impl/Tesseract.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
package dev.vatuu.tesseract.impl;

import dev.vatuu.tesseract.impl.cmd.RegisterTestCommand;
import dev.vatuu.tesseract.impl.cmd.WorldResetCommand;
import dev.vatuu.tesseract.impl.world.DimensionBuilderImpl;
import dev.vatuu.tesseract.impl.world.DimensionRegistryImpl;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.server.ServerStartCallback;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.biome.HorizontalVoronoiBiomeAccessType;
import net.minecraft.world.dimension.DimensionType;

public class Tesseract implements ModInitializer {

public static String MOD_ID = "tesseract";

@Override
public void onInitialize() {
DimensionType cube = DimensionRegistryImpl.getInstance().registerDimensionType(
new Identifier("tesseract", "cube"),
true,
(w, t) -> new DimensionBuilderImpl()
.bedsExplode(true)
.cloudHeight(70f)
.forcedSpawnPoint(new BlockPos(0, 64, 0))
.visibleSky(true)
.renderFog(false)
.build(w, t),
HorizontalVoronoiBiomeAccessType.INSTANCE
);

ServerStartCallback.EVENT.register((ci) -> {
RegisterTestCommand.register(ci.getCommandManager().getDispatcher());
WorldResetCommand.register(ci.getCommandManager().getDispatcher());
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.vatuu.tesseract.impl.cmd;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.vatuu.tesseract.api.DimensionRegistry;
import dev.vatuu.tesseract.impl.Tesseract;
import dev.vatuu.tesseract.impl.world.DimensionBuilderImpl;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Identifier;
import net.minecraft.world.biome.HorizontalVoronoiBiomeAccessType;
import net.minecraft.world.dimension.DimensionType;

public class RegisterTestCommand {

public static void register(CommandDispatcher<ServerCommandSource> dispatcher){
dispatcher.register(
CommandManager.literal("registerTest")
.requires(src -> src.hasPermissionLevel(4))
.executes(ctx -> activate(ctx, "test", false))
.then(CommandManager.argument("id", StringArgumentType.word())
.executes(ctx -> activate(ctx, StringArgumentType.getString(ctx, "id"), false))
.then(CommandManager.argument("save", BoolArgumentType.bool())
.executes(ctx -> activate(ctx, StringArgumentType.getString(ctx, "id"), BoolArgumentType.getBool(ctx, "save")))
)
));
}

private static int activate(CommandContext<ServerCommandSource> src, String id, boolean save) throws CommandSyntaxException {
DimensionType dim = DimensionRegistry.getInstance().registerDimensionType(new Identifier(Tesseract.MOD_ID, id), true, (w, d) -> new DimensionBuilderImpl()
.bedsExplode(true)
.vaporizeWater(true)
.build(w, d), HorizontalVoronoiBiomeAccessType.INSTANCE);
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ private void getWorld(DimensionType dimensionType, CallbackInfoReturnable<Server
}
}

private static final ThreadLocal<Iterator<ServerWorld>> apcraftvolvic = new ThreadLocal<>();
private static final ThreadLocal<Iterator<ServerWorld>> worldIteratorThreadSafe = new ThreadLocal<>();

@Inject(method = "save(ZZZ)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;save(Lnet/minecraft/util/ProgressListener;ZZ)V"), locals = LocalCapture.CAPTURE_FAILHARD)
private void save(boolean suppressLog, boolean flushToDisk, boolean b3, CallbackInfoReturnable<Boolean> cir, boolean b4, Iterator<ServerWorld> iterator){
apcraftvolvic.set(iterator);
worldIteratorThreadSafe.set(iterator);
}

@Redirect(method = "save(ZZZ)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;save(Lnet/minecraft/util/ProgressListener;ZZ)V"))
private void save(ServerWorld world, ProgressListener listener, boolean b1, boolean b2) throws SessionLockException {
Iterator<ServerWorld> it = apcraftvolvic.get();

Iterator<ServerWorld> it = worldIteratorThreadSafe.get();
worldIteratorThreadSafe.remove();
if (world.getDimension() instanceof TesseractDimension && it != null) {
DimensionState state = ((TesseractDimension) world.getDimension()).getSaveState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public DimensionBuilderImpl worldBorder(WorldBorder b){
return this;
}

public DimensionBuilderImpl beesExplode(boolean b){
dim.beesExplode = b;
return this;
}

public DimensionBuilderImpl forcedSpawnPoint(BlockPos pos){
dim.forcedSpawn = pos;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class DimensionSettings {
boolean shouldBedsExplode = false;
boolean hasVisibleSky = false;
boolean vaporizeWater = false;
boolean beesExplode = false;
float cloudHeight = 128.0f;
RenderFogFunction isFogThick = (x, z) -> false;
FogColourFunction fogColour = (skyAngle, tickDelta) -> Tesseract.getRgbColour(0, 0, 0);
Expand Down

0 comments on commit 58850c4

Please sign in to comment.