Skip to content

Commit

Permalink
Update to 1.16.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorrell committed Aug 12, 2020
1 parent 395524f commit 0f51039
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 83 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Enable with ```/skyblock wanderingTraderSkyblockTrades true```
Enable with ```/skyblock usefulComposters true```
- Provides a nicer way to get sand/red sand than the 64/24 you can get at a time from a wandering trader.
- Makes dirt generation nicer too.
- Compost result depends on the biome.
Get sand in deserts, beaches, warm oceans etc, red sand from badlands, and dirt elsewhere.

## Installation
- Install [Fabric](https://fabricmc.net/use)
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx1G

# Mod Properties
mod_version = 2.0.1
mod_version = 2.1.0
maven_group = carpet-extension
archives_base_name = skyblock

# Fabric Properties
# see https://modmuss50.me/fabric.html
minecraft_version=1.16.1
yarn_mappings=1.16.1+build.21
loader_version=0.9.0+build.204
fabric_api_version=0.14.1+build.372-1.16
minecraft_version=1.16.2
yarn_mappings=1.16.2+build.1
loader_version=0.9.1+build.205
fabric_api_version=0.17.2+build.396-1.16

# see https://masa.dy.fi/maven/carpet/fabric-carpet/
carpet_core_version=1.16-1.4.0+v200623
carpet_core_version=1.16.2-1.4.8+v200811
27 changes: 13 additions & 14 deletions src/main/java/skyblock/SkyBlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
import com.mojang.serialization.Lifecycle;
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.gen.chunk.ChunkGeneratorType;
import skyblock.mixin.DimensionTypeAccessor;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;

public class SkyBlockUtils {
public static SimpleRegistry<DimensionOptions> getSkyblockSimpleRegistry(long seed) {
SimpleRegistry<DimensionOptions> simpleRegistry = new SimpleRegistry<>(Registry.DIMENSION_OPTIONS, Lifecycle.stable());
simpleRegistry.add(DimensionOptions.NETHER, new DimensionOptions(DimensionTypeAccessor::getTheNether, SkyBlockUtils.createNetherGenerator(seed)));
simpleRegistry.add(DimensionOptions.END, new DimensionOptions(DimensionTypeAccessor::getTheEnd, SkyBlockUtils.createEndGenerator(seed)));
simpleRegistry.markLoaded(DimensionOptions.NETHER);
simpleRegistry.markLoaded(DimensionOptions.END);
public static SimpleRegistry<DimensionOptions> getSkyblockSimpleRegistry(Registry<DimensionType> dimensionTypeRegistry, Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
SimpleRegistry<DimensionOptions> simpleRegistry = new SimpleRegistry<>(Registry.DIMENSION_OPTIONS, Lifecycle.experimental());
simpleRegistry.add(DimensionOptions.NETHER, new DimensionOptions(() -> dimensionTypeRegistry.method_31140(DimensionType.THE_NETHER_REGISTRY_KEY), SkyBlockUtils.createNetherGenerator(biomeRegistry, settingsRegistry, seed)), Lifecycle.stable());
simpleRegistry.add(DimensionOptions.END, new DimensionOptions(() -> dimensionTypeRegistry.method_31140(DimensionType.THE_END_REGISTRY_KEY), SkyBlockUtils.createEndGenerator(biomeRegistry, settingsRegistry, seed)), Lifecycle.stable());
return simpleRegistry;
}

public static SkyblockChunkGenerator createOverworldGenerator(long seed) {
return new SkyblockChunkGenerator(seed, new VanillaLayeredBiomeSource(seed, false, false), ChunkGeneratorType.Preset.OVERWORLD.getChunkGeneratorType());
public static SkyblockChunkGenerator createOverworldGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
return new SkyblockChunkGenerator(seed, new VanillaLayeredBiomeSource(seed, false, false, biomeRegistry), () -> settingsRegistry.method_31140(ChunkGeneratorSettings.OVERWORLD));
}

public static SkyblockChunkGenerator createNetherGenerator(long seed) {
return new SkyblockChunkGenerator(seed, MultiNoiseBiomeSource.Preset.NETHER.getBiomeSource(seed), ChunkGeneratorType.Preset.NETHER.getChunkGeneratorType());
public static SkyblockChunkGenerator createNetherGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
return new SkyblockChunkGenerator(seed, MultiNoiseBiomeSource.Preset.NETHER.getBiomeSource(biomeRegistry, seed), () -> settingsRegistry.method_31140(ChunkGeneratorSettings.NETHER));
}

public static SkyblockChunkGenerator createEndGenerator(long seed) {
return new SkyblockChunkGenerator(seed, new TheEndBiomeSource(seed), ChunkGeneratorType.Preset.END.getChunkGeneratorType());
public static SkyblockChunkGenerator createEndGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
return new SkyblockChunkGenerator(seed, new TheEndBiomeSource(biomeRegistry, seed), () -> settingsRegistry.method_31140(ChunkGeneratorSettings.END));
}
}
54 changes: 29 additions & 25 deletions src/main/java/skyblock/SkyblockChunkGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,71 @@
import net.minecraft.util.registry.Registry;
import net.minecraft.world.*;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.SpawnSettings;
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.dimension.DimensionType;
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.ChunkGeneratorType;
import net.minecraft.world.gen.chunk.SurfaceChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

// Normally, this will always fail validation and give warning on load.
// This warning is disabled through a mixin.
// See validation method DimensionOptions.method_29567
public class SkyblockChunkGenerator extends ChunkGenerator {
private final long seed;
private final ChunkGeneratorType chunkGeneratorType;
private final Supplier<ChunkGeneratorSettings> settings;
// private final ChunkGeneratorType chunkGeneratorType;

// We reference this because SurfaceChunkGenerator final and so can't subclass it
private final SurfaceChunkGenerator reference;
private final NoiseChunkGenerator reference;

public static final Codec<SkyblockChunkGenerator> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
Codec.LONG.fieldOf("seed").stable().forGetter(SkyblockChunkGenerator::getSeed),
BiomeSource.field_24713.fieldOf("biome_source").forGetter(SkyblockChunkGenerator::getBiomeSource),
ChunkGeneratorType.field_24781.fieldOf("settings").forGetter(SkyblockChunkGenerator::getChunkGeneratorType)
BiomeSource.CODEC.fieldOf("biome_source").forGetter(SkyblockChunkGenerator::getBiomeSource),
ChunkGeneratorSettings.REGISTRY_CODEC.fieldOf("settings").forGetter(SkyblockChunkGenerator::getSettings)
).apply(instance, instance.stable(SkyblockChunkGenerator::new)));

public SkyblockChunkGenerator(long seed, BiomeSource biomeSource, ChunkGeneratorType chunkGeneratorType) {
super(biomeSource, chunkGeneratorType.getConfig());
public SkyblockChunkGenerator(long seed, BiomeSource biomeSource, Supplier<ChunkGeneratorSettings> settings) {
super(biomeSource, settings.get().getStructuresConfig());
this.seed = seed;
this.chunkGeneratorType = chunkGeneratorType;
this.reference = new SurfaceChunkGenerator(biomeSource, seed, chunkGeneratorType);
}

public ChunkGeneratorType getChunkGeneratorType() {
return this.chunkGeneratorType;
this.settings = settings;
this.reference = new NoiseChunkGenerator(biomeSource, seed, settings);
}

public long getSeed() {
return this.seed;
}

public Supplier<ChunkGeneratorSettings> getSettings() {
return this.settings;
}

@Override
protected Codec<? extends ChunkGenerator> method_28506() {
protected Codec<? extends ChunkGenerator> getCodec() {
return CODEC;
}

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

@Override
public void buildSurface(ChunkRegion region, Chunk chunk) {
Arrays.fill(chunk.getSectionArray(), WorldChunk.EMPTY_SECTION);

if (region.getDimension().equals(DimensionType.getOverworldDimensionType())) {
if (region.getDimension().isNatural()) {
BlockPos spawn = new BlockPos(region.getLevelProperties().getSpawnX(), region.getLevelProperties().getSpawnY(), region.getLevelProperties().getSpawnZ());
if (chunk.getPos().getStartX() <= spawn.getX() && spawn.getX() <= chunk.getPos().getEndX()
&& chunk.getPos().getStartZ() <= spawn.getZ() && spawn.getZ() <= chunk.getPos().getEndZ()) {
Expand All @@ -99,11 +101,11 @@ public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk c

@Override
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
return 0;
return reference.getHeight(x, z, heightmapType);
}

@Override
public List<Biome.SpawnEntry> getEntitySpawnList(Biome biome, StructureAccessor accessor, SpawnGroup group, BlockPos pos) {
public List<SpawnSettings.SpawnEntry> getEntitySpawnList(Biome biome, StructureAccessor accessor, SpawnGroup group, BlockPos pos) {
return reference.getEntitySpawnList(biome, accessor, group, pos);
}

Expand Down Expand Up @@ -138,11 +140,10 @@ public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
BlockPos pos = chunkPos.getCenterBlockPos();

accessor.getStructuresWithChildren(ChunkSectionPos.from(pos), Registry.STRUCTURE_FEATURE.get(new Identifier("minecraft:stronghold"))).forEach((structureStart) -> {
System.out.println(structureStart.getPos());
for (StructurePiece piece : structureStart.getChildren()) {
if (piece.getType() == StructurePieceType.STRONGHOLD_PORTAL_ROOM) {
BlockPos portalPos = new BlockPos(piece.getBoundingBox().minX, piece.getBoundingBox().minY, piece.getBoundingBox().minZ);
generateStrongholdPortal(region, portalPos);
generateStrongholdPortal(region, portalPos, this.seed);
}
}
});
Expand All @@ -167,11 +168,11 @@ protected static void fillRelativeBlock(WorldAccess world, BlockState block, Blo
}
}

private static void generateStrongholdPortal(ServerWorldAccess world, BlockPos pos) {
private static void generateStrongholdPortal(ServerWorldAccess world, BlockPos pos, long seed) {
boolean completePortal = true;
boolean[] eyes = new boolean[12];

ChunkRandom random = new ChunkRandom();
ChunkRandom random = new ChunkRandom(seed);

for (int i = 0; i < eyes.length; ++i) {
eyes[i] = random.nextFloat() > 0.9F;
Expand Down Expand Up @@ -200,18 +201,21 @@ private static void generateStrongholdPortal(ServerWorldAccess world, BlockPos p
fillRelativeBlock(world, endPortal, pos, 4, 3, 9, 6, 3, 11);
}

int spawnerPositionOption = random.nextInt(4);
int spawnerPositionOption = random.nextInt() % 4;
int x, y = 4, z;
switch (spawnerPositionOption) {
case 0:
x = 5;
z = 6;
break;
case 1:
x = 1;
z = 10;
break;
case 2:
x = 5;
z = 14;
break;
default:
x = 9;
z = 10;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/skyblock/mixin/ComposterBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ public class ComposterBlockMixin {
target = "Lnet/minecraft/entity/ItemEntity;setToDefaultPickupDelay()V",
shift = At.Shift.BEFORE
))
@SuppressWarnings("unused")
private static void setComposterOutput(BlockState arg0, World world, BlockPos pos, CallbackInfoReturnable<BlockState> cir, float f, double d, double e, double g, ItemEntity dropItemEntity) {
if (SkyBlockSettings.usefulComposters) {
Block dropBlock;
Block dropBlock = Blocks.DIRT;

Block surfaceBlock = world.getBiome(pos).getSurfaceConfig().getTopMaterial().getBlock();
Block surfaceBlock = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial().getBlock();
if (possibleSurfaceDrops.contains(surfaceBlock)) {
dropBlock = surfaceBlock;
} else {
dropBlock = Blocks.DIRT;
}

dropItemEntity.setStack(new ItemStack(dropBlock));
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/skyblock/mixin/DimensionTypeAccessor.java

This file was deleted.

7 changes: 5 additions & 2 deletions src/main/java/skyblock/mixin/EnderDragonFightMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.entity.boss.dragon.EnderDragonFight;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -24,10 +25,12 @@ public class EnderDragonFightMixin {

@Inject(method = "generateEndPortal", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/gen/feature/ConfiguredFeature;generate(Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/gen/chunk/ChunkGenerator;Ljava/util/Random;Lnet/minecraft/util/math/BlockPos;)Z",
target = "Lnet/minecraft/world/gen/feature/ConfiguredFeature;generate(Lnet/minecraft/world/StructureWorldAccess;Lnet/minecraft/world/gen/chunk/ChunkGenerator;Ljava/util/Random;Lnet/minecraft/util/math/BlockPos;)Z",
shift = At.Shift.BEFORE))
@SuppressWarnings("unused")
private void adjustExitPortalLocation(boolean open, CallbackInfo ci) {
if (this.world.getChunkManager().getChunkGenerator() instanceof SkyblockChunkGenerator) {
ChunkGenerator chunkGenerator = this.world.getChunkManager().getChunkGenerator();
if (chunkGenerator instanceof SkyblockChunkGenerator) {
this.exitPortalLocation = new BlockPos(this.exitPortalLocation.getX(), exitPortalHeight, this.exitPortalLocation.getZ());
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/skyblock/mixin/GeneratorOptionsMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package skyblock.mixin;

import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.GeneratorOptions;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -13,9 +18,10 @@
@Mixin(GeneratorOptions.class)
public class GeneratorOptionsMixin {
@Inject(method = "fromProperties", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private static void addSkyblockGeneratorOptionWhenLoadingProperties(Properties properties, CallbackInfoReturnable<GeneratorOptions> cir, String string, String string2, boolean generateStructures, String string4, String generatorSettingsValue, long seed) {
@SuppressWarnings("unused")
private static void addSkyblockGeneratorOptionWhenLoadingProperties(DynamicRegistryManager drm, Properties properties, CallbackInfoReturnable<GeneratorOptions> cir, String string, String string2, boolean generateStructures, String string4, String generatorSettingsValue, long seed, Registry<DimensionType> dimensionTypeRegistry, Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry) {
if ("skyblock".equals(generatorSettingsValue)) {
GeneratorOptions generatorOptions = new GeneratorOptions(seed, generateStructures, false, GeneratorOptions.method_28608(SkyBlockUtils.getSkyblockSimpleRegistry(seed), SkyBlockUtils.createOverworldGenerator(seed)));
GeneratorOptions generatorOptions = new GeneratorOptions(seed, generateStructures, false, GeneratorOptions.method_28608(dimensionTypeRegistry, SkyBlockUtils.getSkyblockSimpleRegistry(dimensionTypeRegistry, biomeRegistry, settingsRegistry, seed), SkyBlockUtils.createOverworldGenerator(biomeRegistry, settingsRegistry, seed)));
cir.setReturnValue(generatorOptions);
}
}
Expand Down
Loading

0 comments on commit 0f51039

Please sign in to comment.