Skip to content

Commit

Permalink
Flesh out satellite audio mechanic
Browse files Browse the repository at this point in the history
- Add satellites, which are rockets mounted on top of stations
- Uploading will launch the satellite rocket, crashing one in orbit deletes the audio
- Configurable limit for maximum uploaded audio data (gamerule)
- All phonos sounds are played in the records category (temporary)
- Fixed some indexing issues when applying changes to cable networks
- Server logs more detailed and frequent information about audio uploads
  • Loading branch information
FoundationGames committed Jul 29, 2023
1 parent 5f3df26 commit 2e7ace2
Show file tree
Hide file tree
Showing 26 changed files with 928 additions and 54 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ loader_version=0.14.21
#Fabric api
fabric_version=0.84.0+1.20.1

mod_version = 1.0.0-beta.3
mod_version = 1.0.0-beta.4
maven_group = io.github.foundationgames
archives_base_name = phonos

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/github/foundationgames/phonos/Phonos.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerBlockEntityEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.world.GameRules;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -34,6 +37,9 @@ public class Phonos implements ModInitializer {

public static final ItemGroupQueue PHONOS_ITEMS = new ItemGroupQueue(id("phonos"));

public static final GameRules.Key<GameRules.IntRule> PHONOS_UPLOAD_LIMIT_KB = GameRuleRegistry.register(
"phonosUploadLimitKB", GameRules.Category.MISC, GameRuleFactory.createIntRule(-1, -1));

public static final Identifier STREAMED_SOUND = Phonos.id("streamed");

@Override
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/io/github/foundationgames/phonos/PhonosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.foundationgames.phonos.client.render.block.CableOutputBlockEntityRenderer;
import io.github.foundationgames.phonos.client.render.block.RadioLoudspeakerBlockEntityRenderer;
import io.github.foundationgames.phonos.client.render.block.RadioTransceiverBlockEntityRenderer;
import io.github.foundationgames.phonos.client.render.block.SatelliteStationBlockEntityRenderer;
import io.github.foundationgames.phonos.item.AudioCableItem;
import io.github.foundationgames.phonos.item.PhonosItems;
import io.github.foundationgames.phonos.network.ClientPayloadPackets;
Expand Down Expand Up @@ -32,13 +33,15 @@

public class PhonosClient implements ClientModInitializer {
public static final EntityModelLayer AUDIO_CABLE_END_LAYER = new EntityModelLayer(Phonos.id("audio_cable_end"), "main");
public static final EntityModelLayer SATELLITE_LAYER = new EntityModelLayer(Phonos.id("satellite"), "main");

@Override
public void onInitializeClient() {
ClientPayloadPackets.initClient();
ClientSoundStorage.initClient();

JsonEM.registerModelLayer(AUDIO_CABLE_END_LAYER);
JsonEM.registerModelLayer(SATELLITE_LAYER);

BlockRenderLayerMap.INSTANCE.putBlock(PhonosBlocks.ELECTRONIC_NOTE_BLOCK, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(PhonosBlocks.RADIO_TRANSCEIVER, RenderLayer.getCutout());
Expand All @@ -49,7 +52,7 @@ public void onInitializeClient() {
BlockEntityRendererFactories.register(PhonosBlocks.CONNECTION_HUB_ENTITY, CableOutputBlockEntityRenderer::new);
BlockEntityRendererFactories.register(PhonosBlocks.RADIO_TRANSCEIVER_ENTITY, RadioTransceiverBlockEntityRenderer::new);
BlockEntityRendererFactories.register(PhonosBlocks.RADIO_LOUDSPEAKER_ENTITY, RadioLoudspeakerBlockEntityRenderer::new);
BlockEntityRendererFactories.register(PhonosBlocks.SATELLITE_STATION_ENTITY, CableOutputBlockEntityRenderer::new);
BlockEntityRendererFactories.register(PhonosBlocks.SATELLITE_STATION_ENTITY, SatelliteStationBlockEntityRenderer::new);

ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) ->
world != null && pos != null && state != null ?
Expand Down Expand Up @@ -98,12 +101,4 @@ public void onInitializeClient() {

//ScreenRegistry.<RadioJukeboxGuiDescription, RadioJukeboxScreen>register(Phonos.RADIO_JUKEBOX_HANDLER, (gui, inventory, title) -> new RadioJukeboxScreen(gui, inventory.player));
}

private static long seed(String s) {
if(s == null) return 0;
long l = 0;
for(char c : s.toCharArray())
l = 31L * l + c;
return l;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.foundationgames.phonos.block;

import io.github.foundationgames.phonos.block.entity.SatelliteStationBlockEntity;
import io.github.foundationgames.phonos.network.PayloadPackets;
import io.github.foundationgames.phonos.item.PhonosItems;
import io.github.foundationgames.phonos.util.PhonosUtil;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
Expand Down Expand Up @@ -37,11 +37,28 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
var side = hit.getSide();
var facing = state.get(FACING);

if (side == Direction.DOWN || side == Direction.UP) {
if (side == Direction.DOWN) {
return ActionResult.PASS;
}

if (player.canModifyBlocks() && world.getBlockEntity(pos) instanceof SatelliteStationBlockEntity be) {
if (side == Direction.UP) {
var holding = player.getStackInHand(hand);
if (holding.getItem() == PhonosItems.SATELLITE) {
if (world.isClient()) {
return ActionResult.CONSUME;
} else {
if (be.addRocket() && !player.isCreative()) {
holding.decrement(1);
}

return ActionResult.SUCCESS;
}
}

return ActionResult.PASS;
}

if (!world.isClient()) {
if (PhonosUtil.holdingAudioCable(player)) {
return ActionResult.PASS;
Expand All @@ -54,7 +71,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}
} else {
if (player instanceof ServerPlayerEntity sPlayer) {
PayloadPackets.sendOpenSatelliteStationScreen(sPlayer, pos);
be.tryOpenScreen(sPlayer);
}

return ActionResult.CONSUME;
Expand Down Expand Up @@ -109,6 +126,20 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po
return SHAPE;
}

@Override
public boolean hasComparatorOutput(BlockState state) {
return true;
}

@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
if (world.getBlockEntity(pos) instanceof SatelliteStationBlockEntity be) {
return be.getComparatorOutput();
}

return super.getComparatorOutput(state, world, pos);
}

@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
Expand Down
Loading

0 comments on commit 2e7ace2

Please sign in to comment.