Skip to content

Commit

Permalink
Update to 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 committed Dec 8, 2024
1 parent c0f30fc commit 1b144c1
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 191 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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
Expand Down
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
106 changes: 58 additions & 48 deletions src/main/java/com/hugman/the_towers/game/TowersActive.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.hugman.the_towers.game;

import com.hugman.the_towers.config.TowersConfig;
import com.hugman.the_towers.map.TowersMap;
import com.hugman.the_towers.map.TeamRegion;
import com.hugman.the_towers.map.TowersMap;
import com.hugman.the_towers.util.FormattingUtil;
import eu.pb4.holograms.api.Holograms;
import eu.pb4.holograms.api.holograms.AbstractHologram;
import eu.pb4.holograms.api.holograms.WorldHologram;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -40,23 +37,30 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.plasmid.game.GameActivity;
import xyz.nucleoid.plasmid.game.GameCloseReason;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.game.common.team.*;
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.util.ItemStackBuilder;
import xyz.nucleoid.plasmid.api.game.GameActivity;
import xyz.nucleoid.plasmid.api.game.GameCloseReason;
import xyz.nucleoid.plasmid.api.game.GameSpace;
import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.api.game.common.PlayerLimiter;
import xyz.nucleoid.plasmid.api.game.common.team.*;
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.rule.GameRuleType;
import xyz.nucleoid.plasmid.api.util.ItemStackBuilder;
import xyz.nucleoid.plasmid.api.util.PlayerPos;
import xyz.nucleoid.plasmid.api.util.PlayerRef;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.block.BlockBreakEvent;
import xyz.nucleoid.stimuli.event.block.BlockPlaceEvent;
import xyz.nucleoid.stimuli.event.block.BlockUseEvent;
import xyz.nucleoid.stimuli.event.item.ItemThrowEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;

import java.util.Set;

