From 99b0fee5ae810f0512dd54e1edea0f33fa0fec9d Mon Sep 17 00:00:00 2001 From: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:41:57 -0700 Subject: [PATCH] fix radios in clientside unloaded chunks also: fix satellite station model rename satellite station to satellite broadcast station --- gradle.properties | 2 +- .../phonos/radio/RadioStorage.java | 5 +- .../sound/emitter/SoundEmitterTree.java | 59 +++- .../resources/assets/phonos/lang/en_us.json | 4 +- .../models/block/satellite_station.json | 256 +++++++++--------- 5 files changed, 183 insertions(+), 143 deletions(-) diff --git a/gradle.properties b/gradle.properties index 94b6ff7..d9bf460 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ loader_version=0.16.3 #Fabric api fabric_version=0.92.2+1.20.1 -mod_version = 1.1.0-beta.3 +mod_version = 1.1.1-beta.1 maven_group = io.github.foundationgames archives_base_name = phonos diff --git a/src/main/java/io/github/foundationgames/phonos/radio/RadioStorage.java b/src/main/java/io/github/foundationgames/phonos/radio/RadioStorage.java index 0fafe88..f6439f2 100644 --- a/src/main/java/io/github/foundationgames/phonos/radio/RadioStorage.java +++ b/src/main/java/io/github/foundationgames/phonos/radio/RadioStorage.java @@ -13,10 +13,7 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.world.World; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Consumer; import java.util.function.LongConsumer; diff --git a/src/main/java/io/github/foundationgames/phonos/sound/emitter/SoundEmitterTree.java b/src/main/java/io/github/foundationgames/phonos/sound/emitter/SoundEmitterTree.java index f52a6b8..23530a6 100644 --- a/src/main/java/io/github/foundationgames/phonos/sound/emitter/SoundEmitterTree.java +++ b/src/main/java/io/github/foundationgames/phonos/sound/emitter/SoundEmitterTree.java @@ -9,11 +9,14 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.LongArrayList; import it.unimi.dsi.fastutil.longs.LongList; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; import net.minecraft.network.PacketByteBuf; import net.minecraft.world.World; import java.util.ArrayList; import java.util.HashSet; +import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -84,7 +87,7 @@ public Delta updateServer(World world) { radioChanges.add(channel, metadata); } - final int searchUntil = index; + final int searchUntil = index + 1; // this is intentionally higher than the client version, since the client does more complicated radio logic RadioLongConsumer[] consumerRef = new RadioLongConsumer[1]; RadioLongConsumer consumer = (child, metadata) -> { if (emitters.isLoaded(child) && emitters.getEmitter(child) instanceof RadioStorage.RadioEmitter radioEmitter && radioEmitter.isRadio()) { @@ -135,11 +138,18 @@ public Delta updateServer(World world) { // immediate effects regardless of server speed/latency public void updateClient(World world) { var emitters = SoundEmitterStorage.getInstance(world); + Int2ObjectOpenHashMap> backupSources = new Int2ObjectOpenHashMap<>(radioSources); radioSources.clear(); int index = 0; + LongSet nonIgnoredRadioEmitters; + LongSet nextNonIgnoredRadioEmitters = new LongOpenHashSet(); + while (index < this.levels.size() && !this.levels.get(index).empty()) { + nonIgnoredRadioEmitters = nextNonIgnoredRadioEmitters; + nextNonIgnoredRadioEmitters = new LongOpenHashSet(); + if (index + 1 == this.levels.size()) { this.levels.add(new Level(new LongArrayList(), new LongArrayList())); } @@ -151,14 +161,31 @@ public void updateClient(World world) { nextLevel.active().clear(); for (long l : nextLevel.inactive()) if (RadioStorage.RADIO_EMITTERS.contains(l)) { nextLevel.active().add(l); + nextNonIgnoredRadioEmitters.add(l); } nextLevel.inactive().removeAll(nextLevel.active()); for (long emId : level.active()) { if (emitters.isLoaded(emId)) { + HashSet overriddenRadioSources; + var emitter = emitters.getEmitter(emId); - if (emitter instanceof RadioStorage.RadioEmitter radioEmitter && radioEmitter.isRadio()) - continue; + if (emitter instanceof RadioStorage.RadioEmitter radioEmitter && radioEmitter.isRadio()) { + if (nonIgnoredRadioEmitters.contains(emId)) { + nextNonIgnoredRadioEmitters.remove(emId); + var sources = backupSources.get(radioEmitter.channel); + + if (sources != null) { + radioSources.put(radioEmitter.channel, new HashSet<>(sources)); + } + + overriddenRadioSources = sources; + } else { + continue; + } + } else { + overriddenRadioSources = null; + } if (emitter instanceof RadioDevice.Transmitter radioTransmitter) { int channel = radioTransmitter.getChannel(); @@ -169,19 +196,32 @@ public void updateClient(World world) { final int searchUntil = index; RadioLongConsumer[] consumerRef = new RadioLongConsumer[1]; + LongSet finalNextNonIgnoredRadioEmitters = nextNonIgnoredRadioEmitters; + + int[] depth = new int[] {0}; + RadioLongConsumer consumer = (child, metadata) -> { if (emitters.isLoaded(child) && emitters.getEmitter(child) instanceof RadioStorage.RadioEmitter radioEmitter && radioEmitter.isRadio()) { + depth[0]++; radioEmitter.forEachChild(consumerRef[0]); + depth[0]--; } if (this.contains(child, searchUntil)) { return; } - if (metadata != null && emitter instanceof RadioDevice radioDevice) { - RadioMetadata emitterMetadata = radioDevice.getMetadata(); - if (!emitterMetadata.shouldTransmitTo(metadata)) { - return; + if (metadata != null) { + if (emitter instanceof RadioDevice radioDevice) { + RadioMetadata emitterMetadata = radioDevice.getMetadata(); + if (!emitterMetadata.shouldTransmitTo(metadata)) { + return; + } + } + if (depth[0] == 0 && emitter instanceof RadioStorage.RadioEmitter && overriddenRadioSources != null) { + if (overriddenRadioSources.stream().noneMatch(source -> source.shouldTransmitTo(metadata))) { + return; + } } } @@ -189,6 +229,7 @@ public void updateClient(World world) { if (!nextLevel.active().contains(child)) { nextLevel.active().add(child); + finalNextNonIgnoredRadioEmitters.remove(child); } }; consumerRef[0] = consumer; @@ -245,9 +286,11 @@ public void accept(SoundSource soundSource) { public void forEachSource(World world, Consumer action) { var emitters = SoundEmitterStorage.getInstance(world); + LongSet deduplication = new LongOpenHashSet(); + for (var level : this.levels) for (long em : level.active) { - if (emitters.isLoaded(em)) { + if (deduplication.add(em) && emitters.isLoaded(em)) { var emitter = emitters.getEmitter(em); emitter.forEachSource(emitter instanceof RadioStorage.RadioEmitter radioEmitter && radioEmitter.isRadio() ? new SmartSoundSourceConsumer(action, radioEmitter.channel) diff --git a/src/main/resources/assets/phonos/lang/en_us.json b/src/main/resources/assets/phonos/lang/en_us.json index 2f6e20c..cab4a16 100644 --- a/src/main/resources/assets/phonos/lang/en_us.json +++ b/src/main/resources/assets/phonos/lang/en_us.json @@ -1,7 +1,7 @@ { "itemGroup.phonos.phonos": "Phonos", - "container.phonos.satellite_station": "Satellite Station", + "container.phonos.satellite_station": "Satellite Broadcast Station", "container.phonos.ender_music_box": "Ender Music Box", "hint.phonos.ender_music_box.drag": "+ Drag and drop .ogg file to upload", @@ -48,7 +48,7 @@ "block.phonos.radio_transceiver": "Radio Transceiver", "block.phonos.satellite_receiver": "Satellite Receiver", "block.phonos.radio_loudspeaker": "Radio Loudspeaker", - "block.phonos.satellite_station": "Satellite Station", + "block.phonos.satellite_station": "Satellite Broadcast Station", "block.phonos.audio_switch": "Audio Switch", "block.phonos.ender_music_box": "Ender Music Box", "block.phonos.microphone_base": "Microphone Base", diff --git a/src/main/resources/assets/phonos/models/block/satellite_station.json b/src/main/resources/assets/phonos/models/block/satellite_station.json index b7d2e68..6858d1f 100644 --- a/src/main/resources/assets/phonos/models/block/satellite_station.json +++ b/src/main/resources/assets/phonos/models/block/satellite_station.json @@ -1,130 +1,130 @@ { - "credit": "Made with Blockbench", - "parent": "block/block", - "textures": { - "0": "phonos:block/satellite_dish", - "1": "phonos:block/satellite_station_front", - "3": "phonos:block/satellite_station_top", - "4": "phonos:block/stone_base", - "5": "phonos:block/wireless_hub_front", - "6": "phonos:block/wireless_hub_none", - "particle": "phonos:block/satellite_station_top" - }, - "elements": [ - { - "from": [0, 0, 0], - "to": [16, 7, 16], - "faces": { - "north": {"uv": [0, 9, 16, 16], "texture": "#1"}, - "east": {"uv": [0, 9, 16, 16], "texture": "#5"}, - "south": {"uv": [0, 9, 16, 16], "texture": "#6"}, - "west": {"uv": [0, 9, 16, 16], "texture": "#5"}, - "up": {"uv": [0, 0, 16, 16], "rotation": 180, "texture": "#3"}, - "down": {"uv": [0, 0, 16, 16], "texture": "#4"} - } - }, - { - "from": [10, 7, 10], - "to": [13, 9, 13], - "faces": { - "north": {"uv": [4, 3, 6, 6], "rotation": 270, "texture": "#3"}, - "east": {"uv": [3, 3, 6, 5], "texture": "#3"}, - "south": {"uv": [6, 3, 3, 5], "texture": "#3"}, - "west": {"uv": [6, 3, 4, 6], "rotation": 90, "texture": "#3"}, - "up": {"uv": [3, 3, 6, 6], "rotation": 180, "texture": "#3"} - } - }, - { - "from": [11, 9, 10], - "to": [12, 12, 10], - "rotation": {"angle": 22.5, "axis": "x", "origin": [11, 9, 10]}, - "faces": { - "north": {"uv": [0, 12, 1, 15], "texture": "#0"}, - "south": {"uv": [0, 12, 1, 15], "texture": "#0"} - } - }, - { - "from": [11, 9, 13], - "to": [12, 12, 13], - "rotation": {"angle": -22.5, "axis": "x", "origin": [11, 9, 13]}, - "faces": { - "north": {"uv": [0, 12, 1, 15], "texture": "#0"}, - "south": {"uv": [0, 12, 1, 15], "texture": "#0"} - } - }, - { - "from": [10, 9, 11], - "to": [10, 12, 12], - "rotation": {"angle": -22.5, "axis": "z", "origin": [10, 9, 11]}, - "faces": { - "east": {"uv": [0, 12, 1, 15], "texture": "#0"}, - "west": {"uv": [0, 12, 1, 15], "texture": "#0"} - } - }, - { - "from": [13, 9, 11], - "to": [13, 12, 12], - "rotation": {"angle": 22.5, "axis": "z", "origin": [13, 9, 11]}, - "faces": { - "east": {"uv": [0, 12, 1, 15], "texture": "#0"}, - "west": {"uv": [0, 12, 1, 15], "texture": "#0"} - } - }, - { - "from": [11, 11.25, 11], - "to": [12, 12.25, 12], - "faces": { - "north": {"uv": [0, 10, 1, 11], "texture": "#0"}, - "east": {"uv": [0, 10, 1, 11], "texture": "#0"}, - "south": {"uv": [0, 10, 1, 11], "texture": "#0"}, - "west": {"uv": [0, 10, 1, 11], "texture": "#0"} - } - }, - { - "from": [7.5, 12, 7.5], - "to": [15.5, 13, 15.5], - "rotation": {"angle": -22.5, "axis": "x", "origin": [10, 12, 11.5]}, - "faces": { - "north": {"uv": [1, 15, 9, 16], "rotation": 180, "texture": "#0"}, - "east": {"uv": [8, 8, 9, 16], "rotation": 270, "texture": "#0"}, - "south": {"uv": [1, 8, 9, 9], "texture": "#0"}, - "west": {"uv": [1, 8, 2, 16], "rotation": 90, "texture": "#0"}, - "down": {"uv": [1, 8, 9, 16], "texture": "#0"} - } - }, - { - "from": [7.5, 13, 7.5], - "to": [15.5, 12.42, 15.5], - "rotation": {"angle": -22.5, "axis": "x", "origin": [10, 12, 11.5]}, - "faces": { - "north": {"uv": [1, 15, 9, 16], "rotation": 180, "texture": "#0"}, - "east": {"uv": [8, 8, 9, 16], "rotation": 270, "texture": "#0"}, - "south": {"uv": [1, 8, 9, 9], "texture": "#0"}, - "west": {"uv": [1, 8, 2, 16], "rotation": 90, "texture": "#0"}, - "up": {"uv": [1, 8, 9, 16], "texture": "#0"} - } - }, - { - "from": [11, 10.625, 7.75], - "to": [12, 15.625, 7.75], - "rotation": {"angle": 22.5, "axis": "x", "origin": [0, 10.75, 7.75]}, - "faces": { - "north": {"uv": [9, 11, 10, 16], "texture": "#0"}, - "south": {"uv": [9, 11, 10, 16], "texture": "#0"} - } - }, - { - "from": [11, 15.5, 7.75], - "to": [12, 16.5, 8.75], - "rotation": {"angle": 22.5, "axis": "x", "origin": [0, 10.75, 7.75]}, - "faces": { - "north": {"uv": [9, 11, 10, 12], "texture": "#0"}, - "east": {"uv": [9, 11, 10, 12], "texture": "#0"}, - "south": {"uv": [9, 11, 10, 12], "texture": "#0"}, - "west": {"uv": [9, 11, 10, 12], "texture": "#0"}, - "up": {"uv": [9, 11, 10, 12], "texture": "#0"}, - "down": {"uv": [9, 11, 10, 12], "texture": "#0"} - } - } - ] + "credit": "Made with Blockbench", + "parent": "block/block", + "textures": { + "0": "phonos:block/satellite_dish", + "1": "phonos:block/satellite_station_front", + "3": "phonos:block/satellite_station_top", + "4": "phonos:block/stone_base", + "5": "phonos:block/wireless_hub_front", + "6": "phonos:block/wireless_hub_none", + "particle": "phonos:block/satellite_station_top" + }, + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 7, 16], + "faces": { + "north": {"uv": [0, 9, 16, 16], "texture": "#1"}, + "east": {"uv": [0, 9, 16, 16], "texture": "#6"}, + "south": {"uv": [0, 9, 16, 16], "texture": "#5"}, + "west": {"uv": [0, 9, 16, 16], "texture": "#6"}, + "up": {"uv": [0, 0, 16, 16], "rotation": 180, "texture": "#3"}, + "down": {"uv": [0, 0, 16, 16], "texture": "#4"} + } + }, + { + "from": [10, 7, 10], + "to": [13, 9, 13], + "faces": { + "north": {"uv": [4, 3, 6, 6], "rotation": 270, "texture": "#3"}, + "east": {"uv": [3, 3, 6, 5], "texture": "#3"}, + "south": {"uv": [6, 3, 3, 5], "texture": "#3"}, + "west": {"uv": [6, 3, 4, 6], "rotation": 90, "texture": "#3"}, + "up": {"uv": [3, 3, 6, 6], "rotation": 180, "texture": "#3"} + } + }, + { + "from": [11, 9, 10], + "to": [12, 12, 10], + "rotation": {"angle": 22.5, "axis": "x", "origin": [11, 9, 10]}, + "faces": { + "north": {"uv": [0, 12, 1, 15], "texture": "#0"}, + "south": {"uv": [0, 12, 1, 15], "texture": "#0"} + } + }, + { + "from": [11, 9, 13], + "to": [12, 12, 13], + "rotation": {"angle": -22.5, "axis": "x", "origin": [11, 9, 13]}, + "faces": { + "north": {"uv": [0, 12, 1, 15], "texture": "#0"}, + "south": {"uv": [0, 12, 1, 15], "texture": "#0"} + } + }, + { + "from": [10, 9, 11], + "to": [10, 12, 12], + "rotation": {"angle": -22.5, "axis": "z", "origin": [10, 9, 11]}, + "faces": { + "east": {"uv": [0, 12, 1, 15], "texture": "#0"}, + "west": {"uv": [0, 12, 1, 15], "texture": "#0"} + } + }, + { + "from": [13, 9, 11], + "to": [13, 12, 12], + "rotation": {"angle": 22.5, "axis": "z", "origin": [13, 9, 11]}, + "faces": { + "east": {"uv": [0, 12, 1, 15], "texture": "#0"}, + "west": {"uv": [0, 12, 1, 15], "texture": "#0"} + } + }, + { + "from": [11, 11.25, 11], + "to": [12, 12.25, 12], + "faces": { + "north": {"uv": [0, 10, 1, 11], "texture": "#0"}, + "east": {"uv": [0, 10, 1, 11], "texture": "#0"}, + "south": {"uv": [0, 10, 1, 11], "texture": "#0"}, + "west": {"uv": [0, 10, 1, 11], "texture": "#0"} + } + }, + { + "from": [7.5, 12, 7.5], + "to": [15.5, 13, 15.5], + "rotation": {"angle": -22.5, "axis": "x", "origin": [10, 12, 11.5]}, + "faces": { + "north": {"uv": [1, 15, 9, 16], "rotation": 180, "texture": "#0"}, + "east": {"uv": [8, 8, 9, 16], "rotation": 270, "texture": "#0"}, + "south": {"uv": [1, 8, 9, 9], "texture": "#0"}, + "west": {"uv": [1, 8, 2, 16], "rotation": 90, "texture": "#0"}, + "down": {"uv": [1, 8, 9, 16], "texture": "#0"} + } + }, + { + "from": [7.5, 13, 7.5], + "to": [15.5, 12.42, 15.5], + "rotation": {"angle": -22.5, "axis": "x", "origin": [10, 12, 11.5]}, + "faces": { + "north": {"uv": [1, 15, 9, 16], "rotation": 180, "texture": "#0"}, + "east": {"uv": [8, 8, 9, 16], "rotation": 270, "texture": "#0"}, + "south": {"uv": [1, 8, 9, 9], "texture": "#0"}, + "west": {"uv": [1, 8, 2, 16], "rotation": 90, "texture": "#0"}, + "up": {"uv": [1, 8, 9, 16], "texture": "#0"} + } + }, + { + "from": [11, 10.625, 7.75], + "to": [12, 15.625, 7.75], + "rotation": {"angle": 22.5, "axis": "x", "origin": [0, 10.75, 7.75]}, + "faces": { + "north": {"uv": [9, 11, 10, 16], "texture": "#0"}, + "south": {"uv": [9, 11, 10, 16], "texture": "#0"} + } + }, + { + "from": [11, 15.5, 7.75], + "to": [12, 16.5, 8.75], + "rotation": {"angle": 22.5, "axis": "x", "origin": [0, 10.75, 7.75]}, + "faces": { + "north": {"uv": [9, 11, 10, 12], "texture": "#0"}, + "east": {"uv": [9, 11, 10, 12], "texture": "#0"}, + "south": {"uv": [9, 11, 10, 12], "texture": "#0"}, + "west": {"uv": [9, 11, 10, 12], "texture": "#0"}, + "up": {"uv": [9, 11, 10, 12], "texture": "#0"}, + "down": {"uv": [9, 11, 10, 12], "texture": "#0"} + } + } + ] } \ No newline at end of file