-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
119 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file renamed
BIN
+455 KB
libs/majrusz-library-1.19.2-3.2.0.jar → libs/majrusz-library-1.19.2-3.3.0.jar
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/majruszsdifficulty/gamemodifiers/list/gamestages/AdvancementProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) ); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/majruszsdifficulty/gamemodifiers/list/gamestages/ChatMessageSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/resources/data/majruszsdifficulty/game_stages/messages.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |