Skip to content

Commit

Permalink
Initial 1.21.2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Oct 23, 2024
1 parent 67314ee commit e8a0bc5
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import xyz.jpenilla.squaremap.common.util.Colors;
import xyz.jpenilla.squaremap.common.util.chunksnapshot.ChunkSnapshot;

// TODO(1.21.2): pale forest colors, general foliage colors (dark forest?)
@DefaultQualifier(NonNull.class)
public final class BiomeColors {
private static final int BLOCKPOS_BIOME_CACHE_SIZE = 4096;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private void scanTopRow(final Image image, final int[] lastY, final ChunkSnapsho

private int effectiveMaxHeight(final ChunkSnapshot chunk) {
return this.mapWorld.config().MAP_MAX_HEIGHT == -1
? chunk.getMaxBuildHeight()
? chunk.getMaxY()
: this.mapWorld.config().MAP_MAX_HEIGHT;
}

Expand Down Expand Up @@ -380,7 +380,7 @@ private int scanBlock(final ChunkSnapshot chunk, final int imgX, final int imgZ,
final int topY = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, imgX, imgZ) + 1;
mutablePos.set(blockX, Math.min(topY, this.effectiveMaxHeight(chunk)), blockZ);

if (topY > chunk.getMinBuildHeight() + 1) {
if (topY > chunk.getMinY() + 1) {
state = this.mapWorld.config().MAP_ITERATE_UP
? this.iterateUp(chunk, mutablePos)
: this.iterateDown(chunk, mutablePos);
Expand Down Expand Up @@ -430,19 +430,19 @@ private BlockState iterateDown(final ChunkSnapshot chunk, final BlockPos.Mutable
do {
mutablePos.move(Direction.DOWN);
state = chunk.getBlockState(mutablePos);
} while (!state.isAir() && mutablePos.getY() > chunk.getMinBuildHeight());
} while (!state.isAir() && mutablePos.getY() > chunk.getMinY());
}
do {
mutablePos.move(Direction.DOWN);
state = chunk.getBlockState(mutablePos);
} while ((this.mapWorld.getMapColor(state) == Colors.clearMapColor() || this.mapWorld.advanced().invisibleBlocks.contains(state.getBlock())) && mutablePos.getY() > chunk.getMinBuildHeight());
} while ((this.mapWorld.getMapColor(state) == Colors.clearMapColor() || this.mapWorld.advanced().invisibleBlocks.contains(state.getBlock())) && mutablePos.getY() > chunk.getMinY());
return state;
}

private BlockState iterateUp(final ChunkSnapshot chunk, final BlockPos.MutableBlockPos mutablePos) {
BlockState state;
int height = mutablePos.getY();
mutablePos.setY(chunk.getMinBuildHeight());
mutablePos.setY(chunk.getMinY());
if (chunk.dimensionType().hasCeiling()) {
do {
mutablePos.move(Direction.UP);
Expand All @@ -456,7 +456,7 @@ private BlockState iterateUp(final ChunkSnapshot chunk, final BlockPos.MutableBl
do {
mutablePos.move(Direction.DOWN);
state = chunk.getBlockState(mutablePos);
} while ((this.mapWorld.getMapColor(state) == Colors.clearMapColor() || this.mapWorld.advanced().invisibleBlocks.contains(state.getBlock())) && mutablePos.getY() > chunk.getMinBuildHeight());
} while ((this.mapWorld.getMapColor(state) == Colors.clearMapColor() || this.mapWorld.advanced().invisibleBlocks.contains(state.getBlock())) && mutablePos.getY() > chunk.getMinY());
return state;
}

Expand All @@ -477,7 +477,7 @@ private record DepthResult(int depth, BlockState state) {
}

private static @Nullable DepthResult findDepthIfFluid(final BlockPos blockPos, final BlockState state, final ChunkSnapshot chunk) {
if (blockPos.getY() > chunk.getMinBuildHeight() && !state.getFluidState().isEmpty()) {
if (blockPos.getY() > chunk.getMinY() && !state.getFluidState().isEmpty()) {
BlockState fluidState;
int fluidDepth = 0;

Expand All @@ -488,7 +488,7 @@ private record DepthResult(int depth, BlockState state) {
mutablePos.setY(yBelowSurface--);
fluidState = chunk.getBlockState(mutablePos);
++fluidDepth;
} while (yBelowSurface > chunk.getMinBuildHeight() && fluidDepth <= 10 && !fluidState.getFluidState().isEmpty());
} while (yBelowSurface > chunk.getMinY() && fluidDepth <= 10 && !fluidState.getFluidState().isEmpty());

return new DepthResult(fluidDepth, fluidState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import xyz.jpenilla.squaremap.common.data.DirectoryProvider;

// TODO(1.21.2): test fabric & neoforge
@DefaultQualifier(NonNull.class)
public abstract class AbstractFluidColorExporter {
private final DirectoryProvider directoryProvider;
Expand All @@ -29,8 +30,8 @@ protected AbstractFluidColorExporter(final DirectoryProvider directoryProvider)

public final void export(final RegistryAccess registryAccess) {
final Map<String, String> map = new HashMap<>();
registryAccess.registryOrThrow(Registries.BLOCK).holders().forEach(holder -> {
final Block block = holder.value();
registryAccess.lookupOrThrow(Registries.BLOCK).entrySet().forEach(entry -> {
final Block block = entry.getValue();
final @Nullable Fluid fluid = this.fluid(block);
if (fluid == null
|| fluid == Fluids.WATER || fluid == Fluids.LAVA
Expand All @@ -39,7 +40,7 @@ public final void export(final RegistryAccess registryAccess) {
}
final @Nullable String color = this.color(fluid);
if (color != null) {
map.put(holder.key().location().toString(), color);
map.put(entry.getKey().location().toString(), color);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static <T> T requireEntry(final Registry<T> registry, final ResourceLocat
if (!registry.containsKey(location)) {
throw new IllegalArgumentException("No such entry '" + location + "' in registry '" + registry.key() + "'");
}
return requireNonNull(registry.get(location));
return requireNonNull(registry.getValue(location));
}

public static String levelConfigName(final ServerLevel level) {
Expand Down Expand Up @@ -124,7 +124,7 @@ public static Registry<Biome> biomeRegistry(final CommonLevelAccessor level) {
}

public static Registry<Biome> biomeRegistry(final RegistryAccess registryAccess) {
return registryAccess.registryOrThrow(Registries.BIOME);
return registryAccess.lookupOrThrow(Registries.BIOME);
}

public static @Nullable Manifest manifest(final Class<?> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface ChunkSnapshot extends LevelHeightAccessor, BiomeManager.NoiseBi

@SuppressWarnings({"unchecked", "rawtypes"})
static ChunkSnapshot snapshot(final Level level, final ChunkAccess chunk, final boolean biomesOnly) {
final LevelHeightAccessor heightAccessor = LevelHeightAccessor.create(chunk.getMinBuildHeight(), chunk.getHeight());
final LevelHeightAccessor heightAccessor = LevelHeightAccessor.create(chunk.getMinY(), chunk.getHeight());
final int sectionCount = heightAccessor.getSectionsCount();
final LevelChunkSection[] sections = chunk.getSections();
final PalettedContainer<BlockState>[] states = new PalettedContainer[sectionCount];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public int getHeight() {
}

@Override
public int getMinBuildHeight() {
return this.heightAccessor.getMinBuildHeight();
public int getMinY() {
return this.heightAccessor.getMinY();
}

@Override
Expand All @@ -89,7 +89,7 @@ public boolean sectionEmpty(final int sectionIndex) {

@Override
public Holder<Biome> getNoiseBiome(final int quartX, final int quartY, final int quartZ) {
final int minQuartY = QuartPos.fromBlock(this.getMinBuildHeight());
final int minQuartY = QuartPos.fromBlock(this.getMinY());
final int maxQuartY = minQuartY + QuartPos.fromBlock(this.getHeight()) - 1;
final int clampedQuartY = Mth.clamp(quartY, minQuartY, maxQuartY);
final int sectionIndex = this.getSectionIndex(QuartPos.toBlock(clampedQuartY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public int getFirstAvailable(final int x, final int z) {
}

private int getFirstAvailable(final int index) {
return this.data.get(index) + this.heightAccessor.getMinBuildHeight();
return this.data.get(index) + this.heightAccessor.getMinY();
}

private static int getIndex(final int x, final int z) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ private static boolean preHeightChangeFullChunk(final CompoundTag chunkTag) {
if (targetStatus == null) {
return false;
}
return BuiltInRegistries.CHUNK_STATUS.get(targetStatus).isOrAfter(ChunkStatus.SPAWN);
return BuiltInRegistries.CHUNK_STATUS.getValue(targetStatus).isOrAfter(ChunkStatus.SPAWN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public static int color(final Fluid fluid, final FluidRenderHandler renderHandle
final ColorBlender blender = new ColorBlender();
for (int i = 0; i < sprite.contents().width(); i++) {
for (int h = 0; h < sprite.contents().height(); h++) {
final int rgba = ((SpriteContentsExtension) sprite.contents()).getPixelRGBA(i, h);
final int rgba = ((SpriteContentsExtension) sprite.contents()).getPixel(i, h);
blender.addColor(rgba);
}
}
return color(
Colors.abgrToArgb(blender.result()),
blender.result(),
renderHandler.getFluidColor(null, null, fluid.defaultFluidState())
);
}

public interface SpriteContentsExtension {
int getPixelRGBA(int x, int y);
int getPixel(int x, int y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.portal.DimensionTransition;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -12,14 +11,14 @@
@Mixin(ServerPlayer.class)
abstract class ServerPlayerMixin {
@Inject(
method = "changeDimension",
method = "teleport(Lnet/minecraft/world/level/portal/TeleportTransition;)Lnet/minecraft/server/level/ServerPlayer;",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;sendLevelInfo(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/server/level/ServerLevel;)V",
shift = At.Shift.AFTER
)
)
void injectChangeDimension(DimensionTransition dimensionTransition, CallbackInfoReturnable<Entity> cir) {
void injectChangeDimension(final CallbackInfoReturnable<Entity> cir) {
ServerPlayerEvents.WORLD_CHANGED.invoker().worldChanged((ServerPlayer) (Object) this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ abstract class SpriteContentsMixin implements FabricFluidColorExporter.SpriteCon
@Shadow @Final private NativeImage originalImage;

@Override
public int getPixelRGBA(final int x, final int y) {
public int getPixel(final int x, final int y) {
// always gets from frame 0 of animated texture
return this.originalImage.getPixelRGBA(x, y);
return this.originalImage.getPixel(x, y);
}
}
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ hangar-publish = { id = "io.papermc.hangar-publish-plugin", version = "0.1.2" }
javadoc-links = { id = "org.incendo.cloud-build-logic.javadoc-links", version = "0.0.15" }

[versions]
minecraft = "1.21.1"
minecraft = "1.21.2"
checkerQual = "3.48.0"
cloud = "2.0.0"
cloudMinecraft = "2.0.0-beta.10"
Expand All @@ -17,14 +17,14 @@ configurate = "4.1.2"
adventure = "4.17.0"
examination = "1.3.0"
option = "1.0.0"
adventurePlatformMod = "6.0.0"
adventurePlatformMod = "6.1.0-SNAPSHOT"
paperApi = "1.20.2-R0.1-SNAPSHOT"
bStats = "3.1.0"
fabricApi = "0.105.0+1.21.1"
fabricApi = "0.106.1+1.21.2"
fabricLoader = "0.16.7"
cardinalComponents = "6.1.1"
guice = "7.0.0"
neoforge = "21.1.68"
neoforge = "21.2.0-beta"
htmlSanitizer = "20240325.1"

# buildSrc
Expand All @@ -33,7 +33,7 @@ sponge-gradle = "2.2.0"
shadow = "8.3.0"
vanillaGradle = "0.2.1-SNAPSHOT"
mod-publish-plugin = "0.7.4"
loom = "1.7-SNAPSHOT"
loom = "1.7.298"
paperweight = "1.7.3"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public static int color(final FluidType fluidType) {
blender.addColor(rgba);
}
}
return color(Colors.abgrToArgb(blender.result()), ext.getTintColor());
return color(blender.result(), ext.getTintColor());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public void register() {
if (!(event.getLevel() instanceof ServerLevel level)) {
return;
}
/* TODO: getAffectedBlocks not yet implemented in 1.21.2
for (final BlockPos affectedBlock : event.getAffectedBlocks()) {
this.markBlock(level, affectedBlock);
}
*/
});
NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, false, (BlockGrowFeatureEvent event) -> {
if (!(event.getLevel() instanceof ServerLevel level)) {
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ rootProject.name = "squaremap"

setupSubproject("api")
setupSubproject("common")
setupSubproject("paper")
include(":squaremap-paper:folia")
//setupSubproject("paper")
//include(":squaremap-paper:folia")
setupSubproject("fabric")
setupSubproject("neoforge")
setupSubproject("sponge")
Expand Down

0 comments on commit e8a0bc5

Please sign in to comment.