public class TowersActive {
private final GameSpace gameSpace;
private final GameActivity activity;
Expand Down Expand Up @@ -110,6 +114,7 @@ private void fillTeams(TeamSelectionLobby teamSelection) {

public static void enable(GameSpace gameSpace, ServerWorld world, TowersMap map, TowersConfig config, TeamSelectionLobby teamSelection) {
gameSpace.setActivity(activity -> {
PlayerLimiter.addTo(activity, config.playerConfig().playerConfig());
GlobalWidgets widgets = GlobalWidgets.addTo(activity);
TowersSidebar sidebar = TowersSidebar.create(widgets, gameSpace);
TowersActive active = new TowersActive(gameSpace, activity, world, map, config, sidebar, teamSelection);
Expand All @@ -126,7 +131,8 @@ public static void enable(GameSpace gameSpace, ServerWorld world, TowersMap map,
activity.listen(GameActivityEvents.ENABLE, active::enable);
activity.listen(GameActivityEvents.TICK, active::tick);

activity.listen(GamePlayerEvents.OFFER, active::offerPlayer);
activity.listen(GamePlayerEvents.OFFER, JoinOffer::accept);
activity.listen(GamePlayerEvents.ACCEPT, active::accept);

activity.listen(PlayerDeathEvent.EVENT, active::killPlayer);
activity.listen(ItemThrowEvent.EVENT, active::dropItem);
Expand All @@ -142,7 +148,7 @@ private void enable() {

Text[] GUIDE_LINES = {
Text.literal("+--------------------------------------+").formatted(Formatting.DARK_GRAY),
this.gameSpace.getMetadata().sourceConfig().name().copy().formatted(Formatting.BOLD, Formatting.GOLD),
this.gameSpace.getMetadata().sourceConfig().value().name().copy().formatted(Formatting.BOLD, Formatting.GOLD),
Text.translatable("text.the_towers.guide.craft_stuff").formatted(Formatting.WHITE),
Text.translatable("text.the_towers.guide.jumping_into_pool").formatted(Formatting.WHITE),
Text.translatable("text.the_towers.guide.protect_your_pool").formatted(Formatting.WHITE),
Expand All @@ -161,9 +167,10 @@ private void enable() {
this.resetPlayerInventory(player);
}
});
WorldHologram hologram = Holograms.create(this.world, map.teamRegions().get(gameTeam.key()).pool().centerTop().add(0.0D, 0.5D, 0.0D), Text.translatable("text.the_towers.pool", gameTeam.config().name()).formatted(gameTeam.config().chatFormatting()));
hologram.setAlignment(AbstractHologram.VerticalAlign.CENTER);
hologram.show();
//TODO
//WorldHologram hologram = Holograms.create(this.world, map.teamRegions().get(gameTeam.key()).pool().centerTop().add(0.0D, 0.5D, 0.0D), Text.translatable("text.the_towers.pool", gameTeam.config().name()).formatted(gameTeam.config().chatFormatting()));
//hologram.setAlignment(AbstractHologram.VerticalAlign.CENTER);
//hologram.show();
});
}

Expand Down Expand Up @@ -284,22 +291,25 @@ private void checkWin() {
}

// GENERAL PLAYER MANAGEMENT
private PlayerOfferResult offerPlayer(PlayerOffer offer) {
ServerPlayerEntity player = offer.player();

GameTeamKey gameTeamKey = this.teamManager.teamFor(player);
if (gameTeamKey != null) {
TeamData theTowersTeam = teamMap.get(gameTeamKey);
if (theTowersTeam.health > 0) {
return offer.accept(this.world, this.map.teamRegions().get(gameTeamKey).spawn().center()).and(() -> {
private JoinAcceptorResult accept(JoinAcceptor acceptor) {
return acceptor.teleport(profile -> {
GameTeamKey gameTeamKey = this.teamManager.teamFor(PlayerRef.of(profile));
if (gameTeamKey instanceof GameTeamKey) {
return new PlayerPos(this.world, this.map.teamRegions().get(gameTeamKey).spawn().center(), 0.0f, 0.0f);
}
return new PlayerPos(this.world, this.map.spawn(), 0.0f, 0.0f);
}).thenRunForEach(player -> {
GameTeamKey gameTeamKey = this.teamManager.teamFor(player);
if (gameTeamKey instanceof GameTeamKey) {
TeamData theTowersTeam = teamMap.get(gameTeamKey);
if (theTowersTeam.health > 0) {
player.changeGameMode(GameMode.SURVIVAL);
this.resetPlayer(player);
this.resetPlayerInventory(player);
this.spawnPlayerAtTheirSpawn(player);
});
return;
}
}
}
return offer.accept(this.world, this.map.spawn()).and(() -> {
player.changeGameMode(GameMode.SPECTATOR);
this.resetPlayer(player);
this.spawnPlayerAtCenter(player);
Expand All @@ -311,7 +321,7 @@ public void resetPlayerInventory(ServerPlayerEntity player) {
if (gameTeam != null) {
player.equipStack(EquipmentSlot.HEAD, ItemStackBuilder.of(gameTeam.config().applyDye(new ItemStack(Items.LEATHER_HELMET))).setUnbreakable().build());
player.equipStack(EquipmentSlot.CHEST, ItemStackBuilder.of(gameTeam.config().applyDye(new ItemStack(Items.LEATHER_CHESTPLATE))).setUnbreakable().build());
player.equipStack(EquipmentSlot.LEGS, ItemStackBuilder.of(gameTeam.config().applyDye(new ItemStack(Items.LEATHER_LEGGINGS))).addEnchantment(Enchantments.PROJECTILE_PROTECTION, 2).setUnbreakable().build());
player.equipStack(EquipmentSlot.LEGS, ItemStackBuilder.of(gameTeam.config().applyDye(new ItemStack(Items.LEATHER_LEGGINGS))).addEnchantment(this.world, Enchantments.PROJECTILE_PROTECTION, 2).setUnbreakable().build());
player.equipStack(EquipmentSlot.FEET, ItemStackBuilder.of(gameTeam.config().applyDye(new ItemStack(Items.LEATHER_BOOTS))).setUnbreakable().build());
player.getInventory().insertStack(ItemStackBuilder.of(Items.WOODEN_SWORD).build());
player.getInventory().insertStack(ItemStackBuilder.of(Items.WOODEN_PICKAXE).build());
Expand Down Expand Up @@ -346,23 +356,23 @@ public void spawnPlayerAtTheirSpawn(ServerPlayerEntity player) {
}

public void spawnPlayerAt(ServerPlayerEntity player, Vec3d pos, float yaw, float pitch) {
player.teleport(this.world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch);
player.teleport(this.world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), yaw, pitch, false);
player.setVelocity(Vec3d.ZERO);
player.fallDistance = 0.0f;
}

// GENERAL LISTENERS
private ActionResult dropItem(PlayerEntity player, int i, ItemStack stack) {
private EventResult dropItem(PlayerEntity player, int i, ItemStack stack) {
if (canStackBeDropped(stack)) {
return ActionResult.SUCCESS;
return EventResult.ALLOW;
} else {
Text msg = FormattingUtil.format(FormattingUtil.GENERAL_SYMBOL, FormattingUtil.WARNING_STYLE, Text.translatable("text.the_towers.cannot_drop_armor"));
player.sendMessage(msg, false);
return ActionResult.FAIL;
return EventResult.DENY;
}
}

private ActionResult killPlayer(ServerPlayerEntity player, DamageSource source) {
private EventResult killPlayer(ServerPlayerEntity player, DamageSource source) {
TowersParticipant participant = this.participantMap.get(player);
if (participant == null) {
this.spawnPlayerAtCenter(player);
Expand All @@ -380,35 +390,35 @@ private ActionResult killPlayer(ServerPlayerEntity player, DamageSource source)

this.resetPlayer(player);

player.teleport(player.getX(), player.getY() + 1000, player.getZ());
player.networkHandler.sendPacket(new GameStateChangeS2CPacket(new GameStateChangeS2CPacket.Reason(3), 3));
player.teleport(player.getX(), player.getY() + 1000, player.getZ(), false);
player.networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.GAME_MODE_CHANGED, 3));
PlayerAbilities abilities = new PlayerAbilities();
abilities.allowFlying = false;
player.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(abilities));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, (this.config.respawnCooldown() + 1) * 20, 1, true, false));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOW_FALLING, (this.config.respawnCooldown() + 1) * 20, 10, true, false));
}
return ActionResult.FAIL;
return EventResult.DENY;
}

private ActionResult placeBlock(ServerPlayerEntity playerEntity, ServerWorld world, BlockPos pos, BlockState state, ItemUsageContext itemUsageContext) {
private EventResult placeBlock(ServerPlayerEntity playerEntity, ServerWorld world, BlockPos pos, BlockState state, ItemUsageContext itemUsageContext) {
for (BlockBounds bounds : this.map.protectedBounds()) {
if (bounds.contains(pos)) {
Text msg = FormattingUtil.format(FormattingUtil.GENERAL_SYMBOL, FormattingUtil.WARNING_STYLE, Text.translatable("text.the_towers.cannot_place"));
playerEntity.sendMessage(msg, false);
return ActionResult.FAIL;
return EventResult.DENY;
}
}
for (GameTeam team : this.teamMap.keySet()) {
if (team.key() != teamManager.teamFor(playerEntity)) {
if (this.map.teamRegions().get(team.key()).domains().contains(pos.asLong())) {
Text msg = FormattingUtil.format(FormattingUtil.GENERAL_SYMBOL, FormattingUtil.WARNING_STYLE, Text.translatable("text.the_towers.cannot_place"));
playerEntity.sendMessage(msg, false);
return ActionResult.FAIL;
return EventResult.DENY;
}
}
}
return ActionResult.PASS;
return EventResult.PASS;
}

private ActionResult useBlock(ServerPlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
Expand All @@ -433,25 +443,25 @@ private ActionResult useBlock(ServerPlayerEntity playerEntity, Hand hand, BlockH
return ActionResult.PASS;
}

private ActionResult breakBlock(ServerPlayerEntity playerEntity, ServerWorld world, BlockPos pos) {
private EventResult breakBlock(ServerPlayerEntity playerEntity, ServerWorld world, BlockPos pos) {
for (BlockBounds bounds : this.map.protectedBounds()) {
if (bounds.contains(pos)) {
Text msg = FormattingUtil.format(FormattingUtil.GENERAL_SYMBOL, FormattingUtil.WARNING_STYLE, Text.translatable("text.the_towers.cannot_break"));
playerEntity.sendMessage(msg, false);
return ActionResult.FAIL;
return EventResult.DENY;
}
}
for (GameTeam team : this.teamMap.keySet()) {
if (team.key() != teamManager.teamFor(playerEntity)) {
if (this.map.teamRegions().get(team.key()).domains().contains(pos.asLong())) {
Text msg = FormattingUtil.format(FormattingUtil.GENERAL_SYMBOL, FormattingUtil.WARNING_STYLE, Text.translatable("text.the_towers.cannot_break"));
playerEntity.sendMessage(msg, false);
return ActionResult.FAIL;
return EventResult.DENY;
}
}
}

return ActionResult.PASS;
return EventResult.PASS;
}

// UTILITY
Expand Down
12 changes: 7 additions & 5 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,16 @@
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.GameTeam;
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 Down
Loading

0 comments on commit 1b144c1

Please sign in to comment.