Skip to content

Commit

Permalink
im so happy it's working rn
Browse files Browse the repository at this point in the history
  • Loading branch information
VanderCat committed Apr 10, 2024
1 parent 3b072f0 commit 919b96b
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 80 deletions.
11 changes: 5 additions & 6 deletions src/main/java/gg/moonflower/etched/api/sound/SoundTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gg.moonflower.etched.common.blockentity.AlbumJukeboxBlockEntity;
import gg.moonflower.etched.core.Etched;
import gg.moonflower.etched.core.mixin.client.GuiAccessor;
import gg.moonflower.etched.core.mixin.client.LevelRendererAccessor;
import gg.moonflower.etched.core.registry.EtchedTags;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -150,7 +149,7 @@ public static AbstractOnlineSoundInstance getEtchedRecord(String url, Component
boolean muffled = aboveState.is(BlockTags.WOOL);
boolean hidden = !aboveState.isAir();

Map<BlockPos, SoundInstance> playingRecords = ((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).getPlayingRecords();
Map<BlockPos, SoundInstance> playingRecords = Minecraft.getInstance().levelRenderer.playingRecords;
return new OnlineRecordSoundInstance(url, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, muffled ? 2.0F : 4.0F, muffled ? attenuationDistance / 2 : attenuationDistance, new MusicDownloadListener(title, () -> pos.getX() + 0.5, () -> pos.getY() + 0.5, () -> pos.getZ() + 0.5) {
@Override
public void onSuccess() {
Expand Down Expand Up @@ -178,7 +177,7 @@ public static AbstractOnlineSoundInstance getEtchedRecord(String url, Component

private static void playRecord(BlockPos pos, SoundInstance sound) {
SoundManager soundManager = Minecraft.getInstance().getSoundManager();
Map<BlockPos, SoundInstance> playingRecords = ((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).getPlayingRecords();
Map<BlockPos, SoundInstance> playingRecords = Minecraft.getInstance().levelRenderer.playingRecords;
playingRecords.put(pos, sound);
soundManager.play(sound);
}
Expand Down Expand Up @@ -211,7 +210,7 @@ public static void playBlockRecord(BlockPos pos, TrackData[] tracks, int track)
return;
}
playRecord(pos, StopListeningSound.create(getEtchedRecord(url, trackData.getDisplayName(), level, pos, AudioSource.AudioFileType.FILE), () -> Minecraft.getInstance().tell(() -> {
if (!((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).getPlayingRecords().containsKey(pos)) {
if (!(Minecraft.getInstance().levelRenderer.playingRecords.containsKey(pos))) {
return;
}
playBlockRecord(pos, tracks, track + 1);
Expand Down Expand Up @@ -290,7 +289,7 @@ public static void playBoombox(int entityId, ItemStack record) {
*/
public static void playRadio(@Nullable String url, BlockState state, ClientLevel level, BlockPos pos) {
SoundManager soundManager = Minecraft.getInstance().getSoundManager();
Map<BlockPos, SoundInstance> playingRecords = ((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).getPlayingRecords();
Map<BlockPos, SoundInstance> playingRecords = Minecraft.getInstance().levelRenderer.playingRecords;

SoundInstance soundInstance = playingRecords.get(pos);
if (soundInstance != null) {
Expand Down Expand Up @@ -326,7 +325,7 @@ public static void playRadio(@Nullable String url, BlockState state, ClientLevel
*/
public static void playAlbum(AlbumJukeboxBlockEntity jukebox, BlockState state, ClientLevel level, BlockPos pos, boolean force) {
SoundManager soundManager = Minecraft.getInstance().getSoundManager();
Map<BlockPos, SoundInstance> playingRecords = ((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).getPlayingRecords();
Map<BlockPos, SoundInstance> playingRecords = Minecraft.getInstance().levelRenderer.playingRecords;

if (!state.hasProperty(AlbumJukeboxBlock.POWERED) || !state.getValue(AlbumJukeboxBlock.POWERED) && !force && !jukebox.recalculatePlayingIndex(false)) {// Something must already be playing since it would otherwise be -1 and a change would occur
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import gg.moonflower.etched.common.blockentity.AlbumJukeboxBlockEntity;
import gg.moonflower.etched.core.Etched;
import gg.moonflower.etched.core.mixin.client.LevelRendererAccessor;
import gg.moonflower.etched.core.quilt.EtchedConfig;
import gg.moonflower.etched.core.registry.EtchedBlocks;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -145,7 +144,7 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc
}

Minecraft minecraft = Minecraft.getInstance();
Map<BlockPos, SoundInstance> sounds = ((LevelRendererAccessor) minecraft.levelRenderer).getPlayingRecords();
Map<BlockPos, SoundInstance> sounds = minecraft.levelRenderer.playingRecords;
if (sounds.containsKey(pos) && minecraft.getSoundManager().isActive(sounds.get(pos))) {
level.addParticle(ParticleTypes.NOTE, pos.getX() + 0.5D, pos.getY() + 1.2D, pos.getZ() + 0.5D, random.nextInt(25) / 24D, 0, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import gg.moonflower.etched.common.network.play.ClientboundSetUrlPacket;
import gg.moonflower.etched.core.Etched;
import gg.moonflower.etched.core.EtchedClient;
import gg.moonflower.etched.core.mixin.client.LevelRendererAccessor;
import gg.moonflower.etched.core.quilt.EtchedConfig;
import gg.moonflower.etched.core.registry.EtchedBlocks;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -188,7 +187,7 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc
}

Minecraft minecraft = Minecraft.getInstance();
Map<BlockPos, SoundInstance> sounds = ((LevelRendererAccessor) minecraft.levelRenderer).getPlayingRecords();
Map<BlockPos, SoundInstance> sounds = minecraft.levelRenderer.playingRecords;
if (sounds.containsKey(pos) && minecraft.getSoundManager().isActive(sounds.get(pos))) {
level.addParticle(ParticleTypes.NOTE, pos.getX() + 0.5D, pos.getY() + 0.7D, pos.getZ() + 0.5D, random.nextInt(25) / 24D, 0, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AlbumCoverMenu(int containerId, Inventory inventory) {
}

public AlbumCoverMenu(int containerId, Inventory inventory, int albumCoverIndex) {
super(EtchedMenus.ALBUM_COVER_MENU.get(), containerId);
super(EtchedMenus.ALBUM_COVER_MENU, containerId);
this.albumCoverInventory = albumCoverIndex == -1 ? new SimpleContainer(AlbumCoverItem.MAX_RECORDS) : new AlbumCoverContainer(inventory, albumCoverIndex);
this.albumCoverIndex = albumCoverIndex;
this.inventory = inventory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AlbumJukeboxMenu(int i, Inventory inventory) {
}

public AlbumJukeboxMenu(int i, Inventory inventory, Container container, BlockPos pos) {
super(EtchedMenus.ALBUM_JUKEBOX_MENU.get(), i);
super(EtchedMenus.ALBUM_JUKEBOX_MENU, i);
checkContainerSize(container, 9);
this.container = container;
container.startOpen(inventory.player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public BoomboxMenu(int containerId, Inventory inventory) {
}

public BoomboxMenu(int containerId, Inventory inventory, int index) {
super(EtchedMenus.BOOMBOX_MENU.get(), containerId);
super(EtchedMenus.BOOMBOX_MENU, containerId);
this.boomboxInventory = index == -1 ? new SimpleContainer(1) : new BoomboxContainer(inventory, index);

this.addSlot(new Slot(this.boomboxInventory, 0, 80, 20) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public RadioMenu(int id, Inventory inventory) {
}

public RadioMenu(int id, Inventory inventory, ContainerLevelAccess access, Consumer<String> containerLevelAccess) {
super(EtchedMenus.RADIO_MENU.get(), id);
super(EtchedMenus.RADIO_MENU, id);
this.access = access;
this.urlConsumer = containerLevelAccess;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ private FriendlyByteBuf getBuf() {
default void sendToClient(ServerPlayer player) {
var buf = getBuf();
ServerPlayNetworking.send(player, getPacketId(), buf);
EtchedMessages.LOGGER.info("sent "+getPacketId()+" to "+player.getDisplayName());
EtchedMessages.LOGGER.info(getPacketId()+" (server -> client)");
}

default void sendToClients(Collection<ServerPlayer> players) {
var buf = getBuf();
ServerPlayNetworking.send(players, getPacketId(), buf);
EtchedMessages.LOGGER.info("sent "+getPacketId()+" to "+players);
EtchedMessages.LOGGER.info(getPacketId()+" (server -> clients)");
}

default void sendToServer() {
var buf = getBuf();
ClientPlayNetworking.send(getPacketId(), buf);
EtchedMessages.LOGGER.info(getPacketId()+" (client -> server)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gg.moonflower.etched.client.screen.RadioScreen;
import gg.moonflower.etched.common.blockentity.AlbumJukeboxBlockEntity;
import gg.moonflower.etched.common.network.play.*;
import gg.moonflower.etched.core.mixin.client.LevelRendererAccessor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.resources.sounds.SoundInstance;
Expand Down Expand Up @@ -37,7 +36,7 @@ public static void handlePlayMusicPacket(ClientboundPlayMusicPacket pkt, Minecra
}
client.execute(()->{
BlockPos pos = pkt.pos();
Map<BlockPos, SoundInstance> playingRecords = ((LevelRendererAccessor) client.levelRenderer).getPlayingRecords();
Map<BlockPos, SoundInstance> playingRecords = client.levelRenderer.playingRecords;
SoundInstance soundInstance = playingRecords.get(pos);

if (soundInstance != null) {
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/gg/moonflower/etched/core/EtchedClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package gg.moonflower.etched.core;

import gg.moonflower.etched.client.screen.EtchingScreen;
import gg.moonflower.etched.client.screen.*;
import gg.moonflower.etched.common.menu.AlbumCoverMenu;
import gg.moonflower.etched.common.menu.AlbumJukeboxMenu;
import gg.moonflower.etched.core.registry.EtchedMenus;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.minecraft.client.gui.screens.MenuScreens;
import org.quiltmc.loader.api.minecraft.ClientOnly;

Expand Down Expand Up @@ -30,6 +33,10 @@ public class EtchedClient {

public static void registerItemGroups() {
MenuScreens.register(EtchedMenus.ETCHING_MENU, EtchingScreen::new);
MenuScreens.register(EtchedMenus.BOOMBOX_MENU, BoomboxScreen::new);
MenuScreens.register(EtchedMenus.RADIO_MENU, RadioScreen::new);
MenuScreens.register(EtchedMenus.ALBUM_JUKEBOX_MENU, AlbumJukeboxScreen::new);
MenuScreens.register(EtchedMenus.ALBUM_COVER_MENU, AlbumCoverScreen::new);
//TODO: Move to registrat
/*ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.FUNCTIONAL_BLOCKS).register(event -> {
event.accept(EtchedBlocks.ETCHING_TABLE.asStack(1));
Expand Down Expand Up @@ -59,14 +66,14 @@ public static void registerEntityRenders(EntityRenderersEvent.RegisterRenderers
public static void registerEntityLayers(EntityRenderersEvent.RegisterLayerDefinitions event) {
event.registerLayerDefinition(EtchedModelLayers.JUKEBOX_MINECART, MinecartModel::createBodyLayer);
}
*/

@SubscribeEvent
public static void registerItemColors(RegisterColorHandlersEvent.Item event) {
event.register((stack, index) -> index == 0 || index == 1 ? MusicLabelItem.getLabelColor(stack) : -1, EtchedItems.MUSIC_LABEL.get());
event.register((stack, index) -> index == 0 ? ComplexMusicLabelItem.getPrimaryColor(stack) : index == 1 ? ComplexMusicLabelItem.getSecondaryColor(stack) : -1, EtchedItems.COMPLEX_MUSIC_LABEL.get());
public static void registerItemColors() {
ColorProviderRegistry.ITEM.register((stack, index) -> index == 0 || index == 1 ? MusicLabelItem.getLabelColor(stack) : -1, EtchedItems.MUSIC_LABEL.get());
ColorProviderRegistry.ITEM.register((stack, index) -> index == 0 ? ComplexMusicLabelItem.getPrimaryColor(stack) : index == 1 ? ComplexMusicLabelItem.getSecondaryColor(stack) : -1, EtchedItems.COMPLEX_MUSIC_LABEL.get());

event.register((stack, index) -> index > 0 ? -1 : ((BlankMusicDiscItem) stack.getItem()).getColor(stack), EtchedItems.BLANK_MUSIC_DISC.get());
event.register((stack, index) -> {
ColorProviderRegistry.ITEM.register((stack, index) -> index > 0 ? -1 : ((BlankMusicDiscItem) stack.getItem()).getColor(stack), EtchedItems.BLANK_MUSIC_DISC.get());
ColorProviderRegistry.ITEM.register((stack, index) -> {
if (index == 0) {
return EtchedMusicDiscItem.getDiscColor(stack);
}
Expand All @@ -80,5 +87,5 @@ public static void registerItemColors(RegisterColorHandlersEvent.Item event) {
}
return -1;
}, EtchedItems.ETCHED_MUSIC_DISC.get());
} */
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public void onInitializeClient(ModContainer mod) {
}
return ItemStack.EMPTY;
});
EtchedClient.registerItemColors();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class EtchedBlocks {
.register();
//registerWithItem("album_jukebox", () -> new AlbumJukeboxBlock(BlockBehaviour.Properties.copy(Blocks.JUKEBOX)), new Item.Properties());
public static final BlockEntry<RadioBlock> RADIO =
Etched.REGISTRATE.block("album_jukebox", RadioBlock::new)
Etched.REGISTRATE.block("radio", RadioBlock::new)
.initialProperties(() -> Blocks.JUKEBOX)
.properties(p->p.noOcclusion())
.simpleItem()
Expand Down
47 changes: 12 additions & 35 deletions src/main/java/gg/moonflower/etched/core/registry/EtchedMenus.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,24 @@ public class EtchedMenus {
//public static final DeferredRegister<MenuType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.MENU_TYPES, Etched.MOD_ID);

public static final MenuType<EtchingMenu> ETCHING_MENU =
Registry.register(BuiltInRegistries.MENU, new ResourceLocation(Etched.MOD_ID, "etching_table"), new MenuType(EtchingMenu::new, FeatureFlags.VANILLA_SET));
register("etching_table", EtchingMenu::new);

//register("etching_table", EtchingMenu::new, ()->EtchingScreen::new);
//REGISTRY.register("etching_table", () -> new MenuType<>(EtchingMenu::new, FeatureFlags.VANILLA_SET));
public static final MenuEntry<AlbumJukeboxMenu> ALBUM_JUKEBOX_MENU =
Etched.REGISTRATE.menu(
"album_jukebox",
(type, windowId, inv) -> new AlbumJukeboxMenu(windowId, inv),
()->AlbumJukeboxScreen::new
)
.register();;
public static final MenuEntry<BoomboxMenu> BOOMBOX_MENU =
Etched.REGISTRATE.menu(
"boombox",
(type, windowId, inv) -> new BoomboxMenu(windowId, inv),
()->BoomboxScreen::new
)
.register();
public static final MenuType<AlbumJukeboxMenu> ALBUM_JUKEBOX_MENU =
register("album_jukebox", AlbumJukeboxMenu::new);
public static final MenuType<BoomboxMenu> BOOMBOX_MENU =
register("boombox", BoomboxMenu::new);
//REGISTRY.register("boombox", () -> new MenuType<>(BoomboxMenu::new, FeatureFlags.VANILLA_SET));
public static final MenuEntry<AlbumCoverMenu> ALBUM_COVER_MENU =
Etched.REGISTRATE.menu(
"album_cover",
(type, windowId, inv) -> new AlbumCoverMenu(windowId, inv),
()->AlbumCoverScreen::new
)
.register();
public static final MenuType<AlbumCoverMenu> ALBUM_COVER_MENU =
register("album_cover", AlbumCoverMenu::new);
//REGISTRY.register("album_cover", () -> new MenuType<>(AlbumCoverMenu::new, FeatureFlags.VANILLA_SET));
public static final MenuEntry<RadioMenu> RADIO_MENU =
Etched.REGISTRATE.menu(
"album_cover",
(type, windowId, inv) -> new RadioMenu(windowId, inv),
()->RadioScreen::new
)
.register();
public static final MenuType<RadioMenu> RADIO_MENU =
register("radio", RadioMenu::new);
//REGISTRY.register("radio", () -> new MenuType<>(RadioMenu::new, FeatureFlags.VANILLA_SET));
public static void register() {}

private static <C extends AbstractContainerMenu, S extends Screen & MenuAccess<C>> MenuEntry<C> register(
String name, MenuBuilder.MenuFactory<C> factory, NonNullSupplier<MenuBuilder.ScreenFactory<C, S>> screenFactory) {
return Etched.REGISTRATE
.menu(name, factory, screenFactory)
.register();
public static <T extends AbstractContainerMenu> MenuType<T> register(String name, MenuType.MenuSupplier<T> supplier) {
return Registry.register(BuiltInRegistries.MENU, new ResourceLocation(Etched.MOD_ID, name), new MenuType<T>(supplier, FeatureFlags.VANILLA_SET));
}
public static void register() {}
}
3 changes: 2 additions & 1 deletion src/main/resources/etched.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ accessWidener v2 named
extendable method net/minecraft/world/entity/vehicle/AbstractMinecart getDropItem ()Lnet/minecraft/world/item/Item;
accessible field net/minecraft/data/worldgen/ProcessorLists EMPTY Lnet/minecraft/resources/ResourceKey;
accessible field net/minecraft/client/renderer/texture/SpriteContents originalImage Lcom/mojang/blaze3d/platform/NativeImage;
accessible method net/minecraft/tags/BlockTags create (Ljava/lang/String;)Lnet/minecraft/tags/TagKey;
accessible method net/minecraft/tags/BlockTags create (Ljava/lang/String;)Lnet/minecraft/tags/TagKey;
accessible field net/minecraft/client/renderer/LevelRenderer playingRecords Ljava/util/Map;
1 change: 0 additions & 1 deletion src/main/resources/etched.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"client.HumanoidModelMixin",
"client.ItemRendererMixin",
"client.ItemStackMixin",
"client.LevelRendererAccessor",
"client.ParrotMixin",
"client.SoundEngineMixin",
"fabric.client.ItemEntityMixin",
Expand Down

0 comments on commit 919b96b

Please sign in to comment.