Skip to content

Commit

Permalink
Update to 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorrell committed Feb 14, 2022
1 parent 99f59e2 commit 958e359
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 304 deletions.
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,6 @@ The fox will eat them soon after spawning, so be quick.

---

#### Useful Composters (disabled by default) ####
Provides additional *Sand*, *Red Sand*, and *Dirt*

Enable with ```/skyblock setDefault usefulComposters true``` or ```/skyblock setDefault usefulComposters redstone```

Provides an easier way to get sand/red sand than the 64/24 you can get at a time from a wandering trader.

The datapack now makes it so Husks drop Sand and Red Sand has a crafting recipe, so this is disabled by default.
Additionally, Dirt farming is nicer since 1.17.

Compost result depends on the biome.
Get sand in deserts, beaches, warm oceans etc, red sand from badlands, and dirt elsewhere.

When set to ```redstone```, the composter outputs Bonemeal without a redstone signal.

---

### Additional Datapack Features ###
The included datapack provides additional recipes, and advancements.

Expand Down
4 changes: 2 additions & 2 deletions datapack/data/skyblock/advancements/skyblock/go_down.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"predicate": {
"position": {
"y": {
"max": 10
"max": -54
}
}
},
Expand All @@ -32,4 +32,4 @@
}
}
}
}
}
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Done to increase the memory available to gradle.
# Increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Mod Properties
Expand All @@ -7,10 +7,10 @@ archives_base_name=skyblock

# Fabric Properties
# see https://modmuss50.me/fabric.html
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.65
loader_version=0.13.1
fabric_api_version=0.46.0+1.17
minecraft_version=1.18.1
yarn_mappings=1.18.1+build.22
loader_version=0.13.2
fabric_api_version=0.46.4+1.18

# see https://masa.dy.fi/maven/carpet/fabric-carpet/
carpet_core_version=1.17.1-1.4.57+v220119
carpet_core_version=1.18.1-1.4.57+v220119
34 changes: 1 addition & 33 deletions src/main/java/com/jsorrell/skyblock/SkyBlockSettings.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.jsorrell.skyblock;

import static carpet.settings.RuleCategory.FEATURE;

import java.util.Locale;

import carpet.settings.ParsedRule;
import carpet.settings.Rule;
import carpet.settings.Validator;

import net.minecraft.server.command.ServerCommandSource;
import static carpet.settings.RuleCategory.FEATURE;

public class SkyBlockSettings {
public static final String SKYBLOCK = "skyblock";
Expand Down Expand Up @@ -72,30 +66,4 @@ public class SkyBlockSettings {
desc = "A spawned fox has a chance to hold berries",
category = {SKYBLOCK, FEATURE})
public static boolean foxesSpawnWithBerries = false;

/* Useful Composters */
public static boolean doUsefulComposters = false;
public static boolean usefulCompostersNeedRedstone = false;

private static class UsefulCompostersSetting extends Validator<String> {
@Override
public String validate(
ServerCommandSource source,
ParsedRule<String> currentRule,
String newValue,
String string) {
doUsefulComposters = !newValue.toLowerCase(Locale.ROOT).equals("false");
usefulCompostersNeedRedstone = newValue.toLowerCase(Locale.ROOT).equals("redstone");

return newValue;
}
}

@Rule(
desc = "Composters create sand, red sand, and dirt depending on biome",
category = {SKYBLOCK, FEATURE},
options = {"true", "false", "redstone"},
validate = UsefulCompostersSetting.class)
@SuppressWarnings("unused")
public static String usefulComposters = "false";
}
97 changes: 50 additions & 47 deletions src/main/java/com/jsorrell/skyblock/gen/SkyBlockChunkGenerator.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
package com.jsorrell.skyblock.gen;

import java.util.Arrays;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Supplier;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.EndPortalFrameBlock;
Expand All @@ -22,36 +12,40 @@
import net.minecraft.structure.StructurePiece;
import net.minecraft.structure.StructurePieceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.dynamic.RegistryLookupCodec;
import net.minecraft.util.math.*;
import net.minecraft.util.math.Direction.Axis;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.*;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.gen.ChunkRandom;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
import net.minecraft.world.gen.chunk.*;
import net.minecraft.world.gen.random.ChunkRandom;
import net.minecraft.world.gen.random.RandomSeed;
import net.minecraft.world.gen.random.Xoroshiro128PlusPlusRandom;

import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Supplier;

