Skip to content

Commit

Permalink
Update to 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Mar 3, 2022
1 parent 12fcf6d commit a92e165
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 67 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Build

on:
push:
branches: [ 1.17, 1.18 ]

jobs:
build:
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
minecraft_version=1.18-pre6
yarn_mappings=1.18-pre6+build.3
loader_version=0.12.5
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3

# Mod Properties
mod_version=0.4.3
mod_version=0.4.4
maven_group=xyz.nucleoid
archives_base_name=fantasy

# Dependencies
fabric_version=0.42.9+1.18
fabric_version=0.47.8+1.18.2
4 changes: 4 additions & 0 deletions src/main/java/xyz/nucleoid/fantasy/RemoveFromRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ static <T> boolean remove(SimpleRegistry<T> registry, T value) {
boolean remove(T value);

boolean remove(Identifier key);

void setFrozen(boolean value);

boolean isFrozen();
}
2 changes: 1 addition & 1 deletion src/main/java/xyz/nucleoid/fantasy/RuntimeWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RuntimeWorld extends ServerWorld {
server, Util.getMainWorkerExecutor(), ((MinecraftServerAccess) server).getSession(),
new RuntimeWorldProperties(server.getSaveProperties(), config),
registryKey,
config.createDimensionOptions(server).getDimensionType(),
config.createDimensionOptions(server).getDimensionTypeSupplier(),
VoidWorldProgressListener.INSTANCE,
config.getGenerator(),
false,
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.google.common.base.Preconditions;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.Difficulty;
import net.minecraft.world.GameRules;
Expand All @@ -22,7 +22,7 @@
public final class RuntimeWorldConfig {
private long seed = 0;
private RegistryKey<DimensionType> dimensionTypeKey = Fantasy.DEFAULT_DIM_TYPE;
private DimensionType dimensionType;
private RegistryEntry<DimensionType> dimensionType;
private ChunkGenerator generator = null;
private long timeOfDay = 6000;
private Difficulty difficulty = Difficulty.NORMAL;
Expand All @@ -39,12 +39,19 @@ public RuntimeWorldConfig setSeed(long seed) {
return this;
}

public RuntimeWorldConfig setDimensionType(DimensionType dimensionType) {
public RuntimeWorldConfig setDimensionType(RegistryEntry<DimensionType> dimensionType) {
this.dimensionType = dimensionType;
this.dimensionTypeKey = null;
return this;
}

@Deprecated
public RuntimeWorldConfig setDimensionType(DimensionType dimensionType) {
this.dimensionType = RegistryEntry.of(dimensionType);
this.dimensionTypeKey = null;
return this;
}

public RuntimeWorldConfig setDimensionType(RegistryKey<DimensionType> dimensionType) {
this.dimensionTypeKey = dimensionType;
this.dimensionType = null;
Expand Down Expand Up @@ -110,14 +117,14 @@ public long getSeed() {
}

public DimensionOptions createDimensionOptions(MinecraftServer server) {
DimensionType dimensionType = this.resolveDimensionType(server);
return new DimensionOptions(() -> dimensionType, this.generator);
var dimensionType = this.resolveDimensionType(server);
return new DimensionOptions(dimensionType, this.generator);
}

private DimensionType resolveDimensionType(MinecraftServer server) {
DimensionType dimensionType = this.dimensionType;
private RegistryEntry<DimensionType> resolveDimensionType(MinecraftServer server) {
var dimensionType = this.dimensionType;
if (dimensionType == null) {
dimensionType = server.getRegistryManager().get(Registry.DIMENSION_TYPE_KEY).get(this.dimensionTypeKey);
dimensionType = server.getRegistryManager().get(Registry.DIMENSION_TYPE_KEY).getEntry(this.dimensionTypeKey).orElse(null);
Preconditions.checkNotNull(dimensionType, "invalid dimension type " + this.dimensionTypeKey);
}
return dimensionType;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ RuntimeWorld add(RegistryKey<World> worldKey, RuntimeWorldConfig config, Runtime
DimensionOptions options = config.createDimensionOptions(this.server);

SimpleRegistry<DimensionOptions> dimensionsRegistry = getDimensionsRegistry(this.server);
boolean isFrozen = ((RemoveFromRegistry<?>) dimensionsRegistry).isFrozen();
((RemoveFromRegistry<?>) dimensionsRegistry).setFrozen(false);
dimensionsRegistry.add(RegistryKey.of(Registry.DIMENSION_KEY, worldKey.getValue()), options, Lifecycle.stable());
((RemoveFromRegistry<?>) dimensionsRegistry).setFrozen(isFrozen);

RuntimeWorld world = new RuntimeWorld(this.server, worldKey, config, style);

Expand Down Expand Up @@ -70,6 +73,6 @@ void delete(ServerWorld world) {

private static SimpleRegistry<DimensionOptions> getDimensionsRegistry(MinecraftServer server) {
GeneratorOptions generatorOptions = server.getSaveProperties().getGeneratorOptions();
return generatorOptions.getDimensions();
return (SimpleRegistry<DimensionOptions>) generatorOptions.getDimensions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,78 @@
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.util.registry.SimpleRegistry;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import xyz.nucleoid.fantasy.RemoveFromRegistry;

import java.util.List;
import java.util.Map;
import java.util.Optional;

@Mixin(SimpleRegistry.class)
public class SimpleRegistryMixin<T> implements RemoveFromRegistry<T> {
@Shadow
@Final
private ObjectList<T> rawIdToEntry;
@Shadow
@Final
private Object2IntMap<T> entryToRawId;
@Shadow
@Final
private BiMap<Identifier, T> idToEntry;
@Shadow
@Final
private BiMap<RegistryKey<T>, T> keyToEntry;
@Shadow
@Final
private Map<T, Lifecycle> entryToLifecycle;

@Shadow
protected Object[] randomEntries;
public abstract class SimpleRegistryMixin<T> implements RemoveFromRegistry<T> {

@Shadow @Final private Map<T, RegistryEntry.Reference<T>> valueToEntry;

@Shadow @Nullable private Map<T, RegistryEntry.Reference<T>> unfrozenValueToEntry;

@Shadow @Final private Map<Identifier, RegistryEntry.Reference<T>> idToEntry;

@Shadow @Final private Map<RegistryKey<T>, RegistryEntry.Reference<T>> keyToEntry;

@Shadow @Final private Map<T, Lifecycle> entryToLifecycle;

@Shadow @Final private ObjectList<RegistryEntry.Reference<T>> rawIdToEntry;

@Shadow @Final private Object2IntMap<T> entryToRawId;

@Shadow public abstract Optional<RegistryEntry<T>> getEntry(int rawId);

@Shadow private boolean frozen;

@Shadow @Nullable private List<RegistryEntry.Reference<T>> cachedEntries;

@Override
public boolean remove(T entry) {
var registryEntry = this.valueToEntry.get(entry);
int rawId = this.entryToRawId.removeInt(entry);
if (rawId == -1) {
return false;
}

this.idToEntry.inverse().remove(entry);
this.keyToEntry.inverse().remove(entry);
this.entryToLifecycle.remove(entry);

this.rawIdToEntry.set(rawId, null);

this.randomEntries = null;
this.idToEntry.remove(registryEntry);
this.keyToEntry.remove(registryEntry);
this.entryToLifecycle.remove(entry);
this.valueToEntry.remove(entry);
if (this.cachedEntries != null) {
this.cachedEntries.remove(registryEntry);
}
if (this.unfrozenValueToEntry != null) {
this.unfrozenValueToEntry.remove(entry);
}

return true;
}

@Override
public boolean remove(Identifier key) {
T entry = this.idToEntry.get(key);
return entry != null && this.remove(entry);
var entry = this.idToEntry.get(key);
return entry != null && entry.hasKeyAndValue() && this.remove(entry.value());
}

@Override
public void setFrozen(boolean value) {
this.frozen = value;
}

@Override
public boolean isFrozen() {
return this.frozen;
}
}
74 changes: 51 additions & 23 deletions src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package xyz.nucleoid.fantasy.util;

import com.mojang.serialization.Codec;
import com.mojang.serialization.Lifecycle;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureSet;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.util.registry.*;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.Heightmap;
Expand All @@ -24,12 +22,11 @@
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.Blender;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.StructuresConfig;
import net.minecraft.world.gen.chunk.VerticalBlockSample;
import net.minecraft.world.gen.feature.StructureFeature;
import org.jetbrains.annotations.Nullable;
import net.minecraft.world.gen.densityfunction.DensityFunction;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
Expand All @@ -44,19 +41,58 @@ public class VoidChunkGenerator extends ChunkGenerator {

private static final VerticalBlockSample EMPTY_SAMPLE = new VerticalBlockSample(0, new BlockState[0]);

private final Supplier<Biome> biome;
private final RegistryEntry<Biome> biome;

public VoidChunkGenerator(Supplier<Biome> biome) {
super(new FixedBiomeSource(biome), new StructuresConfig(Optional.empty(), Collections.emptyMap()));
private static final Registry<StructureSet> EMPTY_STRUCTURE_REGISTRY = new SimpleRegistry<>(Registry.STRUCTURE_SET_KEY, Lifecycle.stable(), (x) -> null).freeze();

public static final DensityFunction ZERO_DENSITY_FUNCTION = new DensityFunction() {
@Override
public double sample(NoisePos pos) {
return 0;
}

@Override
public void method_40470(double[] ds, class_6911 arg) { }

@Override
public DensityFunction apply(DensityFunctionVisitor visitor) {
return this;
}

@Override
public double minValue() {
return 0;
}

@Override
public double maxValue() {
return 0;
}

@Override
public Codec<? extends DensityFunction> getCodec() {
return Codec.unit(this);
}
};

public static final MultiNoiseUtil.MultiNoiseSampler EMPTY_SAMPLER = new MultiNoiseUtil.MultiNoiseSampler(ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, Collections.emptyList());

public VoidChunkGenerator(RegistryEntry<Biome> biome) {
super(EMPTY_STRUCTURE_REGISTRY, Optional.empty(), new FixedBiomeSource(biome));
this.biome = biome;
}

@Deprecated
public VoidChunkGenerator(Supplier<Biome> biome) {
this(RegistryEntry.of(biome.get()));
}

public VoidChunkGenerator(Registry<Biome> biomeRegistry) {
this(biomeRegistry, BiomeKeys.THE_VOID);
}

public VoidChunkGenerator(Registry<Biome> biomeRegistry, RegistryKey<Biome> biome) {
this(() -> biomeRegistry.get(biome));
this(biomeRegistry.getEntry(biome).get());
}

@Override
Expand All @@ -71,9 +107,7 @@ public ChunkGenerator withSeed(long seed) {

@Override
public MultiNoiseUtil.MultiNoiseSampler getMultiNoiseSampler() {
return (i, j, k) -> {
return MultiNoiseUtil.createNoiseValuePoint(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
};
return EMPTY_SAMPLER;
}

@Override
Expand Down Expand Up @@ -127,19 +161,13 @@ public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world)
return EMPTY_SAMPLE;
}

@Nullable
@Override
public BlockPos locateStructure(ServerWorld world, StructureFeature<?> feature, BlockPos center, int radius, boolean skipExistingChunks) {
return null;
public void getDebugHudText(List<String> text, BlockPos pos) {

}

@Override
public void buildSurface(ChunkRegion region, StructureAccessor structures, Chunk chunk) {

}

@Override
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"logical_height": 256,
"infiniburn": "minecraft:infiniburn_overworld",
"infiniburn": "#minecraft:infiniburn_overworld",
"effects": "minecraft:overworld",
"ambient_light": 0.0,
"respawn_anchor_works": false,
Expand Down

0 comments on commit a92e165

Please sign in to comment.