Skip to content

Commit

Permalink
First few features of 1.0 beta rewrite
Browse files Browse the repository at this point in the history
- Electronic Jukebox/Note Block
- Audio cables for connecting devices
- Loudspeakers no longer use radio
- Most features of the mod are no longer present, will be re-added later
  • Loading branch information
FoundationGames committed Jul 20, 2023
1 parent d303c38 commit 5d8a2a5
Show file tree
Hide file tree
Showing 402 changed files with 3,266 additions and 7,329 deletions.
37 changes: 8 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
version = "${project.mod_version}+${project.minecraft_version}"
group = project.maven_group

repositories {
Expand All @@ -17,28 +17,14 @@ repositories {
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Artifice because some of the resources can be tedious
modImplementation "net.devtech:arrp:${project.arrp_version}"
include "net.devtech:arrp:${project.arrp_version}"

// LibGui because yes
modImplementation "io.github.cottonmc:LibGui:${project.libgui_version}"
include "io.github.cottonmc:LibGui:${project.libgui_version}"

// Json entity models
modImplementation "maven.modrinth:jsonem:${project.jsonem_version}"
include "maven.modrinth:jsonem:${project.jsonem_version}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}

processResources {
Expand All @@ -49,30 +35,25 @@ processResources {
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
java {
withSourcesJar()
}

jar {
from "LICENSE"
}

// configure the maven publication
loom {
accessWidenerPath = file("src/main/resources/phonos.accesswidener")
}

publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
Expand All @@ -82,9 +63,7 @@ publishing {
}
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}
14 changes: 6 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.18.2
yarn_mappings=1.18.2+build.2
loader_version=0.13.3
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21

#Fabric api
fabric_version=0.48.0+1.18.2
fabric_version=0.84.0+1.20.1

mod_version = 0.3+1.18.2
mod_version = 1.0.0-beta.1
maven_group = io.github.foundationgames
archives_base_name = phonos

arrp_version=0.5.7
libgui_version=5.2.0+1.18
jsonem_version=0.1.1
jsonem_version=0.2.1+1.20

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
76 changes: 38 additions & 38 deletions src/main/java/io/github/foundationgames/phonos/Phonos.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
package io.github.foundationgames.phonos;

import io.github.foundationgames.phonos.block.PhonosBlocks;
import io.github.foundationgames.phonos.block.entity.RadioJukeboxBlockEntity;
import io.github.foundationgames.phonos.item.ItemGroupQueue;
import io.github.foundationgames.phonos.item.PhonosItems;
import io.github.foundationgames.phonos.mixin.PersistentStateManagerAccess;
import io.github.foundationgames.phonos.network.PayloadPackets;
import io.github.foundationgames.phonos.resource.PhonosData;
import io.github.foundationgames.phonos.screen.CustomMusicDiscGuiDescription;
import io.github.foundationgames.phonos.screen.RadioJukeboxGuiDescription;
import io.github.foundationgames.phonos.util.PhonosUtil;
import io.github.foundationgames.phonos.village.TechnicianVillagerProfession;
import io.github.foundationgames.phonos.world.RadioChannelState;
import io.github.foundationgames.phonos.sound.SoundStorage;
import io.github.foundationgames.phonos.sound.emitter.SoundEmitter;
import io.github.foundationgames.phonos.sound.emitter.SoundEmitterStorage;
import io.github.foundationgames.phonos.world.sound.InputPlugPoint;
import io.github.foundationgames.phonos.world.sound.data.SoundDataTypes;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
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.screenhandler.v1.ScreenHandlerRegistry;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.ScreenHandlerType;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Phonos implements ModInitializer {
public static final Logger LOG = LogManager.getLogger("phonos");

public static final ItemGroup PHONOS_ITEM_GROUP = FabricItemGroupBuilder.build(
id("phonos"),
() -> new ItemStack(PhonosBlocks.LOUDSPEAKER));
public static final ItemGroup PHONOS_EXTRAS_GROUP = FabricItemGroupBuilder.build(
id("extras"),
() -> new ItemStack(PhonosBlocks.SPEAK_O_LANTERN));

public static final ScreenHandlerType<RadioJukeboxGuiDescription> RADIO_JUKEBOX_HANDLER = ScreenHandlerRegistry.registerExtended(Phonos.id("radio_jukebox"), (syncId, playerInv, buf) -> {
RadioJukeboxBlockEntity be = null;
BlockPos p = buf.readBlockPos();
if(playerInv.player.world.getBlockEntity(p) instanceof RadioJukeboxBlockEntity) be = (RadioJukeboxBlockEntity)playerInv.player.world.getBlockEntity(p);
return new RadioJukeboxGuiDescription(syncId, playerInv, ScreenHandlerContext.EMPTY, be);
});
public static final ScreenHandlerType<CustomMusicDiscGuiDescription> CUSTOM_DISC_HANDLER = ScreenHandlerRegistry.registerExtended(Phonos.id("custom_music_disc"), (syncId, playerInv, buf) -> {
int slot = buf.readInt();
return new CustomMusicDiscGuiDescription(syncId, playerInv, slot);
});
public static final ItemGroupQueue PHONOS_ITEMS = new ItemGroupQueue(id("phonos"));

@Override
public void onInitialize() {
Registry.register(Registries.ITEM_GROUP, PHONOS_ITEMS.id, FabricItemGroup.builder()
.icon(PhonosBlocks.LOUDSPEAKER.asItem()::getDefaultStack)
.displayName(PHONOS_ITEMS.displayName())
.entries(PHONOS_ITEMS)
.build());

PayloadPackets.initCommon();

PhonosBlocks.init();
PhonosItems.init();
TechnicianVillagerProfession.init();

PhonosData.registerData();
SoundDataTypes.init();
InputPlugPoint.init();

ServerLifecycleEvents.SERVER_STARTED.register(e -> {
SoundStorage.serverReset();
SoundEmitterStorage.serverReset();
});
ServerTickEvents.END_WORLD_TICK.register(world -> SoundStorage.getInstance(world).tick(world));

ServerTickEvents.END_WORLD_TICK.register(world -> {
var pStates = world.getPersistentStateManager();
if (((PersistentStateManagerAccess)pStates).phonos$getLoadedStates().containsKey(RadioChannelState.ID)) {
PhonosUtil.getRadioState(world).tick();
ServerBlockEntityEvents.BLOCK_ENTITY_LOAD.register((be, world) -> {
if (be instanceof SoundEmitter p) {
SoundEmitterStorage.getInstance(world).addEmitter(p);
}
});
ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register((be, world) -> {
if (be instanceof SoundEmitter p) {
SoundEmitterStorage.getInstance(world).removeEmitter(p);
}
});
}

public static Identifier id(String path) {
return new Identifier("phonos", path);
}

public static float getPhonosVolume() {
return 1;
}
}
128 changes: 49 additions & 79 deletions src/main/java/io/github/foundationgames/phonos/PhonosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,78 @@

import io.github.foundationgames.jsonem.JsonEM;
import io.github.foundationgames.phonos.block.PhonosBlocks;
import io.github.foundationgames.phonos.block.RadioNoteBlock;
import io.github.foundationgames.phonos.block.SoundPlayReceivable;
import io.github.foundationgames.phonos.client.ClientReceiverStorage;
import io.github.foundationgames.phonos.client.render.block.PlayerPianoBlockEntityRenderer;
import io.github.foundationgames.phonos.client.render.block.RadioRecorderBlockEntityRenderer;
import io.github.foundationgames.phonos.entity.SoundPlayEntityReceivable;
import io.github.foundationgames.phonos.client.render.block.CableOutputBlockEntityRenderer;
import io.github.foundationgames.phonos.item.AudioCableItem;
import io.github.foundationgames.phonos.item.PhonosItems;
import io.github.foundationgames.phonos.network.ClientPayloadPackets;
import io.github.foundationgames.phonos.resource.PhonosAssets;
import io.github.foundationgames.phonos.screen.CustomMusicDiscGuiDescription;
import io.github.foundationgames.phonos.screen.CustomMusicDiscScreen;
import io.github.foundationgames.phonos.screen.RadioJukeboxGuiDescription;
import io.github.foundationgames.phonos.screen.RadioJukeboxScreen;
import io.github.foundationgames.phonos.sound.ClientSoundStorage;
import io.github.foundationgames.phonos.sound.SoundStorage;
import io.github.foundationgames.phonos.sound.emitter.SoundEmitter;
import io.github.foundationgames.phonos.sound.emitter.SoundEmitterStorage;
import io.github.foundationgames.phonos.util.PhonosUtil;
import io.github.foundationgames.phonos.world.sound.data.SoundDataTypes;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientBlockEntityEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

import java.util.Random;
import net.minecraft.state.property.Properties;

public class PhonosClient implements ClientModInitializer {
public static final EntityModelLayer KEYBOARD_MODEL_LAYER = new EntityModelLayer(Phonos.id("keyboard"), "main");
public static final EntityModelLayer PIANO_ROLL_MODEL_LAYER = new EntityModelLayer(Phonos.id("piano_roll"), "main");
public static final EntityModelLayer AUDIO_CABLE_END_LAYER = new EntityModelLayer(Phonos.id("audio_cable_end"), "main");

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

PhonosAssets.init();
JsonEM.registerModelLayer(AUDIO_CABLE_END_LAYER);

ClientReceiverStorage.init();
ClientReceiverStorage.registerPlaySoundCallback(((sound, blocks, entities, channel, volume, pitch, stoppable) -> {
if(!stoppable) {
PlayerEntity player = MinecraftClient.getInstance().player;
ClientWorld world = MinecraftClient.getInstance().world;
if(player != null && world != null) {
BlockPos pos = player.getBlockPos();
if(blocks != null) {
for(BlockPos receiver : blocks) {
if(pos.isWithinDistance(receiver, 30)) {
if(world.getBlockState(receiver).getBlock() instanceof SoundPlayReceivable) {
((SoundPlayReceivable)world.getBlockState(receiver).getBlock()).onReceivedSoundClient(world, world.getBlockState(receiver), receiver, channel, volume, pitch);
}
}
}
}
BlockPos receiver;
if(entities != null) {
for(Entity e : entities) {
receiver = e.getBlockPos();
if(pos.isWithinDistance(receiver, 30)) {
if(e instanceof SoundPlayEntityReceivable) {
((SoundPlayEntityReceivable)e).onRecievedSoundClient(world, e, channel, volume, pitch);
}
}
}
}
}
}
}));
BlockRenderLayerMap.INSTANCE.putBlock(PhonosBlocks.ELECTRONIC_NOTE_BLOCK, RenderLayer.getCutout());

FabricModelPredicateProviderRegistry.register(PhonosItems.CHANNEL_TUNER, new Identifier("tuned_channel"), (stack, world, entity, seed) -> (float)stack.getOrCreateSubNbt("TunerData").getInt("Channel") / 19);
FabricModelPredicateProviderRegistry.register(PhonosItems.NOTE_BLOCK_TUNER, new Identifier("tuner_mode"), (stack, world, entity, seed) -> (float)stack.getOrCreateSubNbt("TunerData").getInt("Mode") / 2);
FabricModelPredicateProviderRegistry.register(PhonosItems.BOOMBOX, new Identifier("radio_channel"), (stack, world, entity, seed) -> (float)stack.getOrCreateSubNbt("RadioData").getInt("Channel") / 19);
FabricModelPredicateProviderRegistry.register(PhonosItems.FESTIVE_BOOMBOX, new Identifier("radio_channel"), (stack, world, entity, seed) -> (float)stack.getOrCreateSubNbt("RadioData").getInt("Channel") / 19);
BlockEntityRendererFactories.register(PhonosBlocks.ELECTRONIC_NOTE_BLOCK_ENTITY, CableOutputBlockEntityRenderer::new);
BlockEntityRendererFactories.register(PhonosBlocks.ELECTRONIC_JUKEBOX_ENTITY, CableOutputBlockEntityRenderer::new);
BlockEntityRendererFactories.register(PhonosBlocks.CONNECTION_HUB_ENTITY, CableOutputBlockEntityRenderer::new);

JsonEM.registerModelLayer(KEYBOARD_MODEL_LAYER);
JsonEM.registerModelLayer(PIANO_ROLL_MODEL_LAYER);
ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) ->
world != null && pos != null && state != null ?
PhonosUtil.getColorFromNote(state.get(Properties.NOTE)) : 0xFFFFFF,
PhonosBlocks.ELECTRONIC_NOTE_BLOCK);

ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> world != null && pos != null && state != null ? RadioNoteBlock.getColorFromNote(state.get(RadioNoteBlock.NOTE)) : 0xFFFFFF, PhonosBlocks.RADIO_NOTE_BLOCK);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
int note = stack.getOrCreateSubNbt("TunerData").getInt("Note");
return tintIndex > 0 ? -1 : RadioNoteBlock.getColorFromNote(note);
}, PhonosItems.NOTE_BLOCK_TUNER);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
int color = 0;
String seed = stack.getOrCreateSubNbt("MusicData").getString("SoundId");
if(seed != null) color = new Random(seed(seed)).nextInt(0xFFFFFF);
return tintIndex > 0 ? -1 : color;
}, PhonosItems.CUSTOM_MUSIC_DISC);
if (tintIndex == 0 && stack.getItem() instanceof AudioCableItem aud && aud.color != null) {
return PhonosUtil.DYE_COLORS.getInt(aud.color);
}