public class SkyBlockChunkGenerator extends NoiseChunkGenerator {
private final long seed;
private final Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry;

public static final Codec<SkyBlockChunkGenerator> CODEC =
RecordCodecBuilder.create(
(instance) ->
instance
.group(
RegistryLookupCodec
.of(Registry.NOISE_WORLDGEN)
.forGetter(skyblockChunkGenerator -> skyblockChunkGenerator.noiseRegistry),
BiomeSource.CODEC
.fieldOf("biome_source")
.forGetter(SkyBlockChunkGenerator::getBiomeSource),
Expand All @@ -64,10 +58,12 @@ public class SkyBlockChunkGenerator extends NoiseChunkGenerator {
.forGetter(SkyBlockChunkGenerator::getSettings))
.apply(instance, instance.stable(SkyBlockChunkGenerator::new)));

public SkyBlockChunkGenerator(
BiomeSource biomeSource, long seed, Supplier<ChunkGeneratorSettings> settings) {
super(biomeSource, seed, settings);
public SkyBlockChunkGenerator(Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
BiomeSource biomeSource, long seed, Supplier<ChunkGeneratorSettings> settings) {
super(noiseRegistry, biomeSource, seed, settings);
this.seed = seed;
// Need noise registry kept so features generate in identical places to vanilla
this.noiseRegistry = noiseRegistry;
}

public long getSeed() {
Expand All @@ -84,15 +80,17 @@ protected Codec<? extends ChunkGenerator> getCodec() {
}

@Override
@Environment(EnvType.CLIENT)
public ChunkGenerator withSeed(long seed) {
return new SkyBlockChunkGenerator(this.biomeSource.withSeed(seed), seed, this.settings);
return new SkyBlockChunkGenerator(this.noiseRegistry, this.biomeSource.withSeed(seed), seed, this.settings);
}

@Override
public void buildSurface(ChunkRegion region, Chunk chunk) {
Arrays.fill(chunk.getSectionArray(), WorldChunk.EMPTY_SECTION);
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world) {
return new VerticalBlockSample(world.getBottomY(), new BlockState[0]);
}

@Override
public void buildSurface(ChunkRegion region, StructureAccessor structures, Chunk chunk) {
if (region.getDimension().isNatural()) {
BlockPos spawn =
new BlockPos(
Expand All @@ -108,10 +106,10 @@ public void buildSurface(ChunkRegion region, Chunk chunk) {
spawn,
new BlockBox(
chunk.getPos().getStartX(),
0,
chunk.getBottomY(),
chunk.getPos().getStartZ(),
chunk.getPos().getStartX() + 15,
region.getHeight(),
chunk.getTopY(),
chunk.getPos().getStartZ() + 15));
}
}
Expand All @@ -120,23 +118,24 @@ public void buildSurface(ChunkRegion region, Chunk chunk) {
// TODO: Does this hurt something
@Override
public CompletableFuture<Chunk> populateNoise(
Executor executor, StructureAccessor accessor, Chunk chunk) {
Executor executor, Blender blender, StructureAccessor accessor, Chunk chunk) {
return CompletableFuture.completedFuture(chunk);
}

@Override
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {}
public void carve(ChunkRegion chunkRegion, long seed, BiomeAccess access, StructureAccessor structureAccessor, Chunk chunk, GenerationStep.Carver carver) {
}

@Override
public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
ChunkPos chunkPos = region.getCenterPos();
BlockPos pos = new BlockPos(chunkPos.getStartX(), region.getBottomY(), chunkPos.getStartZ());
public void generateFeatures(StructureWorldAccess world, Chunk chunk, StructureAccessor accessor) {
ChunkPos chunkPos = chunk.getPos();
BlockPos pos = new BlockPos(chunkPos.getStartX(), chunk.getBottomY(), chunkPos.getStartZ());
int startX = chunkPos.getStartX();
int startZ = chunkPos.getStartZ();
BlockBox box = new BlockBox(startX, 0, startZ, startX + 15, region.getHeight(), startZ + 15);
BlockBox chunkBoundary = new BlockBox(startX, chunk.getBottomY(), startZ, startX + 15, chunk.getTopY(), startZ + 15);

accessor
.getStructuresWithChildren(
.getStructureStarts(
ChunkSectionPos.from(pos),
Registry.STRUCTURE_FEATURE.get(new Identifier("minecraft:stronghold")))
.forEach(
Expand All @@ -149,18 +148,19 @@ public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
piece.getBoundingBox().getMinY(),
piece.getBoundingBox().getMinZ());
if (piece.intersectsChunk(chunkPos, 0)) {
ChunkRandom random = new ChunkRandom();
ChunkRandom random = new ChunkRandom(new Xoroshiro128PlusPlusRandom(RandomSeed.getSeed()));
random.setCarverSeed(seed, chunkPos.x, chunkPos.z);
generateStrongholdPortalInBox(
region, portalPos, random, Objects.requireNonNull(piece.getFacing()), box);
world, portalPos, random, Objects.requireNonNull(piece.getFacing()), chunkBoundary);
}
}
}
});
}

@Override
public void populateEntities(ChunkRegion region) {}
public void populateEntities(ChunkRegion region) {
}

protected static void placeRelativeBlockInBox(
WorldAccess world,
Expand Down Expand Up @@ -227,6 +227,7 @@ private static void generateStrongholdPortalInBox(
Direction facing,
BlockBox box) {

// TODO switch this to pattern matching when it is no longer a preview
BlockPos portalCenterPosition;
switch (facing) {
case EAST:
Expand Down Expand Up @@ -256,10 +257,12 @@ private static void generateStrongholdPortalInBox(
}
BlockPos spawnerPos = portalCenterPosition.subtract(facing.getVector().multiply(4));

world.setBlockState(spawnerPos, Blocks.SPAWNER.getDefaultState(), 2);
BlockEntity spawnerEntity = world.getBlockEntity(spawnerPos);
if (spawnerEntity instanceof MobSpawnerBlockEntity) {
((MobSpawnerBlockEntity) spawnerEntity).getLogic().setEntityId(EntityType.SILVERFISH);
if (box.contains(spawnerPos)) {
world.setBlockState(spawnerPos, Blocks.SPAWNER.getDefaultState(), 2);
BlockEntity spawnerEntity = world.getBlockEntity(spawnerPos);
if (spawnerEntity instanceof MobSpawnerBlockEntity) {
((MobSpawnerBlockEntity) spawnerEntity).getLogic().setEntityId(EntityType.SILVERFISH);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.jsorrell.skyblock.gen;

import com.mojang.serialization.Lifecycle;

import net.minecraft.util.math.noise.DoublePerlinNoiseSampler;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.MultiNoiseBiomeSource;
import net.minecraft.world.biome.source.TheEndBiomeSource;
import net.minecraft.world.biome.source.VanillaLayeredBiomeSource;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGenerator;
Expand All @@ -19,6 +18,7 @@ public class SkyBlockGenerationSettings {

public static SimpleRegistry<DimensionOptions> getSkyBlockDimensionOptions(
Registry<DimensionType> dimensionTypeRegistry,
Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
Registry<Biome> biomeRegistry,
Registry<ChunkGeneratorSettings> settingsRegistry,
long seed) {
Expand All @@ -28,42 +28,45 @@ public static SimpleRegistry<DimensionOptions> getSkyBlockDimensionOptions(
DimensionOptions.OVERWORLD,
new DimensionOptions(
() -> dimensionTypeRegistry.get(DimensionType.OVERWORLD_REGISTRY_KEY),
createOverworldGenerator(biomeRegistry, settingsRegistry, seed)),
createOverworldGenerator(noiseRegistry, biomeRegistry, settingsRegistry, seed)),
Lifecycle.stable());
simpleRegistry.add(
DimensionOptions.NETHER,
new DimensionOptions(
() -> dimensionTypeRegistry.get(DimensionType.THE_NETHER_REGISTRY_KEY),
createNetherGenerator(biomeRegistry, settingsRegistry, seed)),
createNetherGenerator(noiseRegistry, biomeRegistry, settingsRegistry, seed)),
Lifecycle.stable());
simpleRegistry.add(
DimensionOptions.END,
new DimensionOptions(
() -> dimensionTypeRegistry.get(DimensionType.THE_END_REGISTRY_KEY),
createEndGenerator(biomeRegistry, settingsRegistry, seed)),
createEndGenerator(noiseRegistry, biomeRegistry, settingsRegistry, seed)),
Lifecycle.stable());
return simpleRegistry;
}

public static ChunkGenerator createOverworldGenerator(
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
public static ChunkGenerator createOverworldGenerator(Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
return new SkyBlockChunkGenerator(
new VanillaLayeredBiomeSource(seed, false, false, biomeRegistry),
noiseRegistry,
MultiNoiseBiomeSource.Preset.OVERWORLD.getBiomeSource(biomeRegistry).withSeed(seed),
seed,
() -> settingsRegistry.getOrThrow(ChunkGeneratorSettings.OVERWORLD));
}

public static ChunkGenerator createNetherGenerator(
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
public static ChunkGenerator createNetherGenerator(Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
return new SkyBlockChunkGenerator(
MultiNoiseBiomeSource.Preset.NETHER.getBiomeSource(biomeRegistry, seed),
noiseRegistry,
MultiNoiseBiomeSource.Preset.NETHER.getBiomeSource(biomeRegistry).withSeed(seed),
seed,
() -> settingsRegistry.getOrThrow(ChunkGeneratorSettings.NETHER));
}

public static ChunkGenerator createEndGenerator(
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
public static ChunkGenerator createEndGenerator(Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
return new SkyBlockChunkGenerator(
noiseRegistry,
new TheEndBiomeSource(biomeRegistry, seed),
seed,
() -> settingsRegistry.getOrThrow(ChunkGeneratorSettings.END));
Expand Down
Loading

0 comments on commit 958e359

Please sign in to comment.