Skip to content

Commit

Permalink
up 不开启图片的时候不加载图片
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Sep 15, 2024
1 parent b6fd3db commit 2c12187
Show file tree
Hide file tree
Showing 36 changed files with 865 additions and 916 deletions.
2 changes: 1 addition & 1 deletion forge_1_20_4/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ minecraft_version=1.20.4
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.4,1.21)
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=49.0.46
forge_version=49.1.4
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[0,)
# The loader version range can only use the major version of Forge/FML as bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void handle(FriendlyByteBuf buffer) {
hudUtils.setPos(readString(buffer));
break;
}
buffer.clear();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion forge_1_20_6/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ minecraft_version=1.20.6
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.6,1.21)
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=50.1.6
forge_version=50.1.14
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[0,)
# The loader version range can only use the major version of Forge/FML as bounds
Expand Down
41 changes: 24 additions & 17 deletions hud/HudUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,29 @@
public class HudUtils {

public static final ComType[] types = ComType.values();
public static ConfigObj config;

public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) {
Image resultingImage = originalImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_AREA_AVERAGING);
BufferedImage outputImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
outputImage.getGraphics()
.drawImage(resultingImage, 0, 0, null);
return outputImage;
}

private final Queue<String> urlList = new ConcurrentLinkedDeque<>();
private final Semaphore semaphore = new Semaphore(0);
private final HttpClient client;
public String info = "";
public String list = "";
public String lyric = "";
public SaveOBJ save;
public boolean haveImg;
public boolean thisRoute;
private ByteBuffer byteBuffer;
private int textureID = -1;
public boolean haveImg;
private final Queue<String> urlList = new ConcurrentLinkedDeque<>();
private final Semaphore semaphore = new Semaphore(0);
private final HttpClient client;
public static ConfigObj config;
private HttpGet get;
private InputStream inputStream;
public boolean thisRoute;
private int ang = 0;
private int count = 0;

Expand Down Expand Up @@ -119,17 +128,18 @@ private void getClose() {
}
}

public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) {
Image resultingImage = originalImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_AREA_AVERAGING);
BufferedImage outputImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
outputImage.getGraphics()
.drawImage(resultingImage, 0, 0, null);
return outputImage;
}

