Skip to content

Commit

Permalink
Update to 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Nov 17, 2024
1 parent 50fdf00 commit 01da820
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 98 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 17
java-version: 21

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
Expand All @@ -26,7 +26,7 @@ jobs:
run: ./gradlew build

- name: Upload build artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Item Hunt
path: build/libs
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'fabric-loom' version '1.7.+'
id 'maven-publish'
}

Expand Down Expand Up @@ -40,7 +40,7 @@ processResources {

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 17
it.options.release = 21
}

base {
Expand All @@ -49,8 +49,8 @@ base {

java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.7
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.1
loader_version=0.16.9

# Mod Properties
mod_version = 1.0
maven_group = io.github.jerozgen
archives_base_name = item-hunt

# Dependencies
fabric_version=0.96.3+1.20.4
plasmid_version=0.5.102-SNAPSHOT+1.20.4
fabric_version=0.106.1+1.21.3
plasmid_version=0.6.0+1.21.3
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/main/java/io/github/jerozgen/itemhunt/ItemHunt.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import io.github.jerozgen.itemhunt.game.ItemHuntGame;
import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.GameType;
import xyz.nucleoid.plasmid.api.game.GameType;

public class ItemHunt implements ModInitializer {
public static final String ID = "itemhunt";

public static Identifier id(String path) {
return new Identifier(ID, path);
return Identifier.of(ID, path);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package io.github.jerozgen.itemhunt.game;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.item.ItemStack;
import net.minecraft.util.dynamic.Codecs;
import net.minecraft.world.dimension.DimensionOptions;
import xyz.nucleoid.codecs.MoreCodecs;
import xyz.nucleoid.plasmid.game.common.config.PlayerConfig;
import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle;
import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig;
import xyz.nucleoid.plasmid.api.game.stats.GameStatisticBundle;

import java.util.List;
import java.util.Optional;

public record ItemHuntConfig(PlayerConfig playerConfig, DimensionOptions dimensionOptions, int duration, int endDuration,
public record ItemHuntConfig(WaitingLobbyConfig playerConfig, DimensionOptions dimensionOptions, int duration, int endDuration,
Optional<String> statisticBundleNamespace, boolean crafting, Optional<List<ItemStack>> startItems) {
public static final Codec<ItemHuntConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group(
PlayerConfig.CODEC.fieldOf("players").forGetter(ItemHuntConfig::playerConfig),
public static final MapCodec<ItemHuntConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(ItemHuntConfig::playerConfig),
DimensionOptions.CODEC.fieldOf("dimension_options").forGetter(ItemHuntConfig::dimensionOptions),
Codecs.POSITIVE_INT.optionalFieldOf("duration", 180).forGetter(ItemHuntConfig::duration),
Codecs.POSITIVE_INT.optionalFieldOf("end_duration", 15).forGetter(ItemHuntConfig::endDuration),
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/io/github/jerozgen/itemhunt/game/ItemHuntGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.fantasy.RuntimeWorldConfig;
import xyz.nucleoid.fantasy.util.VoidChunkGenerator;
import xyz.nucleoid.plasmid.game.GameActivity;
import xyz.nucleoid.plasmid.game.GameOpenContext;
import xyz.nucleoid.plasmid.game.GameOpenProcedure;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.rule.GameRuleType;
import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle;
import xyz.nucleoid.plasmid.api.game.GameActivity;
import xyz.nucleoid.plasmid.api.game.GameOpenContext;
import xyz.nucleoid.plasmid.api.game.GameOpenProcedure;
import xyz.nucleoid.plasmid.api.game.GameSpace;
import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.api.game.rule.GameRuleType;
import xyz.nucleoid.plasmid.api.game.stats.GameStatisticBundle;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;

import java.util.function.Consumer;
Expand All @@ -45,7 +46,7 @@ public static GameOpenProcedure open(GameOpenContext<ItemHuntConfig> context) {
.setSeed(Random.create().nextLong());
var loadingWorldConfig = new RuntimeWorldConfig()
.setDimensionType(DimensionTypes.OVERWORLD)
.setGenerator(new VoidChunkGenerator(context.server().getRegistryManager().get(RegistryKeys.BIOME)))
.setGenerator(new VoidChunkGenerator(context.server().getRegistryManager().getOrThrow(RegistryKeys.BIOME)))
.setWorldConstructor(LazyLoadingWorld::new);
return context.open((activity) -> {
var gameSpace = activity.getGameSpace();
Expand All @@ -67,7 +68,7 @@ public static GameOpenProcedure open(GameOpenContext<ItemHuntConfig> context) {
}

public void setup(GameActivity activity) {
activity.listen(PlayerDamageEvent.EVENT, (player, source, amount) -> ActionResult.FAIL);
activity.listen(PlayerDamageEvent.EVENT, (player, source, amount) -> EventResult.DENY);
activity.listen(StatusEffectAddEvent.EVENT, this::onAddStatusEffect);

if (!config.crafting())
Expand All @@ -77,7 +78,7 @@ public void setup(GameActivity activity) {
}

private ActionResult onAddStatusEffect(Entity entity, StatusEffectInstance instance, @Nullable Entity source) {
if (entity instanceof ServerPlayerEntity && instance.getEffectType().getCategory() == StatusEffectCategory.HARMFUL) {
if (entity instanceof ServerPlayerEntity && instance.getEffectType().value().getCategory() == StatusEffectCategory.HARMFUL) {
return ActionResult.FAIL;
}
return ActionResult.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.plasmid.game.common.widget.GameWidget;
import xyz.nucleoid.plasmid.api.game.common.widget.GameWidget;

import java.util.ArrayList;
import java.util.function.Consumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.text.Text;
import net.minecraft.text.Texts;
import net.minecraft.util.Formatting;
import xyz.nucleoid.plasmid.api.game.config.GameConfig;

import java.util.List;
import java.util.UUID;
Expand All @@ -14,11 +15,11 @@ public final class ItemHuntTexts {
public static final int ACCENT_COLOR = 0xaeffda;

public static MutableText loading() {
return Text.translatable("menu.generatingLevel");
return Text.translatable("multiplayer.downloadingTerrain");
}

public static MutableText description(ItemHuntGame game) {
var gameName = game.gameSpace().getMetadata().sourceConfig().name();
var gameName = GameConfig.name(game.gameSpace().getMetadata().sourceConfig());
return Text.empty().formatted(Formatting.GRAY)
.append("\n").append(gameName.copy()
.formatted(Formatting.BOLD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LazyLoadingWorld extends RuntimeWorld {

protected LazyLoadingWorld(MinecraftServer server, RegistryKey<World> registryKey, RuntimeWorldConfig config, Style style) {
super(server, registryKey, config, style);
var biome = server.getRegistryManager().get(RegistryKeys.BIOME).getEntry(BiomeKeys.THE_VOID).get();
var biome = server.getRegistryManager().getOrThrow(RegistryKeys.BIOME).getOrThrow(BiomeKeys.THE_VOID);
this.chunk = new EmptyChunk(this, ChunkPos.ORIGIN, biome) {
@Override
public BlockState getBlockState(BlockPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ObtainedItemsGui(ServerPlayerEntity player, Text title, List<Item> items)
this.maxPage = (items.size() - 1) / (9 * 5);
this.previousPageButtonBuilder = new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(ItemHuntTexts.guiPreviousPage())
.hideFlags()
.hideDefaultTooltip()
.setSkullOwner(PREVIOUS_PAGE_TEXTURE)
.setCallback(() -> {
if (page > 0) {
Expand All @@ -40,7 +40,7 @@ public ObtainedItemsGui(ServerPlayerEntity player, Text title, List<Item> items)
});
this.nextPageButtonBuilder = new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(ItemHuntTexts.guiNextPage())
.hideFlags()
.hideDefaultTooltip()
.setSkullOwner(NEXT_PAGE_TEXTURE)
.setCallback(() -> {
if (page < maxPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.github.jerozgen.itemhunt.game.ItemHuntSidebarWidget;
import io.github.jerozgen.itemhunt.game.ItemHuntTexts;
import io.github.jerozgen.itemhunt.game.ObtainedItemsGui;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.boss.BossBar;
Expand All @@ -21,16 +23,17 @@
import net.minecraft.text.Text;
import net.minecraft.util.Util;
import net.minecraft.world.GameMode;
import xyz.nucleoid.plasmid.game.GameActivity;
import xyz.nucleoid.plasmid.game.GameCloseReason;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.game.common.widget.BossBarWidget;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
import xyz.nucleoid.plasmid.game.player.PlayerOfferResult;
import xyz.nucleoid.plasmid.game.stats.StatisticKey;
import xyz.nucleoid.plasmid.game.stats.StatisticKeys;
import xyz.nucleoid.plasmid.api.game.GameActivity;
import xyz.nucleoid.plasmid.api.game.GameCloseReason;
import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.api.game.common.widget.BossBarWidget;
import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.api.game.player.JoinAcceptor;
import xyz.nucleoid.plasmid.api.game.player.JoinAcceptorResult;
import xyz.nucleoid.plasmid.api.game.player.JoinOffer;
import xyz.nucleoid.plasmid.api.game.stats.StatisticKey;
import xyz.nucleoid.plasmid.api.game.stats.StatisticKeys;

import java.util.*;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -62,17 +65,18 @@ protected void setupPhase(GameActivity activity) {

activity.listen(GameActivityEvents.ENABLE, this::start);
activity.listen(GameActivityEvents.TICK, this::tick);
activity.listen(GamePlayerEvents.OFFER, this::offerPlayer);
activity.listen(GamePlayerEvents.OFFER, JoinOffer::acceptSpectators);
activity.listen(GamePlayerEvents.ACCEPT, this::acceptPlayer);
activity.listen(GamePlayerEvents.ADD, this::addPlayer);
activity.listen(GamePlayerEvents.LEAVE, this::removePlayer);

activity.listen(InventoryChangedEvent.EVENT, this::onInventoryChanged);
}

private void start() {
singleplayer = game.gameSpace().getPlayers().size() == 1;
singleplayer = game.gameSpace().getPlayers().participants().size() == 1;

for (var player : game.gameSpace().getPlayers()) {
for (var player : game.gameSpace().getPlayers().participants()) {
player.getInventory().clear();
player.playerScreenHandler.getCraftingInput().clear();
player.currentScreenHandler.setCursorStack(ItemStack.EMPTY);
Expand All @@ -87,7 +91,7 @@ private void start() {

game.config().startItems().ifPresent(stacks -> stacks.forEach(stack -> {
var stackCopy = stack.copy();
stackCopy.getOrCreateNbt().putBoolean(START_ITEM_NBT_KEY, true);
stackCopy.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT);
player.getInventory().insertStack(stackCopy);
}));

Expand All @@ -97,16 +101,16 @@ private void start() {
game.stat(stats -> stats.forPlayer(player).increment(StatisticKeys.GAMES_PLAYED, 1));
}

game.world().getEntitiesByType(EntityType.ITEM, Entity::isAlive).forEach(Entity::kill);
game.world().getEntitiesByType(EntityType.ITEM, Entity::isAlive).forEach(x -> x.kill(game.world()));
game.world().getWorldBorder().setSize(99999);

startTime = Util.getMeasuringTimeMs();
endTime = startTime + TimeUnit.SECONDS.toMillis(game.config().duration());
}

private PlayerOfferResult offerPlayer(PlayerOffer offer) {
return offer.accept(game.world(), game.spawnPos().toCenterPos()).and(() -> {
offer.player().changeGameMode(GameMode.SPECTATOR);
private JoinAcceptorResult acceptPlayer(JoinAcceptor offer) {
return offer.teleport(game.world(), game.spawnPos().toCenterPos()).thenRunForEach(player -> {
player.changeGameMode(GameMode.SPECTATOR);
});
}

Expand All @@ -133,7 +137,7 @@ private void tick() {

if (secondsLeft <= 10) {
if (secondsLeft > 0) for (var player : game.gameSpace().getPlayers()) {
player.playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.PLAYERS, .6f, 1);
player.playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.PLAYERS, .6f, 1);
}
else this.end();
}
Expand All @@ -152,7 +156,7 @@ private void end() {
var winnerItems = new ArrayList<>(itemsCollectedByPlayers.get(winner));
var guiTitleText = ItemHuntTexts.guiTitle(winner, server);
var winText = ItemHuntTexts.win(winners, maxSize, singleplayer, server);
for (var player : game.gameSpace().getPlayers()) {
for (var player : game.gameSpace().getPlayers().participants()) {
var isWinner = player.getUuid().equals(winner);
if (singleplayer) {
if (isWinner) player.sendMessage(ItemHuntTexts.winSingleplayer(maxSize));
Expand All @@ -172,7 +176,7 @@ private void end() {
private void onInventoryChanged(ServerPlayerEntity player, PlayerInventory inventory, ItemStack stack) {
if (!itemsCollectedByPlayers.containsKey(player.getUuid())) return;
if (stack.isEmpty()) return;
if (stack.getOrCreateNbt().getBoolean(START_ITEM_NBT_KEY)) return;
if (stack.contains(DataComponentTypes.CUSTOM_DATA)) return;

var collectedItems = itemsCollectedByPlayers.get(player.getUuid());
var item = stack.getItem();
Expand All @@ -183,7 +187,7 @@ private void onInventoryChanged(ServerPlayerEntity player, PlayerInventory inven
new TitleFadeS2CPacket(0, 20, 10),
new TitleS2CPacket(Text.of("")),
new SubtitleS2CPacket(ItemHuntTexts.itemObtained(item)))));
player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_BELL.value(), SoundCategory.PLAYERS, 1, 1);
player.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_BELL.value(), SoundCategory.PLAYERS, 1, 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
import net.minecraft.entity.boss.BossBar;
import net.minecraft.text.Text;
import net.minecraft.util.Util;
import xyz.nucleoid.plasmid.game.GameActivity;
import xyz.nucleoid.plasmid.game.GameCloseReason;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.game.common.widget.BossBarWidget;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
import xyz.nucleoid.plasmid.game.player.PlayerOfferResult;
import xyz.nucleoid.plasmid.api.game.GameActivity;
import xyz.nucleoid.plasmid.api.game.GameCloseReason;
import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.api.game.common.widget.BossBarWidget;
import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents;

import java.util.concurrent.TimeUnit;

Expand All @@ -33,7 +31,7 @@ protected void setupPhase(GameActivity activity) {

activity.listen(GameActivityEvents.ENABLE, this::start);
activity.listen(GameActivityEvents.TICK, this::tick);
activity.listen(GamePlayerEvents.OFFER, this::offerPlayer);
activity.listen(GamePlayerEvents.OFFER, offer -> offer.reject(ItemHuntTexts.finishedError()));
}

private void start() {
Expand All @@ -52,8 +50,4 @@ private void tick() {
if (millisLeft <= 0)
game.gameSpace().close(GameCloseReason.FINISHED);
}

private PlayerOfferResult offerPlayer(PlayerOffer offer) {
return offer.reject(ItemHuntTexts.finishedError());
}
}
Loading

0 comments on commit 01da820

Please sign in to comment.