BlockRenderLayerMap.INSTANCE.putBlock(PhonosBlocks.RADIO_NOTE_BLOCK, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(PhonosBlocks.BOOMBOX, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(PhonosBlocks.FESTIVE_BOOMBOX, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(PhonosBlocks.RADIO_RECORDER, RenderLayer.getTranslucent());
return 0xFFFFFF;
}, PhonosItems.ALL_AUDIO_CABLES);

BlockEntityRendererRegistry.register(PhonosBlocks.PLAYER_PIANO_ENTITY, PlayerPianoBlockEntityRenderer::new);
BlockEntityRendererRegistry.register(PhonosBlocks.RADIO_PLAYER_PIANO_ENTITY, PlayerPianoBlockEntityRenderer::new);
BlockEntityRendererRegistry.register(PhonosBlocks.RADIO_RECORDER_ENTITY, RadioRecorderBlockEntityRenderer::new);
ClientEntityEvents.ENTITY_LOAD.register((entity, world) -> {
if (entity == MinecraftClient.getInstance().player) {
SoundStorage.clientReset();
SoundEmitterStorage.clientReset();
}
});

ClientTickEvents.END_WORLD_TICK.register(world -> SoundStorage.getInstance(world).tick(world));

ClientBlockEntityEvents.BLOCK_ENTITY_LOAD.register((be, world) -> {
if (be instanceof SoundEmitter p) {
SoundEmitterStorage.getInstance(world).addEmitter(p);
}
});
ClientBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register((be, world) -> {
if (be instanceof SoundEmitter p) {
SoundEmitterStorage.getInstance(world).removeEmitter(p);
}
});

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

private static long seed(String s) {
Expand Down
Loading

0 comments on commit 5d8a2a5

Please sign in to comment.