private void loadPic(String picUrl) {
haveImg = false;
try {
getClose();

while (save == null) {
Thread.sleep(200);
}
if (!save.pic.enable) {
return;
}

get = new HttpGet(picUrl);
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
Expand All @@ -140,9 +150,6 @@ private void loadPic(String picUrl) {
int[] pixels = new int[width * height];
byteBuffer = ByteBuffer.allocateDirect(width * height * 4);

while (save == null) {
Thread.sleep(200);
}
//图片旋转
if (save.pic.shadow) {
// 透明底的图片
Expand Down
4 changes: 0 additions & 4 deletions neoforge_1_20_4/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

#read more on this at https://github.com/neoforged/NeoGradle/blob/NG_7.0/README.md#apply-parchment-mappings
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
neogradle.subsystems.parchment.minecraftVersion=1.20.4
Expand All @@ -22,13 +21,10 @@ neo_version=20.4.237
neo_version_range=[20.4,)
# The loader version range can only use the major version of FML as bounds
loader_version_range=[2,)

## Mod Properties

# 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.
file_name=[neoforge-1.20.4]AllMusic_Client

mod_id=allmusic_client
# The human-readable display name for the mod.
mod_name=AllMusic Client
Expand Down
25 changes: 12 additions & 13 deletions neoforge_1_20_4/runs/client/config/neoforge-client.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

#Client only settings, mostly things related to rendering
[client]
#Enable NeoForge to queue all chunk updates to the Chunk Update thread.
#May increase FPS significantly, but may also cause weird rendering lag.
#Not recommended for computers without a significant number of cores available.
alwaysSetupTerrainOffThread = false
#EXPERIMENTAL: Enable the NeoForge block rendering pipeline - fixes the lighting of custom models.
experimentalForgeLightPipelineEnabled = false
#When enabled, NeoForge will show any warnings that occurred during loading.
showLoadWarnings = true
#Set to true to use a combined DEPTH_STENCIL attachment instead of two separate ones.
useCombinedDepthStencilAttachment = false
#[Deprecated for Removal] IPv6 addresses will always be compressed
compressLanIPv6Addresses = true
#Enable NeoForge to queue all chunk updates to the Chunk Update thread.
#May increase FPS significantly, but may also cause weird rendering lag.
#Not recommended for computers without a significant number of cores available.
alwaysSetupTerrainOffThread = false
#EXPERIMENTAL: Enable the NeoForge block rendering pipeline - fixes the lighting of custom models.
experimentalForgeLightPipelineEnabled = false
#When enabled, NeoForge will show any warnings that occurred during loading.
showLoadWarnings = true
#Set to true to use a combined DEPTH_STENCIL attachment instead of two separate ones.
useCombinedDepthStencilAttachment = false
#[Deprecated for Removal] IPv6 addresses will always be compressed
compressLanIPv6Addresses = true

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundSource;
import net.neoforged.bus.api.IEventBus;
Expand All @@ -25,13 +24,10 @@
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.event.sound.SoundEvent;
import net.neoforged.neoforge.client.gui.overlay.VanillaGuiOverlay;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import net.neoforged.neoforge.network.handling.IPayloadHandler;
import net.neoforged.neoforge.network.handling.IPlayPayloadHandler;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
Expand All @@ -43,13 +39,12 @@

@Mod("allmusic_client")
public class AllMusic implements IPlayPayloadHandler<PackData> {
public static final ResourceLocation channel =
new ResourceLocation("allmusic", "channel");
private static APlayer nowPlaying;
private static HudUtils hudUtils;
private static GuiGraphics gui;

public static final ResourceLocation channel =
new ResourceLocation("allmusic", "channel");

public AllMusic(IEventBus modEventBus) {
modEventBus.addListener(this::setup);
modEventBus.addListener(this::setup1);
Expand All @@ -64,6 +59,82 @@ public static void sendMessage(String data) {
Minecraft.getInstance().gui.getChat().addMessage(Component.literal(data)));
}

private static String readString(ByteBuf buf) {
int size = buf.readInt();
byte[] temp = new byte[size];
buf.readBytes(temp);

return new String(temp, StandardCharsets.UTF_8);
}

public static int getScreenWidth() {
return Minecraft.getInstance().getWindow().getGuiScaledWidth();
}

public static int getScreenHeight() {
return Minecraft.getInstance().getWindow().getGuiScaledHeight();
}

public static int getTextWidth(String item) {
return Minecraft.getInstance().font.width(item);
}

public static int getFontHeight() {
return Minecraft.getInstance().font.lineHeight;
}

public static float getVolume() {
return Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.RECORDS);
}

public static void drawPic(int textureID, int size, int x, int y, int ang) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, textureID);

PoseStack stack = new PoseStack();
Matrix4f matrix = stack.last().pose();

int a = size / 2;

if (ang > 0) {
matrix = matrix.translationRotate(x + a, y + a, 0,
new Quaternionf().fromAxisAngleDeg(0, 0, 1, ang));
} else {
matrix = matrix.translation(x + a, y + a, 0);
}
int x0 = -a;
int x1 = a;
int y0 = -a;
int y1 = a;
int z = 0;
int u0 = 0;
float u1 = 1;
float v0 = 0;
float v1 = 1;

RenderSystem.setShader(GameRenderer::getPositionTexShader);
BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
bufferBuilder.vertex(matrix, (float) x0, (float) y1, (float) z).uv(u0, v1).endVertex();
bufferBuilder.vertex(matrix, (float) x1, (float) y1, (float) z).uv(u1, v1).endVertex();
bufferBuilder.vertex(matrix, (float) x1, (float) y0, (float) z).uv(u1, v0).endVertex();
bufferBuilder.vertex(matrix, (float) x0, (float) y0, (float) z).uv(u0, v0).endVertex();

BufferUploader.drawWithShader(bufferBuilder.end());

//GuiComponent.blit(stack, x, y, 0, 0, 0, size, size, size, size);
}

public static 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);
}

