Skip to content

Commit

Permalink
Update minigame to Minecraft 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Jan 5, 2024
1 parent 9ca55ef commit 9be6c56
Show file tree
Hide file tree
Showing 27 changed files with 147 additions and 155 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "0.11.32"
id "fabric-loom" version "1.4.6"
id "maven-publish"
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ mod_version = 1.0.0
org.gradle.jvmargs = -Xmx1G

# Versions
minecraft_version = 1.18.2
yarn_mappings = 1.18.2+build.3
loader_version = 0.13.3
fabric_version = 0.50.0+1.18.2
minecraft_version = 1.19.3
yarn_mappings = 1.19.3+build.5
loader_version = 0.15.3
fabric_version = 0.76.1+1.19.3

plasmid_version = 0.5+1.18.2-SNAPSHOT
plasmid_version = 0.5+1.19.3-SNAPSHOT
5 changes: 3 additions & 2 deletions src/main/java/io/github/haykam821/deathswap/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import xyz.nucleoid.plasmid.game.GameType;

public class Main implements ModInitializer {
Expand All @@ -22,6 +23,6 @@ public class Main implements ModInitializer {

@Override
public void onInitialize() {
Registry.register(Registry.BLOCK, BARRIER_AIR_ID, BARRIER_AIR);
Registry.register(Registries.BLOCK, BARRIER_AIR_ID, BARRIER_AIR);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.haykam821.deathswap.block;

import eu.pb4.polymer.api.block.PolymerBlock;
import eu.pb4.polymer.core.api.block.PolymerBlock;
import net.minecraft.block.AirBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import net.minecraft.SharedConstants;
import net.minecraft.entity.boss.BossBar;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.Vec3d;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
Expand All @@ -26,7 +24,7 @@ public class DeathSwapTimer {
private static final BossBar.Color WARNING_COLOR = BossBar.Color.YELLOW;
private static final Formatting NO_SWAP_FORMATTING = Formatting.GREEN;
private static final Formatting WARNING_FORMATTING = Formatting.YELLOW;
private static final Text NO_SWAP_TITLE = new TranslatableText("text.deathswap.timer.no_swap");
private static final Text NO_SWAP_TITLE = Text.translatable("text.deathswap.timer.no_swap");

private static final DecimalFormat MINUTES_FORMAT = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.ROOT));
private final DeathSwapActivePhase phase;
Expand Down Expand Up @@ -75,7 +73,7 @@ private void swap() {
Vec3d position = positions.get(index);
player.teleport(position.getX(), position.getY(), position.getZ());

Text message = new TranslatableText("text.deathswap.timer.swap", previousPlayer.getDisplayName()).formatted(NO_SWAP_FORMATTING);
Text message = Text.translatable("text.deathswap.timer.swap", previousPlayer.getDisplayName()).formatted(NO_SWAP_FORMATTING);
player.sendMessage(message, true);

previousPlayer = player;
Expand Down Expand Up @@ -108,14 +106,14 @@ private Text getWarning() {
double minutes = seconds / 60d;

if (minutes > 1.05) {
return new TranslatableText("text.deathswap.timer.warning.minutes", MINUTES_FORMAT.format(minutes));
return Text.translatable("text.deathswap.timer.warning.minutes", MINUTES_FORMAT.format(minutes));
} else {
return new TranslatableText("text.deathswap.timer.warning.minute");
return Text.translatable("text.deathswap.timer.warning.minute");
}
} else if (seconds == 1) {
return new TranslatableText("text.deathswap.timer.warning.second");
return Text.translatable("text.deathswap.timer.warning.second");
} else {
return new TranslatableText("text.deathswap.timer.warning.seconds", seconds);
return Text.translatable("text.deathswap.timer.warning.seconds", seconds);
}
}

Expand All @@ -124,7 +122,7 @@ private void setBarTitle(Text customText, Formatting formatting) {
}

private Text getBarTitle(Text customText, Formatting formatting) {
Text gameName = new TranslatableText("gameType.deathswap.death_swap").formatted(Formatting.BOLD);
return new LiteralText("").append(gameName).append(" - ").append(customText).formatted(formatting);
Text gameName = Text.translatable("gameType.deathswap.death_swap").formatted(Formatting.BOLD);
return Text.empty().append(gameName).append(" - ").append(customText).formatted(formatting);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import xyz.nucleoid.plasmid.game.player.PlayerIterable;
import xyz.nucleoid.plasmid.util.PlayerRef;
Expand Down Expand Up @@ -100,7 +99,7 @@ public String toString() {
}

private static Text createText(String keySuffix, Formatting formatting, boolean title, Object... args) {
return new TranslatableText("text.deathswap.elimination_collector." + keySuffix, args).styled(style -> {
return Text.translatable("text.deathswap.elimination_collector." + keySuffix, args).styled(style -> {
return style.withFormatting(formatting).withBold(title);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
package io.github.haykam821.deathswap.game.map;

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

import net.minecraft.block.BlockState;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.Heightmap;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.GenerationStep.Carver;
import net.minecraft.world.gen.GeneratorOptions;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.Blender;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
import net.minecraft.world.gen.chunk.VerticalBlockSample;
import net.minecraft.world.gen.noise.NoiseConfig;
import xyz.nucleoid.plasmid.game.world.generator.GameChunkGenerator;

public final class DeathSwapChunkGenerator extends GameChunkGenerator {
private final DeathSwapMapConfig mapConfig;
private final ChunkGenerator chunkGenerator;

public DeathSwapChunkGenerator(MinecraftServer server, DeathSwapMapConfig mapConfig) {
super(server);
super(mapConfig.getDimensionOptions().chunkGenerator().getBiomeSource());

this.mapConfig = mapConfig;
this.chunkGenerator = mapConfig.getDimensionOptions().chunkGenerator();
}

long seed = server.getOverworld().getRandom().nextLong();
public ChunkGeneratorSettings getSettings() {
if (this.chunkGenerator instanceof NoiseChunkGenerator noiseChunkGenerator) {
return noiseChunkGenerator.getSettings().value();
}

RegistryKey<ChunkGeneratorSettings> chunkGeneratorSettingsKey = RegistryKey.of(Registry.CHUNK_GENERATOR_SETTINGS_KEY, mapConfig.getChunkGeneratorSettingsId());
this.chunkGenerator = GeneratorOptions.createGenerator(server.getRegistryManager(), seed, chunkGeneratorSettingsKey);
return null;
}

private boolean isChunkPosWithinArea(ChunkPos chunkPos) {
Expand All @@ -51,11 +53,11 @@ private boolean isChunkWithinArea(Chunk chunk) {
}

@Override
public CompletableFuture<Chunk> populateBiomes(Registry<Biome> registry, Executor executor, Blender blender, StructureAccessor structures, Chunk chunk) {
public CompletableFuture<Chunk> populateBiomes(Executor executor, NoiseConfig noiseConfig, Blender blender, StructureAccessor structures, Chunk chunk) {
if (this.isChunkWithinArea(chunk)) {
return this.chunkGenerator.populateBiomes(registry, executor, blender, structures, chunk);
return this.chunkGenerator.populateBiomes(executor, noiseConfig, blender, structures, chunk);
} else {
return super.populateBiomes(registry, executor, blender, structures, chunk);
return super.populateBiomes(executor, noiseConfig, blender, structures, chunk);
}
}

Expand All @@ -73,22 +75,17 @@ public void populateEntities(ChunkRegion region) {
}

@Override
public MultiNoiseSampler getMultiNoiseSampler() {
return this.chunkGenerator.getMultiNoiseSampler();
}

@Override
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender, StructureAccessor structures, Chunk chunk) {
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender, NoiseConfig noiseConfig, StructureAccessor structures, Chunk chunk) {
if (this.isChunkWithinArea(chunk)) {
return this.chunkGenerator.populateNoise(executor, blender, structures, chunk);
return this.chunkGenerator.populateNoise(executor, blender, noiseConfig, structures, chunk);
}
return super.populateNoise(executor, blender, structures, chunk);
return super.populateNoise(executor, blender, noiseConfig, structures, chunk);
}

@Override
public void buildSurface(ChunkRegion region, StructureAccessor structures, Chunk chunk) {
public void buildSurface(ChunkRegion region, StructureAccessor structures, NoiseConfig noiseConfig, Chunk chunk) {
if (this.isChunkWithinArea(chunk)) {
this.chunkGenerator.buildSurface(region, structures, chunk);
this.chunkGenerator.buildSurface(region, structures, noiseConfig, chunk);
}
}

Expand Down Expand Up @@ -123,7 +120,7 @@ private void generateWalls(int chunkX, int chunkZ, BlockPos originPos, Chunk chu
// Top
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
pos.set(x + originX, chunk.getTopY(), z + originZ);
pos.set(x + originX, topY, z + originZ);
chunk.setBlockState(pos, this.getTopBarrierState(random, pos), false);
}
}
Expand Down Expand Up @@ -170,17 +167,17 @@ private void generateWalls(int chunkX, int chunkZ, BlockPos originPos, Chunk chu
}

private BlockState getTopBarrierState(Random random, BlockPos pos) {
return this.mapConfig.getTopBarrier().getBlockState(random, pos);
return this.mapConfig.getTopBarrier().get(random, pos);
}

private BlockState getBarrierState(Random random, BlockPos pos) {
return this.mapConfig.getBarrier().getBlockState(random, pos);
return this.mapConfig.getBarrier().get(random, pos);
}

@Override
public void carve(ChunkRegion region, long seed, BiomeAccess access, StructureAccessor structures, Chunk chunk, Carver carver) {
public void carve(ChunkRegion region, long seed, NoiseConfig noiseConfig, BiomeAccess access, StructureAccessor structures, Chunk chunk, Carver carver) {
if (this.isChunkWithinArea(chunk)) {
this.chunkGenerator.carve(region, seed, access, structures, chunk, carver);
this.chunkGenerator.carve(region, seed, noiseConfig, access, structures, chunk, carver);
}
}

Expand All @@ -200,18 +197,18 @@ public int getWorldHeight() {
}

@Override
public int getHeight(int x, int z, Heightmap.Type heightmapType, HeightLimitView world) {
public int getHeight(int x, int z, Heightmap.Type heightmapType, HeightLimitView world, NoiseConfig noiseConfig) {
if (this.isChunkPosWithinArea(new ChunkPos(x >> 4, z >> 4))) {
return this.chunkGenerator.getHeight(x, z, heightmapType, world);
return this.chunkGenerator.getHeight(x, z, heightmapType, world, noiseConfig);
}
return super.getHeight(x, z, heightmapType, world);
return super.getHeight(x, z, heightmapType, world, noiseConfig);
}

@Override
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world) {
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world, NoiseConfig noiseConfig) {
if (this.isChunkPosWithinArea(new ChunkPos(x >> 4, z >> 4))) {
return this.chunkGenerator.getColumnSample(x, z, world);
return this.chunkGenerator.getColumnSample(x, z, world, noiseConfig);
}
return super.getColumnSample(x, z, world);
return super.getColumnSample(x, z, world, noiseConfig);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.haykam821.deathswap.game.map;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockBox;
import net.minecraft.world.Heightmap;
import net.minecraft.world.dimension.DimensionType;

public final class DeathSwapMap {
Expand All @@ -13,8 +15,8 @@ public DeathSwapMap(MinecraftServer server, DeathSwapMapConfig mapConfig, Dimens
this.mapConfig = mapConfig;
this.chunkGenerator = new DeathSwapChunkGenerator(server, this.mapConfig);

int minY = dimensionType.getMinimumY();
int maxY = minY + dimensionType.getHeight();
int minY = dimensionType.minY();
int maxY = minY + dimensionType.height();

this.box = new BlockBox(1, minY + 1, 1, mapConfig.getX() * 16 - 2, maxY - 1, mapConfig.getZ() * 16 - 2);
}
Expand All @@ -26,4 +28,8 @@ public DeathSwapChunkGenerator getChunkGenerator() {
public BlockBox getBox() {
return this.box;
}

public int getSurfaceY(ServerWorld world, int x, int z) {
return this.chunkGenerator.getHeight(x, z, Heightmap.Type.WORLD_SURFACE, world, world.getChunkManager().getNoiseConfig());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,46 @@

import io.github.haykam821.deathswap.Main;
import net.minecraft.block.Blocks;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.entry.RegistryFixedCodec;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionOptionsRegistryHolder;
import net.minecraft.world.gen.WorldPreset;
import net.minecraft.world.gen.stateprovider.BlockStateProvider;

public class DeathSwapMapConfig {
public static final Codec<DeathSwapMapConfig> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(
DimensionType.REGISTRY_CODEC.fieldOf("dimension_type").forGetter(DeathSwapMapConfig::getDimensionType),
Identifier.CODEC.fieldOf("settings").forGetter(DeathSwapMapConfig::getChunkGeneratorSettingsId),
RegistryFixedCodec.of(RegistryKeys.WORLD_PRESET).fieldOf("preset").forGetter(mapConfig -> mapConfig.worldPreset),
RegistryKey.createCodec(RegistryKeys.DIMENSION).optionalFieldOf("dimension_options", DimensionOptions.OVERWORLD).forGetter(mapConfig -> mapConfig.dimensionOptions),
BlockStateProvider.TYPE_CODEC.optionalFieldOf("barrier", BlockStateProvider.of(Blocks.BARRIER)).forGetter(DeathSwapMapConfig::getBarrier),
BlockStateProvider.TYPE_CODEC.optionalFieldOf("top_barrier", BlockStateProvider.of(Main.BARRIER_AIR)).forGetter(DeathSwapMapConfig::getTopBarrier),
Codec.INT.optionalFieldOf("x", 32).forGetter(DeathSwapMapConfig::getX),
Codec.INT.optionalFieldOf("z", 32).forGetter(DeathSwapMapConfig::getZ)
).apply(instance, DeathSwapMapConfig::new);
});

private final RegistryEntry<DimensionType> dimensionType;
private final Identifier chunkGeneratorSettingsId;
private final RegistryEntry<WorldPreset> worldPreset;
private final RegistryKey<DimensionOptions> dimensionOptions;
private final BlockStateProvider barrier;
private final BlockStateProvider topBarrier;
private final int x;
private final int z;

public DeathSwapMapConfig(RegistryEntry<DimensionType> dimensionType, Identifier chunkGeneratorSettingsId, BlockStateProvider barrier, BlockStateProvider topBarrier, int x, int z) {
this.dimensionType = dimensionType;
this.chunkGeneratorSettingsId = chunkGeneratorSettingsId;
public DeathSwapMapConfig(RegistryEntry<WorldPreset> worldPreset, RegistryKey<DimensionOptions> dimensionOptions, BlockStateProvider barrier, BlockStateProvider topBarrier, int x, int z) {
this.worldPreset = worldPreset;
this.dimensionOptions = dimensionOptions;
this.barrier = barrier;
this.topBarrier = topBarrier;
this.x = x;
this.z = z;
}

public RegistryEntry<DimensionType> getDimensionType() {
return this.dimensionType;
}

public Identifier getChunkGeneratorSettingsId() {
return this.chunkGeneratorSettingsId;
public DimensionOptions getDimensionOptions() {
DimensionOptionsRegistryHolder registryHolder = this.worldPreset.value().createDimensionsRegistryHolder();
return registryHolder.dimensions().get(this.dimensionOptions);
}

public BlockStateProvider getBarrier() {
Expand Down
Loading

0 comments on commit 9be6c56

Please sign in to comment.