Skip to content

Commit

Permalink
Electric jukebox (GTNewHorizons#2827)
Browse files Browse the repository at this point in the history
* GT music system

* Minor fix for some glitches when switching dimensions with P2Ps on both sides

* Most features implemented except headphones

* Implement wireless headphones

* Disable debug mode

* Spotless

---------

Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
eigenraven and Dream-Master authored Aug 15, 2024
1 parent 799d5ed commit 5decfda
Show file tree
Hide file tree
Showing 38 changed files with 2,090 additions and 12 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ the chance of strange errors.
Some textures/ideas have been taken from future versions of GT and texture pack authors for GTNH. Credit goes to Jimbno
for the UU-Tex texture pack and its contributions to the base pack here: https://github.com/Jimbno/UU-Tex.

## Music duration metadata

The electric jukebox requires duration metadata to specify how many milliseconds each disk plays for.
These can be included in mods' jar resources under `soundmeta/durations.json`, or in the pack config directory at `config/soundmeta/durations.json`.
The format is a simple key-value map of sound IDs mapping to millisecond counts, and can be generated from the client automatically using `/gt dump_music_durations`.

```json
{
"soundDurationsMs": {
"minecraft:11": 71112,
"minecraft:13": 178086,
"minecraft:blocks": 345914
}
}
```

## License

GT5-Unofficial is free software: you can redistribute it and/or modify it under the terms of the
Expand Down
4 changes: 3 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ dependencies {
compileOnlyApi('com.github.GTNewHorizons:ThaumicTinkerer:2.10.1:dev')
compileOnlyApi("com.github.GTNewHorizons:Mobs-Info:0.4.1-GTNH:dev")
compileOnlyApi("com.github.GTNewHorizons:Navigator:1.0.6:dev")
implementation('com.github.GTNewHorizons:Baubles:1.0.4:dev') {transitive=false}
// Required to prevent an older bauble api from Extra Utilities from loading first in the javac classpath
compileOnly('com.github.GTNewHorizons:Baubles:1.0.4:dev') {transitive=false}

devOnlyNonPublishable("com.github.GTNewHorizons:Infernal-Mobs:1.8.1-GTNH:dev")

Expand Down Expand Up @@ -89,7 +92,6 @@ dependencies {
compileOnly("com.github.GTNewHorizons:CraftTweaker:3.3.1:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:BetterLoadingScreen:1.7.0-GTNH:dev") { transitive = false }

implementation('com.github.GTNewHorizons:Baubles:1.0.4:dev') {transitive=false}
compileOnly('com.github.GTNewHorizons:SC2:2.1.1:dev') {transitive=false}
compileOnly('com.github.GTNewHorizons:Binnie:2.4.1:dev') {transitive = false}
compileOnly('curse.maven:PlayerAPI-228969:2248928') {transitive=false}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ apiPackage =
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# There can be multiple files in a space-separated list.
# Example value: mymodid_at.cfg nei_at.cfg
accessTransformersFile = ggfab_at.cfg tectech_at.cfg
accessTransformersFile = gregtech_at.cfg

# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ public void sendToAllAround(@Nonnull GT_Packet aPacket, NetworkRegistry.TargetPo
.writeAndFlush(aPacket);
}

@Override
public void sendToAll(@Nonnull GT_Packet aPacket) {
this.mChannel.get(Side.SERVER)
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.ALL);
this.mChannel.get(Side.SERVER)
.writeAndFlush(aPacket);
}

@Override
public void sendToServer(@Nonnull GT_Packet aPacket) {
this.mChannel.get(Side.CLIENT)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/gregtech/api/enums/GT_Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ public static final class NBT {
+ "Gold";
public static final String AuthorVolence = "Author: " + EnumChatFormatting.AQUA + "Volence";

public static final String AuthorEigenRaven = "Author: " + EnumChatFormatting.DARK_PURPLE
+ "Eigen"
+ EnumChatFormatting.BOLD
+ "Raven";

public static final String AuthorNotAPenguin = "Author: " + EnumChatFormatting.WHITE
+ EnumChatFormatting.BOLD
+ "Not"
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/gregtech/api/enums/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,15 @@ public enum ItemList implements IItemContainer {
Automation_ChestBuffer_UEV,
Automation_ChestBuffer_UIV,
Automation_ChestBuffer_UMV,
Automation_ChestBuffer_UXV,;
Automation_ChestBuffer_UXV,
BetterJukebox_LV,
BetterJukebox_MV,
BetterJukebox_HV,
BetterJukebox_EV,
BetterJukebox_IV,
WirelessHeadphones,
// semicolon after the comment to reduce merge conflicts
;

public static final ItemList[] DYE_ONLY_ITEMS = { Color_00, Color_01, Color_02, Color_03, Color_04, Color_05,
Color_06, Color_07, Color_08, Color_09, Color_10, Color_11, Color_12, Color_13, Color_14, Color_15 },
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/gregtech/api/enums/MetaTileEntityIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,11 @@ public enum MetaTileEntityIDs {
lsc(13106),
tfftHatch(13109),
WORMHOLE_GENERATOR_CONTROLLER(13115),
BETTER_JUKEBOX_LV(14301),
BETTER_JUKEBOX_MV(14302),
BETTER_JUKEBOX_HV(14303),
BETTER_JUKEBOX_EV(14304),
BETTER_JUKEBOX_IV(14305),
MegaChemicalReactor(13366),
MegaOilCracker(13367),
ExtremeEntityCrusherController(14201),
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/gregtech/api/enums/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ public enum BlockIcons implements IIconContainer, Runnable {
OVERLAY_TOP_STEAM_FURNACE_GLOW,
OVERLAY_TOP_STEAM_ALLOY_SMELTER,
OVERLAY_TOP_STEAM_ALLOY_SMELTER_GLOW,
OVERLAY_TOP_JUKEBOX,

OVERLAY_TOP_STEAM_MACERATOR,
OVERLAY_TOP_STEAM_MACERATOR_GLOW,
Expand Down Expand Up @@ -757,6 +758,7 @@ public enum BlockIcons implements IIconContainer, Runnable {
OVERLAY_SIDE_SCANNER_GLOW,
OVERLAY_SIDE_INDUSTRIAL_APIARY,
OVERLAY_SIDE_INDUSTRIAL_APIARY_GLOW,
OVERLAY_SIDE_JUKEBOX,

OVERLAY_TOP_POTIONBREWER_ACTIVE,
OVERLAY_TOP_POTIONBREWER_ACTIVE_GLOW,
Expand Down Expand Up @@ -1895,6 +1897,7 @@ public enum ItemIcons implements IIconContainer, Runnable {
TURBINE_SMALL,
TURBINE_LARGE,
TURBINE_HUGE,
WIRELESS_HEADPHONES,
POCKET_MULTITOOL_CLOSED,
POCKET_MULTITOOL_BRANCHCUTTER,
POCKET_MULTITOOL_FILE,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ public static FallbackableUITexture fallbackableProgressbar(String name, UITextu
public static final UITexture OVERLAY_BUTTON_ARROW_GREEN_DOWN = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/arrow_green_down");
public static final UITexture OVERLAY_BUTTON_CYCLIC = UITexture.fullImage(GregTech.ID, "gui/overlay_button/cyclic");
public static final UITexture OVERLAY_BUTTON_SHUFFLE = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/shuffle");
public static final UITexture OVERLAY_BUTTON_EMIT_ENERGY = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/emit_energy");
public static final UITexture OVERLAY_BUTTON_EMIT_REDSTONE = UITexture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;

import appeng.api.crafting.ICraftingIconProvider;
import appeng.api.implementations.tiles.ISoundP2PHandler;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.parts.p2p.PartP2PSound;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.ItemList;
Expand All @@ -29,7 +32,7 @@
import gregtech.api.util.GT_Utility;

public abstract class CommonMetaTileEntity extends CoverableTileEntity
implements IGregTechTileEntity, ICraftingIconProvider {
implements IGregTechTileEntity, ICraftingIconProvider, ISoundP2PHandler {

protected boolean mNeedsBlockUpdate = true, mNeedsUpdate = true, mSendClientData = false, mInventoryChanged = false;

Expand Down Expand Up @@ -337,4 +340,33 @@ public ModularWindow createWindow(UIBuildContext buildContext) {
}
return builder.build();
}

@Override
public boolean allowSoundProxying(PartP2PSound p2p) {
if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof ISoundP2PHandler metaHandler) {
return metaHandler.allowSoundProxying(p2p);
}
return ISoundP2PHandler.super.allowSoundProxying(p2p);
}

@Override
public void onSoundP2PAttach(PartP2PSound p2p) {
if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof ISoundP2PHandler metaHandler) {
metaHandler.onSoundP2PAttach(p2p);
}
}

@Override
public void onSoundP2PDetach(PartP2PSound p2p) {
if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof ISoundP2PHandler metaHandler) {
metaHandler.onSoundP2PDetach(p2p);
}
}

@Override
public void onSoundP2POutputUpdate(PartP2PSound p2p, TunnelCollection<PartP2PSound> outputs) {
if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof ISoundP2PHandler metaHandler) {
metaHandler.onSoundP2POutputUpdate(p2p, outputs);
}
}
}
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/net/GT_PacketTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public enum GT_PacketTypes {
MULTI_TILE_ENTITY(18, new GT_Packet_MultiTileEntity(true)),
SEND_OREGEN_PATTERN(19, new GT_Packet_SendOregenPattern()),
TOOL_SWITCH_MODE(20, new GT_Packet_ToolSwitchMode()),
MUSIC_SYSTEM_DATA(21, new GT_Packet_MusicSystemData()),
// merge conflict prevention comment, keep a trailing comma above
;

Expand Down
58 changes: 58 additions & 0 deletions src/main/java/gregtech/api/net/GT_Packet_MusicSystemData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package gregtech.api.net;

import net.minecraft.world.IBlockAccess;

import com.google.common.io.ByteArrayDataInput;

import gregtech.api.util.GT_MusicSystem;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class GT_Packet_MusicSystemData extends GT_Packet_New {

ByteBuf storedData;

public GT_Packet_MusicSystemData() {
super(true);
}

public GT_Packet_MusicSystemData(ByteBuf data) {
super(false);
this.storedData = data;
}

@Override
public byte getPacketID() {
return GT_PacketTypes.MUSIC_SYSTEM_DATA.id;
}

@Override
public void encode(ByteBuf aOut) {
if (storedData == null) {
return;
}
storedData.markReaderIndex();
final int len = storedData.readableBytes();
aOut.writeInt(len);
aOut.writeBytes(storedData);
storedData.resetReaderIndex();
}

@Override
public GT_Packet_New decode(ByteArrayDataInput aData) {
final int len = aData.readInt();
final byte[] fullData = new byte[len];
aData.readFully(fullData);
return new GT_Packet_MusicSystemData(Unpooled.wrappedBuffer(fullData));
}

@Override
public void process(IBlockAccess aWorld) {
if (aWorld == null || storedData == null) {
return;
}
storedData.markReaderIndex();
GT_MusicSystem.ClientSystem.loadUpdatedSources(storedData);
storedData.resetReaderIndex();
}
}
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/net/IGT_NetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public interface IGT_NetworkHandler {

void sendToAllAround(GT_Packet aPacket, TargetPoint aPosition);

default void sendToAll(GT_Packet aPacket) {
throw new UnsupportedOperationException("sendToAll not implemented");
}

void sendToServer(GT_Packet aPacket);

void sendPacketToAllPlayersInRange(World aWorld, GT_Packet aPacket, int aX, int aZ);
Expand Down
Loading

0 comments on commit 5decfda

Please sign in to comment.