Skip to content

Commit

Permalink
port to 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ToCraft committed Nov 3, 2024
1 parent c71749d commit 00341ef
Show file tree
Hide file tree
Showing 52 changed files with 249 additions and 292 deletions.
Binary file modified assets/Elarth.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// 1.20.1 2024-10-31T13:09:49.243567306 CTGen/Registries
// 1.21.3 2024-11-03T13:12:37.008856095 CTGen/Registries
09917112f8476aaef3e39f5780a478b955edc3e7 data/ctgen/worldgen/map_based/zones/plains.json
2d4924f56299c71565b20922e8330ba452c8de13 data/ctgen/worldgen/map_based/zones/badlands_mountains.json
4e10b1b02ad79d86538524c470d56dedf8c779f1 data/ctgen/worldgen/map_based/zones/desert.json
ea8abee99ec67bf274bec024eff481325863952a data/ctgen/worldgen/map_based/zones/stony_flats.json
0bd4367d5837e151081d147227d11e56c29ecffb data/ctgen/worldgen/map_based/zones/river.json
166eb560b75b90c63217a66b4eac9cf59dcb8f9e data/ctgen/worldgen/map_based/zones/lake.json
a78f910d231a5d843042462e8517155aab8b5ca2 data/ctgen/worldgen/map_based/zones/snowy_mountains.json
0bd4367d5837e151081d147227d11e56c29ecffb data/ctgen/worldgen/map_based/zones/river.json
786353e42c828bf1348fb727db3e60adec29c18d data/ctgen/worldgen/map_based/zones/forest.json
a78f910d231a5d843042462e8517155aab8b5ca2 data/ctgen/worldgen/map_based/zones/snowy_mountains.json
3fcf216d906f96f57ba447df2dab0a13157af1ce data/ctgen/worldgen/map_based/zones/snowy_slopes.json
178d1061c64452922300ec3d5db0f066c59ca438 data/ctgen/worldgen/map_based/zones/badlands.json
a034954687c0b0280accf18519f3022d029489b8 data/ctgen/worldgen/map_based/zones/ocean.json
b5339019d9316486c132e0832d7f86a08a9ec1e4 data/ctgen/worldgen/map_based/zones/mountains.json
d281f3a59adaf68e61a56c40493788015fd6ef95 data/ctgen/worldgen/map_based/zones/hills.json
2a289331bed4faa0aabefde7efaaff6ade8fd966 data/ctgen/worldgen/map_based/zones/frozen_river.json
d281f3a59adaf68e61a56c40493788015fd6ef95 data/ctgen/worldgen/map_based/zones/hills.json
bdedb4d289b62ce9049dad7260e5e2a58987dfb3 data/ctgen/worldgen/map_based/zones/snowy_flats.json
e20907968549754b4f2bdd776a641ca5c6f44fcd data/ctgen/worldgen/map_based/zones/deep_ocean.json
ae7297b8304833244f8be82c73215aefae5bb273 data/ctgen/worldgen/map_based/zones/frozen_lake.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public final class CTerrainGeneration {
@Contract("_ -> new")
@ApiStatus.Internal
public static @NotNull ResourceLocation id(String path) {
return new ResourceLocation(MODID, path);
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void register(@NotNull LiteralCommandNode<CommandSourceStack> root
.then(
Commands.literal("zone")
.then(
Commands.argument("dest", new ResourceLocationArgument()).suggests((context1, builder) -> SharedSuggestionProvider.suggest(context.holderLookup(CTRegistries.ZONES_KEY).listElements().map(h -> h.key().location().toString()), builder))
Commands.argument("dest", new ResourceLocationArgument()).suggests((context1, builder) -> SharedSuggestionProvider.suggest(context.lookupOrThrow(CTRegistries.ZONES_KEY).listElements().map(h -> h.key().location().toString()), builder))
.executes(
commandContext -> locate(
commandContext.getSource(),
Expand All @@ -60,7 +60,7 @@ private static int locate(CommandSourceStack source, @NotNull ServerLevel level,
if (level.getChunkSource().getGenerator() instanceof MapBasedChunkGenerator generator) {
Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);

Zone zone = level.registryAccess().registryOrThrow(CTRegistries.ZONES_KEY).getOptional(zoneId).orElseThrow();
Zone zone = level.registryAccess().lookupOrThrow(CTRegistries.ZONES_KEY).getOptional(zoneId).orElseThrow();

MapSettings settings = generator.getSettings();
BufferedImage image = generator.getSettings().getMapImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static void performTeleport(
if (!Level.isInSpawnableBounds(pos)) {
throw INVALID_POSITION.create();
} else {
if (entity.teleportTo(level, pos.getX(), pos.getY(), pos.getZ(), new HashSet<>(), entity.getYRot(), entity.getXRot())) {
if (entity.teleportTo(level, pos.getX(), pos.getY(), pos.getZ(), new HashSet<>(), entity.getYRot(), entity.getXRot(), true)) {
if (!(entity instanceof LivingEntity livingEntity) || !livingEntity.isFallFlying()) {
entity.setDeltaMovement(entity.getDeltaMovement().multiply(1.0, 0.0, 1.0));
entity.setOnGround(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import dev.tocraft.ctgen.CTerrainGeneration;
import dev.tocraft.ctgen.impl.CTGClient;
import dev.tocraft.ctgen.impl.services.ServerPlatform;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class SyncMapPacket {
public class SyncMapPacket implements CustomPacketPayload {
public static final ResourceLocation PACKET_ID = CTerrainGeneration.id("sync_map_id");
public static final Type<SyncMapPacket> TYPE = new Type<>(PACKET_ID);

@Nullable
private final ResourceLocation mapId;
Expand All @@ -32,36 +35,6 @@ public SyncMapPacket(@Nullable ResourceLocation mapId, boolean pixelsAreChunks,
this.mapHeight = mapHeight;
}

@ApiStatus.Internal
public void encode(@NotNull FriendlyByteBuf buf) {
boolean bl = this.mapId != null;
buf.writeBoolean(bl);
if (bl) {
buf.writeResourceLocation(this.mapId);
buf.writeBoolean(this.pixelsAreChunks);
buf.writeInt(this.xOffset);
buf.writeInt(this.yOffset);
buf.writeInt(this.mapWidth);
buf.writeInt(this.mapHeight);
}
}

@ApiStatus.Internal
public static @NotNull SyncMapPacket decode(@NotNull FriendlyByteBuf buf) {
boolean bl = buf.readBoolean();
if (bl) {
ResourceLocation mapId = buf.readResourceLocation();
boolean pixelsAreChunks = buf.readBoolean();
int xOffset = buf.readInt();
int yOffset = buf.readInt();
int mapWidth = buf.readInt();
int mapHeight = buf.readInt();
return new SyncMapPacket(mapId, pixelsAreChunks, xOffset, yOffset, mapWidth, mapHeight);
} else {
return empty();
}
}

@Contract(value = " -> new", pure = true)
@ApiStatus.Internal
public static @NotNull SyncMapPacket empty() {
Expand All @@ -75,7 +48,8 @@ public void handle() {

@ApiStatus.Internal
public void send(ServerPlayer to) {
ServerPlatform.INSTANCE.send(this, to);
ClientboundCustomPayloadPacket payload = new ClientboundCustomPayloadPacket(this);
to.connection.send(payload);
}

public @Nullable ResourceLocation getMapId() {
Expand All @@ -101,4 +75,43 @@ public int getMapHeight() {
public int getMapWidth() {
return mapWidth;
}

@Override
public @NotNull Type<? extends CustomPacketPayload> type() {
return TYPE;
}

public static StreamCodec<RegistryFriendlyByteBuf, SyncMapPacket> streamCodec() {
return new StreamCodec<>() {
@Override
public @NotNull SyncMapPacket decode(@NotNull RegistryFriendlyByteBuf buf) {
boolean bl = buf.readBoolean();
if (bl) {
ResourceLocation mapId = buf.readResourceLocation();
boolean pixelsAreChunks = buf.readBoolean();
int xOffset = buf.readInt();
int yOffset = buf.readInt();
int mapWidth = buf.readInt();
int mapHeight = buf.readInt();
return new SyncMapPacket(mapId, pixelsAreChunks, xOffset, yOffset, mapWidth, mapHeight);
} else {
return empty();
}
}

@Override
public void encode(@NotNull RegistryFriendlyByteBuf buf, @NotNull SyncMapPacket payload) {
boolean bl = payload.mapId != null;
buf.writeBoolean(bl);
if (bl) {
buf.writeResourceLocation(payload.mapId);
buf.writeBoolean(payload.pixelsAreChunks);
buf.writeInt(payload.xOffset);
buf.writeInt(payload.yOffset);
buf.writeInt(payload.mapWidth);
buf.writeInt(payload.mapHeight);
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void render(@NotNull GuiGraphics context, int mouseX, int mouseY, float d
assert minecraft != null && minecraft.player != null;

// transparent background
renderBackground(context);
renderBackground(context, mouseX, mouseY, delta);

// check if texture with was found
if (mapWidget != null && mapWidget.getMapId() != null && minecraft.getResourceManager().getResource(mapWidget.getMapId()).isPresent()) {
Expand All @@ -84,11 +84,11 @@ public void render(@NotNull GuiGraphics context, int mouseX, int mouseY, float d
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
public boolean mouseScrolled(double mouseX, double mouseY, double deltaX, double deltaY) {
if (mapWidget != null) {
return mapWidget.mouseScrolled(mouseX, mouseY, delta);
return mapWidget.mouseScrolled(mouseX, mouseY, deltaX, deltaY);
} else {
return super.mouseScrolled(mouseX, mouseY, delta);
return super.mouseScrolled(mouseX, mouseY, deltaX, deltaY);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static MapWidget ofPacket(Minecraft minecraft, int x, int y, int width, i
int mapWidth = packet.getMapWidth();
int mapHeight = packet.getMapHeight();
if (mapId != null) {
return new MapWidget(minecraft, x, y, width, height, new ResourceLocation(mapId.getNamespace(), "textures/gui/" + mapId.getPath() + ".png"), pixelsAreChunks, xOffset, yOffset, mapWidth, mapHeight);
return new MapWidget(minecraft, x, y, width, height, ResourceLocation.fromNamespaceAndPath(mapId.getNamespace(), "textures/gui/" + mapId.getPath() + ".png"), pixelsAreChunks, xOffset, yOffset, mapWidth, mapHeight);
}
return null;
}
Expand Down Expand Up @@ -278,7 +279,7 @@ public void renderWidget(@NotNull GuiGraphics context, int mouseX, int mouseY, f
RenderSystem.enableScissor((int) (getX() * scaleFactor), (int) (getY() * scaleFactor), (int) (width * scaleFactor), (int) (height * scaleFactor));

// render actual map
context.blit(mapId, getTextureX(), getTextureY(), 0, 0, zoomedWidth, zoomedHeight, zoomedWidth, zoomedHeight);
context.blit(RenderType::guiTextured, mapId, getTextureX(), getTextureY(), 0, 0, zoomedWidth, zoomedHeight, zoomedWidth, zoomedHeight);

if (showPlayer) {
// calculate pixel pos for the player
Expand All @@ -296,9 +297,9 @@ public void renderWidget(@NotNull GuiGraphics context, int mouseX, int mouseY, f
if (playerY > getTextureY() - 4 + zoomedHeight) playerY = getTextureY() - 4 + zoomedHeight;

// render player head
ResourceLocation skin = minecraft.player.getSkinTextureLocation();
context.blit(skin, playerX - 4, playerY - 4, 8, 8, 8.0f, 8, 8, 8, 64, 64);
context.blit(skin, playerX - 4, playerY - 4, 8, 8, 40.0f, 8, 8, 8, 64, 64);
ResourceLocation skin = minecraft.player.getSkin().texture();
context.blit(RenderType::guiTextured, skin, playerX - 4, playerY - 4, 8.0f, 8, 8, 8, 8, 8, 64, 64);
context.blit(RenderType::guiTextured, skin, playerX - 4, playerY - 4, 40.0f, 8, 8, 8, 8, 8, 64, 64);
}

// render cursor position
Expand Down Expand Up @@ -379,13 +380,13 @@ public int mousePixelY(double mouseY) {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
public boolean mouseScrolled(double mouseX, double mouseY, double deltaX, double deltaY) {
double value;

// Zoom in/out with scrolling
if (amount > 0) {
if (deltaY > 0) {
value = ZOOM_FACTOR;
} else if (amount < 0) {
} else if (deltaY < 0) {
value = 1 / ZOOM_FACTOR;
} else {
value = 1;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ private static void onInit(CallbackInfo ci) {
}
}
if (biomeIndex != -1) {
RegistryDataLoader.RegistryData<?> zoneRegistryData = new RegistryDataLoader.RegistryData<>(CTRegistries.ZONES_KEY, Zone.DIRECT_CODEC);
RegistryDataLoader.RegistryData<?> zoneRegistryData = new RegistryDataLoader.RegistryData<>(CTRegistries.ZONES_KEY, Zone.DIRECT_CODEC, false);
worldGenRegistries.add(biomeIndex + 1, zoneRegistryData);
WORLDGEN_REGISTRIES = worldGenRegistries;
WORLDGEN_REGISTRIES = List.copyOf(worldGenRegistries);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.tocraft.ctgen.worldgen;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.tocraft.ctgen.CTerrainGeneration;
import net.minecraft.core.Holder;
Expand All @@ -14,7 +14,7 @@

public class MapBasedBiomeSource extends BiomeSource {
public static final ResourceLocation ID = CTerrainGeneration.id("map_based_biome_source");
public static final Codec<MapBasedBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
public static final MapCodec<MapBasedBiomeSource> CODEC = RecordCodecBuilder.mapCodec((instance) -> instance.group(
MapSettings.CODEC.fieldOf("settings").forGetter(o -> o.settings)
).apply(instance, instance.stable(MapBasedBiomeSource::new)));

Expand All @@ -25,7 +25,7 @@ public MapBasedBiomeSource(MapSettings settings) {
}

@Override
protected @NotNull Codec<? extends BiomeSource> codec() {
protected @NotNull MapCodec<MapBasedBiomeSource> codec() {
return CODEC;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.tocraft.ctgen.worldgen;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.tocraft.ctgen.CTerrainGeneration;
import dev.tocraft.ctgen.xtend.layer.BlockLayer;
Expand Down Expand Up @@ -29,11 +29,10 @@

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

public class MapBasedChunkGenerator extends ChunkGenerator {
public static final ResourceLocation ID = CTerrainGeneration.id("map_based_chunk_generator");
public static final Codec<MapBasedChunkGenerator> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
public static final MapCodec<MapBasedChunkGenerator> CODEC = RecordCodecBuilder.mapCodec((instance) -> instance.group(
MapSettings.CODEC.fieldOf("settings").forGetter(MapBasedChunkGenerator::getSettings)
).apply(instance, instance.stable(MapBasedChunkGenerator::of)));

Expand All @@ -53,12 +52,13 @@ private MapBasedChunkGenerator(MapBasedBiomeSource biomeSource) {
}

@Override
protected @NotNull Codec<MapBasedChunkGenerator> codec() {
protected @NotNull MapCodec<MapBasedChunkGenerator> codec() {
return CODEC;
}

@Override
public void applyCarvers(@NotNull WorldGenRegion level, long pSeed, @NotNull RandomState random, @NotNull BiomeManager pBiomeManager, @NotNull StructureManager pStructureManager, @NotNull ChunkAccess chunk, GenerationStep.@NotNull Carving step) {
public void applyCarvers(WorldGenRegion level, long seed, RandomState random, BiomeManager biomeManager, StructureManager structureManager, ChunkAccess chunk) {

}

@Override
Expand Down Expand Up @@ -122,7 +122,7 @@ private boolean canSetBlock(@NotNull BlockPos pos, double surfaceHeight, int min
@Override
public void spawnOriginalMobs(@NotNull WorldGenRegion pLevel) {
ChunkPos chunkpos = pLevel.getCenter();
Holder<Biome> holder = pLevel.getBiome(chunkpos.getWorldPosition().atY(pLevel.getMaxBuildHeight() - 1));
Holder<Biome> holder = pLevel.getBiome(chunkpos.getWorldPosition().atY(pLevel.getMaxY() - 1));
WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
worldgenrandom.setDecorationSeed(pLevel.getSeed(), chunkpos.getMinBlockX(), chunkpos.getMinBlockZ());
NaturalSpawner.spawnMobsForChunkGeneration(pLevel, holder, chunkpos, worldgenrandom);
Expand All @@ -134,8 +134,8 @@ public int getGenDepth() {
}

@Override
public @NotNull CompletableFuture<ChunkAccess> fillFromNoise(@NotNull Executor pExecutor, @NotNull Blender pBlender, @NotNull RandomState pRandom, @NotNull StructureManager pStructureManager, @NotNull ChunkAccess pChunk) {
return CompletableFuture.completedFuture(pChunk);
public @NotNull CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState randomState, StructureManager structureManager, ChunkAccess chunkAccess) {
return CompletableFuture.completedFuture(chunkAccess);
}

@Override
Expand Down
Loading

0 comments on commit 00341ef

Please sign in to comment.