diff --git a/LICENSE.md b/LICENSE.md index 39ec438..554c989 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,51 +1,89 @@ # Crafted License + Version 1.0, 18 September 2024 Copyright (c) To_Craft Development, https://tocraft.dev This document explains the conditions, terms, and permissions of the licensed project applying to the licensee. ## 1. Definitions + This section defines the used definitions in this license. ### a) project -"Projects" are references in terms of the result of planned tasks to accomplish a goal. Projects are also publicly available with or without their source. + +"Projects" are references in terms of the result of planned tasks to accomplish a goal. Projects are also publicly +available with or without their source. ### b) library -This license defines a "library" as an interface that does not provide any end-user features. In specific, a library cannot be used without writing additional code directly or indirectly interacting with the licensed files. + +This license defines a "library" as an interface that does not provide any end-user features. In specific, a library +cannot be used without writing additional code directly or indirectly interacting with the licensed files. ### c) application -"Applications" represent a licensed project that, in contrast to libraries, actively provides end-user features and does not have to be used in other projects with or without additional code in order to fulfill their purpose. + +"Applications" represent a licensed project that, in contrast to libraries, actively provides end-user features and does +not have to be used in other projects with or without additional code in order to fulfill their purpose. ### d) accessibility -"Accessibility" is used to describe that the end-user must be able to find the accessible object when downloading, viewing, or using the work of the licensee without more than 3 mouse clicks, in the case of a digital project, or by directly being linked to it in the project description. In any way, the licensee must ensure the end-user does not have to pay any amount of money or leak any personal information to reach the project source. -In most cases, this is guaranteed by linking the accessible object in the project meta, the project description, and the project source. + +"Accessibility" is used to describe that the end-user must be able to find the accessible object when downloading, +viewing, or using the work of the licensee without more than 3 mouse clicks, in the case of a digital project, or by +directly being linked to it in the project description. In any way, the licensee must ensure the end-user does not have +to pay any amount of money or leak any personal information to reach the project source. +In most cases, this is guaranteed by linking the accessible object in the project meta, the project description, and the +project source. ## 2. Warranty and Liability -With this license, the author of the licensed project clarifies they will not provide any kind of warranty or liability for the licensed project. Any misuse is the liability of the actor and not the author of this project. By declaring this, the author also agrees the licensed project is not intended for any kind of illegal or unethical usage. + +With this license, the author of the licensed project clarifies they will not provide any kind of warranty or liability +for the licensed project. Any misuse is the liability of the actor and not the author of this project. By declaring +this, the author also agrees the licensed project is not intended for any kind of illegal or unethical usage. ## 3. Validity -This license only applies to the states of the project containing this license. Any version not containing the same Crafted License is subject to the corresponding license. However, this license must not be provided for each file or part of the project. A non-misleading file name in the directory of the project or including this license in the project description automatically licenses every file and/or part of the project with this license if this file or part isn't already licensed with another license or other version of Crafted License. + +This license only applies to the states of the project containing this license. Any version not containing the same +Crafted License is subject to the corresponding license. However, this license must not be provided for each file or +part of the project. A non-misleading file name in the directory of the project or including this license in the project +description automatically licenses every file and/or part of the project with this license if this file or part isn't +already licensed with another license or other version of Crafted License. ## 4. Private Use -If the licensee does not publish their work using the licensed project or any modification of it, nor shares it with more than 15 personally known people without any commercial interest, the licensee is free to use the licensed project in their work without applying the restrictions as defined in Section 5. + +If the licensee does not publish their work using the licensed project or any modification of it, nor shares it with +more than 15 personally known people without any commercial interest, the licensee is free to use the licensed project +in their work without applying the restrictions as defined in Section 5. ## 5. Public Use + Public use is any kind of use that cannot be counted as private use as defined in Section 4. -Public commercial use is not allowed without the approval of the author of the licensed project. Commercial use hereby means usage explicitly for earning any form of money. Sponsors or advertisements do not count as commercial use if the end-user is still able to use the work of the licensee without having to evade or attend to sponsoring or advertising. +Public commercial use is not allowed without the approval of the author of the licensed project. Commercial use hereby +means usage explicitly for earning any form of money. Sponsors or advertisements do not count as commercial use if the +end-user is still able to use the work of the licensee without having to evade or attend to sponsoring or advertising. The licensee must provide their source files, or in the case of coded projects, their source code. This source files must be accessibly linked. ### a) Forking, Modifying, and Distributing + Every condition as specified in Section 5 applies. -Any work not only using the licensed project but forking and/or modifying it must contain the exact same license as the original project and must accessibly link the original project and its license. +Any work not only using the licensed project but forking and/or modifying it must contain the exact same license as the +original project and must accessibly link the original project and its license. ### b) Using Libraries + Every condition as specified in Section 5 applies. -If the licensed project is a library, the licensee does not have to link the library's license to their work as long as they only use it without publishing any parts of the licensed project in any form except the releases of the licensee's work. To ensure this condition in the case of Gradle projects, it's recommended to use Maven Artifacts instead of uploading any jar library of the licensed project. +If the licensed project is a library, the licensee does not have to link the library's license to their work as long as +they only use it without publishing any parts of the licensed project in any form except the releases of the licensee's +work. To ensure this condition in the case of Gradle projects, it's recommended to use Maven Artifacts instead of +uploading any jar library of the licensed project. ### c) Other usage + Every condition as specified in Section 5 applies. -When using a licensed application or other licensed project that cannot be described as a library, the licensee must accessibly link an official source to the source licensed project and its license, if the license is not already explicitly linked in the official source. +When using a licensed application or other licensed project that cannot be described as a library, the licensee must +accessibly link an official source to the source licensed project and its license, if the license is not already +explicitly linked in the official source. ## 6. Additions -The author reserves themselves the right to explicitly lower conditions for a licensee but does not have to name any reason not to do so. However, they cannot limit the permissions guaranteed in this license. \ No newline at end of file + +The author reserves themselves the right to explicitly lower conditions for a licensee but does not have to name any +reason not to do so. However, they cannot limit the permissions guaranteed in this license. \ No newline at end of file diff --git a/README.md b/README.md index d7d3c2a..0314a1a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ # Crafted Terrain Generation Mod *Crafted Terrain Generation Mod* (CTGen) allows you to generate entire Minecraft worlds with just one map image! -It's fully data-driven, so you can configure it entirely via datapacks- no need for java code, even though it's still possible if you prefer it. +It's fully data-driven, so you can configure it entirely via data packs - no need for java code, even though it's still +possible if you prefer it. For an example implementation, you can take a look at [A Storm of Sorts](https://github.com/Deathslayor/AStormOfSwords). ### License diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.java b/common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.java index 3815742..14faa00 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.java @@ -1,5 +1,6 @@ package dev.tocraft.crafted.ctgen; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import dev.tocraft.crafted.ctgen.zone.Zone; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BasicPlacer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BasicPlacer.java new file mode 100644 index 0000000..32dbdef --- /dev/null +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BasicPlacer.java @@ -0,0 +1,43 @@ +package dev.tocraft.crafted.ctgen.blockplacer; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.zone.Codecs; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; +import org.jetbrains.annotations.NotNull; + +public class BasicPlacer extends BlockPlacer { + @NotNull + private final Block value; + + public BasicPlacer(@NotNull Block value) { + this.value = value; + } + + public Block get(SimplexNoise noise, double x, double y, double z, String layer) { + return value; + } + + @Override + public Block get(SimplexNoise noise, double x, double z, String layer) { + return value; + } + + public @NotNull Block getValue() { + return value; + } + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codecs.BLOCK.fieldOf("value").forGetter(o -> o.value) + ).apply(instance, instance.stable(BasicPlacer::new))); + + public static final ResourceLocation ID = CTerrainGeneration.id("basic"); + + @Override + public Codec codec() { + return CODEC; + } +} diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BlockPlacer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BlockPlacer.java index f5a8c35..229fbd3 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BlockPlacer.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BlockPlacer.java @@ -1,24 +1,41 @@ package dev.tocraft.crafted.ctgen.blockplacer; +import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; -import dev.tocraft.crafted.ctgen.CTerrainGeneration; -import dev.tocraft.crafted.ctgen.impl.services.ServerPlatform; +import dev.tocraft.crafted.ctgen.util.CTRegistries; +import dev.tocraft.crafted.ctgen.zone.Codecs; import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.synth.SimplexNoise; +import java.util.Optional; import java.util.function.Function; public abstract class BlockPlacer { - public static final ResourceKey>> BLOCK_PLAYER_REGISTRY_KEY = ResourceKey.createRegistryKey(CTerrainGeneration.id("block_placer")); - public static final Registry> BLOCK_PLACER_REGISTRY = ServerPlatform.INSTANCE.simpleRegistry(BLOCK_PLAYER_REGISTRY_KEY); + public static final Codec DIRECT_CODEC = CTRegistries.BLOCK_PLACER.byNameCodec().dispatchStable(BlockPlacer::codec, Function.identity()); + public static final Codec CODEC = Codec.either(Codecs.BLOCK, DIRECT_CODEC).xmap(either -> { + Optional left = either.left(); + if (left.isPresent()) { + return new BasicPlacer(left.get()); + } else { + return either.right().orElseThrow(); + } + }, placer -> { + if (placer instanceof BasicPlacer basic) { + return Either.left(basic.getValue()); + } else { + return Either.right(placer); + } + }); - public static final Codec CODEC = BLOCK_PLACER_REGISTRY.byNameCodec().dispatchStable(BlockPlacer::codec, Function.identity()); + public static void register() { + Registry.register(CTRegistries.BLOCK_PLACER, BasicPlacer.ID, BasicPlacer.CODEC); + Registry.register(CTRegistries.BLOCK_PLACER, NoisePlacer.ID, NoisePlacer.CODEC); + } - public abstract Block get(SimplexNoise noise, double x, double y, double z); + public abstract Block get(SimplexNoise noise, double x, double y, double z, String layer); - public abstract Block get(SimplexNoise noise, double x, double z); + public abstract Block get(SimplexNoise noise, double x, double z, String layer); protected abstract Codec codec(); } diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/NoisePlacer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/NoisePlacer.java index efd4d06..0467569 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/NoisePlacer.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/NoisePlacer.java @@ -1,10 +1,11 @@ package dev.tocraft.crafted.ctgen.blockplacer; -import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import dev.tocraft.crafted.ctgen.CTerrainGeneration; import dev.tocraft.crafted.ctgen.util.Noise; import dev.tocraft.crafted.ctgen.zone.Codecs; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.synth.SimplexNoise; import org.jetbrains.annotations.Contract; @@ -22,21 +23,12 @@ public class NoisePlacer extends BlockPlacer { @NotNull private final Block defaultValue; - private NoisePlacer(Block value) { - this(null, new HashMap<>(), value); - } - - private NoisePlacer(@Nullable Noise noise, @NotNull Map thresholdMap, @NotNull Block defaultValue) { + private NoisePlacer(@Nullable Noise noise, @NotNull Map thresholdMap, @NotNull Block defaultValue) { this.noise = noise; this.thresholdMap = thresholdMap; this.defaultValue = defaultValue; } - @Contract("_ -> new") - public static @NotNull NoisePlacer of(@NotNull Block value) { - return new NoisePlacer(value); - } - @Contract(value = "_, _, _ -> new", pure = true) public static @NotNull NoisePlacer of(Noise noise, Map thresholdMap, Block value) { return new NoisePlacer(noise, thresholdMap, value); @@ -46,12 +38,12 @@ public boolean hasNoise() { return noise != null && !thresholdMap.isEmpty(); } - public Block get(SimplexNoise noise, double x, double y, double z) { + public Block get(SimplexNoise noise, double x, double y, double z, String layer) { double perlin; if (this.noise != null && hasNoise()) { perlin = this.noise.getPerlin(noise, x, y, z); - } else { + } else { perlin = 0; } @@ -68,12 +60,12 @@ public Block get(SimplexNoise noise, double x, double y, double z) { } @Override - public Block get(SimplexNoise noise, double x, double z) { + public Block get(SimplexNoise noise, double x, double z, String layer) { double perlin; if (this.noise != null && hasNoise()) { perlin = this.noise.getPerlin(noise, x, z); - } else { + } else { perlin = 0; } @@ -106,14 +98,13 @@ public Block get(SimplexNoise noise, double x, double z) { } ); - public static final Codec DIRECT_CODEC = RecordCodecBuilder.create(instance -> instance.group( + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Noise.CODEC.optionalFieldOf("noise", Noise.DEFAULT).forGetter(o -> o.noise), - VALUE_MAP_CODEC.optionalFieldOf("values", new HashMap<>()).forGetter(o -> o.thresholdMap), + VALUE_MAP_CODEC.fieldOf("values").forGetter(o -> o.thresholdMap), Codecs.BLOCK.fieldOf("default").forGetter(o -> o.defaultValue) ).apply(instance, instance.stable(NoisePlacer::new))); - public static final Codec CODEC = Codec.either(Codecs.BLOCK, DIRECT_CODEC) - .xmap(either -> either.right().orElseGet(() -> of(either.left().orElseThrow())), selector -> selector.hasNoise() ? Either.right(selector) : Either.left(selector.defaultValue)); + public static final ResourceLocation ID = CTerrainGeneration.id("noise"); @Override public Codec codec() { diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/network/SyncMapPacket.java b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/network/SyncMapPacket.java index 9ae185c..9d7089d 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/network/SyncMapPacket.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/network/SyncMapPacket.java @@ -52,8 +52,7 @@ public void encode(@NotNull FriendlyByteBuf buf) { int mapWidth = buf.readInt(); int mapHeight = buf.readInt(); return new SyncMapPacket(mapId, xOffset, yOffset, mapWidth, mapHeight); - } - else { + } else { return empty(); } } diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/screen/widget/MapWidget.java b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/screen/widget/MapWidget.java index 3168634..5319c12 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/screen/widget/MapWidget.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/screen/widget/MapWidget.java @@ -164,6 +164,37 @@ public double getRatio() { return ratio; } + public void resetTextureOffsets() { + // calculate pixel pos for the player + double pixelX; + double pixelY; + if (minecraft.player != null) { + BlockPos blockPos = minecraft.player.blockPosition(); + pixelX = (blockPos.getX() >> 2) + pixelOffsetX; + pixelY = (blockPos.getZ() >> 2) + pixelOffsetY; + } else { + pixelX = pixelOffsetX; + pixelY = pixelOffsetY; + } + + // calculate offset for pixel pos + int tX = (int) (pixelX / mapWidth * zoomedWidth + getTextureX()); + int tY = (int) (pixelY / mapHeight * zoomedHeight + getTextureY()); + + setTextureOffsetX(tX); + setTextureOffsetY(tY); + } + + public void setTextureOffsetX(double textureOffsetX) { + this.textureOffsetX = textureOffsetX; + updateZoomedWidth(); + } + + public void setTextureOffsetY(double textureOffsetY) { + this.textureOffsetY = textureOffsetY; + updateZoomedHeight(); + } + /** * @return the virtual y point, where the map texture starts */ diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/services/ClientPlatform.java b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/services/ClientPlatform.java index e63ce79..3289004 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/services/ClientPlatform.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/services/ClientPlatform.java @@ -2,9 +2,6 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; - -import java.util.function.Consumer; @Environment(EnvType.CLIENT) public interface ClientPlatform extends PlatformService { diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/services/ServerPlatform.java b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/services/ServerPlatform.java index 25006b2..0ea72d1 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/services/ServerPlatform.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/services/ServerPlatform.java @@ -1,7 +1,6 @@ package dev.tocraft.crafted.ctgen.impl.services; import dev.tocraft.crafted.ctgen.impl.network.SyncMapPacket; -import net.minecraft.core.MappedRegistry; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/layer/BlockLayer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/BlockLayer.java new file mode 100644 index 0000000..92a077e --- /dev/null +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/BlockLayer.java @@ -0,0 +1,27 @@ +package dev.tocraft.crafted.ctgen.layer; + +import com.mojang.serialization.Codec; +import dev.tocraft.crafted.ctgen.util.CTRegistries; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; + +import java.util.function.Function; + +public abstract class BlockLayer { + public static final Codec CODEC = CTRegistries.BLOCK_LAYER.byNameCodec().dispatchStable(BlockLayer::codec, Function.identity()); + + protected final String name; + + public BlockLayer(String name) { + this.name = name; + } + + public abstract boolean is(SimplexNoise noise, double x, double y, double z); + + public String getName() { + return this.name; + } + + ; + + protected abstract Codec codec(); +} diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/util/CTRegistries.java b/common/src/main/java/dev/tocraft/crafted/ctgen/util/CTRegistries.java new file mode 100644 index 0000000..c9132ed --- /dev/null +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/util/CTRegistries.java @@ -0,0 +1,17 @@ +package dev.tocraft.crafted.ctgen.util; + +import com.mojang.serialization.Codec; +import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; +import dev.tocraft.crafted.ctgen.impl.services.ServerPlatform; +import dev.tocraft.crafted.ctgen.layer.BlockLayer; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; + +public final class CTRegistries { + public static final ResourceKey>> BLOCK_PLAYER_KEY = ResourceKey.createRegistryKey(CTerrainGeneration.id("block_placer")); + public static final Registry> BLOCK_PLACER = ServerPlatform.INSTANCE.simpleRegistry(BLOCK_PLAYER_KEY); + + public static final ResourceKey>> BLOCK_LAYER_KEY = ResourceKey.createRegistryKey(CTerrainGeneration.id("block_layer")); + public static final Registry> BLOCK_LAYER = ServerPlatform.INSTANCE.simpleRegistry(BLOCK_LAYER_KEY); +} diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/util/Noise.java b/common/src/main/java/dev/tocraft/crafted/ctgen/util/Noise.java index 185aa50..3c2f745 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/util/Noise.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/util/Noise.java @@ -28,7 +28,7 @@ public double getPerlin(SimplexNoise noise, double x, double y, double z) { double total = 0; double amplitude = 1; double totalAmplitude = 0; - for(float frequency : octaves) { + for (float frequency : octaves) { total += noise.getValue(x2 * frequency, y2 * frequency, z2 * frequency) * amplitude; totalAmplitude += amplitude; amplitude *= persistence; @@ -45,7 +45,7 @@ public double getPerlin(SimplexNoise noise, double x, double z) { double amplitude = 1; double totalAmplitude = 0; - for(float frequency : octaves) { + for (float frequency : octaves) { total += noise.getValue(x2 * frequency, z2 * frequency) * amplitude; totalAmplitude += amplitude; amplitude *= persistence; diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapBasedChunkGenerator.java b/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapBasedChunkGenerator.java index 7589fa8..014daae 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapBasedChunkGenerator.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapBasedChunkGenerator.java @@ -72,7 +72,7 @@ public void buildSurface(@NotNull WorldGenRegion pLevel, @NotNull StructureManag double surfaceHeight = getSettings().getHeight(noise, xOff, zOff) + getSettings().surfaceLevel; int thresholdModifier = (int) getSettings().getValueWithTransition(xOff, zOff, zo -> (double) zo.thresholdModifier().orElse(getSettings().thresholdModifier)); - Block surfaceBlock = zone.surfaceBlock().get(noise, xOff, zOff); + Block surfaceBlock = zone.surfaceBlock().get(noise, xOff, zOff, ""); // no grass underwater if (surfaceHeight < getSeaLevel() && surfaceBlock == Blocks.GRASS_BLOCK) { surfaceBlock = Blocks.DIRT; @@ -95,13 +95,13 @@ public void buildSurface(@NotNull WorldGenRegion pLevel, @NotNull StructureManag } else if (canSetBlock(pos, surfaceHeight, getSettings().deepslateLevel, minHeight + 3, thresholdModifier)) { if (y < deepslateLevel && deepslateLevel < surfaceHeight) { // place deepslate - chunk.setBlockState(pos, zone.deepslateBlock().get(noise, pos.getX(), pos.getY(), pos.getZ()).defaultBlockState(), false); + chunk.setBlockState(pos, zone.deepslateBlock().get(noise, pos.getX(), pos.getY(), pos.getZ(), "").defaultBlockState(), false); } else if (y < dirtLevel) { // place stone between deepslate and dirt - chunk.setBlockState(pos, zone.stoneBlock().get(noise, pos.getX(), pos.getY(), pos.getZ()).defaultBlockState(), false); + chunk.setBlockState(pos, zone.stoneBlock().get(noise, pos.getX(), pos.getY(), pos.getZ(), "").defaultBlockState(), false); } else if (y < surfaceHeight - 1) { // place dirt below surface - chunk.setBlockState(pos, zone.dirtBlock().get(noise, pos.getX(), pos.getY(), pos.getZ()).defaultBlockState(), false); + chunk.setBlockState(pos, zone.dirtBlock().get(noise, pos.getX(), pos.getY(), pos.getZ(), "").defaultBlockState(), false); } // only surface is missing else { diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zone.java b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zone.java index 2623976..b2066fc 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zone.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zone.java @@ -3,8 +3,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BasicPlacer; import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; -import dev.tocraft.crafted.ctgen.blockplacer.NoisePlacer; import net.minecraft.core.Holder; import net.minecraft.resources.RegistryFileCodec; import net.minecraft.world.level.biome.Biome; @@ -12,14 +12,15 @@ import java.util.Optional; -public record Zone(Holder biome, int color, BlockPlacer deepslateBlock, BlockPlacer stoneBlock, BlockPlacer dirtBlock, +public record Zone(Holder biome, int color, BlockPlacer deepslateBlock, BlockPlacer stoneBlock, + BlockPlacer dirtBlock, BlockPlacer surfaceBlock, int height, double perlinMultiplier, double pixelWeight, Optional thresholdModifier) { - public static final BlockPlacer DEFAULT_DEEPSLATE_BLOCK = NoisePlacer.of(Blocks.DEEPSLATE); - public static final BlockPlacer DEFAULT_STONE_BLOCK = NoisePlacer.of(Blocks.STONE); - public static final BlockPlacer DEFAULT_DIRT_BLOCK = NoisePlacer.of(Blocks.DIRT); - public static final BlockPlacer DEFAULT_SURFACE_BLOCK = NoisePlacer.of(Blocks.GRASS_BLOCK); + public static final BlockPlacer DEFAULT_DEEPSLATE_BLOCK = new BasicPlacer(Blocks.DEEPSLATE); + public static final BlockPlacer DEFAULT_STONE_BLOCK = new BasicPlacer(Blocks.STONE); + public static final BlockPlacer DEFAULT_DIRT_BLOCK = new BasicPlacer(Blocks.DIRT); + public static final BlockPlacer DEFAULT_SURFACE_BLOCK = new BasicPlacer(Blocks.GRASS_BLOCK); public static final int DEFAULT_HEIGHT = 0; public static final double DEFAULT_PERLIN_MULTIPLIER = 8; public static final double DEFAULT_PIXEL_WEIGHT = 1; diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/ZoneBuilder.java b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/ZoneBuilder.java index 08f7ba2..4248dd3 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/ZoneBuilder.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/ZoneBuilder.java @@ -1,10 +1,10 @@ package dev.tocraft.crafted.ctgen.zone; -import dev.tocraft.crafted.ctgen.blockplacer.NoisePlacer; +import dev.tocraft.crafted.ctgen.blockplacer.BasicPlacer; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import net.minecraft.core.Holder; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import java.awt.*; import java.util.Optional; @@ -16,10 +16,10 @@ public class ZoneBuilder { private int height = Zone.DEFAULT_HEIGHT; private double perlinMultiplier = Zone.DEFAULT_PERLIN_MULTIPLIER; private double pixelWeight = Zone.DEFAULT_PIXEL_WEIGHT; - private NoisePlacer deepslateBlock = NoisePlacer.of(Blocks.DEEPSLATE); - private NoisePlacer stoneBlock = NoisePlacer.of(Blocks.STONE); - private NoisePlacer dirtBlock = NoisePlacer.of(Blocks.DIRT); - private NoisePlacer surfaceBlock = NoisePlacer.of(Blocks.GRASS_BLOCK); + private BlockPlacer deepslateBlock = Zone.DEFAULT_DEEPSLATE_BLOCK; + private BlockPlacer stoneBlock = Zone.DEFAULT_STONE_BLOCK; + private BlockPlacer dirtBlock = Zone.DEFAULT_DIRT_BLOCK; + private BlockPlacer surfaceBlock = Zone.DEFAULT_SURFACE_BLOCK; private Optional thresholdModifier = Optional.empty(); public ZoneBuilder setBiome(Holder biome) { @@ -52,43 +52,43 @@ public ZoneBuilder setPixelWeight(double pixelWeight) { return this; } - public ZoneBuilder setDeepslateBlock(NoisePlacer deepslateBlock) { + public ZoneBuilder setDeepslateBlockPlacer(BlockPlacer deepslateBlock) { this.deepslateBlock = deepslateBlock; return this; } - public ZoneBuilder setStoneBlock(NoisePlacer stoneBlock) { + public ZoneBuilder setStoneBlockPlacer(BlockPlacer stoneBlock) { this.stoneBlock = stoneBlock; return this; } - public ZoneBuilder setDirtBlock(NoisePlacer dirtBlock) { + public ZoneBuilder setDirtBlockPlacer(BlockPlacer dirtBlock) { this.dirtBlock = dirtBlock; return this; } - public ZoneBuilder setSurfaceBlock(NoisePlacer surfaceBlock) { + public ZoneBuilder setSurfaceBlockPlacer(BlockPlacer surfaceBlock) { this.surfaceBlock = surfaceBlock; return this; } public ZoneBuilder setDeepslateBlock(Block deepslateBlock) { - this.deepslateBlock = NoisePlacer.of(deepslateBlock); + this.deepslateBlock = new BasicPlacer(deepslateBlock); return this; } public ZoneBuilder setStoneBlock(Block stoneBlock) { - this.stoneBlock = NoisePlacer.of(stoneBlock); + this.stoneBlock = new BasicPlacer(stoneBlock); return this; } public ZoneBuilder setDirtBlock(Block dirtBlock) { - this.dirtBlock = NoisePlacer.of(dirtBlock); + this.dirtBlock = new BasicPlacer(dirtBlock); return this; } public ZoneBuilder setSurfaceBlock(Block surfaceBlock) { - this.surfaceBlock = NoisePlacer.of(surfaceBlock); + this.surfaceBlock = new BasicPlacer(surfaceBlock); return this; } diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zones.java b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zones.java index 1ac796f..b808a6e 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zones.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zones.java @@ -1,15 +1,14 @@ package dev.tocraft.crafted.ctgen.zone; import dev.tocraft.crafted.ctgen.CTerrainGeneration; -import dev.tocraft.crafted.ctgen.util.Noise; import dev.tocraft.crafted.ctgen.blockplacer.NoisePlacer; +import dev.tocraft.crafted.ctgen.util.Noise; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstapContext; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import java.awt.*; @@ -57,7 +56,7 @@ public static void bootstrap(BootstapContext context) { // Western Continent context.register(DESERT, new ZoneBuilder().setBiome(getBiome(context, Biomes.DESERT)).setColor(new Color(165, 171, 54)).setDirtBlock(Blocks.SANDSTONE).setSurfaceBlock(Blocks.SAND).setHeight(5).setPerlinMultiplier(4).build()); context.register(BADLANDS, new ZoneBuilder().setBiome(getBiome(context, Biomes.BADLANDS)).setColor(new Color(84, 84, 56)).setDirtBlock(Blocks.RED_CONCRETE).setSurfaceBlock(Blocks.BROWN_CONCRETE).setHeight(18).setPerlinMultiplier(12).build()); - context.register(BADLANDS_MOUNTAINS, new ZoneBuilder().setBiome(getBiome(context, Biomes.BADLANDS)).setColor(new Color(70, 71, 53)).setDirtBlock(Blocks.RED_CONCRETE).setSurfaceBlock(NoisePlacer.of(new Noise(List.of(1f), 1, 1), new HashMap() { + context.register(BADLANDS_MOUNTAINS, new ZoneBuilder().setBiome(getBiome(context, Biomes.BADLANDS)).setColor(new Color(70, 71, 53)).setDirtBlock(Blocks.RED_CONCRETE).setSurfaceBlockPlacer(NoisePlacer.of(new Noise(List.of(1f), 1, 1), new HashMap<>() { { put(-0.5d, Blocks.ORANGE_CONCRETE); put(0d, Blocks.RED_CONCRETE); diff --git a/common/src/main/resources/ctgen.mixins.json b/common/src/main/resources/ctgen.mixins.json index 2578ce4..e4065da 100644 --- a/common/src/main/resources/ctgen.mixins.json +++ b/common/src/main/resources/ctgen.mixins.json @@ -5,8 +5,8 @@ "compatibilityLevel": "JAVA_17", "mixins": [ "RegistryDataLoaderMixin", - "impl.SendMapToPlayerMixin", - "VanillaRegistriesMixin" + "VanillaRegistriesMixin", + "impl.SendMapToPlayerMixin" ], "client": [ ], diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands.json index 768963c..c7c091b 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands.json @@ -8,16 +8,5 @@ "dirt_block": "minecraft:red_concrete", "height": 18, "perlin_multiplier": 12.0, - "surface_block": { - "default": "minecraft:brown_concrete", - "noise": { - "octaves": [ - 1 - ] - }, - "values": { - "-0.5": "minecraft:orange_concrete", - "0": "minecraft:red_concrete" - } - } + "surface_block": "red_sand" } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands_mountains.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands_mountains.json index 448b5a3..5d6d867 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands_mountains.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands_mountains.json @@ -9,6 +9,7 @@ "height": 28, "perlin_multiplier": 24.0, "surface_block": { + "type": "ctgen:noise", "default": "minecraft:brown_concrete", "noise": { "octaves": [ @@ -17,7 +18,8 @@ }, "values": { "-0.5": "minecraft:orange_concrete", - "0": "minecraft:red_concrete" + "0": "minecraft:red_concrete", + "0.5": "minecraft:gray_concrete" } } } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/deep_ocean.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/deep_ocean.json index c0860e1..f5ec766 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/deep_ocean.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/deep_ocean.json @@ -8,5 +8,4 @@ "height": -60, "perlin_multiplier": 33.0, "threshold_modifier": 26 - } diff --git a/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabric.java b/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabric.java index 3f65b85..5b81f76 100644 --- a/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabric.java +++ b/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabric.java @@ -1,13 +1,12 @@ package dev.tocraft.crafted.ctgen.fabric; import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import dev.tocraft.crafted.ctgen.data.MapImageRegistry; import dev.tocraft.crafted.ctgen.impl.CTGCommand; -import dev.tocraft.crafted.ctgen.impl.network.SyncMapPacket; -import dev.tocraft.crafted.ctgen.worldgen.MapBasedChunkGenerator; import dev.tocraft.crafted.ctgen.worldgen.MapBasedBiomeSource; +import dev.tocraft.crafted.ctgen.worldgen.MapBasedChunkGenerator; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; @@ -53,12 +52,6 @@ public ResourceLocation getFabricId() { CommandRegistrationCallback.EVENT.register((dispatcher, context, environment) -> CTGCommand.register(dispatcher, context)); - ClientPlayNetworking.registerGlobalReceiver( - SyncMapPacket.PACKET_ID, - (client, handler, buf, sender) -> { - SyncMapPacket packet = SyncMapPacket.decode(buf); - packet.handle(); - } - ); + BlockPlacer.register(); } } diff --git a/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabricClient.java b/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabricClient.java index 30a2f85..b9c41f8 100644 --- a/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabricClient.java +++ b/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabricClient.java @@ -1,10 +1,12 @@ package dev.tocraft.crafted.ctgen.fabric; import dev.tocraft.crafted.ctgen.impl.CTGClient; +import dev.tocraft.crafted.ctgen.impl.network.SyncMapPacket; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal @@ -13,5 +15,13 @@ public class CTGFabricClient { public static void initialize() { KeyBindingHelper.registerKeyBinding(CTGClient.OPEN_MAP_KEY); ClientTickEvents.START_CLIENT_TICK.register(CTGClient::tick); + + ClientPlayNetworking.registerGlobalReceiver( + SyncMapPacket.PACKET_ID, + (client, handler, buf, sender) -> { + SyncMapPacket packet = SyncMapPacket.decode(buf); + packet.handle(); + } + ); } } diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index bd1cfbc..bc916fe 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -7,7 +7,7 @@ dependencies { } tasks.withType { - @Suppress("UNCHECKED_CAST")val modMeta = parent!!.ext["mod_meta"]!! as Map + @Suppress("UNCHECKED_CAST") val modMeta = parent!!.ext["mod_meta"]!! as Map filesMatching("META-INF/mods.toml") { expand(modMeta) diff --git a/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForge.java b/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForge.java index 85b0e9f..147ae7d 100644 --- a/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForge.java +++ b/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForge.java @@ -2,10 +2,6 @@ import dev.tocraft.crafted.ctgen.CTerrainGeneration; import dev.tocraft.crafted.ctgen.impl.network.SyncMapPacket; -import dev.tocraft.crafted.ctgen.worldgen.MapBasedChunkGenerator; -import dev.tocraft.crafted.ctgen.worldgen.MapBasedBiomeSource; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.common.Mod; @@ -13,7 +9,6 @@ import net.minecraftforge.fml.loading.FMLEnvironment; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; -import net.minecraftforge.registries.RegisterEvent; import org.jetbrains.annotations.ApiStatus; @SuppressWarnings("unused") @@ -25,7 +20,6 @@ public class CTGForge { public CTGForge() { IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); - eventBus.addListener(this::event); MinecraftForge.EVENT_BUS.register(new CTGForgeEventListener()); SYNC_MAP_CHANNEL.messageBuilder(SyncMapPacket.class, 0) @@ -39,10 +33,7 @@ public CTGForge() { if (FMLEnvironment.dist.isClient()) { new CTGForgeClient(); } - } - private void event(RegisterEvent event) { - Registry.register(BuiltInRegistries.BIOME_SOURCE, CTerrainGeneration.id("map_based_biome_source"), MapBasedBiomeSource.CODEC); - Registry.register(BuiltInRegistries.CHUNK_GENERATOR, CTerrainGeneration.id("map_based_chunk_generator"), MapBasedChunkGenerator.CODEC); + CTerrainGeneration.initialize(); } } diff --git a/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForgeEventListener.java b/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForgeEventListener.java index 49a9597..1f3118f 100644 --- a/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForgeEventListener.java +++ b/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForgeEventListener.java @@ -1,11 +1,20 @@ package dev.tocraft.crafted.ctgen.forge; +import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import dev.tocraft.crafted.ctgen.data.MapImageRegistry; import dev.tocraft.crafted.ctgen.impl.CTGCommand; +import dev.tocraft.crafted.ctgen.util.CTRegistries; +import dev.tocraft.crafted.ctgen.worldgen.MapBasedBiomeSource; +import dev.tocraft.crafted.ctgen.worldgen.MapBasedChunkGenerator; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.packs.resources.PreparableReloadListener; import net.minecraftforge.event.AddReloadListenerEvent; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.registries.RegisterEvent; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -29,4 +38,19 @@ public void addReloadListenerEvent(AddReloadListenerEvent event) { public void registerCommands(RegisterCommandsEvent event) { CTGCommand.register(event.getDispatcher(), event.getBuildContext()); } + + @SuppressWarnings("unchecked") + @SubscribeEvent + public void register(RegisterEvent event) { + // generic stuff + Registry.register(BuiltInRegistries.BIOME_SOURCE, CTerrainGeneration.id("map_based_biome_source"), MapBasedBiomeSource.CODEC); + Registry.register(BuiltInRegistries.CHUNK_GENERATOR, CTerrainGeneration.id("map_based_chunk_generator"), MapBasedChunkGenerator.CODEC); + + // custom built-in registries + Registry.register((Registry>) BuiltInRegistries.REGISTRY, (ResourceKey>) (ResourceKey) CTRegistries.BLOCK_PLAYER_KEY, CTRegistries.BLOCK_PLACER); + Registry.register((Registry>) BuiltInRegistries.REGISTRY, (ResourceKey>) (ResourceKey) CTRegistries.BLOCK_LAYER_KEY, CTRegistries.BLOCK_LAYER); + + // values for the built-in registries + BlockPlacer.register(); + } } diff --git a/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/services/ForgeServerPlatform.java b/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/services/ForgeServerPlatform.java index 5c90fed..d098c15 100644 --- a/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/services/ForgeServerPlatform.java +++ b/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/services/ForgeServerPlatform.java @@ -6,8 +6,6 @@ import dev.tocraft.crafted.ctgen.impl.services.ServerPlatform; import net.minecraft.core.MappedRegistry; import net.minecraft.core.Registry; -import net.minecraft.core.WritableRegistry; -import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.network.NetworkDirection; @@ -21,9 +19,6 @@ public void send(SyncMapPacket packet, ServerPlayer to) { @Override public Registry simpleRegistry(ResourceKey> registryKey) { Lifecycle lifecycle = Lifecycle.stable(); - MappedRegistry registry = new MappedRegistry<>(registryKey, lifecycle, false); - //noinspection unchecked - ((WritableRegistry>) BuiltInRegistries.REGISTRY).register((ResourceKey>) (ResourceKey) registryKey, registry, Lifecycle.stable()); - return registry; + return new MappedRegistry<>(registryKey, lifecycle, false); } } diff --git a/props/1.20.1.properties b/props/1.20.1.properties index 9a62823..5a312e9 100644 --- a/props/1.20.1.properties +++ b/props/1.20.1.properties @@ -1,12 +1,9 @@ # PreProcessor mc_id=1201 - # JDK java=17 - # Mappings mappings=2023.09.03 - # Loader fabric=0.92.2 forge=47.2.0 \ No newline at end of file