public static void runMain(Runnable runnable) {
RenderSystem.recordRenderCall(runnable::run);
}

private void setup(final FMLClientSetupEvent event) {
hudUtils = new HudUtils(FMLPaths.CONFIGDIR.get());
}
Expand All @@ -79,13 +150,6 @@ public void handle(@NotNull PackData payload, PlayPayloadContext context) {
context.workHandler().execute(() -> handle(payload.buffer()));
}

public static class DataReader implements FriendlyByteBuf.Reader<PackData> {
@Override
public PackData apply(FriendlyByteBuf buf) {
return new PackData(buf);
}
}

public void handle(ByteBuf buffer) {
try {
byte type = buffer.readByte();
Expand Down Expand Up @@ -125,39 +189,16 @@ public void handle(ByteBuf buffer) {
hudUtils.setPos(readString(buffer));
break;
}
buffer.clear();
} catch (Exception e) {
e.printStackTrace();
}
}

private static String readString(ByteBuf buf) {
int size = buf.readInt();
byte[] temp = new byte[size];
buf.readBytes(temp);

return new String(temp, StandardCharsets.UTF_8);
}

private void setup1(final FMLCommonSetupEvent event) {
nowPlaying = new APlayer();
}

public static int getScreenWidth() {
return Minecraft.getInstance().getWindow().getGuiScaledWidth();
}

public static int getScreenHeight() {
return Minecraft.getInstance().getWindow().getGuiScaledHeight();
}

public static int getTextWidth(String item) {
return Minecraft.getInstance().font.width(item);
}

public static int getFontHeight() {
return Minecraft.getInstance().font.lineHeight;
}

public void onLoad(final SoundEngineLoadEvent e) {
if (nowPlaying != null) {
nowPlaying.setReload();
Expand Down Expand Up @@ -195,54 +236,6 @@ public void onServerQuit(final ClientPlayerNetworkEvent.LoggingOut e) {
hudUtils.save = null;
}

public static float getVolume() {
return Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.RECORDS);
}

public static void drawPic(int textureID, int size, int x, int y, int ang) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, textureID);

PoseStack stack = new PoseStack();
Matrix4f matrix = stack.last().pose();

int a = size / 2;

if (ang > 0) {
matrix = matrix.translationRotate(x + a, y + a, 0,
new Quaternionf().fromAxisAngleDeg(0, 0, 1, ang));
} else {
matrix = matrix.translation(x + a, y + a, 0);
}
int x0 = -a;
int x1 = a;
int y0 = -a;
int y1 = a;
int z = 0;
int u0 = 0;
float u1 = 1;
float v0 = 0;
float v1 = 1;

RenderSystem.setShader(GameRenderer::getPositionTexShader);
BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
bufferBuilder.vertex(matrix, (float) x0, (float) y1, (float) z).uv(u0, v1).endVertex();
bufferBuilder.vertex(matrix, (float) x1, (float) y1, (float) z).uv(u1, v1).endVertex();
bufferBuilder.vertex(matrix, (float) x1, (float) y0, (float) z).uv(u1, v0).endVertex();
bufferBuilder.vertex(matrix, (float) x0, (float) y0, (float) z).uv(u0, v0).endVertex();

BufferUploader.drawWithShader(bufferBuilder.end());

//GuiComponent.blit(stack, x, y, 0, 0, 0, size, size, size, size);
}

public static 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(RenderGuiOverlayEvent.Pre e) {
if (e.getOverlay().id() == VanillaGuiOverlay.PORTAL.id()) {
Expand All @@ -261,7 +254,10 @@ private void stopPlaying() {
hudUtils.close();
}

public static void runMain(Runnable runnable) {
RenderSystem.recordRenderCall(runnable::run);
public static class DataReader implements FriendlyByteBuf.Reader<PackData> {
@Override
public PackData apply(FriendlyByteBuf buf) {
return new PackData(buf);
}
}
}
Loading

0 comments on commit 2c12187

Please sign in to comment.