Skip to content

Commit

Permalink
Update to 1.21.4 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 authored Dec 18, 2024
2 parents c0f30fc + 83a6385 commit d8a206b
Show file tree
Hide file tree
Showing 21 changed files with 275 additions and 234 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: artifacts
path: build/libs
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

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

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
Expand All @@ -36,7 +36,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

changelog: ${{ github.event.release.body }}
java: 17
java: 21

modrinth-featured: false

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.3-SNAPSHOT"
id "fabric-loom" version "1.9-SNAPSHOT"
id 'maven-publish'
}

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

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

java {
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx1G

# Mod Properties
mod_version=2.1.3
mod_version=2.2.0
maven_group=com.hugman
archives_base_name=the_towers

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.14.22
fabric_version=0.87.0+1.20.1
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.1
loader_version=0.16.9
fabric_version=0.111.0+1.21.4

# check this on https://nucleoid.xyz/use/
plasmid_version=0.5.101-SNAPSHOT+1.20.1
plasmid_version=0.6.3-SNAPSHOT+1.21.4
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
wdistributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/main/java/com/hugman/the_towers/TheTowers.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import xyz.nucleoid.plasmid.game.GameType;
import xyz.nucleoid.plasmid.api.game.GameType;

public class TheTowers implements ModInitializer {
private static final String MOD_ID = "the_towers";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

public static Identifier id(String s) {
return new Identifier(MOD_ID, s);
return Identifier.of(MOD_ID, s);
}

@Override
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/hugman/the_towers/config/TowersConfig.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.hugman.the_towers.config;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.common.config.PlayerConfig;
import xyz.nucleoid.plasmid.game.common.team.GameTeamList;
import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamList;

public record TowersConfig(PlayerConfig playerConfig, GameTeamList teamConfig, Identifier mapTemplateId, int maxHealth,
public record TowersConfig(WaitingLobbyConfig playerConfig, GameTeamList teamConfig, Identifier mapTemplateId,
int maxHealth,
boolean healthStealth, int respawnCooldown, int refillCooldown) {
public static final Codec<TowersConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group(
PlayerConfig.CODEC.fieldOf("players").forGetter(TowersConfig::playerConfig),
public static final MapCodec<TowersConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(TowersConfig::playerConfig),
GameTeamList.CODEC.fieldOf("teams").forGetter(TowersConfig::teamConfig),
Identifier.CODEC.fieldOf("map").forGetter(TowersConfig::mapTemplateId),
Codec.INT.fieldOf("max_health").forGetter(TowersConfig::maxHealth),
Expand Down
190 changes: 108 additions & 82 deletions src/main/java/com/hugman/the_towers/game/TowersActive.java

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions src/main/java/com/hugman/the_towers/game/TowersSidebar.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.game.common.team.GameTeam;
import xyz.nucleoid.plasmid.game.common.widget.SidebarWidget;
import xyz.nucleoid.plasmid.api.game.GameSpace;
import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.api.game.common.team.TeamManager;
import xyz.nucleoid.plasmid.api.game.common.widget.SidebarWidget;

public record TowersSidebar(SidebarWidget sidebarWidget) {
public static TowersSidebar create(GlobalWidgets widgets, GameSpace gameSpace) {
return new TowersSidebar(widgets.addSidebar(gameSpace.getMetadata().sourceConfig().name().copy().formatted(Formatting.BOLD, Formatting.GOLD)));
var gameName = gameSpace.getMetadata().sourceConfig().value().name();
if(gameName == null) gameName = Text.of("The Towers");
return new TowersSidebar(widgets.addSidebar(gameName.copy().formatted(Formatting.BOLD, Formatting.GOLD)));
}

/**
Expand All @@ -22,18 +25,18 @@ public static TowersSidebar create(GlobalWidgets widgets, GameSpace gameSpace) {
* @param time the game's time in ticks
* @param teamMap the map of team
*/
public void update(long time, long nextRefillTick, Object2ObjectMap<GameTeam, TeamData> teamMap) {
public void update(long time, long nextRefillTick, TeamManager teamManager, Object2ObjectMap<GameTeamKey, TeamData> teamMap) {
sidebarWidget.set(content -> {
content.add(Text.literal(""));
teamMap.forEach((gameTeam, team) -> {
teamMap.forEach((teamKey, team) -> {
MutableText text = Text.literal("");
if (team.health > 0) {
text.append(gameTeam.config().name().copyContentOnly().formatted(Formatting.BOLD))
text.append(teamManager.getTeamConfig(teamKey).name().copy().formatted(Formatting.BOLD))
.append(Text.literal(" " + FormattingUtil.GENERAL_SYMBOL + " ").formatted(Formatting.GRAY))
.append(Text.literal(String.valueOf(team.health)).formatted(Formatting.WHITE))
.append(Text.literal(FormattingUtil.HEALTH_SYMBOL).formatted(Formatting.GREEN));
} else {
text.append(gameTeam.config().name().copyContentOnly().formatted(Formatting.DARK_GRAY, Formatting.BOLD))
text.append(teamManager.getTeamConfig(teamKey).name().copy().formatted(Formatting.DARK_GRAY, Formatting.BOLD))
.append(Text.literal(" " + FormattingUtil.GENERAL_SYMBOL + " ").formatted(Formatting.GRAY))
.append(Text.literal(FormattingUtil.X_SYMBOL).formatted(Formatting.DARK_GRAY));
}
Expand Down
67 changes: 33 additions & 34 deletions src/main/java/com/hugman/the_towers/game/TowersWaiting.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,32 @@
import com.hugman.the_towers.config.TowersConfig;
import com.hugman.the_towers.map.TowersMap;
import com.hugman.the_towers.map.TowersMapGenerator;
import eu.pb4.holograms.api.Holograms;
import eu.pb4.holograms.api.holograms.AbstractHologram;
import eu.pb4.holograms.api.holograms.WorldHologram;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ChunkTicketType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import xyz.nucleoid.plasmid.game.GameOpenContext;
import xyz.nucleoid.plasmid.game.GameOpenProcedure;
import xyz.nucleoid.plasmid.game.GameResult;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.common.GameWaitingLobby;
import xyz.nucleoid.plasmid.game.common.team.TeamSelectionLobby;
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.rule.GameRuleType;
import xyz.nucleoid.plasmid.api.game.GameOpenContext;
import xyz.nucleoid.plasmid.api.game.GameOpenProcedure;
import xyz.nucleoid.plasmid.api.game.GameResult;
import xyz.nucleoid.plasmid.api.game.GameSpace;
import xyz.nucleoid.plasmid.api.game.common.GameWaitingLobby;
import xyz.nucleoid.plasmid.api.game.common.team.TeamSelectionLobby;
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.rule.GameRuleType;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.player.PlayerAttackEntityEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;

import java.util.Set;

public record TowersWaiting(GameSpace gameSpace, ServerWorld world, TowersMap map, TowersConfig config,
TeamSelectionLobby teamSelection) {
public static GameOpenProcedure open(GameOpenContext<TowersConfig> context) {
Expand All @@ -44,57 +41,59 @@ public static GameOpenProcedure open(GameOpenContext<TowersConfig> context) {
TeamSelectionLobby teamSelection = TeamSelectionLobby.addTo(activity, config.teamConfig());
TowersWaiting waiting = new TowersWaiting(activity.getGameSpace(), world, map, context.config(), teamSelection);

activity.setRule(GameRuleType.INTERACTION, ActionResult.FAIL);
activity.setRule(GameRuleType.INTERACTION, EventResult.DENY);

activity.listen(GameActivityEvents.ENABLE, waiting::enable);

activity.listen(GamePlayerEvents.OFFER, waiting::offerPlayer);
activity.listen(GamePlayerEvents.ACCEPT, waiting::offerPlayer);

activity.listen(GameActivityEvents.REQUEST_START, waiting::requestStart);

activity.listen(PlayerDamageEvent.EVENT, (player, source, amount) -> ActionResult.FAIL);
activity.listen(PlayerDamageEvent.EVENT, (player, source, amount) -> EventResult.DENY);
activity.listen(PlayerDeathEvent.EVENT, waiting::killPlayer);
activity.listen(PlayerAttackEntityEvent.EVENT, (attacker, hand, attacked, hitResult) -> ActionResult.FAIL);
activity.listen(PlayerAttackEntityEvent.EVENT, (attacker, hand, attacked, hitResult) -> EventResult.DENY);
});
}

private void enable() {
var gameName = this.gameSpace.getMetadata().sourceConfig().value().name();
if(gameName == null) gameName = Text.of("The Towers");
Text[] GUIDE_LINES = {
this.gameSpace.getMetadata().sourceConfig().name().copy().formatted(Formatting.BOLD, Formatting.GOLD),
gameName.copy().formatted(Formatting.BOLD, Formatting.GOLD),
Text.translatable("text.the_towers.guide.craft_stuff").formatted(Formatting.YELLOW),
Text.translatable("text.the_towers.guide.jumping_into_pool").formatted(Formatting.YELLOW),
Text.translatable("text.the_towers.guide.protect_your_pool").formatted(Formatting.YELLOW),
};

Vec3d pos = this.map.rules();
this.world.getChunk(BlockPos.ofFloored(pos));
WorldHologram hologram = Holograms.create(this.world, pos, GUIDE_LINES);
hologram.setAlignment(AbstractHologram.VerticalAlign.TOP);
hologram.show();
//TODO
// WorldHologram hologram = Holograms.create(this.world, pos, GUIDE_LINES);
// hologram.setAlignment(AbstractHologram.VerticalAlign.TOP);
// hologram.show();
}

private GameResult requestStart() {
TowersActive.enable(this.gameSpace, this.world, this.map, this.config, this.teamSelection);
return GameResult.ok();
}

private PlayerOfferResult offerPlayer(PlayerOffer offer) {
return offer.accept(this.world, this.map.spawn()).and(() -> {
ServerPlayerEntity player = offer.player();
player.changeGameMode(GameMode.ADVENTURE);
private JoinAcceptorResult offerPlayer(JoinAcceptor acceptor) {
return acceptor.teleport(this.world, this.map.spawn()).thenRun((players) -> {
players.forEach((player) -> {
player.changeGameMode(GameMode.ADVENTURE);
});
});
}

private ActionResult killPlayer(ServerPlayerEntity player, DamageSource source) {
private EventResult killPlayer(ServerPlayerEntity player, DamageSource source) {
player.setHealth(20.0f);
this.tpPlayer(player);
return ActionResult.FAIL;
return EventResult.DENY;
}

private void tpPlayer(ServerPlayerEntity player) {
var pos = this.map.spawn();
ChunkPos chunkPos = new ChunkPos((int) pos.getX() >> 4, (int) pos.getZ() >> 4);
this.world.getChunkManager().addTicket(ChunkTicketType.POST_TELEPORT, chunkPos, 1, player.getId());
player.teleport(this.world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0.0F, 0.0F);
player.teleport(this.world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, Set.of(), 0.0F, 0.0F, false);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/hugman/the_towers/map/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import net.minecraft.text.Text;
import net.minecraft.util.math.Vec3d;
import xyz.nucleoid.map_templates.TemplateRegion;
import xyz.nucleoid.plasmid.game.GameOpenContext;
import xyz.nucleoid.plasmid.game.GameOpenException;
import xyz.nucleoid.plasmid.api.game.GameOpenContext;
import xyz.nucleoid.plasmid.api.game.GameOpenException;

public record Generator(GeneratorConfig type, Vec3d pos) {
public static final String CONFIG_KEY = "Type"; // we should use something else
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/hugman/the_towers/map/TeamRegion.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.hugman.the_towers.map;

import com.hugman.the_towers.TheTowers;
import it.unimi.dsi.fastutil.longs.LongArraySet;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.text.Text;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.map_templates.MapTemplateMetadata;
import xyz.nucleoid.map_templates.TemplateRegion;
import xyz.nucleoid.plasmid.game.GameOpenException;
import xyz.nucleoid.plasmid.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.api.game.GameOpenException;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey;

import java.util.Objects;

Expand All @@ -28,7 +29,7 @@ public static TeamRegion fromTemplate(GameTeamKey teamKey, MapTemplateMetadata m
BlockBounds pool = Objects.requireNonNull(poolRegion).getBounds();

LongSet domains = new LongArraySet();
metadata.getRegionBounds(teamKey + "_domain").forEach(blockPos -> blockPos.forEach(pos -> domains.add(pos.asLong())));
metadata.getRegionBounds(teamKey.id() + "_domain").forEach(blockPos -> blockPos.forEach(pos -> domains.add(pos.asLong())));

return new TeamRegion(spawn, pool, domains, spawnYaw, spawnPitch);
} catch (NullPointerException e) {
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/com/hugman/the_towers/map/TowersMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@
import xyz.nucleoid.map_templates.MapTemplate;
import xyz.nucleoid.map_templates.MapTemplateMetadata;
import xyz.nucleoid.map_templates.TemplateRegion;
import xyz.nucleoid.plasmid.game.GameOpenContext;
import xyz.nucleoid.plasmid.game.common.team.GameTeam;
import xyz.nucleoid.plasmid.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.game.world.generator.TemplateChunkGenerator;
import xyz.nucleoid.plasmid.api.game.GameOpenContext;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeam;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.api.game.world.generator.TemplateChunkGenerator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public record TowersMap(MapTemplate template, Vec3d spawn, Vec3d rules, List<BlockBounds> protectedBounds,
List<Generator> generators, Map<GameTeamKey, TeamRegion> teamRegions,
RuntimeWorldConfig worldConfig) {
public record TowersMap(
MapTemplate template,
Vec3d spawn,
Vec3d rules,
List<BlockBounds> protectedBounds,
List<Generator> generators,
Map<GameTeamKey, TeamRegion> teamRegions,
RuntimeWorldConfig worldConfig
) {
/**
* Creates the map from a map template by reading its metadata.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import net.minecraft.text.Text;
import xyz.nucleoid.map_templates.MapTemplate;
import xyz.nucleoid.map_templates.MapTemplateSerializer;
import xyz.nucleoid.plasmid.game.GameOpenContext;
import xyz.nucleoid.plasmid.game.GameOpenException;
import xyz.nucleoid.plasmid.api.game.GameOpenContext;
import xyz.nucleoid.plasmid.api.game.GameOpenException;

import java.io.IOException;

Expand Down
Loading

0 comments on commit d8a206b

Please sign in to comment.