Skip to content

Commit

Permalink
Add DoubleRunner (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 authored Nov 17, 2024
2 parents 45cae6b + 22d63f9 commit 88f05c1
Show file tree
Hide file tree
Showing 50 changed files with 1,247 additions and 110 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ loader_version=0.16.9
fabric_version=0.108.0+1.21.3

# check this on https://nucleoid.xyz/use/
plasmid_version=0.6.0-SNAPSHOT+1.21.3
plasmid_version=0.6.0+1.21.3
1 change: 1 addition & 0 deletions src/main/java/com/hugman/uhc/config/UHCConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public List<Modifier> getModifiers() {
}

public <V extends Modifier> List<V> getModifiers(ModifierType<V> type) {
//TODO: cache modules so it's quicker to sort by type
List<V> modifiers = new ArrayList<>();
for (var moduleEntry : modules) {
for (Modifier modifier : moduleEntry.value().modifiers()) {
Expand Down
36 changes: 20 additions & 16 deletions src/main/java/com/hugman/uhc/game/phase/UHCActive.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket;
import net.minecraft.network.packet.s2c.play.WorldBorderInitializeS2CPacket;
import net.minecraft.network.packet.s2c.play.WorldBorderInterpolateSizeS2CPacket;
import net.minecraft.scoreboard.AbstractTeam;
Expand Down Expand Up @@ -46,6 +47,7 @@
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.block.BlockBreakEvent;
import xyz.nucleoid.stimuli.event.block.BlockDropItemsEvent;
import xyz.nucleoid.stimuli.event.entity.EntityDamageEvent;
import xyz.nucleoid.stimuli.event.entity.EntityDropItemsEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;
Expand Down Expand Up @@ -304,20 +306,6 @@ private void playerLeave(ServerPlayerEntity player) {
}
}

private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
if (participants.containsKey(player)) {
if (!getParticipant(player).isEliminated()) {
PlayerSet players = this.gameSpace.getPlayers();
players.sendMessage(Text.literal("\n☠ ").append(source.getDeathMessage(player).copy()).append("!\n").formatted(Formatting.DARK_RED));
players.playSound(SoundEvents.ENTITY_WITHER_SPAWN);
this.eliminateParticipant(player);
return EventResult.DENY;
}
}
this.spawnLogic.spawnPlayerAtCenter(player);
return EventResult.DENY;
}

private void eliminateParticipant(ServerPlayerEntity player) {
ItemScatterer.spawn(player.getWorld(), player.getBlockPos(), player.getInventory());
player.changeGameMode(GameMode.SPECTATOR);
Expand Down Expand Up @@ -345,8 +333,9 @@ public void clearPlayer(ServerPlayerEntity player) {

public void refreshPlayerAttributes(ServerPlayerEntity player) {
for (PlayerAttributeModifier piece : this.config.getModifiers(ModifierType.PLAYER_ATTRIBUTE)) {
piece.setAttribute(player);
piece.refreshAttribute(player);
}
player.networkHandler.sendPacket(new EntityAttributesS2CPacket(player.getId(), player.getAttributes().getTracked()));
}

public void applyPlayerEffects(ServerPlayerEntity player) {
Expand Down Expand Up @@ -393,6 +382,7 @@ private void checkForWinner() {
private void setInvulnerable(boolean b) {
this.invulnerable = b;
this.activity.setRule(GameRuleType.HUNGER, b ? EventResult.DENY : EventResult.ALLOW);
//TODO check modules
this.activity.setRule(GameRuleType.FALL_DAMAGE, b ? EventResult.DENY : EventResult.ALLOW);
}

Expand Down Expand Up @@ -461,7 +451,7 @@ private void sendWarning(String s, Object... args) {
public void sendModuleListToChat() {
var moduleEntries = this.config.modules();
if (moduleEntries.size() > 0) {
MutableText text = Text.literal("\n").append(Text.translatable("text.uhc.modules_enabled").formatted(Formatting.GOLD));
MutableText text = Text.literal("\n").append(Text.translatable("text.uhc.enabled_modules").formatted(Formatting.GOLD));
moduleEntries.forEach(moduleEntry -> {
var module = moduleEntry.value();
Style style = Style.EMPTY;
Expand All @@ -486,6 +476,20 @@ private EventResult onPlayerDamage(ServerPlayerEntity entity, DamageSource damag
}
}

private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
if (participants.containsKey(player)) {
if (!getParticipant(player).isEliminated()) {
PlayerSet players = this.gameSpace.getPlayers();
players.sendMessage(Text.literal("\n☠ ").append(source.getDeathMessage(player).copy()).append("!\n").formatted(Formatting.DARK_RED));
players.playSound(SoundEvents.ENTITY_WITHER_SPAWN);
this.eliminateParticipant(player);
return EventResult.DENY;
}
}
this.spawnLogic.spawnPlayerAtCenter(player);
return EventResult.DENY;
}

private EventResult onBlockBroken(ServerPlayerEntity playerEntity, ServerWorld world, BlockPos pos) {
for (TraversalBreakModifier piece : this.config.getModifiers(ModifierType.TRAVERSAL_BREAK)) {
piece.breakBlock(this.world, playerEntity, pos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package com.hugman.uhc.modifier;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.ServerPlayerEntity;

public record PlayerAttributeModifier(RegistryEntry<EntityAttribute> attribute, double value) implements Modifier {
public record PlayerAttributeModifier(
RegistryEntry<EntityAttribute> attribute,
EntityAttributeModifier modifier
) implements Modifier {
public static final MapCodec<PlayerAttributeModifier> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
EntityAttribute.CODEC.fieldOf("attribute").forGetter(PlayerAttributeModifier::attribute),
Codec.doubleRange(0.0F, Double.MAX_VALUE).fieldOf("value").forGetter(PlayerAttributeModifier::value)
EntityAttributeModifier.MAP_CODEC.forGetter(PlayerAttributeModifier::modifier)
).apply(instance, PlayerAttributeModifier::new));

@Override
public ModifierType<?> getType() {
return ModifierType.PLAYER_ATTRIBUTE;
}

public void setAttribute(ServerPlayerEntity player) {
public void refreshAttribute(ServerPlayerEntity player) {
EntityAttributeInstance instance = player.getAttributes().getCustomInstance(this.attribute);
if (instance != null) {
instance.setBaseValue(value);
player.networkHandler.sendPacket(new EntityAttributesS2CPacket(player.getId(), player.getAttributes().getTracked()));
instance.removeModifier(modifier);
instance.addPersistentModifier(modifier);
}
}
}
41 changes: 41 additions & 0 deletions src/main/resources/data/doublerunner/game_portals/standard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"type": "nucleoid_extras:styled/advanced_menu",
"name": {
"translate": "game.doublerunner"
},
"icon": "minecraft:enchanted_golden_apple",
"entries": [
{
"type": "plasmid:game",
"icon": "minecraft:red_candle",
"game": "doublerunner:solo",
"name": {
"translate": "mode.solo"
}
},
{
"type": "plasmid:game",
"icon": "minecraft:lime_candle",
"game": "doublerunner:duos",
"name": {
"translate": "mode.duos"
}
},
{
"type": "plasmid:game",
"icon": "minecraft:pink_candle",
"game": "doublerunner:trios",
"name": {
"translate": "mode.trios"
}
},
{
"type": "plasmid:game",
"icon": "minecraft:blue_candle",
"game": "doublerunner:squads",
"name": {
"translate": "mode.squads"
}
}
]
}
20 changes: 20 additions & 0 deletions src/main/resources/data/doublerunner/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"game.doublerunner": "DoubleRunner",

"module.doublerunner.blasted_ores_plus": "Blasted Ores+",
"module.doublerunner.dasher_plus": "Dasher+",
"module.doublerunner.dasher_plus.description": "Permanent haste and speed, and no fall damage",
"module.doublerunner.faster_resources_plus": "Faster Resources+",
"module.doublerunner.guaranteed_golden_apples": "Guaranteed Golden Apples",
"module.doublerunner.guaranteed_golden_apples.description": "All leaves only drop golden apples",
"module.doublerunner.ore_boost_plus": "Ore Boost+",
"module.doublerunner.potion_drops": "Potion Drops",
"module.doublerunner.potion_drops.description": "Some entities drop potions",
"module.doublerunner.timberman.description": "Trees get cut instantly and drop oak planks",

"module_description.doublerunner.zombies_drop_strength_potions": "Zombies drops potions of Strength",
"module_description.doublerunner.spiders_drop_poison_potions": "Spiders drops potions of Poison",
"module_description.doublerunner.sugar_cane_drops_swiftness_potions": "Sugar cane drops potions of Swiftness",
"module_description.doublerunner.rabbits_drop_leaping_potions": "Rabbits drops potions of Leaping",
"module_description.doublerunner.bats_drop_night_vision_potions": "Bats drops potions of Night Vision"
}
44 changes: 44 additions & 0 deletions src/main/resources/data/doublerunner/plasmid/game/duos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "uhc:standard",
"name": {
"translate": "game.generic.mode",
"with": [
{
"translate": "game.doublerunner"
},
{
"translate": "mode.duos"
}
]
},
"team_size": 2,
"players": {
"min": 4,
"threshold": 16
},
"map": {
"dimension": {
"type": "minecraft:overworld",
"generator": {
"type": "minecraft:noise",
"settings": "minecraft:overworld",
"biome_source": {
"type": "minecraft:multi_noise",
"preset": "minecraft:overworld"
}
}
},
"shrinking_speed": 0.6,
"start_size": {
"min": 200,
"max": 8000
}
},
"chapters": {
"warmup": {
"min": 600,
"max": 800
}
},
"modules": "#doublerunner:standard"
}
44 changes: 44 additions & 0 deletions src/main/resources/data/doublerunner/plasmid/game/solo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "uhc:standard",
"name": {
"translate": "game.generic.mode",
"with": [
{
"translate": "game.doublerunner"
},
{
"translate": "mode.solo"
}
]
},
"team_size": 1,
"players": {
"min": 2,
"threshold": 8
},
"map": {
"dimension": {
"type": "minecraft:overworld",
"generator": {
"type": "minecraft:noise",
"settings": "minecraft:overworld",
"biome_source": {
"type": "minecraft:multi_noise",
"preset": "minecraft:overworld"
}
}
},
"shrinking_speed": 0.6,
"start_size": {
"min": 200,
"max": 8000
}
},
"chapters": {
"warmup": {
"min": 600,
"max": 800
}
},
"modules": "#doublerunner:standard"
}
44 changes: 44 additions & 0 deletions src/main/resources/data/doublerunner/plasmid/game/squads.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "uhc:standard",
"name": {
"translate": "game.generic.mode",
"with": [
{
"translate": "game.doublerunner"
},
{
"translate": "mode.squads"
}
]
},
"team_size": 4,
"players": {
"min": 8,
"threshold": 32
},
"map": {
"dimension": {
"type": "minecraft:overworld",
"generator": {
"type": "minecraft:noise",
"settings": "minecraft:overworld",
"biome_source": {
"type": "minecraft:multi_noise",
"preset": "minecraft:overworld"
}
}
},
"shrinking_speed": 0.6,
"start_size": {
"min": 200,
"max": 8000
}
},
"chapters": {
"warmup": {
"min": 600,
"max": 800
}
},
"modules": "#doublerunner:standard"
}
44 changes: 44 additions & 0 deletions src/main/resources/data/doublerunner/plasmid/game/trios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "uhc:standard",
"name": {
"translate": "game.generic.mode",
"with": [
{
"translate": "game.doublerunner"
},
{
"translate": "mode.trios"
}
]
},
"team_size": 3,
"players": {
"min": 6,
"threshold": 24
},
"map": {
"dimension": {
"type": "minecraft:overworld",
"generator": {
"type": "minecraft:noise",
"settings": "minecraft:overworld",
"biome_source": {
"type": "minecraft:multi_noise",
"preset": "minecraft:overworld"
}
}
},
"shrinking_speed": 0.6,
"start_size": {
"min": 200,
"max": 8000
}
},
"chapters": {
"warmup": {
"min": 600,
"max": 800
}
},
"modules": "#doublerunner:standard"
}
Loading

0 comments on commit 88f05c1

Please sign in to comment.