Skip to content

Commit

Permalink
Update minigame to Minecraft 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Patbox committed Dec 12, 2024
1 parent 0c8956d commit 5484643
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,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
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -33,7 +33,7 @@ jobs:
run: ./gradlew build

- name: Upload GitHub release
uses: AButler/upload-release-assets@v2.0
uses: AButler/upload-release-assets@v3.0
with:
files: 'build/libs/*.jar;!build/libs/*-sources.jar;!build/libs/*-dev.jar'
repo-token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6.+'
id 'fabric-loom' version '1.9.+'
id 'maven-publish'
}

Expand All @@ -18,7 +18,7 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation 'xyz.nucleoid:plasmid:0.5.102-SNAPSHOT+1.20.4'
modImplementation 'xyz.nucleoid:plasmid:0.6.2-SNAPSHOT+1.21.3'
}

processResources {
Expand All @@ -31,14 +31,14 @@ processResources {

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

java {
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.11
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.9
# Mod Properties
mod_version=1.0.0
maven_group=xyz.nucleoid
archives_base_name=slime-mould
# Dependencies
fabric_version=0.97.1+1.20.4
fabric_version=0.110.0+1.21.3
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/xyz/nucleoid/slime_mould/SlimeMould.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.GameType;
import xyz.nucleoid.plasmid.api.game.GameType;
import xyz.nucleoid.slime_mould.game.SlimeMouldConfig;
import xyz.nucleoid.slime_mould.game.SlimeMouldWaiting;

public final class SlimeMould implements ModInitializer {
public static final String ID = "slime_mould";
private static final String ID = "slime_mould";

@Override
public void onInitialize() {
GameType.register(
new Identifier(SlimeMould.ID, "slime_mould"),
SlimeMould.identifier("slime_mould"),
SlimeMouldConfig.CODEC,
SlimeMouldWaiting::open
);
}

public static Identifier identifier(String path) {
return Identifier.of(SlimeMould.ID, path);
}
}
98 changes: 62 additions & 36 deletions src/main/java/xyz/nucleoid/slime_mould/game/SlimeMouldActive.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.mojang.authlib.GameProfile;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.SharedConstants;
import net.minecraft.block.BlockState;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.UseCooldownComponent;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -20,53 +24,59 @@
import net.minecraft.util.DyeColor;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.GameMode;
import org.jetbrains.annotations.Nullable;
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.GameTeam;
import xyz.nucleoid.plasmid.game.common.team.GameTeamConfig;
import xyz.nucleoid.plasmid.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.game.common.widget.SidebarWidget;
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.player.PlayerSet;
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.team.GameTeam;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamConfig;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.api.game.common.widget.SidebarWidget;
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.player.PlayerSet;
import xyz.nucleoid.plasmid.api.game.rule.GameRuleType;
import xyz.nucleoid.plasmid.api.util.ItemStackBuilder;
import xyz.nucleoid.slime_mould.SlimeMould;
import xyz.nucleoid.slime_mould.game.map.SlimeMouldMap;
import xyz.nucleoid.slime_mould.game.map.SlimeMouldPlate;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.block.BlockUseEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Optional;
import java.util.Set;

public final class SlimeMouldActive {
private static final long CLOSE_TICKS = 20 * 5;

private static final Identifier GROWTH_ID = SlimeMould.identifier("growth");
private static final Item GROWTH_ITEM = Items.WOODEN_HOE;

private static final ItemStackBuilder GROWTH_STACK = ItemStackBuilder.of(GROWTH_ITEM)
private static final ItemStack BASE_GROWTH_STACK = ItemStackBuilder.of(GROWTH_ITEM)
.setName(Text.translatable("text.slime_mould.growth_stack.name").formatted(Formatting.GREEN, Formatting.BOLD))
.addLore(Text.translatable("text.slime_mould.growth_stack.description"));
.addLore(Text.translatable("text.slime_mould.growth_stack.description"))
.build();

private static final UUID STRETCHED_THIN_MODIFIER_UUID = UUID.fromString("566d6476-a2ec-43de-9697-b67ca3900bd7");
private static final Identifier STRETCHED_THIN_MODIFIER_ID = SlimeMould.identifier("stretched_thin");

private static final EntityAttributeModifier STRETCHED_THIN_MODIFIER = new EntityAttributeModifier(
STRETCHED_THIN_MODIFIER_UUID,
"slime_mould_stretched_thin",
STRETCHED_THIN_MODIFIER_ID,
-0.5,
EntityAttributeModifier.Operation.MULTIPLY_BASE
EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE
);

private final GameSpace gameSpace;
Expand All @@ -80,6 +90,8 @@ public final class SlimeMouldActive {

private final SlimeMouldFood food;

private final ItemStack growthStack;

private boolean singlePlayer;

private long lastFoodSpawnTime;
Expand All @@ -94,6 +106,15 @@ private SlimeMouldActive(GameActivity activity, ServerWorld world, SlimeMouldMap

this.food = new SlimeMouldFood(activity, world);

if (this.config.growCooldown > 0) {
this.growthStack = BASE_GROWTH_STACK.copy();

UseCooldownComponent useCooldown = new UseCooldownComponent(this.config.growCooldown / (float) SharedConstants.TICKS_PER_SECOND, Optional.of(GROWTH_ID));
this.growthStack.set(DataComponentTypes.USE_COOLDOWN, useCooldown);
} else {
this.growthStack = BASE_GROWTH_STACK;
}

this.sidebar = widgets.addSidebar(Text.translatable("text.slime_mould.sidebar.title").formatted(Formatting.RED, Formatting.BOLD));
}

Expand All @@ -113,12 +134,13 @@ public static void open(GameSpace gameSpace, ServerWorld world, SlimeMouldMap ma

activity.listen(GameActivityEvents.ENABLE, active::onEnable);

activity.listen(GamePlayerEvents.OFFER, active::onOffer);
activity.listen(GamePlayerEvents.ACCEPT, active::onAcceptPlayers);
activity.listen(GamePlayerEvents.OFFER, JoinOffer::acceptSpectators);

activity.listen(GameActivityEvents.TICK, active::tick);
activity.listen(BlockUseEvent.EVENT, active::onUseBlock);

activity.listen(PlayerDamageEvent.EVENT, (player, source, amount) -> ActionResult.FAIL);
activity.listen(PlayerDamageEvent.EVENT, (player, source, amount) -> EventResult.DENY);
});
}

Expand Down Expand Up @@ -156,12 +178,15 @@ private void spawnPlayer(ServerPlayerEntity player, Mould mould, double theta, d
float yaw = (float) Math.toDegrees(theta);

BlockPos spawnPos = this.map.getPlate().getSpawnPos(theta, radius);
player.teleport(this.world, spawnPos.getX() + 0.5, spawnPos.getY() + 1, spawnPos.getZ() + 0.5, yaw, 0.0F);
player.teleport(this.world, spawnPos.getX() + 0.5, spawnPos.getY() + 1, spawnPos.getZ() + 0.5, Set.of(), yaw, 0.0F, true);

this.world.setBlockState(spawnPos, mould.block);

player.getInventory().insertStack(GROWTH_STACK.build());
player.addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, Integer.MAX_VALUE, 200, false, false));
player.getInventory().insertStack(this.growthStack.copy());

EntityAttributeInstance jumpStrength = player.getAttributes().getCustomInstance(EntityAttributes.JUMP_STRENGTH);
jumpStrength.setBaseValue(0);

player.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, Integer.MAX_VALUE, 0, false, false));
}

