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 committed Nov 20, 2024
1 parent ce5a276 commit 25e35f8
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 138 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.gradle/loom-cache
~/.gradle/caches
key: gradle-${{hashFiles('**/*.gradle*')}}
restore-keys: gradle-
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 17
cache: gradle
distribution: microsoft
java-version: 21
- name: Build with Gradle
run: gradle build
- name: Upload Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: artifacts
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.7.2"
id "fabric-loom" version "1.8.12"
id "maven-publish"
}

Expand Down Expand Up @@ -40,12 +40,12 @@ processResources {
}

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

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

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.20.4
yarn_mappings = 1.20.4+build.3
loader_version = 0.15.11
fabric_version = 0.97.1+1.20.4
minecraft_version = 1.21.3
yarn_mappings = 1.21.3+build.2
loader_version = 0.16.9
fabric_version = 0.109.0+1.21.3

plasmid_version = 0.5.102-SNAPSHOT+1.20.4
plasmid_version = 0.6.0+1.21.3
10 changes: 7 additions & 3 deletions src/main/java/io/github/haykam821/volleyball/Volleyball.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import io.github.haykam821.volleyball.game.phase.VolleyballWaitingPhase;
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 Volleyball implements ModInitializer {
public static final String MOD_ID = "volleyball";
private static final String MOD_ID = "volleyball";

private static final Identifier VOLLEYBALL_ID = new Identifier(MOD_ID, "volleyball");
private static final Identifier VOLLEYBALL_ID = Volleyball.identifier("volleyball");
public static final GameType<VolleyballConfig> VOLLEYBALL_TYPE = GameType.register(VOLLEYBALL_ID, VolleyballConfig.CODEC, VolleyballWaitingPhase::open);

@Override
public void onInitialize() {
VolleyballEntityTypes.register();
}

public static Identifier identifier(String path) {
return Identifier.of(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import xyz.nucleoid.packettweaker.PacketContext;

public class BallEntity extends HittableEntity implements PolymerEntity {
private static final String BALL_TEXTURE = encodeTexture("9efb0547d31598b9359a66dc24d5d9d9771c37cd1492a90c9d6eaa2bac36b0e9");
Expand Down Expand Up @@ -75,6 +76,7 @@ public Vec3d getPos() {
this.interaction.setHeight(this.getHeight());

this.holder.addElement(this.interaction);
this.interaction.ignorePositionUpdates();

VirtualEntityUtils.addVirtualPassenger(this, this.interaction.getEntityId());
} else {
Expand Down Expand Up @@ -166,7 +168,7 @@ public void remove(RemovalReason reason) {
}

@Override
public EntityType<?> getPolymerEntityType(ServerPlayerEntity player) {
public EntityType<?> getPolymerEntityType(PacketContext context) {
return EntityType.ARMOR_STAND;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.projectile.WitherSkullEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.DamageTypeTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Arm;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
Expand Down Expand Up @@ -71,7 +74,7 @@ public HittableEntity(EntityType<? extends HittableEntity> type, World world, Ba
if (this.config.displayType().isPresent()) {
float eyeHeight;
try {
eyeHeight = this.config.displayType().get().create(world).getStandingEyeHeight();
eyeHeight = this.config.displayType().get().create(world, SpawnReason.SPAWNER).getStandingEyeHeight();
} catch (Exception exception) {
eyeHeight = this.getStandingEyeHeight();
}
Expand All @@ -87,17 +90,12 @@ public float getSize() {
}

@Override
public EntityDimensions getDimensions(EntityPose pose) {
return super.getDimensions(pose).scaled(this.getSize());
public EntityDimensions getBaseDimensions(EntityPose pose) {
return super.getBaseDimensions(pose).scaled(this.getSize());
}

@Override
protected float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
return super.getActiveEyeHeight(pose, dimensions) * this.getSize();
}

@Override
public boolean hasStatusEffect(StatusEffect effect) {
public boolean hasStatusEffect(RegistryEntry<StatusEffect> effect) {
return effect == StatusEffects.SLOW_FALLING || super.hasStatusEffect(effect);
}

Expand Down Expand Up @@ -153,9 +151,9 @@ private void alignToGround() {
}

@Override
public boolean damage(DamageSource source, float amount) {
public boolean damage(ServerWorld world, DamageSource source, float amount) {
if (source.isIn(DamageTypeTags.BYPASSES_INVULNERABILITY)) {
return super.damage(source, amount);
return super.damage(world, source, amount);
}

if (source.getAttacker() != null && source.getAttacker() != this) {
Expand All @@ -176,9 +174,9 @@ public boolean damage(DamageSource source, float amount) {

private void shootSkullAt(Entity target) {
Vec3d skullPos = this.getSkullPos();
Vec3d direction = target.getPos().subtract(skullPos);
Vec3d direction = target.getPos().subtract(skullPos).normalize();

WitherSkullEntity skull = new WitherSkullEntity(this.getWorld(), this, direction.getX(), direction.getY(), direction.getZ());
WitherSkullEntity skull = new WitherSkullEntity(this.getWorld(), this, direction);
skull.setPos(skullPos.getX(), skullPos.getY(), skullPos.getZ());

if (this.getWorld().getRandom().nextInt(1000) == 0) {
Expand All @@ -194,7 +192,7 @@ protected Vec3d getSkullPos() {
}

@Override
protected void drop(DamageSource source) {
protected void drop(ServerWorld world, DamageSource source) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
import net.minecraft.entity.SpawnGroup;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;

public final class VolleyballEntityTypes {
private static final Identifier BALL_ID = new Identifier(Volleyball.MOD_ID, "ball");
private static final Identifier BALL_ID = Volleyball.identifier("ball");
private static final RegistryKey<EntityType<?>> BALL_KEY = RegistryKey.of(RegistryKeys.ENTITY_TYPE, BALL_ID);

public static final EntityType<BallEntity> BALL = EntityType.Builder.<BallEntity>create(BallEntity::new, SpawnGroup.MISC)
.setDimensions(8 / 16f, 8 / 16f)
.build();
.dimensions(8 / 16f, 8 / 16f)
.build(BALL_KEY);

private VolleyballEntityTypes() {
return;
}

public static void register() {
Registry.register(Registries.ENTITY_TYPE, BALL_ID, BALL);
Registry.register(Registries.ENTITY_TYPE, BALL_KEY, BALL);

PolymerEntityUtils.registerType(BALL);
FabricDefaultAttributeRegistry.register(BALL, LivingEntity.createLivingAttributes());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package io.github.haykam821.volleyball.game;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import io.github.haykam821.volleyball.entity.BallEntityConfig;
import net.minecraft.SharedConstants;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.intprovider.ConstantIntProvider;
import net.minecraft.util.math.intprovider.IntProvider;
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 class VolleyballConfig {
public static final Codec<VolleyballConfig> CODEC = RecordCodecBuilder.create(instance -> {
public static final MapCodec<VolleyballConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> {
return instance.group(
Identifier.CODEC.fieldOf("map").forGetter(VolleyballConfig::getMap),
PlayerConfig.CODEC.fieldOf("players").forGetter(VolleyballConfig::getPlayerConfig),
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(VolleyballConfig::getPlayerConfig),
GameTeamList.CODEC.fieldOf("teams").forGetter(VolleyballConfig::getTeams),
BallEntityConfig.CODEC.optionalFieldOf("ball_entity", BallEntityConfig.DEFAULT).forGetter(VolleyballConfig::getBallEntityConfig),
IntProvider.NON_NEGATIVE_CODEC.optionalFieldOf("ticks_until_close", ConstantIntProvider.create(SharedConstants.TICKS_PER_SECOND * 5)).forGetter(VolleyballConfig::getTicksUntilClose),
Expand All @@ -26,15 +27,15 @@ public class VolleyballConfig {
});

private final Identifier map;
private final PlayerConfig playerConfig;
private final WaitingLobbyConfig playerConfig;
private final GameTeamList teams;
private final BallEntityConfig ballEntityConfig;
private final int requiredScore;
private final int resetBallTicks;
private final int inactiveBallTicks;
private final IntProvider ticksUntilClose;

public VolleyballConfig(Identifier map, PlayerConfig playerConfig, GameTeamList teams, BallEntityConfig ballEntityConfig, IntProvider ticksUntilClose, int requiredScore, int resetBallTicks, int inactiveBallTicks) {
public VolleyballConfig(Identifier map, WaitingLobbyConfig playerConfig, GameTeamList teams, BallEntityConfig ballEntityConfig, IntProvider ticksUntilClose, int requiredScore, int resetBallTicks, int inactiveBallTicks) {
this.map = map;
this.playerConfig = playerConfig;
this.teams = teams;
Expand All @@ -49,7 +50,7 @@ public Identifier getMap() {
return this.map;
}

public PlayerConfig getPlayerConfig() {
public WaitingLobbyConfig getPlayerConfig() {
return this.playerConfig;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package io.github.haykam821.volleyball.game.map;

import java.util.Set;

import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import xyz.nucleoid.map_templates.MapTemplate;
import xyz.nucleoid.map_templates.TemplateRegion;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
import xyz.nucleoid.plasmid.game.player.PlayerOfferResult;
import xyz.nucleoid.plasmid.game.world.generator.TemplateChunkGenerator;
import xyz.nucleoid.plasmid.api.game.player.JoinAcceptor;
import xyz.nucleoid.plasmid.api.game.player.JoinAcceptorResult;
import xyz.nucleoid.plasmid.api.game.world.generator.TemplateChunkGenerator;

public class VolleyballMap {
public static final String FACING_KEY = "Facing";
Expand Down Expand Up @@ -43,10 +44,10 @@ public void spawnAtWaiting(ServerWorld world, Entity entity) {
this.spawn(world, entity, this.getWaitingSpawnPos());
}

public PlayerOfferResult acceptOffer(PlayerOffer offer, ServerWorld world, GameMode gameMode) {
return offer.accept(world, this.getWaitingSpawnPos()).and(() -> {
offer.player().setYaw(this.getWaitingSpawnYaw());
offer.player().changeGameMode(gameMode);
public JoinAcceptorResult acceptJoins(JoinAcceptor acceptor, ServerWorld world, GameMode gameMode) {
return acceptor.teleport(world, this.getWaitingSpawnPos()).thenRunForEach(player -> {
player.setYaw(this.getWaitingSpawnYaw());
player.changeGameMode(gameMode);
});
}

Expand All @@ -60,14 +61,7 @@ public void spawnAtBall(ServerWorld world, Entity entity) {

private void spawn(ServerWorld world, Entity entity, Vec3d pos) {
float yaw = this.getWaitingSpawnYaw();

if (entity instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) entity;
player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), yaw, 0);
} else {
entity.teleport(pos.getX(), pos.getY(), pos.getZ());
entity.setYaw(yaw);
}
entity.teleport(world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), yaw, 0, true);
}

private TemplateRegion getSpawnRegion(String type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.text.Text;
import xyz.nucleoid.map_templates.MapTemplate;
import xyz.nucleoid.map_templates.MapTemplateSerializer;
import xyz.nucleoid.plasmid.game.GameOpenException;
import xyz.nucleoid.plasmid.api.game.GameOpenException;

public class VolleyballMapBuilder {
private final VolleyballConfig config;
Expand Down
Loading

0 comments on commit 25e35f8

Please sign in to comment.