Skip to content

Commit

Permalink
Merge pull request Vatuu#3 from Draylar/parameters
Browse files Browse the repository at this point in the history
General cleanup & mappings fix
  • Loading branch information
Vatuu authored Nov 18, 2019
2 parents ba9947a + b5106d9 commit 3428df1
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface DimensionBuilder {

DimensionBuilder bedsExplode(boolean shouldExplode);

DimensionBuilder renderSkybox(boolean shouldRenderSkybox);
DimensionBuilder visibleSky(boolean hasVisibleSky);

DimensionBuilder vaporizeWater(boolean vaporizeWater);

Expand Down
15 changes: 6 additions & 9 deletions src/main/java/dev/vatuu/tesseract/api/DimensionState.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package dev.vatuu.tesseract.api;

/**
* Test Javadoc
*/
public enum DimensionState {
SAVE(false, false, false),
SAVE_UNLOAD(true, false, false),
Expand Down Expand Up @@ -32,13 +29,13 @@ public boolean shouldUnregister(){
return unregister;
}

public static DimensionState getByValues(boolean unload, boolean reset, boolean unregister){
if(reset){
if(unregister) return RESET_UNREGISTER;
public static DimensionState getByValues(boolean unload, boolean reset, boolean unregister) {
if (reset) {
if (unregister) return RESET_UNREGISTER;
else return RESET;
}else{
if(unregister) return SAVE_UNREGISTER;
if(unload) return SAVE_UNLOAD;
} else {
if (unregister) return SAVE_UNREGISTER;
if (unload) return SAVE_UNLOAD;
}
return SAVE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import net.minecraft.util.math.Vec3d;

public interface FogColourFunction {
Vec3d apply(float f1, float f2);
Vec3d apply(float skyAngle, float tickDelta);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package dev.vatuu.tesseract.api.extensions;

public interface RenderFogFunction {
boolean apply(int i1, int i2);
boolean apply(int skyAngle, int tickDelta);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import net.minecraft.util.math.ChunkPos;

public interface SpawnChunkPosFunction {
BlockPos apply(ChunkPos pos, boolean b);
BlockPos apply(ChunkPos pos, boolean checkMobSpawnValidity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

@FunctionalInterface
public interface SpawnTopFunction{
BlockPos apply(int i1, int i2, boolean b);
BlockPos apply(int x, int z, boolean checkMobSpawnValidity);
}
3 changes: 1 addition & 2 deletions src/main/java/dev/vatuu/tesseract/impl/Tesseract.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.biome.BiomeAccess;
import net.minecraft.world.biome.HorizontalVoronoiBiomeAccessType;
import net.minecraft.world.dimension.DimensionType;

Expand All @@ -23,7 +22,7 @@ public void onInitialize() {
.bedsExplode(true)
.cloudHeight(70f)
.forcedSpawnPoint(new BlockPos(0, 64, 0))
.renderSkybox(true)
.visibleSky(true)
.renderFog(false)
.build(w, t),
HorizontalVoronoiBiomeAccessType.INSTANCE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher){
));
}

private static int activate(CommandContext<ServerCommandSource> src, DimensionType t, boolean unregister) throws CommandSyntaxException{
if(!(t instanceof TesseractDimensionType)){
throw INVALID_DIMENSION.create(Registry.DIMENSION.getId(t));
private static int activate(CommandContext<ServerCommandSource> context, DimensionType type, boolean unregister) throws CommandSyntaxException{
if(!(type instanceof TesseractDimensionType)){
throw INVALID_DIMENSION.create(Registry.DIMENSION.getId(type));
}
ServerWorld w = src.getSource().getPlayer().getServer().getWorld(t);
((TesseractDimension)w.getServer().getWorld(t).getDimension()).setSaveState(DimensionState.getByValues(true, true, unregister));
w.getServer().save(true, true, false);

ServerWorld playerWorld = context.getSource().getPlayer().getServer().getWorld(type);
((TesseractDimension) playerWorld.getServer().getWorld(type).getDimension()).setSaveState(DimensionState.getByValues(true, true, unregister));
playerWorld.getServer().save(true, true, false);

return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import net.minecraft.world.level.LevelProperties;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.Validate;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -38,24 +36,28 @@ public abstract class MinecraftServerMixin {
@Shadow @Final private Map<DimensionType, ServerWorld> worlds;
@Shadow @Final private DisableableProfiler profiler;

private WorldSaveHandler saveHandler;
private WorldGenerationProgressListener generationProgress;
@Mutable private WorldSaveHandler saveHandler;
@Mutable private WorldGenerationProgressListener generationProgress;

@Inject(method = "createWorlds", at = @At(value = "INVOKE", shift = At.Shift.BEFORE, target = "Lnet/minecraft/world/dimension/DimensionType;getAll()Ljava/lang/Iterable;"), cancellable = true)
private void createWorld(WorldSaveHandler save, LevelProperties props, LevelInfo info, WorldGenerationProgressListener listener, CallbackInfo ci){
this.saveHandler = save;
this.generationProgress = listener;

ci.cancel();
}

@Inject(method = "getWorld", at = @At("RETURN"), cancellable = true)
private void getWorld(DimensionType dimensionType, CallbackInfoReturnable<ServerWorld> cir) {
Validate.notNull(dimensionType, "Dimension type must not be NULL");
if(dimensionType != DimensionType.OVERWORLD && cir.getReturnValue() == null) {
ServerWorld overWorld = worlds.get(DimensionType.OVERWORLD);
Validate.notNull(overWorld, "Overworld not loaded!");
ServerWorld world = new SecondaryServerWorld(overWorld, (MinecraftServer)(Object)this, ((MinecraftServer)(Object)this).getWorkerExecutor(), this.saveHandler, dimensionType, this.profiler, generationProgress);

if (dimensionType != DimensionType.OVERWORLD && cir.getReturnValue() == null) {
ServerWorld overworld = worlds.get(DimensionType.OVERWORLD);
Validate.notNull(overworld, "Overworld not loaded!");

ServerWorld world = new SecondaryServerWorld(overworld, (MinecraftServer) (Object) this, ((MinecraftServer) (Object) this).getWorkerExecutor(), this.saveHandler, dimensionType, this.profiler, generationProgress);
worlds.put(dimensionType, world);

cir.setReturnValue(world);
}
}
Expand All @@ -68,48 +70,58 @@ private void save(boolean suppressLog, boolean flushToDisk, boolean b3, Callback
}

@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 w, ProgressListener listener, boolean b1, boolean b2) throws SessionLockException{
private void save(ServerWorld world, ProgressListener listener, boolean b1, boolean b2) throws SessionLockException {
Iterator<ServerWorld> it = apcraftvolvic.get();
if(w.getDimension() instanceof TesseractDimension && it != null){
DimensionState state = ((TesseractDimension)w.getDimension()).getSaveState();
if(state.shouldUnload()) unloadWorld(w, it);
if(state.shouldReset()) resetWorld(w); else w.save(listener, b1, b2);
if(state.shouldUnregister()) unregister(w.getDimension().getType());
}else{
w.save(listener, b1, b2);

if (world.getDimension() instanceof TesseractDimension && it != null) {
DimensionState state = ((TesseractDimension) world.getDimension()).getSaveState();

if (state.shouldUnload()) unloadWorld(world, it);
if (state.shouldReset()) resetWorld(world);
else world.save(listener, b1, b2);

if (state.shouldUnregister()) unregister(world.getDimension().getType());
} else {
world.save(listener, b1, b2);
}
}

private void unloadWorld(ServerWorld w, Iterator<ServerWorld> it){
if(!w.getPlayers().isEmpty()){
BlockPos entryPoint = ((TesseractDimension)w.dimension).entryPoint;
w.getPlayers().forEach((p) -> p.teleport(
w.getServer().getWorld(DimensionType.OVERWORLD),
@Unique
private void unloadWorld(ServerWorld world, Iterator<ServerWorld> it){
if(!world.getPlayers().isEmpty()) {
BlockPos entryPoint = ((TesseractDimension) world.dimension).entryPoint;

world.getPlayers().forEach(player -> player.teleport(
world.getServer().getWorld(DimensionType.OVERWORLD),
entryPoint.getX(),
entryPoint.getY(),
entryPoint.getZ(),
p.pitch, p.yaw));
player.pitch, player.yaw
));
}

try{
w.close();
}catch(IOException e){
try {
world.close();
} catch(IOException e) {
e.printStackTrace();
}

it.remove();
}

private void resetWorld(ServerWorld w){
w.savingDisabled = true;
try{
File f = w.dimension.getType().getSaveDirectory(w.getSaveHandler().getWorldDir());
FileUtils.deleteDirectory(f);
}catch(IOException e){
@Unique
private void resetWorld(ServerWorld world){
world.savingDisabled = true;

try {
File worldSaveDirectory = world.dimension.getType().getSaveDirectory(world.getSaveHandler().getWorldDir());
FileUtils.deleteDirectory(worldSaveDirectory);
} catch(IOException e) {
e.printStackTrace();
}
}

@Unique
private void unregister(DimensionType type){
DimensionRegistryImpl.unregister(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class ServerChunkManagerMixin {
@Shadow @Final private ServerWorld world;

@Inject(method = "save(Z)V", at = @At("HEAD"), cancellable = true)
private void save(boolean boolean_1, CallbackInfo ci){
private void save(boolean flush, CallbackInfo ci){
if(world.dimension instanceof TesseractDimension){
if(((TesseractDimension)world.dimension).getSaveState().shouldReset())
ci.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public DimensionBuilderImpl bedsExplode(boolean shouldExplode){
return this;
}

public DimensionBuilderImpl renderSkybox(boolean shouldRenderSkybox){
dim.shouldRenderSkybox = shouldRenderSkybox;
public DimensionBuilderImpl visibleSky(boolean hasVisibleSky){
dim.hasVisibleSky = hasVisibleSky;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public static DimensionRegistryImpl getInstance(){
else return INSTANCE;
}

public DimensionType registerDimensionType(Identifier name, boolean hasSkyLight, BiFunction<World, DimensionType, ? extends Dimension> create, BiomeAccessType biomeAccessor){
public DimensionType registerDimensionType(Identifier name, boolean hasSkyLight, BiFunction<World, DimensionType, ? extends Dimension> factory, BiomeAccessType biomeAccessor){
int id = registered.size() + 3;
TesseractDimensionType t = new TesseractDimensionType(id, name.getPath(), hasSkyLight, create, biomeAccessor);
TesseractDimensionType t = new TesseractDimensionType(id, name.getPath(), hasSkyLight, factory, biomeAccessor);
registered.put(id, t);
return Registry.register(Registry.DIMENSION, id, name.toString(), t);
}

public static boolean unregister(DimensionType t){
return ((SimpleRegistryMixin)Registry.DIMENSION).getEntries().values().remove(t);
public static boolean unregister(DimensionType type){
return ((SimpleRegistryMixin)Registry.DIMENSION).getEntries().values().remove(type);
}
}
21 changes: 10 additions & 11 deletions src/main/java/dev/vatuu/tesseract/impl/world/DimensionSettings.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dev.vatuu.tesseract.impl.world;

import dev.vatuu.tesseract.api.DimensionRegistry;
import dev.vatuu.tesseract.impl.Tesseract;
import dev.vatuu.tesseract.api.extensions.FogColourFunction;
import dev.vatuu.tesseract.api.extensions.RenderFogFunction;
import dev.vatuu.tesseract.api.extensions.SpawnTopFunction;
import dev.vatuu.tesseract.api.extensions.SpawnChunkPosFunction;
import dev.vatuu.tesseract.api.extensions.SpawnTopFunction;
import dev.vatuu.tesseract.impl.Tesseract;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -20,24 +19,24 @@
final class DimensionSettings {

boolean shouldBedsExplode = false;
boolean shouldRenderSkybox = false;
boolean hasVisibleSky = false;
boolean vaporizeWater = false;
float cloudHeight = 128.0f;
RenderFogFunction isFogThick = (i1, i2) -> false;
FogColourFunction fogColour = (f1, f2) -> Tesseract.getRgbColour(0, 0, 0);
SpawnChunkPosFunction spawningBlockChunk = (pos, b) -> null;
SpawnTopFunction topSpawningBlockPos = (i1, i2, b) -> null;
RenderFogFunction isFogThick = (x, z) -> false;
FogColourFunction fogColour = (skyAngle, tickDelta) -> Tesseract.getRgbColour(0, 0, 0);
SpawnChunkPosFunction spawningBlockChunk = (pos, checkMobSpawnValidity) -> null;
SpawnTopFunction topSpawningBlockPos = (x, z, checkMobSpawnValidity) -> null;
WorldBorder border = new WorldBorder();
BlockPos forcedSpawn = null;
Function<World, ChunkGenerator<? extends ChunkGeneratorConfig>> chunkGenerator = DEFAULT_VOID_WORLD;

private static Function<World, ChunkGenerator<? extends ChunkGeneratorConfig>> DEFAULT_VOID_WORLD = (w) -> {
private static Function<World, ChunkGenerator<? extends ChunkGeneratorConfig>> DEFAULT_VOID_WORLD = (world) -> {
FlatChunkGeneratorConfig config = ChunkGeneratorType.FLAT.createSettings();
config.getLayers().add(new FlatChunkGeneratorLayer(1, Blocks.AIR));
config.setBiome(Biomes.THE_VOID);
config.updateLayerBlocks();
FixedBiomeSourceConfig biomeConfig = BiomeSourceType.FIXED.getConfig(w.getLevelProperties()).setBiome(Biomes.THE_VOID);
FixedBiomeSourceConfig biomeConfig = BiomeSourceType.FIXED.getConfig(world.getLevelProperties()).setBiome(Biomes.THE_VOID);

return ChunkGeneratorType.FLAT.create(w, BiomeSourceType.FIXED.applyConfig(biomeConfig), config);
return ChunkGeneratorType.FLAT.create(world, BiomeSourceType.FIXED.applyConfig(biomeConfig), config);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class TesseractDimension extends OverworldDimension {

public BlockPos entryPoint;

TesseractDimension(World w, DimensionType t, DimensionSettings s){
super(w, t);
this.type = t;
this.settings = s;
TesseractDimension(World world, DimensionType type, DimensionSettings settings){
super(world, type);
this.type = type;
this.settings = settings;
this.saveState = DimensionState.SAVE;
this.entryPoint = new BlockPos(0, 64, 0);
}
Expand All @@ -33,12 +33,12 @@ public class TesseractDimension extends OverworldDimension {
@Override public boolean isNether() { return false; }
@Override public WorldBorder createWorldBorder() { return settings.border; }
@Override public ChunkGenerator<? extends ChunkGeneratorConfig> createChunkGenerator() { return settings.chunkGenerator.apply(this.world); }
@Override public BlockPos getSpawningBlockInChunk(ChunkPos pos, boolean b) { return settings.spawningBlockChunk.apply(pos, b); }
@Override public BlockPos getTopSpawningBlockPosition(int i1, int i2, boolean b) { return settings.topSpawningBlockPos.apply(i1, i2, b); }
@Override public boolean hasVisibleSky() { return settings.shouldRenderSkybox; }
@Override public Vec3d getFogColor(float f1, float f2) { return settings.fogColour.apply(f1, f2); }
@Override public BlockPos getSpawningBlockInChunk(ChunkPos pos, boolean checkMobSpawnValidity) { return settings.spawningBlockChunk.apply(pos, checkMobSpawnValidity); }
@Override public BlockPos getTopSpawningBlockPosition(int x, int z, boolean checkMobSpawnValidity) { return settings.topSpawningBlockPos.apply(x, z, checkMobSpawnValidity); }
@Override public boolean hasVisibleSky() { return settings.hasVisibleSky; }
@Override public Vec3d getFogColor(float skyAngle, float tickDelta) { return settings.fogColour.apply(skyAngle, tickDelta); }
@Override public boolean canPlayersSleep() { return !settings.shouldBedsExplode; }
@Override public boolean isFogThick(int i1, int i2) { return settings.isFogThick.apply(i1, i2); }
@Override public boolean isFogThick(int x, int iz) { return settings.isFogThick.apply(x, iz); }
@Override public DimensionType getType() { return type; }

public DimensionState getSaveState() { return saveState; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.function.BiFunction;

public class TesseractDimensionType extends DimensionType {
TesseractDimensionType(int id, String name, boolean hasSky, BiFunction<World, DimensionType, ? extends Dimension> create, BiomeAccessType biomeAccessor) {
super(id, name.toUpperCase(), name.toLowerCase(), create, hasSky, biomeAccessor);
TesseractDimensionType(int dimensionId, String name, boolean hasSkyLight, BiFunction<World, DimensionType, ? extends Dimension> factory, BiomeAccessType biomeAccessor) {
super(dimensionId, name.toUpperCase(), name.toLowerCase(), factory, hasSkyLight, biomeAccessor);
}
}

0 comments on commit 3428df1

Please sign in to comment.