Skip to content

Commit

Permalink
Merged 1.7.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Mar 9, 2023
1 parent 622f6de commit dbff9ee
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 91 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [Modrinth](https://modrinth.com/mod/majruszs-progressive-difficulty)

## Current Mod Releases (Source Code)
- [v1.7.1 for Minecraft 1.19.3](https://github.com/Majrusz/MajruszsProgressiveDifficultyMod/tree/1.19.X/)
- [v1.7.2 for Minecraft 1.19.3](https://github.com/Majrusz/MajruszsProgressiveDifficultyMod/tree/1.19.X/)
- [v1.4.4 for Minecraft 1.18.2](https://github.com/Majrusz/MajruszsProgressiveDifficultyMod/tree/1.18.X/) *(not supported anymore)*
- [v1.3.0 for Minecraft 1.17.1](https://github.com/Majrusz/MajruszsProgressiveDifficultyMod/tree/1.17.1/) *(not supported anymore)*
- [v1.1.0 for Minecraft 1.16.4](https://github.com/Majrusz/MajruszsProgressiveDifficultyMod/tree/1.16.4/) *(not supported anymore)*
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'

version = '1.7.1'
version = '1.7.2'
group = 'com.majruszsdifficulty'
archivesBaseName = 'majruszs-difficulty-1.19.2'

Expand Down Expand Up @@ -76,7 +76,7 @@ repositories {

dependencies {
minecraft 'net.minecraftforge:forge:1.19.2-43.2.0'
implementation fg.deobf( 'com.mlib:majrusz-library-1.19.2:3.2.0' )
implementation fg.deobf( 'com.mlib:majrusz-library-1.19.2:3.3.0' )
}

// Example for how to get properties into the manifest for reading at runtime.
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
import com.majruszsdifficulty.GameStage;
import com.majruszsdifficulty.Registries;
import com.majruszsdifficulty.gamemodifiers.configs.StageProgressConfig;
import com.majruszsdifficulty.gamemodifiers.contexts.OnGameStageChange;
import com.mlib.annotations.AutoInstance;
import com.mlib.config.BooleanConfig;
import com.mlib.config.EnumConfig;
import com.mlib.gamemodifiers.GameModifier;
import com.mlib.gamemodifiers.contexts.OnDeath;
import com.mlib.gamemodifiers.contexts.OnDimensionChanged;
import com.mlib.gamemodifiers.parameters.Priority;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.entity.EntityType;

@AutoInstance
Expand Down Expand Up @@ -50,12 +45,6 @@ public IncreaseGameStage() {
.addCondition( data->this.masterMode.entityTriggersChange( EntityType.getKey( data.target.getType() ) ) )
.insertTo( this );

new OnGameStageChange.Context( this::notifyPlayers )
.priority( Priority.HIGHEST )
.addCondition( data->!data.isLoadedFromDisk() )
.addCondition( data->data.previous == GameStage.NORMAL && data.current == GameStage.EXPERT || data.current == GameStage.MASTER )
.insertTo( this );

this.addConfig( DEFAULT_GAME_STAGE.name( "default_mode" ).comment( "Game stage set at the beginning of a new world." ) )
.addConfig( this.enteringAnyDimensionStartsExpertMode
.name( "any_dimension_expert" )
Expand All @@ -79,25 +68,4 @@ private void startMasterMode( OnDimensionChanged.Data data ) {
private void startMasterMode( OnDeath.Data data ) {
GameStage.changeStage( GameStage.MASTER, data.target.getServer() );
}

private void notifyPlayers( OnGameStageChange.Data data ) {
String messageId = data.current == GameStage.EXPERT ? "majruszsdifficulty.on_expert_mode_start" : "majruszsdifficulty.on_master_mode_start";

sendMessageToAllPlayers( data.server, data.current, messageId );
triggerAdvancement( data.server, data.current );
}

private static void triggerAdvancement( MinecraftServer server, GameStage current ) {
server.getPlayerList()
.getPlayers()
.forEach( player->Registries.GAME_STATE_TRIGGER.trigger( player, current ) );
}

private static void sendMessageToAllPlayers( MinecraftServer server, GameStage current, String messageId ) {
MutableComponent message = Component.translatable( messageId ).withStyle( current.getChatFormatting() );

server.getPlayerList()
.getPlayers()
.forEach( player->player.displayClientMessage( message, false ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.majruszsdifficulty.gamemodifiers.list.gamestages;

import com.majruszsdifficulty.Registries;
import com.majruszsdifficulty.gamemodifiers.contexts.OnGameStageChange;
import com.mlib.annotations.AutoInstance;
import com.mlib.gamemodifiers.GameModifier;

@AutoInstance
public class AdvancementProvider extends GameModifier {
public AdvancementProvider() {
new OnGameStageChange.Context( this::giveAdvancement )
.addCondition( data->!data.isLoadedFromDisk() )
.addCondition( data->data.previous.ordinal() < data.current.ordinal() )
.insertTo( this );
}

private void giveAdvancement( OnGameStageChange.Data data ) {
data.server.getPlayerList()
.getPlayers()
.forEach( player->Registries.GAME_STATE_TRIGGER.trigger( player, data.current ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.majruszsdifficulty.gamemodifiers.list.gamestages;

import com.majruszsdifficulty.GameStage;
import com.majruszsdifficulty.Registries;
import com.majruszsdifficulty.gamemodifiers.contexts.OnGameStageChange;
import com.mlib.annotations.AutoInstance;
import com.mlib.data.JsonListener;
import com.mlib.data.SerializableStructure;
import com.mlib.gamemodifiers.GameModifier;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;

@AutoInstance
public class ChatMessageSender extends GameModifier {
final Supplier< Messages > messages;

public ChatMessageSender() {
this.messages = JsonListener.add( "game_stages", Registries.getLocation( "messages" ), Messages.class, Messages::new );

new OnGameStageChange.Context( this::sendMessage )
.addCondition( data->!data.isLoadedFromDisk() )
.addCondition( data->data.previous.ordinal() < data.current.ordinal() )
.insertTo( this );
}

private void sendMessage( OnGameStageChange.Data data ) {
this.messages.get().stream()
.filter( message->data.current == message.gameStage )
.forEach( message->{
MutableComponent component = Component.translatable( message.id )
.withStyle( message.chatFormatting != null ? new ChatFormatting[]{ message.chatFormatting } : data.current.getChatFormatting() );

data.server.getPlayerList()
.getPlayers()
.forEach( player->player.displayClientMessage( component, false ) );
} );
}

static class Messages extends SerializableStructure {
List< Message > messages = new ArrayList<>();

public Messages() {
this.define( null, ()->this.messages, x->this.messages = x, Message::new );
}

public Stream< Message > stream() {
return this.messages.stream();
}
}

static class Message extends SerializableStructure {
String id = "";
GameStage gameStage = GameStage.NORMAL;
ChatFormatting chatFormatting = null;

public Message() {
this.define( "id", ()->this.id, x->this.id = x );
this.define( "game_stage", ()->this.gameStage, x->this.gameStage = x, GameStage::values );
this.define( "style", ()->this.chatFormatting, x->this.chatFormatting = x, ChatFormatting::values );
}
}
}
40 changes: 4 additions & 36 deletions src/main/java/com/majruszsdifficulty/undeadarmy/Config.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,38 @@
package com.majruszsdifficulty.undeadarmy;

import com.google.gson.JsonElement;
import com.majruszsdifficulty.GameStage;
import com.majruszsdifficulty.Registries;
import com.majruszsdifficulty.gamemodifiers.contexts.OnGameStageChange;
import com.majruszsdifficulty.undeadarmy.data.UndeadArmyInfo;
import com.majruszsdifficulty.undeadarmy.data.WaveDef;
import com.majruszsdifficulty.undeadarmy.data.WavesDef;
import com.mlib.annotations.AutoInstance;
import com.mlib.config.BooleanConfig;
import com.mlib.config.DoubleConfig;
import com.mlib.config.IntegerConfig;
import com.mlib.data.JsonListener;
import com.mlib.gamemodifiers.Condition;
import com.mlib.gamemodifiers.GameModifier;
import com.mlib.gamemodifiers.contexts.OnDeath;
import com.mlib.gamemodifiers.contexts.OnLoot;
import com.mlib.gamemodifiers.contexts.OnServerTick;
import com.mlib.items.ItemHelper;
import com.mlib.loot.LootHelper;
import com.mlib.math.Range;
import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
import net.minecraft.util.Mth;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.Deserializers;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.event.TickEvent;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

@AutoInstance
public class Config extends GameModifier {
Expand All @@ -56,19 +44,12 @@ public class Config extends GameModifier {
private final DoubleConfig extraSizePerPlayer = new DoubleConfig( 0.5, new Range<>( 0.0, 1.0 ) );
private final IntegerConfig armyRadius = new IntegerConfig( 70, new Range<>( 35, 140 ) );
private final IntegerConfig killRequirement = new IntegerConfig( 75, new Range<>( 0, 1000 ) );
private WavesDef wavesDef = null;
private final Supplier< WavesDef > wavesDef;

public Config() {
super( Registries.Modifiers.UNDEAD_ARMY );

var gson = Deserializers.createFunctionSerializer().registerTypeAdapter( WavesDef.class, new WavesDef.Serializer() ).create();
var listener = new SimpleJsonResourceReloadListener( gson, "undead_army" ) {
@Override
protected void apply( Map< ResourceLocation, JsonElement > elements, ResourceManager manager, ProfilerFiller filler ) {
Config.this.wavesDef = gson.fromJson( elements.get( Registries.getLocation( "waves" ) ), WavesDef.class );
}
};
MinecraftForge.EVENT_BUS.addListener( ( AddReloadListenerEvent event )->event.addListener( listener ) );
this.wavesDef = JsonListener.add( "undead_army", Registries.getLocation( "waves" ), WavesDef.class, WavesDef::new );

new OnServerTick.Context( data->Registries.getUndeadArmyManager().tick() )
.addCondition( data->data.event.phase == TickEvent.Phase.END )
Expand All @@ -89,11 +70,6 @@ protected void apply( Map< ResourceLocation, JsonElement > elements, ResourceMan
.addCondition( data->Registries.getUndeadArmyManager().isPartOfUndeadArmy( data.entity ) )
.insertTo( this );

new OnGameStageChange.Context( this::notifyPlayers )
.addCondition( data->!data.isLoadedFromDisk() )
.addCondition( data->data.previous == GameStage.NORMAL && data.current == GameStage.EXPERT )
.insertTo( this );

this.addConfig( this.availability.name( "is_enabled" ).comment( "Determines whether the Undead Army can spawn in any way." ) )
.addConfig( this.waveDuration.name( "wave_duration" ).comment( "Duration that players have to defeat a single wave (in seconds)." ) )
.addConfig( this.preparationDuration.name( "preparation_duration" ).comment( "Duration before the next wave arrives (in seconds)." ) )
Expand Down Expand Up @@ -185,12 +161,4 @@ private LootContext toExtraLootContext( OnLoot.Data data ) {
.withOptionalParameter( LootContextParams.KILLER_ENTITY, data.killer )
.create( LootContextParamSets.ENTITY );
}

private void notifyPlayers( OnGameStageChange.Data data ) {
MutableComponent message = Component.translatable( "majruszsdifficulty.undead_army.on_expert" ).withStyle( ChatFormatting.DARK_PURPLE );

data.server.getPlayerList()
.getPlayers()
.forEach( player->player.displayClientMessage( message, false ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.BossEvent;
import net.minecraft.world.entity.LivingEntity;

import java.util.ArrayList;
import java.util.Collection;

class ProgressIndicator implements IComponent {
Expand Down Expand Up @@ -61,7 +62,7 @@ private void updateParticipants() {
if( this.undeadArmy.phase.state == Phase.State.FINISHED )
return;

Collection< ServerPlayer > currentParticipants = this.waveInfo.getPlayers();
Collection< ServerPlayer > currentParticipants = new ArrayList<>( this.waveInfo.getPlayers() );
this.undeadArmy.participants.forEach( player->{
if( !currentParticipants.contains( player ) ) {
this.waveInfo.addPlayer( player );
Expand Down
20 changes: 3 additions & 17 deletions src/main/java/com/majruszsdifficulty/undeadarmy/data/WavesDef.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.majruszsdifficulty.undeadarmy.data;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.mlib.data.SerializableStructure;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class WavesDef extends SerializableStructure {
public final List< WaveDef > waveDefs = new ArrayList<>();
Expand All @@ -17,17 +13,7 @@ public WavesDef() {
this.define( null, ()->this.waveDefs, this.waveDefs::addAll, WaveDef::new );
}

public List< WaveDef > get() {
return this.waveDefs;
}

public static class Serializer implements JsonDeserializer< WavesDef > {
@Override
public WavesDef deserialize( JsonElement element, Type type, JsonDeserializationContext context ) throws JsonParseException {
WavesDef wavesDef = new WavesDef();
wavesDef.read( element );

return wavesDef;
}
public Stream< WaveDef > stream() {
return this.waveDefs.stream();
}
}
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ issueTrackerURL = "https://github.com/Majrusz/MajruszsProgressiveDifficultyMod/i

[[mods]]
modId = "majruszsdifficulty"
version = "1.7.1"
version = "1.7.2"
displayName = "Majrusz's Progressive Difficulty"
updateJSONURL = "https://raw.githubusercontent.com/Majrusz/MinecraftCommon/main/ProgressiveDifficulty/update.json"
displayURL = "https://www.curseforge.com/minecraft/mc-mods/majruszs-progressive-difficulty"
Expand All @@ -31,6 +31,6 @@ issueTrackerURL = "https://github.com/Majrusz/MajruszsProgressiveDifficultyMod/i
[[dependencies.majruszsdifficulty]]
modId = "mlib"
mandatory = true
versionRange = "[3.2.0,4.0.0)"
versionRange = "[3.3.0,4.0.0)"
ordering = "NONE"
side = "BOTH"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"id": "majruszsdifficulty.on_expert_mode_start",
"game_stage": "EXPERT"
},
{
"id": "majruszsdifficulty.undead_army.on_expert",
"game_stage": "EXPERT",
"style": "DARK_PURPLE"
},
{
"id": "majruszsdifficulty.on_master_mode_start",
"game_stage": "MASTER"
}
]

0 comments on commit dbff9ee

Please sign in to comment.