Expand Down Expand Up @@ -249,12 +274,12 @@ private void onMouldMove(ServerPlayerEntity player, Mould mould, BlockPos pos) {
boolean slowed = surface != mould.block && !this.hasAdjacentMould(pos, mould);

if (mould.updateSlowed(slowed)) {
EntityAttributeInstance attribute = player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED);
EntityAttributeInstance attribute = player.getAttributes().getCustomInstance(EntityAttributes.MOVEMENT_SPEED);
if (attribute != null) {
if (slowed) {
attribute.addTemporaryModifier(STRETCHED_THIN_MODIFIER);
} else {
attribute.removeModifier(STRETCHED_THIN_MODIFIER_UUID);
attribute.removeModifier(STRETCHED_THIN_MODIFIER_ID);
}
}
}
Expand All @@ -277,7 +302,7 @@ private ActionResult onUseBlock(ServerPlayerEntity player, Hand hand, BlockHitRe
}

private boolean tryGrowInto(ServerPlayerEntity player, Mould mould, BlockPos pos) {
if (this.world.getBlockState(pos) == mould.block || player.getItemCooldownManager().isCoolingDown(GROWTH_ITEM)) {
if (this.world.getBlockState(pos) == mould.block || player.getItemCooldownManager().isCoolingDown(this.growthStack)) {
return false;
}

Expand All @@ -295,12 +320,13 @@ private boolean tryGrowInto(ServerPlayerEntity player, Mould mould, BlockPos pos
}

private void growInto(ServerPlayerEntity player, Mould mould, BlockPos pos) {
if (this.config.growCooldown > 0) {
player.getItemCooldownManager().set(GROWTH_ITEM, this.config.growCooldown);
UseCooldownComponent useCooldown = this.growthStack.get(DataComponentTypes.USE_COOLDOWN);
if (useCooldown != null) {
useCooldown.set(this.growthStack, player);
}

if (this.food.removeFoodAt(pos.up())) {
player.playSound(SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 1.0F, 1.0F);
player.playSoundToPlayer(SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 1.0F, 1.0F);
mould.food += this.config.foodLevelPerFood;
}

Expand Down Expand Up @@ -343,9 +369,9 @@ private Mould getMouldFor(BlockState block) {
return null;
}

private PlayerOfferResult onOffer(PlayerOffer offer) {
return offer.accept(this.world, this.map.getWaitingSpawn()).and(() -> {
offer.player().changeGameMode(GameMode.SPECTATOR);
private JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) {
return acceptor.teleport(this.world, this.map.getWaitingSpawn()).thenRunForEach(player -> {
player.changeGameMode(GameMode.SPECTATOR);
});
}

Expand Down
Loading

0 comments on commit 5484643

Please sign in to comment.