Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b1f3a791d | ||
|
|
10b1cd9c5e | ||
|
|
ef18e0ae32 | ||
|
|
1c2e000da3 | ||
|
|
9e35c244ec | ||
|
|
e82cb33407 | ||
|
|
e126ec9eea | ||
|
|
13a74ddbd2 | ||
|
|
b221ca1b52 | ||
|
|
05505279f8 | ||
|
|
61e66d3a11 | ||
|
|
3aa36ed129 | ||
|
|
90b9eee27e | ||
|
|
7d800d8932 | ||
|
|
913a754f20 | ||
|
|
73d32999e5 | ||
|
|
86034ca71f | ||
|
|
db91698c09 | ||
|
|
7f74114d31 | ||
|
|
53db634ec2 | ||
|
|
400f1f6289 | ||
|
|
596432f3f7 |
+63
-2
@@ -6,9 +6,69 @@ Ce journal suit les **versions du modpack**. Lorsqu'un seul module change, sa ve
|
||||
- Depuis `26.2.0-alpha.6`, le pack et les modules ont des versions indépendantes. I Like To Move It et Only Fun deviennent les cinquième et sixième modules actifs dans l'alpha 46.
|
||||
- Les versions ci-dessous ont été reconstituées à partir des JAR archivés, des packs locaux et du code source actuel. Les dates n'étant pas enregistrées de manière fiable, elles ne sont pas inventées.
|
||||
|
||||
## Non distribué
|
||||
## `26.2.0-alpha.217`
|
||||
|
||||
Modules modifiés : **It's Alive `0.0.0-alpha.36`**, **Sanctuary `0.0.0-alpha.119`**, **Ambiance `0.0.0-alpha.15`**, **Only Fun `0.0.0-alpha.24`** et **Ouch `0.0.0-alpha.10`**. Le pack distribué reste en `26.2.0-alpha.210` jusqu’à la prochaine release.
|
||||
Modules modifiés : **Red-Stoner `0.0.0-alpha.11`**, **Only Fun `0.0.0-alpha.25`** et **Sanctuary `0.0.0-alpha.121`**. Les sept autres modules conservent leur version issue de l'alpha.216.
|
||||
|
||||
- ajoute `redstoner:storage_terminal`, une demi-dalle verticale de huit pixels qui se pose uniquement sur la face horizontale d’un coffre, coffre piégé ou baril ;
|
||||
- découvre sans charger de chunk les conteneurs adjacents par face, verticalement compris, et refuse clairement tout réseau qui dépasse 128 blocs physiques ;
|
||||
- agrège uniquement les piles dont l’item et tous les composants sont strictement identiques, puis les affiche sur des pages défilantes de 54 entrées ;
|
||||
- valide côté serveur la distance, le terminal, la topologie, la page et l’identité de chaque pile avant un retrait par pile, un retrait unitaire ou un dépôt par shift-clic ;
|
||||
- fabrique le terminal avec quatre plaques d’argent, trois verres teintés, un Controller et un lingot de titane, sans entrée Shop, Black Market ni récompense de lootbox ;
|
||||
- ajoute les traductions FR/EN/RU, les ressources bloc/item/loot/recette et des tests déterministes de topologie, pagination, agrégation et transferts ;
|
||||
- conserve les données Red-Stoner v3, Only Fun v2 et Sanctuary v11 ; seul le protocole réseau Red-Stoner passe de 5 à 6, sans nouveau monde ni réinitialisation des sauvegardes.
|
||||
|
||||
## `26.2.0-alpha.216`
|
||||
|
||||
Module modifié : **Ambiance `0.0.0-alpha.19`**. Les neuf autres modules conservent leur version issue de l'alpha.215.
|
||||
|
||||
- corrige le disque blanc ralenti et dégradé en remplissant continûment les tampons PCM d’une seconde demandés par Minecraft au lieu de les compléter prématurément avec du silence ;
|
||||
- conserve une fréquence réelle de 48 kHz, un flux mono 16 bits little-endian et force la vitesse OpenAL normale à `1.0` ;
|
||||
- borne chaque attente de trame à 250 ms après le démarrage afin de garder un flux continu sans bloquer indéfiniment le thread audio ;
|
||||
- ajoute un test déterministe des tampons Minecraft et renforce le test YouTube réel sur quatre secondes complètes ;
|
||||
- conserve les données Ambiance v2, le protocole réseau 6, les IDs et les sauvegardes existantes ;
|
||||
- distribue Ambiance `0.0.0-alpha.19` dans Packwiz et le `.mrpack` partagé client/serveur, sans exiger de nouveau monde ni réinitialiser les sauvegardes.
|
||||
|
||||
## `26.2.0-alpha.215`
|
||||
|
||||
Module modifié : **Ambiance `0.0.0-alpha.18`**. Les neuf autres modules conservent leur version issue de l'alpha.214.
|
||||
|
||||
- corrige le crash natif déclenché par l’insertion ou l’arrêt du disque blanc en laissant Minecraft libérer le canal OpenAL sur son thread audio ;
|
||||
- rétablit le décodage audible du lien YouTube signalé grâce au profil iOS corrigé et à une révision épinglée de `youtube-source` ;
|
||||
- borne uniquement l’attente initiale du flux puis poursuit la lecture sans blocage, avec silence de compensation lorsque les données arrivent en retard ;
|
||||
- transforme les erreurs et blocages de lecture en arrêt propre accompagné d’un message au joueur ;
|
||||
- conserve les données Ambiance v2, le protocole réseau 6, les IDs et les sauvegardes existantes ;
|
||||
- distribue Ambiance `0.0.0-alpha.18` dans Packwiz et le `.mrpack` partagé client/serveur, sans exiger de nouveau monde ni réinitialiser les sauvegardes.
|
||||
|
||||
## `26.2.0-alpha.214`
|
||||
|
||||
Module modifié : **Ambiance `0.0.0-alpha.17`**. Les neuf autres modules conservent leur version issue de l'alpha.213.
|
||||
|
||||
- attend de façon bornée la synchronisation client du jukebox avant de charger un disque blanc, ce qui rétablit sa lecture en solo ;
|
||||
- affiche immédiatement le chargement puis un échec explicite si le jukebox n'est toujours pas synchronisé après cinq secondes ;
|
||||
- accepte toujours les liens de partage YouTube avec paramètres, notamment `https://youtu.be/Ue5ZBe-GzSM?si=…` ;
|
||||
- conserve les données Ambiance v2 et le protocole réseau 6, sans migration de sauvegarde ;
|
||||
- distribue Ambiance `0.0.0-alpha.17` dans Packwiz et le `.mrpack` partagé client/serveur, sans exiger de nouveau monde ni réinitialiser les sauvegardes.
|
||||
|
||||
## `26.2.0-alpha.213`
|
||||
|
||||
Module modifié : **Ambiance `0.0.0-alpha.16`**. Les neuf autres modules conservent leur version issue de l'alpha.212.
|
||||
|
||||
- corrige le crash client au démarrage d'Ambiance sous Minecraft 26.2 en ciblant le nouveau gestionnaire vanilla `LevelEventHandler` pour l'arrêt du disque blanc ;
|
||||
- conserve les données Ambiance v2 et le protocole réseau 6, sans migration de sauvegarde ;
|
||||
- remplace le JAR Ambiance cassé dans Packwiz et le `.mrpack` partagé client/serveur, sans exiger de nouveau monde ni réinitialiser les sauvegardes.
|
||||
|
||||
## `26.2.0-alpha.212`
|
||||
|
||||
Module modifié : **Sanctuary `0.0.0-alpha.120`**. Les neuf autres modules conservent leur version issue de l'alpha.211.
|
||||
|
||||
- corrige le crash client au démarrage provoqué par le mixin du clic molette du Black Market sous Minecraft 26.2 ;
|
||||
- cible désormais la méthode vanilla `pickBlockOrEntity`, sans modifier les données Sanctuary v11 ni le protocole réseau 22.
|
||||
- remplace le JAR Sanctuary cassé dans Packwiz et le `.mrpack` partagé client/serveur, sans exiger de nouveau monde ni réinitialiser les sauvegardes.
|
||||
|
||||
## `26.2.0-alpha.211`
|
||||
|
||||
Modules modifiés : **Ambiance `0.0.0-alpha.15`**, **It's Alive `0.0.0-alpha.36`**, **Only Fun `0.0.0-alpha.24`**, **Ouch `0.0.0-alpha.10`** et **Sanctuary `0.0.0-alpha.119`**. Les cinq autres modules conservent leur version issue de l’alpha.210.
|
||||
|
||||
- remplace les pages noires du Livre interdit par l’affichage clair du livre vanilla ;
|
||||
- conserve les seize entrées, les découvertes personnelles, le partage sur pupitre, les IDs, les données v3 et le protocole réseau 4.
|
||||
@@ -26,6 +86,7 @@ Modules modifiés : **It's Alive `0.0.0-alpha.36`**, **Sanctuary `0.0.0-alpha.11
|
||||
- ajoute la touche configurable « Chier » dans les contrôles Only Fun, assignée à `J` par défaut et sans répétition lorsque la touche reste maintenue ;
|
||||
- transmet une demande C2S vide, déduplique le spam d’un même tick et revalide côté serveur la connexion, la vie et le mode spectateur avant de réutiliser exactement l’action `/shit` ;
|
||||
- conserve les données Only Fun v2 et porte son protocole réseau de 2 à 3, sans nouveau cooldown, besoin ni donnée persistante.
|
||||
- distribue les cinq JAR mis à jour dans Packwiz et le `.mrpack` partagé client/serveur, sans exiger de nouveau monde ni réinitialiser les sauvegardes.
|
||||
|
||||
## `26.2.0-alpha.210`
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Licence : **GNU GPL 3.0 or Later** (`GPL-3.0-or-later`)
|
||||
| `anotherworld` | Another World | choses matérielles | matière, photographie, instruments météo et 108 biomes natifs |
|
||||
| `itsalive` | It's Alive ! | vivant | Creepers, créatures, agriculture et gameplay serveur complet de Canaplia |
|
||||
| `ambiance` | Ambiance | perception | atmosphère, météo, lumières dynamiques, audio positionnel, calendrier et composition visuelle accessible |
|
||||
| `redstoner` | Red-Stoner | calcul et signaux | ordinateurs, identité serveur, Drawer et Particuleur |
|
||||
| `redstoner` | Red-Stoner | calcul et signaux | ordinateurs, identité serveur, terminal de stockage, Drawer et Particuleur |
|
||||
| `iliketomoveit` | I Like To Move It | déplacement | portails, véhicules, grappin, poulies et waystones locaux |
|
||||
| `ouch` | Ouch | combat et destruction | arsenal actif (6 armes) et TNT météo |
|
||||
| `onlyfun` | Only Fun | règles ludiques absurdes | lootboxes, Lucky Block, raretés et règles absurdes |
|
||||
@@ -22,11 +22,13 @@ Licence : **GNU GPL 3.0 or Later** (`GPL-3.0-or-later`)
|
||||
|
||||
Les descriptions FR/EN/RU sont déclarées dans chaque `fabric.mod.json` et dans les fichiers de langue. Les images fournies servent d'icônes Fabric de leur module.
|
||||
|
||||
Version courante du pack distribué : **`26.2.0-alpha.210`**. Cette release distribue le Livre interdit Canaplia avec It's Alive **`0.0.0-alpha.35`**, ainsi que Sanctuary **`0.0.0-alpha.118`**, Only Fun **`0.0.0-alpha.21`** et I Like To Move It **`0.0.0-alpha.15`**.
|
||||
Version courante du pack distribué : **`26.2.0-alpha.217`**. Cette release distribue Red-Stoner **`0.0.0-alpha.11`**, Only Fun **`0.0.0-alpha.25`** et Sanctuary **`0.0.0-alpha.121`** ; les sept autres modules conservent leur version issue de l'alpha.216.
|
||||
|
||||
La migration [CANA-01 à CANA-09](CANAPLIA.md) porte Canaplia vers Minecraft 26.2. It's Alive **`0.0.0-alpha.35`** enregistre les seize familles, les découvertes, hybridations, résines, effets serveur et le Livre interdit personnel, partageable temporairement sur un pupitre. Ambiance **`0.0.0-alpha.14`** compose les profils visuels bornés avec ses réglages d'accessibilité, et Only Fun **`0.0.0-alpha.21`** exclut explicitement Canaplia et les raccourcis de progression du Shop.
|
||||
|
||||
L’alpha.210 ajoute le Livre interdit, accélère le Happy Ghast piloté, regroupe les corrections du Shop, des requêtes, des capes et des noms de Zombies, puis actualise JEI en **`30.28.0.193`**. Elle met à jour les packs Modrinth, Prism et Packwiz sans exiger de nouveau monde ni réinitialiser les sauvegardes.
|
||||
L’alpha.217 ajoute le terminal de stockage Red-Stoner : cette demi-dalle verticale se fixe sur un coffre, un coffre piégé ou un baril et donne accès, par pages défilantes de 54 types, à un réseau contigu borné à 128 conteneurs chargés. Les retraits et dépôts sont validés par le serveur, les composants d’items restent strictement séparés et le terminal endgame est exclu du Shop, du Black Market et des récompenses Only Fun.
|
||||
|
||||
L’alpha.216 corrige la lecture lente et dégradée du disque blanc : les quatre tampons PCM initiaux de Minecraft sont maintenant remplis continûment à 48 kHz, avec une vitesse OpenAL normale, au lieu d’être majoritairement complétés par du silence. Les packs Modrinth, Prism et Packwiz sont mis à jour sans exiger de nouveau monde ni réinitialiser les sauvegardes.
|
||||
|
||||
L’alpha.207 rend le stockage du coffre-fort pratiquement illimité : rubis, saphirs et émeraudes utilisent chacun un solde 64 bits. Les 27 anciennes piles sont additionnées automatiquement lors du chargement, le Shop continue de consommer directement ces soldes et les 20 % pillés sont crédités dans le coffre-fort de l’attaquant sans créer des millions d’entités ou de piles d’objets.
|
||||
|
||||
|
||||
@@ -24,8 +24,10 @@ Ambiance conserve ses données v2 ; son protocole passe de 5 à 6.
|
||||
|
||||
## Dépendances clientes embarquées
|
||||
|
||||
Le décodage repose sur Lavaplayer `2.2.7` (Apache-2.0) et youtube-source `1.18.2` (MIT), ainsi que
|
||||
leurs dépendances transitives placées en JAR imbriqués par Loom. Leurs avis de licence restent dans
|
||||
les archives d’origine. L’accès YouTube est effectué uniquement par le client et peut cesser de
|
||||
fonctionner si YouTube modifie ses mécanismes de lecture ; aucune clé ou URL arbitraire n’est
|
||||
acceptée par le serveur.
|
||||
Le décodage repose sur Lavaplayer `2.2.7` (Apache-2.0) et sur le commit youtube-source
|
||||
`f45bbb7aebfcbc1c553769e04af6cd43afa8b7c3` (MIT), épinglé pour intégrer les correctifs de lecture
|
||||
YouTube publiés après `1.18.2`. Le profil iOS corrigé est utilisé sans compte, OAuth, jeton privé ou
|
||||
service de chiffrement tiers. Les dépendances sont placées en JAR imbriqués par Loom et leurs avis
|
||||
de licence restent dans les archives d’origine. L’accès YouTube est effectué uniquement par le
|
||||
client et peut cesser de fonctionner si YouTube modifie ses mécanismes de lecture ; aucune clé ou
|
||||
URL arbitraire n’est acceptée par le serveur.
|
||||
|
||||
+52
-7
@@ -1,5 +1,7 @@
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
def youtubeSourceVersion = "f45bbb7aebfcbc1c553769e04af6cd43afa8b7c3-SNAPSHOT"
|
||||
|
||||
configurations {
|
||||
whiteDiscLibraries
|
||||
implementation.extendsFrom whiteDiscLibraries
|
||||
@@ -13,14 +15,14 @@ dependencies {
|
||||
exclude group: "org.slf4j", module: "slf4j-api"
|
||||
exclude group: "org.jetbrains", module: "annotations"
|
||||
}
|
||||
whiteDiscLibraries("dev.lavalink.youtube:v2:1.18.2") {
|
||||
whiteDiscLibraries("dev.lavalink.youtube:v2:${youtubeSourceVersion}") {
|
||||
exclude group: "org.slf4j", module: "slf4j-api"
|
||||
exclude group: "org.jetbrains", module: "annotations"
|
||||
}
|
||||
[
|
||||
"dev.arbjerg:lavaplayer-natives:2.2.7",
|
||||
"dev.arbjerg:lava-common:2.2.7",
|
||||
"dev.lavalink.youtube:common:1.18.2",
|
||||
"dev.lavalink.youtube:common:${youtubeSourceVersion}",
|
||||
"org.mozilla:rhino-engine:1.7.15",
|
||||
"org.mozilla:rhino:1.7.15",
|
||||
"commons-io:commons-io:2.13.0",
|
||||
@@ -64,15 +66,33 @@ tasks.register("whiteDiscUrlSmoke", JavaExec) {
|
||||
mainClass = "fr.koka99cab.sanctuary26.ambiance.white_disc.WhiteDiscUrlSmoke"
|
||||
}
|
||||
|
||||
tasks.register("whiteDiscPlaybackSmoke", JavaExec) {
|
||||
group = "verification"
|
||||
description = "Manually checks live YouTube loading and PCM decoding for the white disc."
|
||||
dependsOn tasks.named("testClasses")
|
||||
classpath = sourceSets.test.runtimeClasspath
|
||||
mainClass = "fr.koka99cab.sanctuary26.ambiance.client.audio.WhiteDiscPlaybackSmoke"
|
||||
}
|
||||
|
||||
tasks.register("whiteDiscStreamSmoke", JavaExec) {
|
||||
group = "verification"
|
||||
description = "Checks continuous 48 kHz PCM buffering for Minecraft's white-disc channel."
|
||||
dependsOn tasks.named("testClasses")
|
||||
classpath = sourceSets.test.runtimeClasspath
|
||||
mainClass = "fr.koka99cab.sanctuary26.ambiance.client.audio.LavaplayerAudioStreamSmoke"
|
||||
}
|
||||
|
||||
tasks.named("test") {
|
||||
failOnNoDiscoveredTests = false
|
||||
}
|
||||
|
||||
tasks.register("verifyAmbiance") {
|
||||
group = "verification"
|
||||
description = "Checks Ambiance alpha.15, including the bounded YouTube white-disc playback contract."
|
||||
description = "Checks Ambiance alpha.19, including continuous white-disc PCM playback."
|
||||
inputs.files(fileTree("src/main/java"))
|
||||
inputs.files(fileTree("src/main/resources"))
|
||||
inputs.file(file("src/test/java/fr/koka99cab/sanctuary26/ambiance/client/audio/WhiteDiscPlaybackSmoke.java"))
|
||||
inputs.file(file("src/test/java/fr/koka99cab/sanctuary26/ambiance/client/audio/LavaplayerAudioStreamSmoke.java"))
|
||||
inputs.file(rootProject.file("pack/migrations/26.2.0-alpha.125-realtime-calendar-to-alpha.126.json"))
|
||||
inputs.file(rootProject.file("pack/migrations/26.2.0-alpha.127-daily-ambiance-sodium-iris-to-alpha.128.json"))
|
||||
inputs.file(rootProject.file("pack/migrations/26.2.0-alpha.128-ambiance-visuals-canon-iris-to-alpha.129.json"))
|
||||
@@ -120,8 +140,14 @@ tasks.register("verifyAmbiance") {
|
||||
file("src/main/resources/data/ambiance/recipe/white_disc.json"))
|
||||
def whiteDiscSong = new JsonSlurper().parse(
|
||||
file("src/main/resources/data/ambiance/jukebox_song/white_disc.json"))
|
||||
def levelEventMixin = file(
|
||||
"src/main/java/fr/koka99cab/sanctuary26/ambiance/mixin/client/LevelEventHandlerMixin.java").text
|
||||
def whiteDiscAudioPlayer = file(
|
||||
"src/main/java/fr/koka99cab/sanctuary26/ambiance/client/audio/WhiteDiscAudioPlayer.java").text
|
||||
def whiteDiscPlaybackSmoke = file(
|
||||
"src/test/java/fr/koka99cab/sanctuary26/ambiance/client/audio/WhiteDiscPlaybackSmoke.java").text
|
||||
|
||||
if (project.version.toString() != "0.0.0-alpha.15"
|
||||
if (project.version.toString() != "0.0.0-alpha.19"
|
||||
|| migration.source?.pack_version != "26.2.0-alpha.125"
|
||||
|| migration.target?.pack_version != "26.2.0-alpha.126"
|
||||
|| migration.target?.modules?.ambiance != "0.0.0-alpha.1"
|
||||
@@ -319,10 +345,23 @@ tasks.register("verifyAmbiance") {
|
||||
|| !javaText.contains('PlayerLookup.tracking(level, pos)')
|
||||
|| !javaText.contains('ServerPlayNetworking.canSend(receiver, WhiteDiscPlaybackPayload.ID)')
|
||||
|| !javaText.contains('MAXIMUM_SIMULTANEOUS_DISCS = 4')
|
||||
|| !javaText.contains('REQUESTS.size() + PLAYBACKS.size() >= MAXIMUM_SIMULTANEOUS_DISCS')
|
||||
|| !javaText.contains('PENDING_STARTS.size() + REQUESTS.size() + PLAYBACKS.size()')
|
||||
|| !javaText.contains('MAXIMUM_START_WAIT_TICKS = 100')
|
||||
|| !javaText.contains('tickPendingStarts(client)')
|
||||
|| !javaText.contains('client.level.dimension().equals(playback.dimension())')
|
||||
|| !javaText.contains('MAXIMUM_TRACK_MILLIS = 30L * 60L * 1_000L')
|
||||
|| !javaText.contains('new Pcm16AudioDataFormat(1, LavaplayerAudioStream.SAMPLE_RATE')
|
||||
|| !javaText.contains('new YoutubeAudioSourceManager(false, new Ios())')
|
||||
|| !javaText.contains('player.addListener(new AudioEventAdapter()')
|
||||
|| !javaText.contains('failPlayback(client, key, failedPlayer)')
|
||||
|| !javaText.contains('initialWaitAttempted')
|
||||
|| !javaText.contains('CONTINUATION_FRAME_WAIT_MILLIS = 250L')
|
||||
|| !javaText.contains('player.provide(waitMillis, TimeUnit.MILLISECONDS)')
|
||||
|| !whiteDiscAudioPlayer.contains('channel.setPitch(1.0F)')
|
||||
|| !whiteDiscAudioPlayer.contains('handle.execute(channel -> channel.stop())')
|
||||
|| whiteDiscAudioPlayer.contains('.release()')
|
||||
|| !whiteDiscPlaybackSmoke.contains('https://www.youtube.com/watch?v=Ue5ZBe-GzSM')
|
||||
|| !whiteDiscPlaybackSmoke.contains('Decoded audible PCM data')
|
||||
|| !javaText.contains('SoundSource.RECORDS')
|
||||
|| !javaText.contains('channel.linearAttenuation(ATTENUATION_DISTANCE)')
|
||||
|| !javaText.contains('LONG_HOSTS = Set.of(')
|
||||
@@ -334,6 +373,9 @@ tasks.register("verifyAmbiance") {
|
||||
|| whiteDiscRecipe.key?.W != "minecraft:white_dye"
|
||||
|| whiteDiscSong.sound_event != "minecraft:intentionally_empty"
|
||||
|| whiteDiscSong.length_in_seconds != 1800
|
||||
|| !levelEventMixin.contains('@Mixin(LevelEventHandler.class)')
|
||||
|| !levelEventMixin.contains('@Inject(method = "levelEvent"')
|
||||
|| !levelEventMixin.contains('ambiance$stopWhiteDisc(int type, BlockPos pos, int data,')
|
||||
|| ambianceLanguages.any { locale, translations ->
|
||||
!["item.ambiance.white_disc", "tooltip.ambiance.white_disc",
|
||||
"message.ambiance.white_disc.invalid_url", "message.ambiance.white_disc.failed"].every {
|
||||
@@ -341,8 +383,10 @@ tasks.register("verifyAmbiance") {
|
||||
}
|
||||
}
|
||||
|| !file("build.gradle").text.contains('dev.arbjerg:lavaplayer:2.2.7')
|
||||
|| !file("build.gradle").text.contains('dev.lavalink.youtube:v2:1.18.2')) {
|
||||
throw new GradleException("Ambiance alpha.15 white-disc playback contract is incomplete")
|
||||
|| !file("build.gradle").text.contains(
|
||||
'def youtubeSourceVersion = "f45bbb7aebfcbc1c553769e04af6cd43afa8b7c3-SNAPSHOT"')
|
||||
|| !file("build.gradle").text.contains('dev.lavalink.youtube:v2:${youtubeSourceVersion}')) {
|
||||
throw new GradleException("Ambiance white-disc playback contract is incomplete")
|
||||
}
|
||||
|
||||
[
|
||||
@@ -396,4 +440,5 @@ tasks.named("check") {
|
||||
dependsOn tasks.named("ambianceScheduleSmoke")
|
||||
dependsOn tasks.named("ambianceVisualApiSmoke")
|
||||
dependsOn tasks.named("whiteDiscUrlSmoke")
|
||||
dependsOn tasks.named("whiteDiscStreamSmoke")
|
||||
}
|
||||
|
||||
+14
-6
@@ -12,13 +12,14 @@ import net.minecraft.client.sounds.AudioStream;
|
||||
/** Adapts bounded mono PCM frames from Lavaplayer to Minecraft's streaming OpenAL channel. */
|
||||
final class LavaplayerAudioStream implements AudioStream {
|
||||
static final int SAMPLE_RATE = 48_000;
|
||||
private static final int FRAME_SAMPLES = 960;
|
||||
private static final int BYTES_PER_SAMPLE = 2;
|
||||
private static final long INITIAL_FRAME_WAIT_MILLIS = 2_000L;
|
||||
private static final long CONTINUATION_FRAME_WAIT_MILLIS = 250L;
|
||||
private static final AudioFormat FORMAT =
|
||||
new AudioFormat(SAMPLE_RATE, 16, 1, true, false);
|
||||
private final AudioPlayer player;
|
||||
private byte[] pending = new byte[0];
|
||||
private int pendingOffset;
|
||||
private boolean initialWaitAttempted;
|
||||
private volatile boolean closed;
|
||||
private volatile boolean ended;
|
||||
|
||||
@@ -45,9 +46,8 @@ final class LavaplayerAudioStream implements AudioStream {
|
||||
AudioFrame frame = nextFrame();
|
||||
if (frame == null) {
|
||||
if (ended) break;
|
||||
int silence = Math.min(output.remaining(), FRAME_SAMPLES * BYTES_PER_SAMPLE);
|
||||
for (int index = 0; index < silence; index++) output.put((byte) 0);
|
||||
continue;
|
||||
while (output.hasRemaining()) output.put((byte) 0);
|
||||
break;
|
||||
}
|
||||
if (frame.isTerminator()) {
|
||||
ended = true;
|
||||
@@ -63,7 +63,11 @@ final class LavaplayerAudioStream implements AudioStream {
|
||||
|
||||
private AudioFrame nextFrame() throws IOException {
|
||||
try {
|
||||
AudioFrame frame = player.provide(2, TimeUnit.SECONDS);
|
||||
long waitMillis = initialWaitAttempted
|
||||
? CONTINUATION_FRAME_WAIT_MILLIS
|
||||
: INITIAL_FRAME_WAIT_MILLIS;
|
||||
initialWaitAttempted = true;
|
||||
AudioFrame frame = player.provide(waitMillis, TimeUnit.MILLISECONDS);
|
||||
if (frame == null && player.getPlayingTrack() == null) ended = true;
|
||||
return frame;
|
||||
} catch (TimeoutException ignored) {
|
||||
@@ -78,6 +82,10 @@ final class LavaplayerAudioStream implements AudioStream {
|
||||
return ended;
|
||||
}
|
||||
|
||||
boolean uses(AudioPlayer expectedPlayer) {
|
||||
return player == expectedPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (closed) return;
|
||||
|
||||
+103
-17
@@ -5,10 +5,12 @@ import com.sedmelluq.discord.lavaplayer.format.Pcm16AudioDataFormat;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import dev.lavalink.youtube.YoutubeAudioSourceManager;
|
||||
import dev.lavalink.youtube.clients.Ios;
|
||||
import fr.koka99cab.sanctuary26.ambiance.AmbianceMod;
|
||||
import fr.koka99cab.sanctuary26.ambiance.mixin.client.SoundEngineAccessor;
|
||||
import fr.koka99cab.sanctuary26.ambiance.mixin.client.SoundManagerAccessor;
|
||||
@@ -30,10 +32,12 @@ import net.minecraft.world.phys.Vec3;
|
||||
/** Client-only, positional and resource-bounded YouTube playback for white discs. */
|
||||
public final class WhiteDiscAudioPlayer {
|
||||
private static final int MAXIMUM_SIMULTANEOUS_DISCS = 4;
|
||||
private static final int MAXIMUM_START_WAIT_TICKS = 100;
|
||||
private static final long MAXIMUM_TRACK_MILLIS = 30L * 60L * 1_000L;
|
||||
private static final long FINISHED_GRACE_NANOS = 5_000_000_000L;
|
||||
private static final float ATTENUATION_DISTANCE = 64.0F;
|
||||
private static final DefaultAudioPlayerManager MANAGER = createManager();
|
||||
private static final Map<Long, PendingStart> PENDING_STARTS = new HashMap<>();
|
||||
private static final Map<Long, Long> REQUESTS = new HashMap<>();
|
||||
private static final LinkedHashMap<Long, Playback> PLAYBACKS = new LinkedHashMap<>();
|
||||
private static long requestSequence;
|
||||
@@ -43,16 +47,27 @@ public final class WhiteDiscAudioPlayer {
|
||||
}
|
||||
|
||||
public static void play(Minecraft client, BlockPos pos, String videoId) {
|
||||
if (shutdown || !WhiteDiscUrl.validVideoId(videoId) || !validTarget(client, pos)) return;
|
||||
if (shutdown || !WhiteDiscUrl.validVideoId(videoId) || !validJukeboxTarget(client, pos)) return;
|
||||
long key = pos.asLong();
|
||||
if (REQUESTS.containsKey(key)) return;
|
||||
if (PENDING_STARTS.containsKey(key) || REQUESTS.containsKey(key)) return;
|
||||
boolean replacingPlayback = PLAYBACKS.containsKey(key);
|
||||
if (!replacingPlayback
|
||||
&& REQUESTS.size() + PLAYBACKS.size() >= MAXIMUM_SIMULTANEOUS_DISCS) return;
|
||||
&& PENDING_STARTS.size() + REQUESTS.size() + PLAYBACKS.size()
|
||||
>= MAXIMUM_SIMULTANEOUS_DISCS) return;
|
||||
stop(key);
|
||||
client.player.sendOverlayMessage(Component.translatable("message.ambiance.white_disc.loading"));
|
||||
if (!validTarget(client, pos)) {
|
||||
PENDING_STARTS.put(key, new PendingStart(pos.immutable(), client.level.dimension(), videoId,
|
||||
MAXIMUM_START_WAIT_TICKS));
|
||||
return;
|
||||
}
|
||||
startLoading(client, pos, videoId);
|
||||
}
|
||||
|
||||
private static void startLoading(Minecraft client, BlockPos pos, String videoId) {
|
||||
long key = pos.asLong();
|
||||
long request = ++requestSequence;
|
||||
REQUESTS.put(key, request);
|
||||
client.player.sendOverlayMessage(Component.translatable("message.ambiance.white_disc.loading"));
|
||||
MANAGER.loadItemOrdered(key, WhiteDiscUrl.canonicalUrl(videoId), new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
@@ -101,24 +116,50 @@ public final class WhiteDiscAudioPlayer {
|
||||
ChannelAccess channels = ((SoundEngineAccessor) ((SoundManagerAccessor) client.getSoundManager())
|
||||
.ambiance$getSoundEngine()).ambiance$getChannelAccess();
|
||||
channels.createHandle(Library.Pool.STREAMING).thenAccept(handle -> client.execute(() -> {
|
||||
if (handle == null || REQUESTS.getOrDefault(key, -1L) != request) {
|
||||
if (handle != null) handle.release();
|
||||
if (handle == null || REQUESTS.getOrDefault(key, -1L) != request
|
||||
|| !validTarget(client, pos)) {
|
||||
if (handle != null) handle.execute(channel -> channel.stop());
|
||||
if (REQUESTS.getOrDefault(key, -1L) == request) REQUESTS.remove(key);
|
||||
return;
|
||||
}
|
||||
AudioPlayer player = MANAGER.createPlayer();
|
||||
player.playTrack(track);
|
||||
LavaplayerAudioStream stream = new LavaplayerAudioStream(player);
|
||||
Playback playback = new Playback(pos.immutable(), client.level.dimension(), handle, stream);
|
||||
PLAYBACKS.put(key, playback);
|
||||
REQUESTS.remove(key);
|
||||
player.addListener(new AudioEventAdapter() {
|
||||
@Override
|
||||
public void onTrackException(AudioPlayer failedPlayer, AudioTrack failedTrack,
|
||||
FriendlyException exception) {
|
||||
AmbianceMod.LOGGER.warn("White-disc playback failed for YouTube video {}: {}",
|
||||
failedTrack.getIdentifier(), exception.getMessage());
|
||||
client.execute(() -> failPlayback(client, key, failedPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackStuck(AudioPlayer stuckPlayer, AudioTrack stuckTrack,
|
||||
long thresholdMs) {
|
||||
AmbianceMod.LOGGER.warn("White-disc playback stalled for YouTube video {} after {} ms",
|
||||
stuckTrack.getIdentifier(), thresholdMs);
|
||||
client.execute(() -> failPlayback(client, key, stuckPlayer));
|
||||
}
|
||||
});
|
||||
player.playTrack(track);
|
||||
float volume = client.options.getFinalSoundSourceVolume(SoundSource.RECORDS);
|
||||
handle.execute(channel -> {
|
||||
channel.setSelfPosition(Vec3.atCenterOf(pos));
|
||||
channel.setRelative(false);
|
||||
channel.linearAttenuation(ATTENUATION_DISTANCE);
|
||||
channel.setVolume(volume);
|
||||
channel.attachBufferStream(stream);
|
||||
channel.play();
|
||||
try {
|
||||
channel.setSelfPosition(Vec3.atCenterOf(pos));
|
||||
channel.setRelative(false);
|
||||
channel.setPitch(1.0F);
|
||||
channel.linearAttenuation(ATTENUATION_DISTANCE);
|
||||
channel.setVolume(volume);
|
||||
channel.attachBufferStream(stream);
|
||||
channel.play();
|
||||
} catch (RuntimeException | LinkageError exception) {
|
||||
AmbianceMod.LOGGER.error("Unable to attach white-disc audio to Minecraft's sound engine",
|
||||
exception);
|
||||
client.execute(() -> failPlayback(client, key, player));
|
||||
}
|
||||
});
|
||||
if (client.player != null) client.player.sendOverlayMessage(
|
||||
Component.translatable("message.ambiance.white_disc.playing", track.getInfo().title));
|
||||
@@ -132,17 +173,25 @@ public final class WhiteDiscAudioPlayer {
|
||||
Component.translatable("message.ambiance.white_disc.failed"));
|
||||
}
|
||||
|
||||
private static void failPlayback(Minecraft client, long key, AudioPlayer player) {
|
||||
Playback playback = PLAYBACKS.get(key);
|
||||
if (playback == null || !playback.stream().uses(player)) return;
|
||||
stop(key);
|
||||
if (client.player != null) client.player.sendOverlayMessage(
|
||||
Component.translatable("message.ambiance.white_disc.failed"));
|
||||
}
|
||||
|
||||
public static void stop(BlockPos pos) {
|
||||
stop(pos.asLong());
|
||||
}
|
||||
|
||||
private static void stop(long key) {
|
||||
PENDING_STARTS.remove(key);
|
||||
REQUESTS.remove(key);
|
||||
Playback playback = PLAYBACKS.remove(key);
|
||||
if (playback == null) return;
|
||||
playback.stream().close();
|
||||
playback.handle().execute(channel -> channel.stop());
|
||||
playback.handle().release();
|
||||
}
|
||||
|
||||
public static void tick(Minecraft client) {
|
||||
@@ -150,6 +199,7 @@ public final class WhiteDiscAudioPlayer {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
tickPendingStarts(client);
|
||||
long now = System.nanoTime();
|
||||
for (Map.Entry<Long, Playback> entry : Map.copyOf(PLAYBACKS).entrySet()) {
|
||||
Playback playback = entry.getValue();
|
||||
@@ -167,6 +217,7 @@ public final class WhiteDiscAudioPlayer {
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
PENDING_STARTS.clear();
|
||||
REQUESTS.clear();
|
||||
for (long key : PLAYBACKS.keySet().stream().mapToLong(Long::longValue).toArray()) stop(key);
|
||||
}
|
||||
@@ -184,16 +235,51 @@ public final class WhiteDiscAudioPlayer {
|
||||
new Pcm16AudioDataFormat(1, LavaplayerAudioStream.SAMPLE_RATE, 960, false));
|
||||
manager.setFrameBufferDuration(5_000);
|
||||
manager.setItemLoaderThreadPoolSize(2);
|
||||
manager.registerSourceManager(new YoutubeAudioSourceManager(false));
|
||||
manager.registerSourceManager(new YoutubeAudioSourceManager(false, new Ios()));
|
||||
return manager;
|
||||
}
|
||||
|
||||
private static boolean validTarget(Minecraft client, BlockPos pos) {
|
||||
return validJukeboxTarget(client, pos)
|
||||
&& client.level.getBlockState(pos).getValue(JukeboxBlock.HAS_RECORD);
|
||||
}
|
||||
|
||||
private static boolean validJukeboxTarget(Minecraft client, BlockPos pos) {
|
||||
return client.player != null && client.level != null
|
||||
&& client.player.distanceToSqr(Vec3.atCenterOf(pos))
|
||||
<= ATTENUATION_DISTANCE * ATTENUATION_DISTANCE * 4.0D
|
||||
&& client.level.getBlockState(pos).is(Blocks.JUKEBOX)
|
||||
&& client.level.getBlockState(pos).getValue(JukeboxBlock.HAS_RECORD);
|
||||
&& client.level.getBlockState(pos).is(Blocks.JUKEBOX);
|
||||
}
|
||||
|
||||
private static void tickPendingStarts(Minecraft client) {
|
||||
for (Map.Entry<Long, PendingStart> entry : Map.copyOf(PENDING_STARTS).entrySet()) {
|
||||
long key = entry.getKey();
|
||||
PendingStart pending = entry.getValue();
|
||||
if (!client.level.dimension().equals(pending.dimension())
|
||||
|| !validJukeboxTarget(client, pending.pos())) {
|
||||
PENDING_STARTS.remove(key);
|
||||
continue;
|
||||
}
|
||||
if (validTarget(client, pending.pos())) {
|
||||
PENDING_STARTS.remove(key);
|
||||
startLoading(client, pending.pos(), pending.videoId());
|
||||
continue;
|
||||
}
|
||||
if (pending.ticksRemaining() <= 1) {
|
||||
PENDING_STARTS.remove(key);
|
||||
if (client.player != null) client.player.sendOverlayMessage(
|
||||
Component.translatable("message.ambiance.white_disc.failed"));
|
||||
continue;
|
||||
}
|
||||
PENDING_STARTS.put(key, pending.waitOneTick());
|
||||
}
|
||||
}
|
||||
|
||||
private record PendingStart(BlockPos pos, ResourceKey<Level> dimension, String videoId,
|
||||
int ticksRemaining) {
|
||||
private PendingStart waitOneTick() {
|
||||
return new PendingStart(pos, dimension, videoId, ticksRemaining - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private record Playback(BlockPos pos, ResourceKey<Level> dimension,
|
||||
|
||||
+4
-6
@@ -1,19 +1,17 @@
|
||||
package fr.koka99cab.sanctuary26.ambiance.mixin.client;
|
||||
|
||||
import fr.koka99cab.sanctuary26.ambiance.client.audio.WhiteDiscAudioPlayer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.LevelEventHandler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LevelRenderer.class)
|
||||
public abstract class LevelRendererMixin {
|
||||
@Mixin(LevelEventHandler.class)
|
||||
public abstract class LevelEventHandlerMixin {
|
||||
@Inject(method = "levelEvent", at = @At("HEAD"))
|
||||
private void ambiance$stopWhiteDisc(Entity source, int type, BlockPos pos, int data,
|
||||
CallbackInfo callback) {
|
||||
private void ambiance$stopWhiteDisc(int type, BlockPos pos, int data, CallbackInfo callback) {
|
||||
if (type == 1011) WhiteDiscAudioPlayer.stop(pos);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
"GameRendererMixin",
|
||||
"LightCoordsUtilMixin",
|
||||
"LightmapRenderStateExtractorMixin",
|
||||
"LevelRendererMixin",
|
||||
"LevelEventHandlerMixin",
|
||||
"SoundEngineAccessor",
|
||||
"SoundManagerAccessor",
|
||||
"SkyRendererMixin"
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package fr.koka99cab.sanctuary26.ambiance.client.audio;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.format.Pcm16AudioDataFormat;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
||||
import com.sedmelluq.discord.lavaplayer.track.playback.ImmutableAudioFrame;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/** Deterministic check for Minecraft's four one-second streaming buffers. */
|
||||
public final class LavaplayerAudioStreamSmoke {
|
||||
private static final int FRAME_SAMPLES = 960;
|
||||
private static final int FRAME_BYTES = FRAME_SAMPLES * 2;
|
||||
private static final int FRAMES_PER_SECOND = LavaplayerAudioStream.SAMPLE_RATE / FRAME_SAMPLES;
|
||||
|
||||
private LavaplayerAudioStreamSmoke() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Queue<AudioFrame> frames = new ArrayDeque<>();
|
||||
Pcm16AudioDataFormat format = new Pcm16AudioDataFormat(
|
||||
1, LavaplayerAudioStream.SAMPLE_RATE, FRAME_SAMPLES, false);
|
||||
for (int index = 0; index < FRAMES_PER_SECOND; index++) {
|
||||
byte[] data = new byte[FRAME_BYTES];
|
||||
Arrays.fill(data, (byte) (index + 1));
|
||||
frames.add(new ImmutableAudioFrame(index * 20L, data, 100, format));
|
||||
}
|
||||
|
||||
AtomicInteger timedProvides = new AtomicInteger();
|
||||
AtomicInteger nonBlockingProvides = new AtomicInteger();
|
||||
AtomicBoolean destroyed = new AtomicBoolean();
|
||||
AudioPlayer player = (AudioPlayer) Proxy.newProxyInstance(
|
||||
AudioPlayer.class.getClassLoader(), new Class<?>[] {AudioPlayer.class},
|
||||
(proxy, method, arguments) -> switch (method.getName()) {
|
||||
case "provide" -> {
|
||||
if (method.getParameterCount() == 2) {
|
||||
timedProvides.incrementAndGet();
|
||||
yield frames.poll();
|
||||
}
|
||||
nonBlockingProvides.incrementAndGet();
|
||||
yield null;
|
||||
}
|
||||
case "destroy" -> {
|
||||
destroyed.set(true);
|
||||
yield null;
|
||||
}
|
||||
case "getPlayingTrack" -> null;
|
||||
case "getVolume" -> 100;
|
||||
case "isPaused", "startTrack" -> false;
|
||||
default -> null;
|
||||
});
|
||||
|
||||
LavaplayerAudioStream stream = new LavaplayerAudioStream(player);
|
||||
ByteBuffer pcm = stream.read(LavaplayerAudioStream.SAMPLE_RATE * 2);
|
||||
if (pcm == null || pcm.remaining() != LavaplayerAudioStream.SAMPLE_RATE * 2) {
|
||||
throw new IllegalStateException("The stream did not fill Minecraft's one-second buffer");
|
||||
}
|
||||
while (pcm.hasRemaining()) {
|
||||
if (pcm.get() == 0) {
|
||||
throw new IllegalStateException("The stream padded available PCM with silence");
|
||||
}
|
||||
}
|
||||
if (timedProvides.get() != FRAMES_PER_SECOND || nonBlockingProvides.get() != 0) {
|
||||
throw new IllegalStateException("PCM frames were not read with bounded waits");
|
||||
}
|
||||
if (stream.getFormat().getSampleRate() != LavaplayerAudioStream.SAMPLE_RATE
|
||||
|| stream.getFormat().isBigEndian()) {
|
||||
throw new IllegalStateException("The OpenAL PCM format is not 48 kHz little-endian");
|
||||
}
|
||||
stream.close();
|
||||
if (!destroyed.get()) {
|
||||
throw new IllegalStateException("Closing the stream did not destroy its player");
|
||||
}
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package fr.koka99cab.sanctuary26.ambiance.client.audio;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.format.Pcm16AudioDataFormat;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import dev.lavalink.youtube.YoutubeAudioSourceManager;
|
||||
import dev.lavalink.youtube.clients.Ios;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/** Manual network smoke test for the exact YouTube playback path used by white discs. */
|
||||
public final class WhiteDiscPlaybackSmoke {
|
||||
private static final String VIDEO_URL = "https://www.youtube.com/watch?v=Ue5ZBe-GzSM";
|
||||
|
||||
private WhiteDiscPlaybackSmoke() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DefaultAudioPlayerManager manager = new DefaultAudioPlayerManager();
|
||||
manager.getConfiguration().setOutputFormat(
|
||||
new Pcm16AudioDataFormat(1, LavaplayerAudioStream.SAMPLE_RATE, 960, false));
|
||||
manager.registerSourceManager(new YoutubeAudioSourceManager(false, new Ios()));
|
||||
try {
|
||||
AudioTrack track = load(manager).get(30, TimeUnit.SECONDS);
|
||||
AudioPlayer player = manager.createPlayer();
|
||||
player.playTrack(track);
|
||||
LavaplayerAudioStream stream = new LavaplayerAudioStream(player);
|
||||
int decodedBytes = 0;
|
||||
int totalBytes = 0;
|
||||
for (int index = 0; index < 4; index++) {
|
||||
ByteBuffer pcm = stream.read(LavaplayerAudioStream.SAMPLE_RATE * 2);
|
||||
if (pcm == null) break;
|
||||
while (pcm.hasRemaining()) {
|
||||
totalBytes++;
|
||||
if (pcm.get() != 0) decodedBytes++;
|
||||
}
|
||||
}
|
||||
if (decodedBytes == 0) {
|
||||
throw new IllegalStateException("YouTube playback produced no audible PCM data");
|
||||
}
|
||||
double audibleRatio = (double) decodedBytes / totalBytes;
|
||||
if (totalBytes != LavaplayerAudioStream.SAMPLE_RATE * 2 * 4) {
|
||||
throw new IllegalStateException("YouTube playback did not fill four PCM seconds");
|
||||
}
|
||||
if (audibleRatio < 0.75) {
|
||||
throw new IllegalStateException("YouTube PCM stream was mostly silence: "
|
||||
+ Math.round(audibleRatio * 100.0) + "% audible bytes");
|
||||
}
|
||||
System.out.printf("Decoded audible PCM data: %.1f%% at %.0f Hz from %s%n",
|
||||
audibleRatio * 100.0, stream.getFormat().getSampleRate(), track.getInfo().title);
|
||||
stream.close();
|
||||
} finally {
|
||||
manager.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private static CompletableFuture<AudioTrack> load(DefaultAudioPlayerManager manager) {
|
||||
CompletableFuture<AudioTrack> result = new CompletableFuture<>();
|
||||
manager.loadItem(VIDEO_URL, new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
result.complete(track);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
AudioTrack selected = playlist.getSelectedTrack();
|
||||
if (selected == null && !playlist.getTracks().isEmpty()) {
|
||||
selected = playlist.getTracks().getFirst();
|
||||
}
|
||||
if (selected == null) result.completeExceptionally(
|
||||
new IllegalStateException("YouTube playlist contained no track"));
|
||||
else result.complete(selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noMatches() {
|
||||
result.completeExceptionally(new IllegalStateException("YouTube returned no match"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFailed(FriendlyException exception) {
|
||||
result.completeExceptionally(exception);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+2
@@ -10,6 +10,8 @@ public final class WhiteDiscUrlSmoke {
|
||||
public static void main(String[] args) {
|
||||
require(VIDEO_ID.equals(id("https://www.youtube.com/watch?v=" + VIDEO_ID)), "watch URL rejected");
|
||||
require(VIDEO_ID.equals(id("https://youtu.be/" + VIDEO_ID + "?si=abc")), "short URL rejected");
|
||||
require("Ue5ZBe-GzSM".equals(id("https://youtu.be/Ue5ZBe-GzSM?si=78LSbtBQzUYzhA2Y")),
|
||||
"reported white-disc URL rejected");
|
||||
require(VIDEO_ID.equals(id("https://music.youtube.com/watch?v=" + VIDEO_ID)), "music URL rejected");
|
||||
require(VIDEO_ID.equals(id("https://www.youtube.com/shorts/" + VIDEO_ID)), "shorts URL rejected");
|
||||
require(VIDEO_ID.equals(id("https://www.youtube.com/embed/" + VIDEO_ID)), "embed URL rejected");
|
||||
|
||||
+766
-106
File diff suppressed because it is too large
Load Diff
+5
-5
@@ -12,9 +12,9 @@ fabric_api_version=0.158.0+26.2
|
||||
# Standby modules stay at zero until their migration really begins.
|
||||
mod_version=0.0.0-alpha.0
|
||||
module_lifecycle=standby
|
||||
ambiance_version=0.0.0-alpha.15
|
||||
ambiance_version=0.0.0-alpha.19
|
||||
ambiance_lifecycle=active
|
||||
redstoner_version=0.0.0-alpha.10
|
||||
redstoner_version=0.0.0-alpha.11
|
||||
redstoner_lifecycle=active
|
||||
anotherworld_version=0.0.0-alpha.55
|
||||
anotherworld_lifecycle=active
|
||||
@@ -26,9 +26,9 @@ masterkey_version=0.0.0-alpha.8
|
||||
masterkey_lifecycle=active
|
||||
iliketomoveit_version=0.0.0-alpha.15
|
||||
iliketomoveit_lifecycle=active
|
||||
onlyfun_version=0.0.0-alpha.24
|
||||
onlyfun_version=0.0.0-alpha.25
|
||||
onlyfun_lifecycle=active
|
||||
sanctuary_version=0.0.0-alpha.119
|
||||
sanctuary_version=0.0.0-alpha.121
|
||||
sanctuary_lifecycle=active
|
||||
pack_version=26.2.0-alpha.210
|
||||
pack_version=26.2.0-alpha.217
|
||||
maven_group=fr.koka99cab.sanctuary26
|
||||
|
||||
@@ -44,6 +44,7 @@ public final class OnlyFunItemPolicy {
|
||||
if (namespace.equals("canaplia") || namespace.equals("itsalive")) return true;
|
||||
if (namespace.equals("minecraft") && VANILLA_SHOP_GAMEPLAY_BYPASSES.contains(path)) return true;
|
||||
if (namespace.equals("anotherworld") && isProtectedAnotherWorldItem(path)) return true;
|
||||
if (isStorageTerminal(namespace, path)) return true;
|
||||
if (TECHNICAL_OR_REWARD_BLOCKS.contains(path) || path.startsWith("infested_")
|
||||
|| path.contains("command_block")) return true;
|
||||
if (path.contains("lootbox") || path.contains("loot_box")) return true;
|
||||
@@ -61,6 +62,7 @@ public final class OnlyFunItemPolicy {
|
||||
String namespace = id.getNamespace().toLowerCase(Locale.ROOT);
|
||||
String path = normalizedPath(id);
|
||||
return namespace.equals("canaplia") || path.contains("lootbox") || path.contains("loot_box")
|
||||
|| isStorageTerminal(namespace, path)
|
||||
|| (namespace.equals("onlyfun") && path.equals("lucky_block"))
|
||||
|| (namespace.equals("sanctuary") && path.equals("delivery_box"))
|
||||
|| TECHNICAL_OR_REWARD_BLOCKS.contains(path) || path.startsWith("infested_")
|
||||
@@ -77,6 +79,10 @@ public final class OnlyFunItemPolicy {
|
||||
|| path.contains("titanium") || path.contains("rainbow_block");
|
||||
}
|
||||
|
||||
private static boolean isStorageTerminal(String namespace, String path) {
|
||||
return namespace.equals("redstoner") && path.equals("storage_terminal");
|
||||
}
|
||||
|
||||
private static String normalizedPath(Identifier id) {
|
||||
return id.getPath().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
+7
@@ -81,6 +81,13 @@ public final class OnlyFunShopCatalogSmoke {
|
||||
require(!OnlyFunItemPolicy.excludedFromShop(Identifier.parse(rawFoodId)),
|
||||
"Raw ingredient was removed with finished food: " + rawFoodId);
|
||||
}
|
||||
Identifier storageTerminal = Identifier.parse("redstoner:storage_terminal");
|
||||
require(OnlyFunItemPolicy.excludedFromShop(storageTerminal),
|
||||
"Storage Terminal reached the Shop policy");
|
||||
require(OnlyFunItemPolicy.excludedFromRewards(storageTerminal),
|
||||
"Storage Terminal reached lootbox rewards");
|
||||
require(find(all, storageTerminal.toString()) == null,
|
||||
"Storage Terminal reached the generated Shop catalogue");
|
||||
require(OnlyFunBossShopGate.requiresBoss("iliketomoveit:magic_carpet"),
|
||||
"Magic Carpet must remain boss-gated");
|
||||
require(OnlyFunBossShopGate.requiresBoss("iliketomoveit:magic_cloud"),
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"source": {
|
||||
"pack_version": "26.2.0-alpha.210",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.14",
|
||||
"itsalive": "0.0.0-alpha.35",
|
||||
"onlyfun": "0.0.0-alpha.21",
|
||||
"ouch": "0.0.0-alpha.9",
|
||||
"sanctuary": "0.0.0-alpha.118"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pack_version": "26.2.0-alpha.211",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.15",
|
||||
"itsalive": "0.0.0-alpha.36",
|
||||
"onlyfun": "0.0.0-alpha.24",
|
||||
"ouch": "0.0.0-alpha.10",
|
||||
"sanctuary": "0.0.0-alpha.119"
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"canaplia_codex_uses_vanilla_book_pages": true,
|
||||
"black_market_middle_click_restored": true,
|
||||
"white_disc_youtube_audio": true,
|
||||
"white_disc_max_concurrent_streams": 4,
|
||||
"abjection_server_actions": ["piss", "vomit", "shit", "smoke"],
|
||||
"abjection_shit_ball_projectile": true,
|
||||
"abjection_shit_cube": true,
|
||||
"abjection_default_key": "J",
|
||||
"abjection_projectile_nausea_seconds": 7
|
||||
},
|
||||
"compatibility": {
|
||||
"new_world_required": false,
|
||||
"save_reset_required": false,
|
||||
"existing_saves_supported": true,
|
||||
"registry_ids_added": [
|
||||
"ambiance:white_disc",
|
||||
"abjection:shit_ball",
|
||||
"abjection:shit_cube"
|
||||
],
|
||||
"data_versions": {
|
||||
"ambiance": 2,
|
||||
"itsalive": 3,
|
||||
"onlyfun": 2,
|
||||
"ouch": 1,
|
||||
"sanctuary": 11
|
||||
},
|
||||
"network_protocols": {
|
||||
"ambiance": 6,
|
||||
"itsalive": 4,
|
||||
"onlyfun": 3,
|
||||
"ouch": 1,
|
||||
"sanctuary": 22
|
||||
}
|
||||
},
|
||||
"distribution": {
|
||||
"pack_release_updated": true,
|
||||
"packwiz_index_refreshed": true,
|
||||
"prism_modrinth_index_updated": true,
|
||||
"shared_client_server_mrpack": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"source": {
|
||||
"pack_version": "26.2.0-alpha.211",
|
||||
"modules": {
|
||||
"sanctuary": "0.0.0-alpha.119"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pack_version": "26.2.0-alpha.212",
|
||||
"modules": {
|
||||
"sanctuary": "0.0.0-alpha.120"
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"black_market_middle_click_preserved": true,
|
||||
"minecraft_mixin_target": "pickBlockOrEntity",
|
||||
"client_startup_crash_fixed": true
|
||||
},
|
||||
"compatibility": {
|
||||
"new_world_required": false,
|
||||
"save_reset_required": false,
|
||||
"existing_saves_supported": true,
|
||||
"registry_ids_changed": false,
|
||||
"sanctuary_data_version": 11,
|
||||
"sanctuary_network_protocol": 22
|
||||
},
|
||||
"distribution": {
|
||||
"pack_release_updated": true,
|
||||
"packwiz_index_refreshed": true,
|
||||
"prism_modrinth_index_updated": true,
|
||||
"shared_client_server_mrpack": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"source": {
|
||||
"pack_version": "26.2.0-alpha.212",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.15"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pack_version": "26.2.0-alpha.213",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.16"
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"white_disc_stop_event_preserved": true,
|
||||
"minecraft_mixin_target_class": "LevelEventHandler",
|
||||
"minecraft_mixin_target_method": "levelEvent",
|
||||
"client_startup_crash_fixed": true
|
||||
},
|
||||
"compatibility": {
|
||||
"new_world_required": false,
|
||||
"save_reset_required": false,
|
||||
"existing_saves_supported": true,
|
||||
"registry_ids_changed": false,
|
||||
"ambiance_data_version": 2,
|
||||
"ambiance_network_protocol": 6
|
||||
},
|
||||
"distribution": {
|
||||
"pack_release_updated": true,
|
||||
"packwiz_index_refreshed": true,
|
||||
"prism_modrinth_index_updated": true,
|
||||
"shared_client_server_mrpack": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"source": {
|
||||
"pack_version": "26.2.0-alpha.213",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.16"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pack_version": "26.2.0-alpha.214",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.17"
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"white_disc_solo_playback_restored": true,
|
||||
"client_jukebox_sync_wait_ticks": 100,
|
||||
"loading_feedback_immediate": true,
|
||||
"sync_timeout_feedback": true,
|
||||
"youtube_share_parameters_supported": true
|
||||
},
|
||||
"compatibility": {
|
||||
"new_world_required": false,
|
||||
"save_reset_required": false,
|
||||
"existing_saves_supported": true,
|
||||
"registry_ids_changed": false,
|
||||
"ambiance_data_version": 2,
|
||||
"ambiance_network_protocol": 6
|
||||
},
|
||||
"distribution": {
|
||||
"pack_release_updated": true,
|
||||
"packwiz_index_refreshed": true,
|
||||
"prism_modrinth_index_updated": true,
|
||||
"shared_client_server_mrpack": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"source": {
|
||||
"pack_version": "26.2.0-alpha.214",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.17"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pack_version": "26.2.0-alpha.215",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.18"
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"white_disc_native_crash_fixed": true,
|
||||
"openal_channel_release_owned_by_audio_thread": true,
|
||||
"youtube_client_profile": "Ios",
|
||||
"youtube_source_commit": "f45bbb7aebfcbc1c553769e04af6cd43afa8b7c3",
|
||||
"initial_stream_wait_bounded": true,
|
||||
"subsequent_stream_polls_non_blocking": true,
|
||||
"playback_errors_stop_safely": true,
|
||||
"live_pcm_smoke_video_id": "Ue5ZBe-GzSM"
|
||||
},
|
||||
"compatibility": {
|
||||
"new_world_required": false,
|
||||
"save_reset_required": false,
|
||||
"existing_saves_supported": true,
|
||||
"registry_ids_changed": false,
|
||||
"ambiance_data_version": 2,
|
||||
"ambiance_network_protocol": 6
|
||||
},
|
||||
"distribution": {
|
||||
"pack_release_updated": true,
|
||||
"packwiz_index_refreshed": true,
|
||||
"prism_modrinth_index_updated": true,
|
||||
"shared_client_server_mrpack": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"source": {
|
||||
"pack_version": "26.2.0-alpha.215",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.18"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pack_version": "26.2.0-alpha.216",
|
||||
"modules": {
|
||||
"ambiance": "0.0.0-alpha.19"
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"white_disc_continuous_pcm_buffering": true,
|
||||
"sample_rate_hz": 48000,
|
||||
"channel_count": 1,
|
||||
"sample_size_bits": 16,
|
||||
"minecraft_stream_buffer_seconds": 1,
|
||||
"minecraft_initial_buffer_count": 4,
|
||||
"initial_frame_wait_millis": 2000,
|
||||
"continuation_frame_wait_millis": 250,
|
||||
"openal_pitch": 1.0,
|
||||
"live_pcm_smoke_video_id": "Ue5ZBe-GzSM",
|
||||
"minimum_live_audible_byte_ratio": 0.75,
|
||||
"deterministic_stream_smoke": true
|
||||
},
|
||||
"compatibility": {
|
||||
"new_world_required": false,
|
||||
"save_reset_required": false,
|
||||
"existing_saves_supported": true,
|
||||
"registry_ids_changed": false,
|
||||
"ambiance_data_version": 2,
|
||||
"ambiance_network_protocol": 6
|
||||
},
|
||||
"distribution": {
|
||||
"pack_release_updated": true,
|
||||
"packwiz_index_refreshed": true,
|
||||
"prism_modrinth_index_updated": true,
|
||||
"shared_client_server_mrpack": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"source": {
|
||||
"pack_version": "26.2.0-alpha.216",
|
||||
"modules": {
|
||||
"redstoner": "0.0.0-alpha.10",
|
||||
"onlyfun": "0.0.0-alpha.24",
|
||||
"sanctuary": "0.0.0-alpha.120"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pack_version": "26.2.0-alpha.217",
|
||||
"modules": {
|
||||
"redstoner": "0.0.0-alpha.11",
|
||||
"onlyfun": "0.0.0-alpha.25",
|
||||
"sanctuary": "0.0.0-alpha.121"
|
||||
}
|
||||
},
|
||||
"storage_terminal": {
|
||||
"owner": "redstoner",
|
||||
"id": "redstoner:storage_terminal",
|
||||
"shape_depth_pixels": 8,
|
||||
"horizontal_wall_mount_only": true,
|
||||
"supported_containers": [
|
||||
"minecraft:chest",
|
||||
"minecraft:trapped_chest",
|
||||
"minecraft:barrel"
|
||||
],
|
||||
"ender_chest_supported": false,
|
||||
"face_adjacent_network_includes_vertical": true,
|
||||
"loaded_chunks_only": true,
|
||||
"maximum_physical_containers": 128,
|
||||
"oversized_network_rejected": true,
|
||||
"page_size": 54,
|
||||
"strict_item_component_aggregation": true,
|
||||
"server_authoritative_transfers": true,
|
||||
"left_click_extracts_stack": true,
|
||||
"right_click_extracts_one": true,
|
||||
"shift_click_deposits_player_stack": true,
|
||||
"crafting_pattern": ["PGP", "GCG", "PTP"],
|
||||
"crafting_ingredients": {
|
||||
"P": "anotherworld:silver_plate",
|
||||
"G": "minecraft:tinted_glass",
|
||||
"C": "redstoner:controller",
|
||||
"T": "anotherworld:titanium_ingot"
|
||||
},
|
||||
"available_in_shop": false,
|
||||
"available_in_black_market": false,
|
||||
"available_in_lootbox_rewards": false
|
||||
},
|
||||
"compatibility": {
|
||||
"new_world_required": false,
|
||||
"save_reset_required": false,
|
||||
"existing_saves_supported": true,
|
||||
"registry_ids_added": ["redstoner:storage_terminal"],
|
||||
"redstoner_data_version": 3,
|
||||
"redstoner_source_network_protocol": 5,
|
||||
"redstoner_target_network_protocol": 6,
|
||||
"onlyfun_data_version": 2,
|
||||
"onlyfun_network_protocol": 3,
|
||||
"sanctuary_data_version": 11,
|
||||
"sanctuary_network_protocol": 22
|
||||
},
|
||||
"distribution": {
|
||||
"pack_release_updated": true,
|
||||
"packwiz_index_refreshed": true,
|
||||
"prism_modrinth_index_updated": true,
|
||||
"shared_client_server_mrpack": true
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -13,16 +13,16 @@ file = "instance-icon.png"
|
||||
hash = "41f4f4c88c71d0a23446d5014f7407d55ad477441847099cad24492b032335a0"
|
||||
|
||||
[[files]]
|
||||
file = "mods/ambiance-0.0.0-alpha.14.jar"
|
||||
hash = "a4b2a36e046a3095ada58e3dbf5fd30ab7c8ba42eaf2abcf513b38b8cc2f3e4a"
|
||||
file = "mods/ambiance-0.0.0-alpha.19.jar"
|
||||
hash = "9138adaaa0fb063100906e44453442d9e2596199769067207a2f7bd44f372756"
|
||||
|
||||
[[files]]
|
||||
file = "mods/anotherworld-0.0.0-alpha.55.jar"
|
||||
hash = "da7163a34ca71e1c2385a84221cddccc09f0f83d9a00bce0ed6263b19ec519cb"
|
||||
hash = "2d6250686739fd0bddcbff2d382e22fb9e403472926931f2879f6870af96ed64"
|
||||
|
||||
[[files]]
|
||||
file = "mods/events-0.0.0-alpha.0.jar"
|
||||
hash = "7400d63c905d1c87a5290adaa2fe91305fa1f067827ca8f0610a6ae4e17624da"
|
||||
hash = "4ac4ec54bf702a164443eb184796cca603cbad84607e794c2b24dbd5c7c221b9"
|
||||
|
||||
[[files]]
|
||||
file = "mods/fabric-api.pw.toml"
|
||||
@@ -31,7 +31,7 @@ metafile = true
|
||||
|
||||
[[files]]
|
||||
file = "mods/iliketomoveit-0.0.0-alpha.15.jar"
|
||||
hash = "a084cf25a4afa50086ce220f40b6b3946a06389de105f23c0246df1577deb3c8"
|
||||
hash = "fe73255673eda5cbe16fe0bfd4a13951d9f103f58461ca84020e27cde408e569"
|
||||
|
||||
[[files]]
|
||||
file = "mods/iris.pw.toml"
|
||||
@@ -39,8 +39,8 @@ hash = "84a3cef87679c0d21dceb4641167dc0368b9a3593698f6a3632485e9b3a8d5da"
|
||||
metafile = true
|
||||
|
||||
[[files]]
|
||||
file = "mods/itsalive-0.0.0-alpha.35.jar"
|
||||
hash = "4a6433abdfc03a0872f7c810fb17016a0f20acda5e223e0fef479dd786cc73ac"
|
||||
file = "mods/itsalive-0.0.0-alpha.36.jar"
|
||||
hash = "49aab5f4b3c9145d3cc4e64ce46bff138e4c6147c83c985d402024920d929d0d"
|
||||
|
||||
[[files]]
|
||||
file = "mods/jei.pw.toml"
|
||||
@@ -49,23 +49,23 @@ metafile = true
|
||||
|
||||
[[files]]
|
||||
file = "mods/masterkey-0.0.0-alpha.8.jar"
|
||||
hash = "eaf70f6c5a78ee7ab2d3be498d4f7d67fcba433ed61b65b305e958f03b387d94"
|
||||
hash = "9429a818c517b3943fdcbdd442800b9d854bf73c605df0f1ec761366574c129a"
|
||||
|
||||
[[files]]
|
||||
file = "mods/onlyfun-0.0.0-alpha.21.jar"
|
||||
hash = "7e319a0cc6149d5819ef2359fe3ad4035066a9cddd5ae0a16c12c9db64bc3f6a"
|
||||
file = "mods/onlyfun-0.0.0-alpha.25.jar"
|
||||
hash = "005202d009ba00c5a3019aec6813cbdc2006d191299b2d1829051f73c2fb604a"
|
||||
|
||||
[[files]]
|
||||
file = "mods/ouch-0.0.0-alpha.9.jar"
|
||||
hash = "f3cf2d8c83afa32b1c70e8239dd514be3c74834397f9d09efe177bc8c5ef9ac4"
|
||||
file = "mods/ouch-0.0.0-alpha.10.jar"
|
||||
hash = "b4b5c5cf8164f6a0ce6131031fcbd0840c048a249d1b7c6e08f5b7aeed0e7656"
|
||||
|
||||
[[files]]
|
||||
file = "mods/redstoner-0.0.0-alpha.10.jar"
|
||||
hash = "a9049b9d3a323015545194c92ce9da7a5dca4ff9a28ea26b02bead96748328ab"
|
||||
file = "mods/redstoner-0.0.0-alpha.11.jar"
|
||||
hash = "457b4502ce2946963b4c2f21514a29c941f81df9bd1457f5db43fecdfa859a7e"
|
||||
|
||||
[[files]]
|
||||
file = "mods/sanctuary-0.0.0-alpha.118.jar"
|
||||
hash = "1a1319e5f09de941ad8a7561aff9d2fb8c7460a8cd8d2374817d8f39c5682030"
|
||||
file = "mods/sanctuary-0.0.0-alpha.121.jar"
|
||||
hash = "ef2c827774c768289e034c9715d4f27c347b533f7476a6d355c7b45123fedcec"
|
||||
|
||||
[[files]]
|
||||
file = "mods/simple-voice-chat.pw.toml"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
name = "Sanctuary 26.2"
|
||||
author = "KOKA99CAB"
|
||||
version = "26.2.0-alpha.210"
|
||||
version = "26.2.0-alpha.217"
|
||||
pack-format = "packwiz:1.1.0"
|
||||
|
||||
[index]
|
||||
file = "index.toml"
|
||||
hash-format = "sha256"
|
||||
hash = "e20c051f8895ce3164ec72b7764b8904f411e36f63bf1e046b1bcc9108d00a31"
|
||||
hash = "176382d1bdb3797ba19d8d7acb093b9b49156f3b5b3270db803e59d24c6de7e1"
|
||||
|
||||
[versions]
|
||||
fabric = "0.19.3"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"game": "minecraft",
|
||||
"name": "Sanctuary 26.2",
|
||||
"summary": "Sanctuary 26.2 — progression, exploration, worldgen and multiplayer systems by KOKA99CAB.",
|
||||
"versionId": "26.2.0-alpha.210",
|
||||
"versionId": "26.2.0-alpha.217",
|
||||
"files": [
|
||||
{
|
||||
"path": "mods/fabric-api-0.158.0+26.2.jar",
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"pack_version": "26.2.0-alpha.210",
|
||||
"pack_version": "26.2.0-alpha.217",
|
||||
"release_channel": "alpha",
|
||||
"minecraft_version": "26.2",
|
||||
"fabric_loader_version": "0.19.3",
|
||||
@@ -9,7 +9,7 @@
|
||||
"project_id": "FgOqyAXd",
|
||||
"project_slug": "sanctuary-koka99",
|
||||
"project_url": "https://modrinth.com/modpack/sanctuary-koka99",
|
||||
"primary_file": "sanctuary-26.2.0-alpha.210.mrpack",
|
||||
"primary_file": "sanctuary-26.2.0-alpha.217.mrpack",
|
||||
"shared_client_server_pack": true,
|
||||
"update_owner": "packwiz-installer",
|
||||
"check_on_launch": true,
|
||||
|
||||
@@ -27,7 +27,7 @@ public final class RedStonerMod implements ModInitializer {
|
||||
RedStonerApi.registerServerIdentityProvider(SanctuaryServerIdentity::get);
|
||||
RedStonerRegistries.initialize();
|
||||
RedStonerNetworking.initialize();
|
||||
LOGGER.info("[{}] Computers, Drawer and Particuleur ready (data v{}, network v{}).",
|
||||
LOGGER.info("[{}] Computers, Drawer, Particuleur and Storage Terminal ready (data v{}, network v{}).",
|
||||
DISPLAY_NAME, CURRENT_DATA_VERSION, RedStonerNetworking.PROTOCOL_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.block;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import fr.koka99cab.sanctuary26.redstoner.network.RedStonerNetworking;
|
||||
import fr.koka99cab.sanctuary26.redstoner.storage.StorageTerminalNetwork;
|
||||
import java.util.Map;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.ScheduledTickAccess;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public final class StorageTerminalBlock extends Block {
|
||||
public static final MapCodec<StorageTerminalBlock> CODEC = simpleCodec(StorageTerminalBlock::new);
|
||||
public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
|
||||
private static final Map<Direction, VoxelShape> SHAPES = Map.of(
|
||||
Direction.NORTH, Block.box(0.0D, 0.0D, 8.0D, 16.0D, 16.0D, 16.0D),
|
||||
Direction.SOUTH, Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 8.0D),
|
||||
Direction.WEST, Block.box(8.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D),
|
||||
Direction.EAST, Block.box(0.0D, 0.0D, 0.0D, 8.0D, 16.0D, 16.0D)
|
||||
);
|
||||
|
||||
public StorageTerminalBlock(Properties properties) {
|
||||
super(properties);
|
||||
registerDefaultState(stateDefinition.any().setValue(FACING, Direction.NORTH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCodec<StorageTerminalBlock> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
Direction facing = context.getClickedFace();
|
||||
if (!facing.getAxis().isHorizontal()) return null;
|
||||
BlockState state = defaultBlockState().setValue(FACING, facing);
|
||||
return state.canSurvive(context.getLevel(), context.getClickedPos()) ? state : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
||||
BlockPos support = pos.relative(state.getValue(FACING).getOpposite());
|
||||
return StorageTerminalNetwork.isCompatibleStorage(level.getBlockState(support));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks,
|
||||
BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) {
|
||||
return direction == state.getValue(FACING).getOpposite() && !state.canSurvive(level, pos)
|
||||
? Blocks.AIR.defaultBlockState()
|
||||
: super.updateShape(state, level, ticks, pos, direction, neighborPos, neighborState, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
||||
return SHAPES.get(state.getValue(FACING));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos,
|
||||
Player player, InteractionHand hand, BlockHitResult hit) {
|
||||
return open(level, pos, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos,
|
||||
Player player, BlockHitResult hit) {
|
||||
return open(level, pos, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState rotate(BlockState state, Rotation rotation) {
|
||||
return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState mirror(BlockState state, Mirror mirror) {
|
||||
return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
||||
}
|
||||
|
||||
private static InteractionResult open(Level level, BlockPos pos, Player player) {
|
||||
if (level.isClientSide()) return InteractionResult.SUCCESS;
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
RedStonerNetworking.openStorageTerminal(serverPlayer, pos);
|
||||
return InteractionResult.SUCCESS_SERVER;
|
||||
}
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
}
|
||||
+11
@@ -3,9 +3,11 @@ package fr.koka99cab.sanctuary26.redstoner.client;
|
||||
import fr.koka99cab.sanctuary26.redstoner.RedStonerMod;
|
||||
import fr.koka99cab.sanctuary26.redstoner.client.gui.ComputerScreen;
|
||||
import fr.koka99cab.sanctuary26.redstoner.client.gui.PersonalComputerScreen;
|
||||
import fr.koka99cab.sanctuary26.redstoner.client.gui.StorageTerminalScreen;
|
||||
import fr.koka99cab.sanctuary26.redstoner.client.renderer.DrawerBlockEntityRenderer;
|
||||
import fr.koka99cab.sanctuary26.redstoner.network.OpenComputerPayload;
|
||||
import fr.koka99cab.sanctuary26.redstoner.network.OpenPersonalComputerPayload;
|
||||
import fr.koka99cab.sanctuary26.redstoner.network.StorageTerminalSnapshotPayload;
|
||||
import fr.koka99cab.sanctuary26.redstoner.registry.RedStonerRegistries;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
@@ -26,6 +28,15 @@ public final class RedStonerClient implements ClientModInitializer {
|
||||
context.client().gui.setScreen(new PersonalComputerScreen(payload));
|
||||
}
|
||||
}));
|
||||
ClientPlayNetworking.registerGlobalReceiver(StorageTerminalSnapshotPayload.TYPE, (payload, context) ->
|
||||
context.client().execute(() -> {
|
||||
if (context.client().gui.screen() instanceof StorageTerminalScreen screen
|
||||
&& screen.represents(payload)) {
|
||||
screen.acceptSnapshot(payload);
|
||||
} else {
|
||||
context.client().gui.setScreen(new StorageTerminalScreen(payload));
|
||||
}
|
||||
}));
|
||||
RedStonerMod.LOGGER.info("[{}] Client renderers and laboratory screens ready.", RedStonerMod.DISPLAY_NAME);
|
||||
}
|
||||
|
||||
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.client.gui;
|
||||
|
||||
import fr.koka99cab.sanctuary26.redstoner.network.StorageTerminalActionPayload;
|
||||
import fr.koka99cab.sanctuary26.redstoner.network.StorageTerminalSnapshotPayload;
|
||||
import fr.koka99cab.sanctuary26.redstoner.storage.StorageTerminalRules;
|
||||
import fr.koka99cab.sanctuary26.redstoner.storage.StorageTerminalStatus;
|
||||
import java.util.Locale;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public final class StorageTerminalScreen extends Screen {
|
||||
private static final int PANEL_WIDTH = 204;
|
||||
private static final int PANEL_HEIGHT = 236;
|
||||
private static final int SLOT_SIZE = 18;
|
||||
private static final int GRID_X = 8;
|
||||
private static final int GRID_Y = 20;
|
||||
private static final int PLAYER_GRID_Y = 152;
|
||||
private static final int HOTBAR_Y = 210;
|
||||
private static final int SCROLL_X = 176;
|
||||
private static final int SCROLL_WIDTH = 8;
|
||||
private static final int REFRESH_TICKS = 20;
|
||||
|
||||
private StorageTerminalSnapshotPayload snapshot;
|
||||
private int requestedPage;
|
||||
private int refreshCooldown = REFRESH_TICKS;
|
||||
|
||||
public StorageTerminalScreen(StorageTerminalSnapshotPayload snapshot) {
|
||||
super(Component.translatable("screen.redstoner.storage_terminal.title"));
|
||||
this.snapshot = snapshot;
|
||||
this.requestedPage = snapshot.page();
|
||||
}
|
||||
|
||||
public boolean represents(StorageTerminalSnapshotPayload other) {
|
||||
return snapshot.pos().equals(other.pos());
|
||||
}
|
||||
|
||||
public void acceptSnapshot(StorageTerminalSnapshotPayload refreshed) {
|
||||
if (!represents(refreshed)) return;
|
||||
snapshot = refreshed;
|
||||
requestedPage = refreshed.page();
|
||||
refreshCooldown = REFRESH_TICKS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
addRenderableWidget(Button.builder(Component.literal("×"), button -> onClose())
|
||||
.bounds(panelX() + PANEL_WIDTH - 22, panelY() + 4, 18, 14).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (--refreshCooldown <= 0) requestPage(requestedPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float tickDelta) {
|
||||
graphics.fill(0, 0, width, height, 0xCC101010);
|
||||
int x = panelX();
|
||||
int y = panelY();
|
||||
graphics.fill(x + 3, y + 3, x + PANEL_WIDTH + 3, y + PANEL_HEIGHT + 3, 0xA0000000);
|
||||
graphics.fill(x, y, x + PANEL_WIDTH, y + PANEL_HEIGHT, 0xFFC6C6C6);
|
||||
graphics.outline(x, y, PANEL_WIDTH, PANEL_HEIGHT, 0xFF373737);
|
||||
graphics.text(font, title, x + 8, y + 7, 0xFF202020, false);
|
||||
|
||||
if (snapshot.status() == StorageTerminalStatus.READY) {
|
||||
renderTerminalGrid(graphics, x, y, mouseX, mouseY);
|
||||
} else {
|
||||
graphics.centeredText(font, Component.translatable("screen.redstoner.storage_terminal.error."
|
||||
+ snapshot.status().name().toLowerCase(Locale.ROOT)), x + 90, y + 70, 0xFFAA3333);
|
||||
}
|
||||
renderPlayerInventory(graphics, x, y, mouseX, mouseY);
|
||||
super.extractRenderState(graphics, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
|
||||
if (snapshot.status() == StorageTerminalStatus.READY && scrollY != 0.0D && insidePanel(mouseX, mouseY)) {
|
||||
requestPage(requestedPage + (scrollY < 0.0D ? 1 : -1));
|
||||
return true;
|
||||
}
|
||||
return super.mouseScrolled(mouseX, mouseY, scrollX, scrollY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
|
||||
if (super.mouseClicked(event, doubleClick)) return true;
|
||||
if (snapshot.status() == StorageTerminalStatus.READY) {
|
||||
int entryIndex = terminalEntryAt(event.x(), event.y());
|
||||
if (entryIndex >= 0 && entryIndex < snapshot.entries().size()
|
||||
&& (event.button() == 0 || event.button() == 1)) {
|
||||
StorageTerminalSnapshotPayload.Entry entry = snapshot.entries().get(entryIndex);
|
||||
send(event.button() == 1 ? StorageTerminalActionPayload.Action.TAKE_ONE
|
||||
: StorageTerminalActionPayload.Action.TAKE_STACK, snapshot.page(), entryIndex, -1, entry.stack());
|
||||
return true;
|
||||
}
|
||||
if (insideScrollBar(event.x(), event.y()) && event.button() == 0) {
|
||||
double ratio = Math.max(0.0D, Math.min(0.999D,
|
||||
(event.y() - panelY() - GRID_Y) / (StorageTerminalRules.PAGE_SIZE / 9.0D * SLOT_SIZE)));
|
||||
requestPage((int) Math.floor(ratio * snapshot.pageCount()));
|
||||
return true;
|
||||
}
|
||||
int playerSlot = playerSlotAt(event.x(), event.y());
|
||||
if (playerSlot >= 0 && event.button() == 0 && event.hasShiftDown() && minecraft.player != null) {
|
||||
ItemStack stack = minecraft.player.getInventory().getItem(playerSlot);
|
||||
if (!stack.isEmpty()) {
|
||||
send(StorageTerminalActionPayload.Action.DEPOSIT_SLOT, snapshot.page(), -1, playerSlot, stack);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPauseScreen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void renderTerminalGrid(GuiGraphicsExtractor graphics, int x, int y, int mouseX, int mouseY) {
|
||||
for (int index = 0; index < StorageTerminalRules.PAGE_SIZE; index++) {
|
||||
int slotX = x + GRID_X + index % 9 * SLOT_SIZE;
|
||||
int slotY = y + GRID_Y + index / 9 * SLOT_SIZE;
|
||||
drawSlot(graphics, slotX, slotY);
|
||||
if (index >= snapshot.entries().size()) continue;
|
||||
StorageTerminalSnapshotPayload.Entry entry = snapshot.entries().get(index);
|
||||
graphics.item(entry.stack(), slotX + 1, slotY + 1);
|
||||
graphics.itemDecorations(font, entry.stack(), slotX + 1, slotY + 1, compactCount(entry.total()));
|
||||
if (inside(mouseX, mouseY, slotX, slotY, SLOT_SIZE, SLOT_SIZE)) {
|
||||
graphics.setTooltipForNextFrame(font, entry.stack(), mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
int trackX = x + SCROLL_X;
|
||||
int trackY = y + GRID_Y;
|
||||
int trackHeight = 6 * SLOT_SIZE;
|
||||
graphics.fill(trackX, trackY, trackX + SCROLL_WIDTH, trackY + trackHeight, 0xFF575757);
|
||||
int thumbHeight = snapshot.pageCount() <= 1 ? trackHeight : Math.max(10, trackHeight / snapshot.pageCount());
|
||||
int travel = trackHeight - thumbHeight;
|
||||
int thumbY = trackY + (snapshot.pageCount() <= 1 ? 0
|
||||
: Math.round(travel * snapshot.page() / (float) (snapshot.pageCount() - 1)));
|
||||
graphics.fill(trackX + 1, thumbY + 1, trackX + SCROLL_WIDTH - 1, thumbY + thumbHeight - 1, 0xFFD8D8D8);
|
||||
graphics.text(font, Component.translatable("screen.redstoner.storage_terminal.summary",
|
||||
snapshot.page() + 1, snapshot.pageCount(), snapshot.containerCount(), snapshot.totalEntries()),
|
||||
x + 8, y + 131, 0xFF555555, false);
|
||||
}
|
||||
|
||||
private void renderPlayerInventory(GuiGraphicsExtractor graphics, int x, int y, int mouseX, int mouseY) {
|
||||
graphics.text(font, Component.translatable("container.inventory"), x + 8, y + 141, 0xFF202020, false);
|
||||
if (minecraft.player == null) return;
|
||||
Inventory inventory = minecraft.player.getInventory();
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
int inventorySlot = 9 + row * 9 + column;
|
||||
drawPlayerSlot(graphics, inventory, inventorySlot, x + GRID_X + column * SLOT_SIZE,
|
||||
y + PLAYER_GRID_Y + row * SLOT_SIZE, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
for (int column = 0; column < 9; column++) {
|
||||
drawPlayerSlot(graphics, inventory, column, x + GRID_X + column * SLOT_SIZE,
|
||||
y + HOTBAR_Y, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPlayerSlot(GuiGraphicsExtractor graphics, Inventory inventory, int inventorySlot,
|
||||
int x, int y, int mouseX, int mouseY) {
|
||||
drawSlot(graphics, x, y);
|
||||
ItemStack stack = inventory.getItem(inventorySlot);
|
||||
if (stack.isEmpty()) return;
|
||||
graphics.item(stack, x + 1, y + 1);
|
||||
graphics.itemDecorations(font, stack, x + 1, y + 1);
|
||||
if (inside(mouseX, mouseY, x, y, SLOT_SIZE, SLOT_SIZE)) {
|
||||
graphics.setTooltipForNextFrame(font, stack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawSlot(GuiGraphicsExtractor graphics, int x, int y) {
|
||||
graphics.fill(x, y, x + SLOT_SIZE, y + SLOT_SIZE, 0xFF373737);
|
||||
graphics.fill(x + 1, y + 1, x + SLOT_SIZE - 1, y + SLOT_SIZE - 1, 0xFF8B8B8B);
|
||||
}
|
||||
|
||||
private void requestPage(int page) {
|
||||
requestedPage = Math.max(0, Math.min(snapshot.pageCount() - 1, page));
|
||||
refreshCooldown = REFRESH_TICKS;
|
||||
send(StorageTerminalActionPayload.Action.REQUEST_PAGE, requestedPage, -1, -1, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
private void send(StorageTerminalActionPayload.Action action, int page, int entryIndex,
|
||||
int playerSlot, ItemStack expected) {
|
||||
if (ClientPlayNetworking.canSend(StorageTerminalActionPayload.TYPE)) {
|
||||
ClientPlayNetworking.send(new StorageTerminalActionPayload(
|
||||
snapshot.pos(), action, page, entryIndex, playerSlot, expected));
|
||||
}
|
||||
}
|
||||
|
||||
private int terminalEntryAt(double mouseX, double mouseY) {
|
||||
int relativeX = (int) mouseX - panelX() - GRID_X;
|
||||
int relativeY = (int) mouseY - panelY() - GRID_Y;
|
||||
if (relativeX < 0 || relativeY < 0 || relativeX >= 9 * SLOT_SIZE || relativeY >= 6 * SLOT_SIZE) return -1;
|
||||
return relativeY / SLOT_SIZE * 9 + relativeX / SLOT_SIZE;
|
||||
}
|
||||
|
||||
private int playerSlotAt(double mouseX, double mouseY) {
|
||||
int relativeX = (int) mouseX - panelX() - GRID_X;
|
||||
if (relativeX < 0 || relativeX >= 9 * SLOT_SIZE) return -1;
|
||||
int column = relativeX / SLOT_SIZE;
|
||||
int mainY = (int) mouseY - panelY() - PLAYER_GRID_Y;
|
||||
if (mainY >= 0 && mainY < 3 * SLOT_SIZE) return 9 + mainY / SLOT_SIZE * 9 + column;
|
||||
int hotbarY = (int) mouseY - panelY() - HOTBAR_Y;
|
||||
return hotbarY >= 0 && hotbarY < SLOT_SIZE ? column : -1;
|
||||
}
|
||||
|
||||
private boolean insideScrollBar(double mouseX, double mouseY) {
|
||||
return inside(mouseX, mouseY, panelX() + SCROLL_X, panelY() + GRID_Y,
|
||||
SCROLL_WIDTH, 6 * SLOT_SIZE);
|
||||
}
|
||||
|
||||
private boolean insidePanel(double mouseX, double mouseY) {
|
||||
return inside(mouseX, mouseY, panelX(), panelY(), PANEL_WIDTH, PANEL_HEIGHT);
|
||||
}
|
||||
|
||||
private static boolean inside(double mouseX, double mouseY, int x, int y, int width, int height) {
|
||||
return mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + height;
|
||||
}
|
||||
|
||||
private int panelX() {
|
||||
return (width - PANEL_WIDTH) / 2;
|
||||
}
|
||||
|
||||
private int panelY() {
|
||||
return (height - PANEL_HEIGHT) / 2;
|
||||
}
|
||||
|
||||
private static String compactCount(int count) {
|
||||
if (count >= 1_000_000) return (count / 1_000_000) + "m";
|
||||
if (count >= 10_000) return (count / 1_000) + "k";
|
||||
return Integer.toString(count);
|
||||
}
|
||||
}
|
||||
+28
-1
@@ -4,7 +4,11 @@ import fr.koka99cab.sanctuary26.redstoner.RedStonerMod;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.entity.ComputerBlockEntity;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.entity.PersonalComputerBlockEntity;
|
||||
import fr.koka99cab.sanctuary26.redstoner.registry.RedStonerRegistries;
|
||||
import fr.koka99cab.sanctuary26.redstoner.storage.StorageTerminalNetwork;
|
||||
import fr.koka99cab.sanctuary26.redstoner.storage.StorageTerminalService;
|
||||
import fr.koka99cab.sanctuary26.sanctuary.api.atlas.SanctuaryAtlasLandmarks;
|
||||
import java.util.List;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -12,7 +16,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public final class RedStonerNetworking {
|
||||
public static final int PROTOCOL_VERSION = 5;
|
||||
public static final int PROTOCOL_VERSION = 6;
|
||||
private static boolean initialized;
|
||||
|
||||
private RedStonerNetworking() {
|
||||
@@ -25,6 +29,8 @@ public final class RedStonerNetworking {
|
||||
initialized = true;
|
||||
PayloadTypeRegistry.clientboundPlay().register(OpenComputerPayload.TYPE, OpenComputerPayload.STREAM_CODEC);
|
||||
PayloadTypeRegistry.clientboundPlay().register(OpenPersonalComputerPayload.TYPE, OpenPersonalComputerPayload.STREAM_CODEC);
|
||||
PayloadTypeRegistry.clientboundPlay().register(StorageTerminalSnapshotPayload.TYPE,
|
||||
StorageTerminalSnapshotPayload.STREAM_CODEC);
|
||||
PayloadTypeRegistry.serverboundPlay().register(SaveComputerProgramPayload.TYPE, SaveComputerProgramPayload.STREAM_CODEC);
|
||||
PayloadTypeRegistry.serverboundPlay().register(PlaceAtlasLandmarkPayload.TYPE, PlaceAtlasLandmarkPayload.STREAM_CODEC);
|
||||
PayloadTypeRegistry.serverboundPlay().register(RequestPersonalComputerSnapshotPayload.TYPE,
|
||||
@@ -33,6 +39,8 @@ public final class RedStonerNetworking {
|
||||
AcknowledgePersonalComputerIntroPayload.STREAM_CODEC);
|
||||
PayloadTypeRegistry.serverboundPlay().register(ShutdownPersonalComputerPayload.TYPE,
|
||||
ShutdownPersonalComputerPayload.STREAM_CODEC);
|
||||
PayloadTypeRegistry.serverboundPlay().register(StorageTerminalActionPayload.TYPE,
|
||||
StorageTerminalActionPayload.STREAM_CODEC);
|
||||
ServerPlayNetworking.registerGlobalReceiver(SaveComputerProgramPayload.TYPE, (payload, context) ->
|
||||
context.server().execute(() -> saveProgram(context.player(), payload)));
|
||||
ServerPlayNetworking.registerGlobalReceiver(PlaceAtlasLandmarkPayload.TYPE, (payload, context) ->
|
||||
@@ -43,6 +51,8 @@ public final class RedStonerNetworking {
|
||||
context.server().execute(() -> acknowledgePersonalComputerIntro(context.player(), payload)));
|
||||
ServerPlayNetworking.registerGlobalReceiver(ShutdownPersonalComputerPayload.TYPE, (payload, context) ->
|
||||
context.server().execute(() -> shutdownPersonalComputer(context.player(), payload)));
|
||||
ServerPlayNetworking.registerGlobalReceiver(StorageTerminalActionPayload.TYPE, (payload, context) ->
|
||||
context.server().execute(() -> storageTerminalAction(context.player(), payload)));
|
||||
RedStonerMod.LOGGER.debug("[{}] Networking contract v{} registered.", RedStonerMod.DISPLAY_NAME, PROTOCOL_VERSION);
|
||||
}
|
||||
|
||||
@@ -77,6 +87,23 @@ public final class RedStonerNetworking {
|
||||
}
|
||||
}
|
||||
|
||||
public static void openStorageTerminal(ServerPlayer player, BlockPos pos) {
|
||||
sendStorageTerminalSnapshot(player, pos, StorageTerminalService.snapshot(player, pos, 0));
|
||||
}
|
||||
|
||||
private static void storageTerminalAction(ServerPlayer player, StorageTerminalActionPayload payload) {
|
||||
sendStorageTerminalSnapshot(player, payload.pos(), StorageTerminalService.handle(player, payload));
|
||||
}
|
||||
|
||||
private static void sendStorageTerminalSnapshot(ServerPlayer player, BlockPos pos,
|
||||
StorageTerminalNetwork.Snapshot snapshot) {
|
||||
if (!ServerPlayNetworking.canSend(player, StorageTerminalSnapshotPayload.TYPE)) return;
|
||||
List<StorageTerminalSnapshotPayload.Entry> entries = snapshot.entries().stream()
|
||||
.map(entry -> new StorageTerminalSnapshotPayload.Entry(entry.stack(), entry.total())).toList();
|
||||
ServerPlayNetworking.send(player, new StorageTerminalSnapshotPayload(pos, snapshot.status(), snapshot.page(),
|
||||
snapshot.pageCount(), snapshot.containerCount(), snapshot.totalEntries(), entries));
|
||||
}
|
||||
|
||||
private static void requestPersonalComputerSnapshot(ServerPlayer player,
|
||||
RequestPersonalComputerSnapshotPayload payload) {
|
||||
PersonalComputerBlockEntity computer = validatedPersonalComputer(
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.network;
|
||||
|
||||
import fr.koka99cab.sanctuary26.redstoner.RedStonerMod;
|
||||
import fr.koka99cab.sanctuary26.redstoner.storage.StorageTerminalRules;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public record StorageTerminalActionPayload(BlockPos pos, Action action, int page, int entryIndex,
|
||||
int playerSlot, ItemStack expected) implements CustomPacketPayload {
|
||||
public static final Type<StorageTerminalActionPayload> TYPE =
|
||||
new Type<>(RedStonerMod.id("c2s/storage_terminal_action"));
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, StorageTerminalActionPayload> STREAM_CODEC =
|
||||
StreamCodec.of(StorageTerminalActionPayload::write, StorageTerminalActionPayload::read);
|
||||
|
||||
public StorageTerminalActionPayload {
|
||||
pos = pos == null ? BlockPos.ZERO : pos.immutable();
|
||||
action = action == null ? Action.REQUEST_PAGE : action;
|
||||
page = Math.max(0, Math.min(StorageTerminalRules.MAX_PAGE_COUNT - 1, page));
|
||||
entryIndex = entryIndex >= 0 && entryIndex < StorageTerminalRules.PAGE_SIZE ? entryIndex : -1;
|
||||
playerSlot = playerSlot >= 0 && playerSlot < StorageTerminalRules.PLAYER_STORAGE_SLOTS ? playerSlot : -1;
|
||||
expected = expected == null || expected.isEmpty() ? ItemStack.EMPTY : expected.copyWithCount(1);
|
||||
}
|
||||
|
||||
private static StorageTerminalActionPayload read(RegistryFriendlyByteBuf buffer) {
|
||||
BlockPos pos = buffer.readBlockPos();
|
||||
int ordinal = buffer.readVarInt();
|
||||
Action[] values = Action.values();
|
||||
Action action = ordinal >= 0 && ordinal < values.length ? values[ordinal] : Action.REQUEST_PAGE;
|
||||
return new StorageTerminalActionPayload(pos, action, buffer.readVarInt(), buffer.readVarInt(),
|
||||
buffer.readVarInt(), ItemStack.OPTIONAL_UNTRUSTED_STREAM_CODEC.decode(buffer));
|
||||
}
|
||||
|
||||
private static void write(RegistryFriendlyByteBuf buffer, StorageTerminalActionPayload payload) {
|
||||
buffer.writeBlockPos(payload.pos);
|
||||
buffer.writeVarInt(payload.action.ordinal());
|
||||
buffer.writeVarInt(payload.page);
|
||||
buffer.writeVarInt(payload.entryIndex);
|
||||
buffer.writeVarInt(payload.playerSlot);
|
||||
ItemStack.OPTIONAL_UNTRUSTED_STREAM_CODEC.encode(buffer, payload.expected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
REQUEST_PAGE,
|
||||
TAKE_STACK,
|
||||
TAKE_ONE,
|
||||
DEPOSIT_SLOT
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.network;
|
||||
|
||||
import fr.koka99cab.sanctuary26.redstoner.RedStonerMod;
|
||||
import fr.koka99cab.sanctuary26.redstoner.storage.StorageTerminalRules;
|
||||
import fr.koka99cab.sanctuary26.redstoner.storage.StorageTerminalStatus;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public record StorageTerminalSnapshotPayload(BlockPos pos, StorageTerminalStatus status, int page,
|
||||
int pageCount, int containerCount, int totalEntries, List<Entry> entries) implements CustomPacketPayload {
|
||||
public static final Type<StorageTerminalSnapshotPayload> TYPE =
|
||||
new Type<>(RedStonerMod.id("s2c/storage_terminal_snapshot"));
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, StorageTerminalSnapshotPayload> STREAM_CODEC =
|
||||
StreamCodec.of(StorageTerminalSnapshotPayload::write, StorageTerminalSnapshotPayload::read);
|
||||
|
||||
public StorageTerminalSnapshotPayload {
|
||||
pos = pos == null ? BlockPos.ZERO : pos.immutable();
|
||||
status = status == null ? StorageTerminalStatus.INVALID_TERMINAL : status;
|
||||
pageCount = Math.max(1, Math.min(StorageTerminalRules.MAX_PAGE_COUNT, pageCount));
|
||||
page = Math.max(0, Math.min(pageCount - 1, page));
|
||||
containerCount = Math.max(0, Math.min(StorageTerminalRules.MAX_CONTAINERS, containerCount));
|
||||
totalEntries = Math.max(0, Math.min(StorageTerminalRules.MAX_ENTRIES, totalEntries));
|
||||
entries = entries == null ? List.of() : List.copyOf(entries.stream()
|
||||
.limit(StorageTerminalRules.PAGE_SIZE).toList());
|
||||
}
|
||||
|
||||
private static StorageTerminalSnapshotPayload read(RegistryFriendlyByteBuf buffer) {
|
||||
BlockPos pos = buffer.readBlockPos();
|
||||
StorageTerminalStatus status = status(buffer.readVarInt());
|
||||
int page = buffer.readVarInt();
|
||||
int pageCount = buffer.readVarInt();
|
||||
int containerCount = buffer.readVarInt();
|
||||
int totalEntries = buffer.readVarInt();
|
||||
int size = buffer.readVarInt();
|
||||
if (size < 0 || size > StorageTerminalRules.PAGE_SIZE) {
|
||||
throw new IllegalArgumentException("Storage terminal page exceeds " + StorageTerminalRules.PAGE_SIZE);
|
||||
}
|
||||
List<Entry> entries = new ArrayList<>(size);
|
||||
for (int index = 0; index < size; index++) {
|
||||
entries.add(new Entry(ItemStack.OPTIONAL_UNTRUSTED_STREAM_CODEC.decode(buffer), buffer.readVarInt()));
|
||||
}
|
||||
return new StorageTerminalSnapshotPayload(pos, status, page, pageCount, containerCount, totalEntries, entries);
|
||||
}
|
||||
|
||||
private static void write(RegistryFriendlyByteBuf buffer, StorageTerminalSnapshotPayload payload) {
|
||||
buffer.writeBlockPos(payload.pos);
|
||||
buffer.writeVarInt(payload.status.ordinal());
|
||||
buffer.writeVarInt(payload.page);
|
||||
buffer.writeVarInt(payload.pageCount);
|
||||
buffer.writeVarInt(payload.containerCount);
|
||||
buffer.writeVarInt(payload.totalEntries);
|
||||
buffer.writeVarInt(payload.entries.size());
|
||||
for (Entry entry : payload.entries) {
|
||||
ItemStack.OPTIONAL_UNTRUSTED_STREAM_CODEC.encode(buffer, entry.stack);
|
||||
buffer.writeVarInt(entry.total);
|
||||
}
|
||||
}
|
||||
|
||||
private static StorageTerminalStatus status(int ordinal) {
|
||||
StorageTerminalStatus[] values = StorageTerminalStatus.values();
|
||||
return values[Math.max(0, Math.min(values.length - 1, ordinal))];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public record Entry(ItemStack stack, int total) {
|
||||
public Entry {
|
||||
stack = stack == null || stack.isEmpty() ? ItemStack.EMPTY : stack.copyWithCount(1);
|
||||
total = stack.isEmpty() ? 0 : Math.max(1, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -5,6 +5,7 @@ import fr.koka99cab.sanctuary26.redstoner.block.ComputerBlock;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.DrawerBlock;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.PersonalComputerBlock;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.ParticuleurBlock;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.StorageTerminalBlock;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.entity.ComputerBlockEntity;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.entity.DrawerBlockEntity;
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.entity.PersonalComputerBlockEntity;
|
||||
@@ -64,6 +65,12 @@ public final class RedStonerRegistries {
|
||||
ParticuleurBlock::new,
|
||||
particuleurProperties(RedStonerMod.id("particuleur"))
|
||||
);
|
||||
public static final StorageTerminalBlock STORAGE_TERMINAL = registerBlock(
|
||||
RedStonerMod.id("storage_terminal"),
|
||||
StorageTerminalBlock::new,
|
||||
BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_GRAY).strength(4.0F, 6.0F).sound(SoundType.METAL)
|
||||
.requiresCorrectToolForDrops().noOcclusion().setId(blockKey(RedStonerMod.id("storage_terminal")))
|
||||
);
|
||||
|
||||
public static final ComputerBlock LEGACY_EIGHT_BIT_COMPUTER = registerBlock(
|
||||
LEGACY_COMPUTER_ID, ComputerBlock::new, computerProperties(LEGACY_COMPUTER_ID, MapColor.COLOR_RED));
|
||||
@@ -83,6 +90,8 @@ public final class RedStonerRegistries {
|
||||
public static final Item PERSONAL_COMPUTER_ITEM = registerBlockItem(RedStonerMod.id("personal_computer"), PERSONAL_COMPUTER);
|
||||
public static final Item DRAWER_ITEM = registerBlockItem(RedStonerMod.id("drawer"), DRAWER);
|
||||
public static final Item PARTICULEUR_ITEM = registerBlockItem(RedStonerMod.id("particuleur"), PARTICULEUR);
|
||||
public static final Item STORAGE_TERMINAL_ITEM = registerBlockItem(
|
||||
RedStonerMod.id("storage_terminal"), STORAGE_TERMINAL);
|
||||
|
||||
public static final Item LEGACY_EIGHT_BIT_COMPUTER_ITEM = registerBlockItem(LEGACY_COMPUTER_ID, LEGACY_EIGHT_BIT_COMPUTER);
|
||||
public static final Item LEGACY_CONTROLLER_ITEM = registerBlockItem(LEGACY_CONTROLLER_ID, LEGACY_CONTROLLER);
|
||||
@@ -117,6 +126,7 @@ public final class RedStonerRegistries {
|
||||
output.accept(EIGHT_BIT_COMPUTER_ITEM);
|
||||
output.accept(CONTROLLER_ITEM);
|
||||
output.accept(PARTICULEUR_ITEM);
|
||||
output.accept(STORAGE_TERMINAL_ITEM);
|
||||
})
|
||||
.build()
|
||||
);
|
||||
@@ -132,7 +142,7 @@ public final class RedStonerRegistries {
|
||||
}
|
||||
initialized = true;
|
||||
registerDrawerAttack();
|
||||
RedStonerMod.LOGGER.info("[{}] Registered five active blocks and five legacy block aliases.", RedStonerMod.DISPLAY_NAME);
|
||||
RedStonerMod.LOGGER.info("[{}] Registered six active blocks and five legacy block aliases.", RedStonerMod.DISPLAY_NAME);
|
||||
}
|
||||
|
||||
public static boolean isController(BlockState state) {
|
||||
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.storage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public final class StorageTerminalInventory {
|
||||
private StorageTerminalInventory() {
|
||||
}
|
||||
|
||||
public static List<Entry> aggregate(List<? extends Container> containers) {
|
||||
Map<StackKey, MutableEntry> grouped = new LinkedHashMap<>();
|
||||
for (Container container : containers) {
|
||||
for (int slot = 0; slot < container.getContainerSize(); slot++) {
|
||||
ItemStack stack = container.getItem(slot);
|
||||
if (stack.isEmpty()) continue;
|
||||
StackKey key = new StackKey(stack);
|
||||
MutableEntry entry = grouped.computeIfAbsent(key, ignored -> new MutableEntry(key.stack));
|
||||
entry.total = saturatedAdd(entry.total, stack.getCount());
|
||||
}
|
||||
}
|
||||
List<Entry> result = new ArrayList<>(grouped.size());
|
||||
for (MutableEntry entry : grouped.values()) result.add(new Entry(entry.stack, entry.total));
|
||||
return List.copyOf(result);
|
||||
}
|
||||
|
||||
/** Inserts into compatible existing stacks first, then into empty slots. Mutates {@code source}. */
|
||||
public static int insert(List<? extends Container> containers, ItemStack source) {
|
||||
if (source == null || source.isEmpty()) return 0;
|
||||
int before = source.getCount();
|
||||
for (Container container : containers) {
|
||||
for (int slot = 0; slot < container.getContainerSize() && !source.isEmpty(); slot++) {
|
||||
ItemStack target = container.getItem(slot);
|
||||
if (target.isEmpty() || !ItemStack.isSameItemSameComponents(target, source)
|
||||
|| !container.canPlaceItem(slot, source)) continue;
|
||||
int limit = Math.min(container.getMaxStackSize(source), source.getMaxStackSize());
|
||||
int moved = Math.min(source.getCount(), Math.max(0, limit - target.getCount()));
|
||||
if (moved <= 0) continue;
|
||||
target.grow(moved);
|
||||
source.shrink(moved);
|
||||
container.setChanged();
|
||||
}
|
||||
}
|
||||
for (Container container : containers) {
|
||||
for (int slot = 0; slot < container.getContainerSize() && !source.isEmpty(); slot++) {
|
||||
if (!container.getItem(slot).isEmpty() || !container.canPlaceItem(slot, source)) continue;
|
||||
int limit = Math.min(container.getMaxStackSize(source), source.getMaxStackSize());
|
||||
int moved = Math.min(source.getCount(), Math.max(0, limit));
|
||||
if (moved <= 0) continue;
|
||||
container.setItem(slot, source.copyWithCount(moved));
|
||||
source.shrink(moved);
|
||||
container.setChanged();
|
||||
}
|
||||
}
|
||||
return before - source.getCount();
|
||||
}
|
||||
|
||||
public static ItemStack take(List<? extends Container> containers, ItemStack expected, int requested) {
|
||||
if (expected == null || expected.isEmpty() || requested <= 0) return ItemStack.EMPTY;
|
||||
int remaining = requested;
|
||||
int total = 0;
|
||||
for (Container container : containers) {
|
||||
for (int slot = 0; slot < container.getContainerSize() && remaining > 0; slot++) {
|
||||
ItemStack stored = container.getItem(slot);
|
||||
if (stored.isEmpty() || !ItemStack.isSameItemSameComponents(stored, expected)) continue;
|
||||
ItemStack removed = container.removeItem(slot, Math.min(remaining, stored.getCount()));
|
||||
if (removed.isEmpty()) continue;
|
||||
total += removed.getCount();
|
||||
remaining -= removed.getCount();
|
||||
container.setChanged();
|
||||
}
|
||||
}
|
||||
return total <= 0 ? ItemStack.EMPTY : expected.copyWithCount(total);
|
||||
}
|
||||
|
||||
private static int saturatedAdd(int left, int right) {
|
||||
return (int) Math.min(Integer.MAX_VALUE, (long) left + Math.max(0, right));
|
||||
}
|
||||
|
||||
public record Entry(ItemStack stack, int total) {
|
||||
public Entry {
|
||||
stack = stack == null || stack.isEmpty() ? ItemStack.EMPTY : stack.copyWithCount(1);
|
||||
total = stack.isEmpty() ? 0 : Math.max(1, total);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MutableEntry {
|
||||
private final ItemStack stack;
|
||||
private int total;
|
||||
|
||||
private MutableEntry(ItemStack stack) {
|
||||
this.stack = stack.copyWithCount(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class StackKey {
|
||||
private final ItemStack stack;
|
||||
private final int hash;
|
||||
|
||||
private StackKey(ItemStack stack) {
|
||||
this.stack = stack.copyWithCount(1);
|
||||
this.hash = ItemStack.hashItemAndComponents(this.stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof StackKey key && ItemStack.isSameItemSameComponents(stack, key.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.storage;
|
||||
|
||||
import fr.koka99cab.sanctuary26.redstoner.block.StorageTerminalBlock;
|
||||
import fr.koka99cab.sanctuary26.redstoner.registry.RedStonerRegistries;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.RandomizableContainer;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BarrelBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public final class StorageTerminalNetwork {
|
||||
private StorageTerminalNetwork() {
|
||||
}
|
||||
|
||||
public static boolean isCompatibleStorage(BlockState state) {
|
||||
return state.is(Blocks.CHEST) || state.is(Blocks.TRAPPED_CHEST) || state.is(Blocks.BARREL);
|
||||
}
|
||||
|
||||
public static Discovery discover(ServerPlayer player, BlockPos terminalPos) {
|
||||
if (!(player.level() instanceof ServerLevel level)) return Discovery.error(StorageTerminalStatus.INVALID_TERMINAL);
|
||||
BlockState terminalState = level.getBlockState(terminalPos);
|
||||
if (!terminalState.is(RedStonerRegistries.STORAGE_TERMINAL)
|
||||
|| !terminalState.hasProperty(StorageTerminalBlock.FACING)) {
|
||||
return Discovery.error(StorageTerminalStatus.INVALID_TERMINAL);
|
||||
}
|
||||
BlockPos start = terminalPos.relative(terminalState.getValue(StorageTerminalBlock.FACING).getOpposite());
|
||||
StorageTerminalTopology.Result topology = StorageTerminalTopology.discover(start, pos ->
|
||||
level.hasChunkAt(pos) && isCompatibleStorage(level.getBlockState(pos)) && storageEntity(level, pos) != null);
|
||||
if (topology.tooLarge()) return Discovery.error(StorageTerminalStatus.TOO_LARGE);
|
||||
if (topology.positions().isEmpty()) return Discovery.error(StorageTerminalStatus.DISCONNECTED);
|
||||
|
||||
List<BaseContainerBlockEntity> containers = new ArrayList<>(topology.positions().size());
|
||||
for (BlockPos pos : topology.positions()) {
|
||||
BaseContainerBlockEntity container = storageEntity(level, pos);
|
||||
if (container == null) return Discovery.error(StorageTerminalStatus.DISCONNECTED);
|
||||
if (container.isLocked()) return Discovery.error(StorageTerminalStatus.LOCKED);
|
||||
if (container instanceof RandomizableContainer randomizable) randomizable.unpackLootTable(player);
|
||||
containers.add(container);
|
||||
}
|
||||
return new Discovery(StorageTerminalStatus.READY, containers);
|
||||
}
|
||||
|
||||
public static Snapshot snapshot(Discovery discovery, int requestedPage) {
|
||||
if (discovery.status() != StorageTerminalStatus.READY) {
|
||||
return new Snapshot(discovery.status(), 0, 1, 0, 0, List.of());
|
||||
}
|
||||
List<StorageTerminalInventory.Entry> all = StorageTerminalInventory.aggregate(discovery.containers());
|
||||
int page = StorageTerminalRules.clampPage(requestedPage, all.size());
|
||||
int start = StorageTerminalRules.pageStart(page, all.size());
|
||||
int end = Math.min(all.size(), start + StorageTerminalRules.PAGE_SIZE);
|
||||
return new Snapshot(StorageTerminalStatus.READY, page, StorageTerminalRules.pageCount(all.size()),
|
||||
discovery.containers().size(), all.size(), all.subList(start, end));
|
||||
}
|
||||
|
||||
private static BaseContainerBlockEntity storageEntity(ServerLevel level, BlockPos pos) {
|
||||
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof ChestBlockEntity chest) return chest;
|
||||
if (blockEntity instanceof BarrelBlockEntity barrel) return barrel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public record Discovery(StorageTerminalStatus status, List<BaseContainerBlockEntity> containers) {
|
||||
public Discovery {
|
||||
status = status == null ? StorageTerminalStatus.INVALID_TERMINAL : status;
|
||||
containers = containers == null ? List.of() : List.copyOf(containers);
|
||||
}
|
||||
|
||||
public static Discovery error(StorageTerminalStatus status) {
|
||||
return new Discovery(status, List.of());
|
||||
}
|
||||
|
||||
public List<? extends Container> inventoryContainers() {
|
||||
return containers;
|
||||
}
|
||||
}
|
||||
|
||||
public record Snapshot(StorageTerminalStatus status, int page, int pageCount, int containerCount,
|
||||
int totalEntries, List<StorageTerminalInventory.Entry> entries) {
|
||||
public Snapshot {
|
||||
status = status == null ? StorageTerminalStatus.INVALID_TERMINAL : status;
|
||||
entries = entries == null ? List.of() : List.copyOf(entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.storage;
|
||||
|
||||
public final class StorageTerminalRules {
|
||||
public static final int PAGE_SIZE = 54;
|
||||
public static final int MAX_CONTAINERS = 128;
|
||||
public static final int SLOTS_PER_CONTAINER = 27;
|
||||
public static final int MAX_ENTRIES = MAX_CONTAINERS * SLOTS_PER_CONTAINER;
|
||||
public static final int MAX_PAGE_COUNT = MAX_ENTRIES / PAGE_SIZE;
|
||||
public static final int PLAYER_STORAGE_SLOTS = 36;
|
||||
|
||||
private StorageTerminalRules() {
|
||||
}
|
||||
|
||||
public static int pageCount(int entryCount) {
|
||||
int bounded = Math.max(0, Math.min(MAX_ENTRIES, entryCount));
|
||||
return Math.max(1, (bounded + PAGE_SIZE - 1) / PAGE_SIZE);
|
||||
}
|
||||
|
||||
public static int clampPage(int requestedPage, int entryCount) {
|
||||
return Math.max(0, Math.min(pageCount(entryCount) - 1, requestedPage));
|
||||
}
|
||||
|
||||
public static int pageStart(int requestedPage, int entryCount) {
|
||||
return clampPage(requestedPage, entryCount) * PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.storage;
|
||||
|
||||
import fr.koka99cab.sanctuary26.redstoner.network.StorageTerminalActionPayload;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public final class StorageTerminalService {
|
||||
private static final double MAX_DISTANCE_SQUARED = 64.0D;
|
||||
|
||||
private StorageTerminalService() {
|
||||
}
|
||||
|
||||
public static StorageTerminalNetwork.Snapshot snapshot(ServerPlayer player, BlockPos pos, int page) {
|
||||
if (player.distanceToSqr(Vec3.atCenterOf(pos)) > MAX_DISTANCE_SQUARED) {
|
||||
return StorageTerminalNetwork.snapshot(
|
||||
StorageTerminalNetwork.Discovery.error(StorageTerminalStatus.INVALID_TERMINAL), 0);
|
||||
}
|
||||
return StorageTerminalNetwork.snapshot(StorageTerminalNetwork.discover(player, pos), page);
|
||||
}
|
||||
|
||||
public static StorageTerminalNetwork.Snapshot handle(ServerPlayer player, StorageTerminalActionPayload payload) {
|
||||
if (player.distanceToSqr(Vec3.atCenterOf(payload.pos())) > MAX_DISTANCE_SQUARED) {
|
||||
return StorageTerminalNetwork.snapshot(
|
||||
StorageTerminalNetwork.Discovery.error(StorageTerminalStatus.INVALID_TERMINAL), 0);
|
||||
}
|
||||
StorageTerminalNetwork.Discovery discovery = StorageTerminalNetwork.discover(player, payload.pos());
|
||||
StorageTerminalNetwork.Snapshot before = StorageTerminalNetwork.snapshot(discovery, payload.page());
|
||||
if (before.status() != StorageTerminalStatus.READY
|
||||
|| payload.action() == StorageTerminalActionPayload.Action.REQUEST_PAGE) return before;
|
||||
|
||||
boolean changed = switch (payload.action()) {
|
||||
case TAKE_STACK -> take(player, discovery, before, payload, false);
|
||||
case TAKE_ONE -> take(player, discovery, before, payload, true);
|
||||
case DEPOSIT_SLOT -> deposit(player, discovery, payload);
|
||||
case REQUEST_PAGE -> false;
|
||||
};
|
||||
if (changed) {
|
||||
player.getInventory().setChanged();
|
||||
player.containerMenu.broadcastChanges();
|
||||
player.inventoryMenu.broadcastChanges();
|
||||
}
|
||||
return StorageTerminalNetwork.snapshot(discovery, before.page());
|
||||
}
|
||||
|
||||
private static boolean take(ServerPlayer player, StorageTerminalNetwork.Discovery discovery,
|
||||
StorageTerminalNetwork.Snapshot snapshot, StorageTerminalActionPayload payload, boolean single) {
|
||||
if (payload.entryIndex() < 0 || payload.entryIndex() >= snapshot.entries().size()) return false;
|
||||
StorageTerminalInventory.Entry entry = snapshot.entries().get(payload.entryIndex());
|
||||
if (payload.expected().isEmpty()
|
||||
|| !ItemStack.isSameItemSameComponents(entry.stack(), payload.expected())) return false;
|
||||
int capacity = playerCapacity(player.getInventory(), entry.stack());
|
||||
int requested = single ? 1 : entry.stack().getMaxStackSize();
|
||||
int amount = Math.min(entry.total(), Math.min(capacity, requested));
|
||||
if (amount <= 0) return false;
|
||||
ItemStack extracted = StorageTerminalInventory.take(discovery.inventoryContainers(), entry.stack(), amount);
|
||||
if (extracted.isEmpty()) return false;
|
||||
int inserted = insertPlayer(player.getInventory(), extracted);
|
||||
if (!extracted.isEmpty()) StorageTerminalInventory.insert(discovery.inventoryContainers(), extracted);
|
||||
return inserted > 0;
|
||||
}
|
||||
|
||||
private static boolean deposit(ServerPlayer player, StorageTerminalNetwork.Discovery discovery,
|
||||
StorageTerminalActionPayload payload) {
|
||||
int slot = payload.playerSlot();
|
||||
if (slot < 0 || slot >= StorageTerminalRules.PLAYER_STORAGE_SLOTS) return false;
|
||||
Inventory inventory = player.getInventory();
|
||||
ItemStack source = inventory.getItem(slot);
|
||||
if (source.isEmpty() || payload.expected().isEmpty()
|
||||
|| !ItemStack.isSameItemSameComponents(source, payload.expected())) return false;
|
||||
int inserted = StorageTerminalInventory.insert(discovery.inventoryContainers(), source);
|
||||
if (source.isEmpty()) inventory.setItem(slot, ItemStack.EMPTY);
|
||||
return inserted > 0;
|
||||
}
|
||||
|
||||
private static int playerCapacity(Inventory inventory, ItemStack expected) {
|
||||
long capacity = 0L;
|
||||
for (int slot = 0; slot < StorageTerminalRules.PLAYER_STORAGE_SLOTS; slot++) {
|
||||
ItemStack stack = inventory.getItem(slot);
|
||||
if (stack.isEmpty()) capacity += expected.getMaxStackSize();
|
||||
else if (ItemStack.isSameItemSameComponents(stack, expected)) {
|
||||
capacity += Math.max(0, stack.getMaxStackSize() - stack.getCount());
|
||||
}
|
||||
}
|
||||
return (int) Math.min(Integer.MAX_VALUE, capacity);
|
||||
}
|
||||
|
||||
/** Inserts into the 36 survival storage slots and mutates {@code source}. */
|
||||
private static int insertPlayer(Inventory inventory, ItemStack source) {
|
||||
int before = source.getCount();
|
||||
for (int slot = 0; slot < StorageTerminalRules.PLAYER_STORAGE_SLOTS && !source.isEmpty(); slot++) {
|
||||
ItemStack target = inventory.getItem(slot);
|
||||
if (target.isEmpty() || !ItemStack.isSameItemSameComponents(target, source)) continue;
|
||||
int moved = Math.min(source.getCount(), Math.max(0, target.getMaxStackSize() - target.getCount()));
|
||||
if (moved <= 0) continue;
|
||||
target.grow(moved);
|
||||
source.shrink(moved);
|
||||
}
|
||||
for (int slot = 0; slot < StorageTerminalRules.PLAYER_STORAGE_SLOTS && !source.isEmpty(); slot++) {
|
||||
if (!inventory.getItem(slot).isEmpty()) continue;
|
||||
int moved = Math.min(source.getCount(), source.getMaxStackSize());
|
||||
inventory.setItem(slot, source.copyWithCount(moved));
|
||||
source.shrink(moved);
|
||||
}
|
||||
return before - source.getCount();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.storage;
|
||||
|
||||
public enum StorageTerminalStatus {
|
||||
READY,
|
||||
INVALID_TERMINAL,
|
||||
DISCONNECTED,
|
||||
TOO_LARGE,
|
||||
LOCKED
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.storage;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
public final class StorageTerminalTopology {
|
||||
private StorageTerminalTopology() {
|
||||
}
|
||||
|
||||
public static Result discover(BlockPos start, Predicate<BlockPos> storageAt) {
|
||||
if (start == null || storageAt == null) return new Result(List.of(), false);
|
||||
ArrayDeque<BlockPos> pending = new ArrayDeque<>();
|
||||
Set<BlockPos> visited = new HashSet<>();
|
||||
List<BlockPos> storage = new ArrayList<>();
|
||||
pending.add(start.immutable());
|
||||
|
||||
while (!pending.isEmpty()) {
|
||||
BlockPos pos = pending.removeFirst();
|
||||
if (!visited.add(pos) || !storageAt.test(pos)) continue;
|
||||
if (storage.size() >= StorageTerminalRules.MAX_CONTAINERS) {
|
||||
return new Result(storage, true);
|
||||
}
|
||||
storage.add(pos);
|
||||
for (Direction direction : Direction.values()) {
|
||||
BlockPos neighbor = pos.relative(direction);
|
||||
if (!visited.contains(neighbor)) pending.addLast(neighbor.immutable());
|
||||
}
|
||||
}
|
||||
|
||||
return new Result(storage, false);
|
||||
}
|
||||
|
||||
public record Result(List<BlockPos> positions, boolean tooLarge) {
|
||||
public Result {
|
||||
positions = positions == null ? List.of() : List.copyOf(positions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"variants": {
|
||||
"facing=north": { "model": "redstoner:block/storage_terminal" },
|
||||
"facing=east": { "model": "redstoner:block/storage_terminal", "y": 90 },
|
||||
"facing=south": { "model": "redstoner:block/storage_terminal", "y": 180 },
|
||||
"facing=west": { "model": "redstoner:block/storage_terminal", "y": 270 }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "redstoner:block/storage_terminal"
|
||||
}
|
||||
}
|
||||
@@ -49,5 +49,12 @@
|
||||
"message.redstoner.computer.invalid": "Program rejected: %s",
|
||||
"block.redstoner.particuleur": "Particle Emitter",
|
||||
"block.particuleur.particuleur": "Legacy Particle Emitter",
|
||||
"tooltip.redstoner.particuleur": "Insert a catalyst, then power the block with redstone."
|
||||
"tooltip.redstoner.particuleur": "Insert a catalyst, then power the block with redstone.",
|
||||
"block.redstoner.storage_terminal": "Storage Terminal",
|
||||
"screen.redstoner.storage_terminal.title": "Storage Terminal",
|
||||
"screen.redstoner.storage_terminal.summary": "%s/%s · %s blocks · %s types",
|
||||
"screen.redstoner.storage_terminal.error.invalid_terminal": "The terminal is no longer accessible.",
|
||||
"screen.redstoner.storage_terminal.error.disconnected": "No connected chest or barrel.",
|
||||
"screen.redstoner.storage_terminal.error.too_large": "Network too large (maximum 128 storage blocks).",
|
||||
"screen.redstoner.storage_terminal.error.locked": "The network contains a locked storage block."
|
||||
}
|
||||
|
||||
@@ -49,5 +49,12 @@
|
||||
"message.redstoner.computer.invalid": "Programme refusé : %s",
|
||||
"block.redstoner.particuleur": "Particuleur",
|
||||
"block.particuleur.particuleur": "Particuleur historique",
|
||||
"tooltip.redstoner.particuleur": "Insérez un catalyseur puis alimentez le bloc en redstone."
|
||||
"tooltip.redstoner.particuleur": "Insérez un catalyseur puis alimentez le bloc en redstone.",
|
||||
"block.redstoner.storage_terminal": "Terminal de stockage",
|
||||
"screen.redstoner.storage_terminal.title": "Terminal de stockage",
|
||||
"screen.redstoner.storage_terminal.summary": "%s/%s · %s blocs · %s types",
|
||||
"screen.redstoner.storage_terminal.error.invalid_terminal": "Le terminal n'est plus accessible.",
|
||||
"screen.redstoner.storage_terminal.error.disconnected": "Aucun coffre ou baril connecté.",
|
||||
"screen.redstoner.storage_terminal.error.too_large": "Réseau trop grand (128 stockages maximum).",
|
||||
"screen.redstoner.storage_terminal.error.locked": "Le réseau contient un stockage verrouillé."
|
||||
}
|
||||
|
||||
@@ -49,5 +49,12 @@
|
||||
"message.redstoner.computer.invalid": "Программа отклонена: %s",
|
||||
"block.redstoner.particuleur": "Генератор частиц",
|
||||
"block.particuleur.particuleur": "Старый генератор частиц",
|
||||
"tooltip.redstoner.particuleur": "Вставьте катализатор и подайте сигнал редстоуна."
|
||||
"tooltip.redstoner.particuleur": "Вставьте катализатор и подайте сигнал редстоуна.",
|
||||
"block.redstoner.storage_terminal": "Терминал хранилища",
|
||||
"screen.redstoner.storage_terminal.title": "Терминал хранилища",
|
||||
"screen.redstoner.storage_terminal.summary": "%s/%s · блоков: %s · типов: %s",
|
||||
"screen.redstoner.storage_terminal.error.invalid_terminal": "Терминал больше недоступен.",
|
||||
"screen.redstoner.storage_terminal.error.disconnected": "Нет подключённых сундуков или бочек.",
|
||||
"screen.redstoner.storage_terminal.error.too_large": "Сеть слишком велика (не более 128 хранилищ).",
|
||||
"screen.redstoner.storage_terminal.error.locked": "В сети есть запертое хранилище."
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"parent": "minecraft:block/block",
|
||||
"textures": {
|
||||
"particle": "redstoner:block/redstone_controller_front",
|
||||
"front": "redstoner:block/redstone_controller_front",
|
||||
"back": "redstoner:block/redstone_controller_back",
|
||||
"side": "redstoner:block/redstone_controller_right",
|
||||
"top": "redstoner:block/redstone_controller_top",
|
||||
"bottom": "redstoner:block/redstone_controller_bottom"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"from": [0, 0, 8],
|
||||
"to": [16, 16, 16],
|
||||
"faces": {
|
||||
"north": { "uv": [0, 0, 16, 16], "texture": "#front" },
|
||||
"south": { "uv": [0, 0, 16, 16], "texture": "#back" },
|
||||
"west": { "uv": [8, 0, 16, 16], "texture": "#side" },
|
||||
"east": { "uv": [0, 0, 8, 16], "texture": "#side" },
|
||||
"up": { "uv": [0, 8, 16, 16], "texture": "#top" },
|
||||
"down": { "uv": [0, 0, 16, 8], "texture": "#bottom" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
{"replace":false,"values":["redstoner:eight_bit_computer","redstoner:controller","redstoner:personal_computer","redstoner:particuleur","redstone_computer:redstone_computer","redstone_computer:redstone_controller","redstone_computer:personal_computer","particuleur:particuleur"]}
|
||||
{"replace":false,"values":["redstoner:eight_bit_computer","redstoner:controller","redstoner:personal_computer","redstoner:particuleur","redstoner:storage_terminal","redstone_computer:redstone_computer","redstone_computer:redstone_controller","redstone_computer:personal_computer","particuleur:particuleur"]}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"replace":false,"values":["redstoner:eight_bit_computer","redstoner:controller","redstoner:personal_computer","redstoner:particuleur","redstone_computer:redstone_computer","redstone_computer:redstone_controller","redstone_computer:personal_computer","particuleur:particuleur"]}
|
||||
{"replace":false,"values":["redstoner:eight_bit_computer","redstoner:controller","redstoner:personal_computer","redstoner:particuleur","redstoner:storage_terminal","redstone_computer:redstone_computer","redstone_computer:redstone_controller","redstone_computer:personal_computer","particuleur:particuleur"]}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "redstoner:storage_terminal"
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"random_sequence": "redstoner:blocks/storage_terminal"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "redstone",
|
||||
"pattern": [
|
||||
"PGP",
|
||||
"GCG",
|
||||
"PTP"
|
||||
],
|
||||
"key": {
|
||||
"P": "anotherworld:silver_plate",
|
||||
"G": "minecraft:tinted_glass",
|
||||
"C": "redstoner:controller",
|
||||
"T": "anotherworld:titanium_ingot"
|
||||
},
|
||||
"result": {
|
||||
"id": "redstoner:storage_terminal",
|
||||
"count": 1
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
"system_type": "gameplay-system",
|
||||
"namespace": "redstoner",
|
||||
"data_version": 3,
|
||||
"network_protocol": 5,
|
||||
"network_protocol": 6,
|
||||
"lifecycle": "${lifecycle}",
|
||||
"pack_version": "${pack_version}",
|
||||
"descriptions": {
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
package fr.koka99cab.sanctuary26.redstoner.storage;
|
||||
|
||||
import fr.koka99cab.sanctuary26.redstoner.network.StorageTerminalActionPayload;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public final class StorageTerminalSmoke {
|
||||
private StorageTerminalSmoke() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
verifyTopology();
|
||||
verifyPagination();
|
||||
verifyActionBounds();
|
||||
verifyAggregationAndTransfers();
|
||||
}
|
||||
|
||||
private static void verifyTopology() {
|
||||
Set<BlockPos> line = new HashSet<>();
|
||||
for (int x = 0; x < StorageTerminalRules.MAX_CONTAINERS; x++) line.add(new BlockPos(x, 0, 0));
|
||||
StorageTerminalTopology.Result exact = StorageTerminalTopology.discover(BlockPos.ZERO, line::contains);
|
||||
require(!exact.tooLarge() && exact.positions().size() == StorageTerminalRules.MAX_CONTAINERS,
|
||||
"An exact 128-container network was rejected");
|
||||
|
||||
line.add(new BlockPos(StorageTerminalRules.MAX_CONTAINERS, 0, 0));
|
||||
StorageTerminalTopology.Result oversized = StorageTerminalTopology.discover(BlockPos.ZERO, line::contains);
|
||||
require(oversized.tooLarge() && oversized.positions().size() == StorageTerminalRules.MAX_CONTAINERS,
|
||||
"A 129-container network was not bounded");
|
||||
|
||||
Set<BlockPos> loaded = Set.of(BlockPos.ZERO, new BlockPos(0, 1, 0), new BlockPos(0, 2, 0),
|
||||
new BlockPos(20, 0, 0));
|
||||
StorageTerminalTopology.Result bounded = StorageTerminalTopology.discover(BlockPos.ZERO, loaded::contains);
|
||||
require(!bounded.tooLarge() && bounded.positions().size() == 3
|
||||
&& !bounded.positions().contains(new BlockPos(20, 0, 0)),
|
||||
"Topology crossed a disconnected or unloaded gap");
|
||||
}
|
||||
|
||||
private static void verifyPagination() {
|
||||
require(StorageTerminalRules.pageCount(0) == 1, "An empty terminal must keep one page");
|
||||
require(StorageTerminalRules.pageCount(54) == 1, "A full visible page overflowed");
|
||||
require(StorageTerminalRules.pageCount(55) == 2, "The second page did not open");
|
||||
require(StorageTerminalRules.clampPage(999, 55) == 1, "A hostile page index was not clamped");
|
||||
}
|
||||
|
||||
private static void verifyActionBounds() {
|
||||
StorageTerminalActionPayload hostile = new StorageTerminalActionPayload(BlockPos.ZERO,
|
||||
StorageTerminalActionPayload.Action.DEPOSIT_SLOT, -5, 999, 999, ItemStack.EMPTY);
|
||||
require(hostile.page() == 0 && hostile.entryIndex() == -1 && hostile.playerSlot() == -1,
|
||||
"Hostile terminal action indexes were mapped to valid slots");
|
||||
StorageTerminalActionPayload missingAction = new StorageTerminalActionPayload(
|
||||
BlockPos.ZERO, null, 0, -1, -1, ItemStack.EMPTY);
|
||||
require(missingAction.action() == StorageTerminalActionPayload.Action.REQUEST_PAGE,
|
||||
"A missing terminal action did not fall back to a read-only request");
|
||||
}
|
||||
|
||||
private static void verifyAggregationAndTransfers() {
|
||||
SimpleContainer first = new SimpleContainer(27);
|
||||
SimpleContainer second = new SimpleContainer(27);
|
||||
Holder<Item> cobblestone = new Holder.Direct<>(Items.COBBLESTONE, DataComponentMap.builder()
|
||||
.set(DataComponents.MAX_STACK_SIZE, 64).build());
|
||||
first.setItem(0, new ItemStack(cobblestone, 60));
|
||||
ItemStack named = new ItemStack(cobblestone, 5);
|
||||
named.set(DataComponents.CUSTOM_NAME, Component.literal("Distinct"));
|
||||
second.setItem(3, named);
|
||||
|
||||
ItemStack deposit = new ItemStack(cobblestone, 10);
|
||||
int inserted = StorageTerminalInventory.insert(List.of(first, second), deposit);
|
||||
require(inserted == 10 && deposit.isEmpty(), "Terminal deposit lost or retained items");
|
||||
require(first.getItem(0).getCount() == 64 && first.getItem(1).getCount() == 6,
|
||||
"Terminal deposit did not fill matching stacks before empty slots");
|
||||
|
||||
List<StorageTerminalInventory.Entry> entries = StorageTerminalInventory.aggregate(List.of(first, second));
|
||||
require(entries.size() == 2, "Items with distinct components were merged");
|
||||
StorageTerminalInventory.Entry plain = entries.stream()
|
||||
.filter(entry -> !entry.stack().has(DataComponents.CUSTOM_NAME)).findFirst().orElseThrow();
|
||||
require(plain.total() == 70, "Aggregated terminal quantity is incorrect");
|
||||
|
||||
ItemStack taken = StorageTerminalInventory.take(List.of(first, second), plain.stack(), 64);
|
||||
require(taken.getCount() == 64 && ItemStack.isSameItemSameComponents(taken, plain.stack()),
|
||||
"Terminal extraction changed item identity or quantity");
|
||||
List<StorageTerminalInventory.Entry> remaining = StorageTerminalInventory.aggregate(List.of(first, second));
|
||||
require(remaining.stream().filter(entry -> !entry.stack().has(DataComponents.CUSTOM_NAME))
|
||||
.findFirst().orElseThrow().total() == 6, "Terminal extraction did not update physical slots");
|
||||
}
|
||||
|
||||
private static void require(boolean condition, String message) {
|
||||
if (!condition) throw new IllegalStateException(message);
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -121,7 +121,7 @@ tasks.register("verifyBlackMarket") {
|
||||
def questData = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/shop/QuestBoardData.java").text
|
||||
def quests = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/shop/QuestBoardService.java").text
|
||||
def inventoryView = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/api/inventory/SanctuaryPlayerInventoryView.java").text
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| !data.contains('SAVE_KEY = "black_market"') || !data.contains("DATA_VERSION = 2")
|
||||
|| !data.contains("ItemStack.CODEC.fieldOf(\"item\")") || !data.contains("replaceListing")
|
||||
|| !service.contains("LISTING_FEE_RUBIES = 1") || !service.contains("COMMISSION_PERCENT = 5")
|
||||
@@ -132,7 +132,7 @@ tasks.register("verifyBlackMarket") {
|
||||
|| !interactionRules.contains("middleClick || secondaryUse")
|
||||
|| !client.contains("handleBlackMarketMiddleClick")
|
||||
|| !client.contains("ClientPlayNetworking.send(new BlackMarketInteractPayload())")
|
||||
|| !minecraftMixin.contains('method = "pickBlock"')
|
||||
|| !minecraftMixin.contains('method = "pickBlockOrEntity"')
|
||||
|| !middleClickPayload.contains('SanctuaryMod.id("c2s/black_market_interact")')
|
||||
|| !middleClickPayload.contains("No client position, listing ID, item or price is trusted")
|
||||
|| !network.contains("PROTOCOL_VERSION = 22")
|
||||
@@ -2818,7 +2818,7 @@ tasks.register("verifyShopCurrencyRowsRelease") {
|
||||
"src/main/java/fr/koka99cab/sanctuary26/sanctuary/shop/BlackMarketService.java").text
|
||||
def shop = file(
|
||||
"src/main/java/fr/koka99cab/sanctuary26/sanctuary/shop/ShopService.java").text
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| migration.target?.modules?.sanctuary != "0.0.0-alpha.117"
|
||||
|| migration.shop_currency_inventory?.all_unlocked_rows_counted != true
|
||||
|| migration.shop_currency_inventory?.overflow_rows_counted != true
|
||||
@@ -2984,7 +2984,7 @@ tasks.register("verifyProgressivePauseMenu") {
|
||||
"pack/migrations/26.2.0-alpha.190-progressive-pause-menu-to-alpha.191.json"))
|
||||
def pauseMenu = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/mixin/client/PauseScreenMixin.java").text
|
||||
def costs = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/progression/SanctuaryProgressionCosts.java").text
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| migration.target?.pack_version != "26.2.0-alpha.191"
|
||||
|| migration.target?.modules?.sanctuary != "0.0.0-alpha.109"
|
||||
|| migration.pause_menu?.progression_full_width != true
|
||||
@@ -3022,7 +3022,7 @@ tasks.register("verifyShopPricingLayout") {
|
||||
"pack/migrations/26.2.0-alpha.192-shop-pricing-layout-to-alpha.193.json"))
|
||||
def screen = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/client/SanctuaryShopScreen.java").text
|
||||
def progression = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/shop/ShopProgression.java").text
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| migration.target?.modules?.sanctuary != "0.0.0-alpha.110"
|
||||
|| migration.shop_layout?.locked_offer_buttons != 6
|
||||
|| migration.shop_layout?.button_slots != [4, 5, 6, 7, 8, 9]
|
||||
@@ -3053,7 +3053,7 @@ tasks.register("verifyShopCsvBossGates") {
|
||||
"pack/migrations/26.2.0-alpha.194-shop-csv-boss-gates-to-alpha.195.json"))
|
||||
def provider = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/shop/ShopCatalogProvider.java").text
|
||||
def catalog = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/shop/ShopOfferCatalog.java").text
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| migration.target?.pack_version != "26.2.0-alpha.195"
|
||||
|| migration.target?.modules?.sanctuary != "0.0.0-alpha.111"
|
||||
|| migration.compatibility?.sanctuary_data_version != 11
|
||||
@@ -3084,7 +3084,7 @@ tasks.register("verifyDeliveryBoxOrientation") {
|
||||
def blockstate = new JsonSlurper().parse(
|
||||
file("src/main/resources/assets/sanctuary/blockstates/delivery_box.json"))
|
||||
def expectedVariants = ["facing=north", "facing=east", "facing=south", "facing=west"].toSet()
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| migration.target?.modules?.sanctuary != "0.0.0-alpha.112"
|
||||
|| migration.mailbox?.id != "sanctuary:delivery_box"
|
||||
|| migration.mailbox?.horizontal_facing != true
|
||||
@@ -3112,7 +3112,7 @@ tasks.register("verifyInventoryShiftClick") {
|
||||
def mixin = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/mixin/AbstractContainerMenuMixin.java").text
|
||||
def screen = file("src/main/java/fr/koka99cab/sanctuary26/sanctuary/mixin/client/AbstractContainerScreenMixin.java").text
|
||||
def gui = file("INVENTORY_GUI.md").text
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| !transfer.contains("shouldAppendOverflow")
|
||||
|| !transfer.contains("isVanillaStorageRange")
|
||||
|| !transfer.contains("hotbarStart")
|
||||
@@ -3158,7 +3158,7 @@ tasks.register("verifyQuestRequests") {
|
||||
new JsonSlurper().parse(file("src/main/resources/data/sanctuary/loot_table/blocks/${path}.json"))
|
||||
.pools[0].entries[0].name
|
||||
}
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| migration.target?.modules?.sanctuary != "0.0.0-alpha.113"
|
||||
|| migration.quest_requests?.save_key != "quest_requests"
|
||||
|| migration.quest_requests?.data_version != 1
|
||||
@@ -3216,7 +3216,7 @@ tasks.register("verifyQuestRequestContracts") {
|
||||
def locales = ["fr_fr", "en_us", "ru_ru"].collectEntries { locale ->
|
||||
[(locale): new JsonSlurper().parse(file("src/main/resources/assets/sanctuary/lang/${locale}.json"))]
|
||||
}
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| migration.source?.pack_version != "26.2.0-alpha.198"
|
||||
|| migration.source?.modules?.sanctuary != "0.0.0-alpha.114"
|
||||
|| migration.target?.pack_version != "26.2.0-alpha.199"
|
||||
@@ -3285,7 +3285,7 @@ tasks.register("verifyQuestRequestEscrow") {
|
||||
def locales = ["fr_fr", "en_us", "ru_ru"].collectEntries { locale ->
|
||||
[(locale): new JsonSlurper().parse(file("src/main/resources/assets/sanctuary/lang/${locale}.json"))]
|
||||
}
|
||||
if (project.version.toString() != "0.0.0-alpha.119"
|
||||
if (project.version.toString() != "0.0.0-alpha.121"
|
||||
|| migration.source?.pack_version != "26.2.0-alpha.200"
|
||||
|| migration.source?.modules?.sanctuary != "0.0.0-alpha.115"
|
||||
|| migration.target?.pack_version != "26.2.0-alpha.201"
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
/** Gives the game window the Sanctuary identity while preserving its connection suffix. */
|
||||
@Mixin(Minecraft.class)
|
||||
public abstract class MinecraftMixin {
|
||||
@Inject(method = "pickBlock", at = @At("HEAD"), cancellable = true)
|
||||
@Inject(method = "pickBlockOrEntity", at = @At("HEAD"), cancellable = true)
|
||||
private void sanctuary$blackMarketMiddleClick(CallbackInfo callback) {
|
||||
if (SanctuaryClient.handleBlackMarketMiddleClick((Minecraft) (Object) this)) callback.cancel();
|
||||
}
|
||||
|
||||
+11
-5
@@ -29,6 +29,15 @@ public final class BlackMarketItemPolicy {
|
||||
if (stack == null || stack.isEmpty() || stack.has(DataComponents.CREATIVE_SLOT_LOCK)) return true;
|
||||
if (depth > 8 || stack.has(DataComponents.CONTAINER_LOOT)) return true;
|
||||
Identifier id = BuiltInRegistries.ITEM.getKey(stack.getItem());
|
||||
if (forbidden(id)
|
||||
|| stack.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof GameMasterBlock) return true;
|
||||
var container = stack.get(DataComponents.CONTAINER);
|
||||
if (container != null && container.nonEmptyItemCopyStream().anyMatch(item -> forbidden(item, depth + 1))) return true;
|
||||
var bundle = stack.get(DataComponents.BUNDLE_CONTENTS);
|
||||
return bundle != null && bundle.itemCopyStream().anyMatch(item -> forbidden(item, depth + 1));
|
||||
}
|
||||
|
||||
public static boolean forbidden(Identifier id) {
|
||||
if (id == null) return true;
|
||||
String namespace = id.getNamespace().toLowerCase(Locale.ROOT);
|
||||
String path = id.getPath().toLowerCase(Locale.ROOT);
|
||||
@@ -37,13 +46,10 @@ public final class BlackMarketItemPolicy {
|
||||
|| path.contains("rainbow_block")) return true;
|
||||
if (namespace.equals("onlyfun") && path.equals("lucky_block")) return true;
|
||||
if (namespace.equals("sanctuary") && path.equals("delivery_box")) return true;
|
||||
if (namespace.equals("redstoner") && path.equals("storage_terminal")) return true;
|
||||
if (namespace.equals("anotherworld") && (path.equals("ruby") || path.equals("sapphire")
|
||||
|| path.equals("saphire") || path.startsWith("ruby_") || path.startsWith("sapphire_")
|
||||
|| path.startsWith("saphire_"))) return true;
|
||||
if (stack.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof GameMasterBlock) return true;
|
||||
var container = stack.get(DataComponents.CONTAINER);
|
||||
if (container != null && container.nonEmptyItemCopyStream().anyMatch(item -> forbidden(item, depth + 1))) return true;
|
||||
var bundle = stack.get(DataComponents.BUNDLE_CONTENTS);
|
||||
return bundle != null && bundle.itemCopyStream().anyMatch(item -> forbidden(item, depth + 1));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -1,6 +1,7 @@
|
||||
package fr.koka99cab.sanctuary26.sanctuary.shop;
|
||||
|
||||
import java.util.UUID;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/** Pure ledger/policy smoke; live sign and mailbox behavior is covered by the server smoke. */
|
||||
@@ -40,6 +41,8 @@ public final class BlackMarketModelSmoke {
|
||||
require(data.parcels().isEmpty() && data.casinoVaultSize() == 1,
|
||||
"An expired parcel did not transfer exactly once to the casino vault");
|
||||
require(BlackMarketItemPolicy.forbidden(ItemStack.EMPTY), "An empty escrow item was accepted");
|
||||
require(BlackMarketItemPolicy.forbidden(Identifier.parse("redstoner:storage_terminal")),
|
||||
"Storage Terminal reached the Black Market");
|
||||
}
|
||||
|
||||
private static void require(boolean value, String message) {
|
||||
|
||||
Reference in New Issue
Block a user