mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-21 16:12:11 +00:00
up 新增2合1 mod
This commit is contained in:
1 parent
9e5d392427
commit
2fcd9d3053
8 files changed
+235
-19
No files matched your search
@@ -28,4 +28,6 @@ lib
|
||||
**/allmusic/server/core/
|
||||
**/allmusic/server/codec/
|
||||
**/allmusic/server/bstats/
|
||||
**/allmusic/client/core/
|
||||
**/allmusic/client/core/player/decoder/mp3/
|
||||
.DS_Store
|
||||
+1
-1
Submodule client updated: 6842736046...44179f4e12.
@@ -15,6 +15,7 @@ import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.sql.IEconomy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -37,4 +37,8 @@ for %%i in (%array1%) do (
|
||||
if not exist "onejar\%%i\src\main\java\com\coloryr\allmusic\server\core" mklink /j "onejar\%%i\src\main\java\com\coloryr\allmusic\server\core" "core"
|
||||
if not exist "onejar\%%i\build" mkdir "onejar\%%i\build" && mklink /j "onejar\%%i\build\libs" "build\libs"
|
||||
if not exist "onejar\%%i\src\main\java\com\coloryr\allmusic\server\codec" mklink /j "onejar\%%i\src\main\java\com\coloryr\allmusic\server\codec" "codec"
|
||||
if not exist "onejar\%%i\src\main\java\com\coloryr\allmusic\client" mkdir "onejar\%%i\src\main\java\com\coloryr\allmusic\client"
|
||||
if not exist "onejar\%%i\src\main\java\com\coloryr\allmusic\client\core" mklink /j "onejar\%%i\src\main\java\com\coloryr\allmusic\client\core" "client\core"
|
||||
if not exist "onejar\%%i\src\main\resources\com\coloryr\allmusic\client\core\player\decoder" mkdir "onejar\%%i\src\main\resources\com\coloryr\allmusic\client\core\player\decoder"
|
||||
if not exist "onejar\%%i\src\main\resources\com\coloryr\allmusic\client\core\player\decoder\mp3" mklink /j "onejar\%%i\src\main\resources\com\coloryr\allmusic\client\core\player\decoder\mp3" "client\mp3"
|
||||
)
|
||||
@@ -14,7 +14,7 @@ tasks.named('wrapper', Wrapper).configure {
|
||||
}
|
||||
|
||||
def getVersionFromFile() {
|
||||
def versionFile = file('../version')
|
||||
def versionFile = file('../../version')
|
||||
if (versionFile.exists()) {
|
||||
return versionFile.text.trim()
|
||||
} else {
|
||||
|
||||
@@ -26,13 +26,13 @@ kff_version=5.7.0
|
||||
|
||||
## Mod Properties
|
||||
|
||||
file_name = [neoforge-1.21.6]AllMusic_Server
|
||||
file_name = [neoforge-1.21.6]AllMusic
|
||||
|
||||
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
|
||||
# Must match the String constant located in the main mod class annotated with @Mod.
|
||||
mod_id=allmusic_server
|
||||
mod_id=allmusic
|
||||
# The human-readable display name for the mod.
|
||||
mod_name=AllMusic Server
|
||||
mod_name=AllMusic
|
||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=GPL-3.0
|
||||
# The mod version. See https://semver.org/
|
||||
@@ -40,8 +40,8 @@ mod_version=3.3.2
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
mod_group_id=com.coloryr.allmusic.server
|
||||
mod_group_id=com.coloryr.allmusic
|
||||
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
|
||||
mod_authors=Color_yr
|
||||
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
|
||||
mod_description=AllMusic Server Mod
|
||||
mod_description=AllMusic Mod
|
||||
@@ -0,0 +1,214 @@
|
||||
package com.coloryr.allmusic.client;
|
||||
|
||||
import com.coloryr.allmusic.client.core.AllMusicBridge;
|
||||
import com.coloryr.allmusic.client.core.AllMusicCore;
|
||||
import com.coloryr.allmusic.server.core.objs.enums.ComType;
|
||||
import com.coloryr.allmusic.server.side.forge.PackData;
|
||||
import com.mojang.blaze3d.opengl.GlTexture;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.textures.FilterMode;
|
||||
import com.mojang.blaze3d.textures.GpuTexture;
|
||||
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||
import com.mojang.blaze3d.textures.TextureFormat;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.RenderPipelines;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.fml.loading.FMLPaths;
|
||||
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
import net.neoforged.neoforge.client.event.RenderGuiLayerEvent;
|
||||
import net.neoforged.neoforge.client.event.sound.PlaySoundSourceEvent;
|
||||
import net.neoforged.neoforge.client.event.sound.PlayStreamingSourceEvent;
|
||||
import net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent;
|
||||
import net.neoforged.neoforge.client.gui.VanillaGuiLayers;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Matrix3x2fStack;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class AllMusicClient implements IPayloadHandler<PackData>, StreamCodec<RegistryFriendlyByteBuf, PackData>, AllMusicBridge {
|
||||
private static GuiGraphics gui;
|
||||
|
||||
public static final ResourceLocation channel =
|
||||
ResourceLocation.fromNamespaceAndPath("allmusic", "channel");
|
||||
|
||||
public static class Tex extends AbstractTexture {
|
||||
public Tex(GpuTexture tex, GpuTextureView view) {
|
||||
this.texture = tex;
|
||||
this.textureView = view;
|
||||
}
|
||||
}
|
||||
|
||||
public AllMusicClient(IEventBus modEventBus) {
|
||||
modEventBus.addListener(this::setup);
|
||||
modEventBus.addListener(this::setup1);
|
||||
modEventBus.addListener(this::onLoad);
|
||||
|
||||
NeoForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public void sendMessage(String data) {
|
||||
Minecraft.getInstance().execute(() ->
|
||||
Minecraft.getInstance().gui.getChat().addMessage(Component.literal(data)));
|
||||
}
|
||||
|
||||
private void setup(final FMLClientSetupEvent event) {
|
||||
event.enqueueWork(AllMusicCore::glInit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackData decode(RegistryFriendlyByteBuf pack) {
|
||||
handle(pack);
|
||||
pack.clear();
|
||||
return new PackData(ComType.CLEAR, "", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(RegistryFriendlyByteBuf pack, PackData data) {
|
||||
PackData.CODEC.encode(pack, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(@NotNull PackData payload, IPayloadContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopPlayMusic() {
|
||||
Minecraft.getInstance().getSoundManager().stop(null, SoundSource.MUSIC);
|
||||
Minecraft.getInstance().getSoundManager().stop(null, SoundSource.RECORDS);
|
||||
}
|
||||
|
||||
public void handle(ByteBuf buffer) {
|
||||
try {
|
||||
AllMusicCore.packRead(buffer);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void setup1(final FMLCommonSetupEvent event) {
|
||||
AllMusicCore.init(FMLPaths.CONFIGDIR.get(), this);
|
||||
}
|
||||
|
||||
public int getScreenWidth() {
|
||||
return Minecraft.getInstance().getWindow().getGuiScaledWidth();
|
||||
}
|
||||
|
||||
public int getScreenHeight() {
|
||||
return Minecraft.getInstance().getWindow().getGuiScaledHeight();
|
||||
}
|
||||
|
||||
public int getTextWidth(String item) {
|
||||
return Minecraft.getInstance().font.width(item);
|
||||
}
|
||||
|
||||
public int getFontHeight() {
|
||||
return Minecraft.getInstance().font.lineHeight;
|
||||
}
|
||||
|
||||
public void onLoad(final SoundEngineLoadEvent e) {
|
||||
AllMusicCore.reload();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSound(final PlaySoundSourceEvent e) {
|
||||
if (!AllMusicCore.isPlay()) return;
|
||||
SoundSource data = e.getSound().getSource();
|
||||
switch (data) {
|
||||
case MUSIC, RECORDS -> e.getChannel().stop();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSound(final PlayStreamingSourceEvent e) {
|
||||
if (!AllMusicCore.isPlay()) return;
|
||||
SoundSource data = e.getSound().getSource();
|
||||
switch (data) {
|
||||
case MUSIC, RECORDS -> e.getChannel().stop();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerQuit(final ClientPlayerNetworkEvent.LoggingOut e) {
|
||||
AllMusicCore.onServerQuit();
|
||||
}
|
||||
|
||||
public float getVolume() {
|
||||
return Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.RECORDS);
|
||||
}
|
||||
|
||||
public void drawPic(Object tex, int size, int x, int y, int ang) {
|
||||
Matrix3x2fStack stack = gui.pose();
|
||||
Matrix3x2fStack matrix = stack.pushMatrix();
|
||||
|
||||
int a = size / 2;
|
||||
|
||||
if (ang > 0) {
|
||||
matrix.translation(x + a, y + a);
|
||||
matrix.pushMatrix().rotate((float) Math.toRadians(ang));
|
||||
} else {
|
||||
matrix.translation(x + a, y + a);
|
||||
}
|
||||
|
||||
gui.blit(RenderPipelines.GUI_TEXTURED, channel, -a, -a, 0, 0, size, size, size, size, size, size);
|
||||
stack.popMatrix();
|
||||
if (ang > 0) {
|
||||
stack.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
public void drawText(String item, int x, int y, int color, boolean shadow) {
|
||||
var hud = Minecraft.getInstance().font;
|
||||
gui.drawString(hud, item, x, y, color, shadow);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderOverlay(RenderGuiLayerEvent.Post e) {
|
||||
if (e.getName().equals(VanillaGuiLayers.CAMERA_OVERLAYS)) {
|
||||
gui = e.getGuiGraphics();
|
||||
AllMusicCore.hudUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(ClientTickEvent.Post event) {
|
||||
AllMusicCore.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object genTexture(int size) {
|
||||
var device = RenderSystem.getDevice();
|
||||
var tex = device.createTexture("allmusic:gui_textured", 5, TextureFormat.RGBA8, size, size, 1, 1);
|
||||
tex.setTextureFilter(FilterMode.NEAREST, false);
|
||||
|
||||
var view = device.createTextureView(tex);
|
||||
|
||||
Tex tex1 = new Tex(tex, view);
|
||||
|
||||
Minecraft.getInstance().getTextureManager().register(channel, tex1);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTexture(Object tex, int size, ByteBuffer byteBuffer) {
|
||||
if (tex instanceof GlTexture tex1) {
|
||||
AllMusicCore.updateGLTexture(tex1.glId(), size, byteBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -1,5 +1,6 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.client.AllMusicClient;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.side.forge.CommandForge;
|
||||
import com.coloryr.allmusic.server.side.forge.LogForge;
|
||||
@@ -19,10 +20,7 @@ import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -34,12 +32,14 @@ import java.util.Locale;
|
||||
public class AllMusicForge {
|
||||
public static final ResourceLocation channel = ResourceLocation.fromNamespaceAndPath("allmusic", "channel");
|
||||
// Define mod id in a common place for everything to reference
|
||||
public static final String MODID = "allmusic_server";
|
||||
public static final String MODID = "allmusic";
|
||||
// Directly reference a slf4j logger
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("AllMusic_Server");
|
||||
public static MinecraftServer server;
|
||||
// Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace
|
||||
|
||||
private static AllMusicClient client;
|
||||
|
||||
public AllMusicForge(IEventBus modEventBus) {
|
||||
// Register the commonSetup method for modloading
|
||||
modEventBus.addListener(this::commonSetup);
|
||||
@@ -47,6 +47,8 @@ public class AllMusicForge {
|
||||
|
||||
// Register ourselves for server and other game events we are interested in
|
||||
NeoForge.EVENT_BUS.register(this);
|
||||
|
||||
client = new AllMusicClient(modEventBus);
|
||||
}
|
||||
|
||||
private void commonSetup(final FMLCommonSetupEvent event) {
|
||||
@@ -61,7 +63,7 @@ public class AllMusicForge {
|
||||
public void register(final RegisterPayloadHandlersEvent event) {
|
||||
LOGGER.info("注册插件信道");
|
||||
final PayloadRegistrar registrar = event.registrar("1.0");
|
||||
registrar.optional().playToClient(PackData.TYPE, PackData.CODEC, new HandelPack());
|
||||
registrar.optional().playToClient(PackData.TYPE, client, client);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -94,11 +96,4 @@ public class AllMusicForge {
|
||||
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
AllMusic.joinPlay(event.getEntity().getName().getString());
|
||||
}
|
||||
|
||||
private static class HandelPack implements IPayloadHandler<PackData> {
|
||||
@Override
|
||||
public void handle(@NotNull PackData payload, IPayloadContext context) {
|
||||
//context.handle(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user