Skip to content

Commit

Permalink
Fixed the server crash, switched to official mappings because parchme…
Browse files Browse the repository at this point in the history
…nt stopped working
  • Loading branch information
RaydanOMGr committed Jun 22, 2024
1 parent 9d03f25 commit 9a99c20
Show file tree
Hide file tree
Showing 32 changed files with 177 additions and 170 deletions.
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ loader_version_range=[43,)
#
# Parchment is an unofficial project maintained by ParchmentMC, separate from Minecraft Forge.
# Additional setup is needed to use their mappings, see https://parchmentmc.org/docs/getting-started
mapping_channel=parchment
mapping_channel=official
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=2022.08.14-1.19.2
mapping_version=1.19.2
#2022.08.14-1.19.2


## Mod Properties
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/me/andreasmelone/glowingeyes/GlowingEyes.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package me.andreasmelone.glowingeyes;

import me.andreasmelone.glowingeyes.common.GlowingEyesEvents;
import me.andreasmelone.glowingeyes.common.capability.data.PlayerDataCapability;
import me.andreasmelone.glowingeyes.common.capability.data.PlayerDataHandler;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesHandler;
import me.andreasmelone.glowingeyes.common.packets.PacketManager;
import me.andreasmelone.glowingeyes.common.scheduler.CodeScheduler;
import me.andreasmelone.glowingeyes.common.scheduler.Scheduler;
import com.mojang.logging.LogUtils;
import me.andreasmelone.glowingeyes.server.GlowingEyesEvents;
import me.andreasmelone.glowingeyes.server.capability.data.PlayerDataCapability;
import me.andreasmelone.glowingeyes.server.capability.data.PlayerDataHandler;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesHandler;
import me.andreasmelone.glowingeyes.server.packets.PacketManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import com.mojang.logging.LogUtils;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import me.andreasmelone.glowingeyes.GlowingEyes;
import me.andreasmelone.glowingeyes.client.presets.PresetManager;
import me.andreasmelone.glowingeyes.client.render.RenderManager;
import me.andreasmelone.glowingeyes.common.scheduler.CodeScheduler;
import me.andreasmelone.glowingeyes.common.scheduler.Scheduler;
import me.andreasmelone.glowingeyes.server.scheduler.CodeScheduler;
import me.andreasmelone.glowingeyes.server.scheduler.Scheduler;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.andreasmelone.glowingeyes.client;

import me.andreasmelone.glowingeyes.client.gui.EyesEditorScreen;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesCapability;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.TickEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import me.andreasmelone.glowingeyes.client.util.ColorUtil;
import me.andreasmelone.glowingeyes.client.util.GuiUtil;
import me.andreasmelone.glowingeyes.client.util.TextureLocations;
import me.andreasmelone.glowingeyes.common.util.Util;
import me.andreasmelone.glowingeyes.server.util.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.Screen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.andreasmelone.glowingeyes.client.util.ColorUtil;
import me.andreasmelone.glowingeyes.client.util.GuiUtil;
import me.andreasmelone.glowingeyes.client.util.TextureLocations;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesCapability;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ImageButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import me.andreasmelone.glowingeyes.client.presets.PresetManager;
import me.andreasmelone.glowingeyes.client.util.GuiUtil;
import me.andreasmelone.glowingeyes.client.util.TextureLocations;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesCapability;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import me.andreasmelone.glowingeyes.client.presets.PresetManager;
import me.andreasmelone.glowingeyes.client.util.GuiUtil;
import me.andreasmelone.glowingeyes.client.util.TextureLocations;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesCapability;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.resources.ResourceLocation;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.HashMap;

public class Preset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import com.mojang.logging.LogUtils;
import me.andreasmelone.glowingeyes.client.presets.gson.GsonPresetsFileModel;
import me.andreasmelone.glowingeyes.client.presets.gson.PointColorMapSerializer;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesCapability;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.player.Player;
import org.slf4j.Logger;

import javax.annotation.Nullable;
import java.awt.*;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesImpl;
import me.andreasmelone.glowingeyes.common.capability.eyes.IGlowingEyes;
import me.andreasmelone.glowingeyes.client.util.DynamicTextureCache;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesCapability;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.MultiBufferSource;
Expand All @@ -22,16 +21,16 @@ public GlowingEyesHeadLayer(RenderLayerParent<T, Q> pRenderer) {

@Override
public void render(PoseStack poseStack, MultiBufferSource multiBufferSource,
int i, T t, float v, float v1, float v2,
int i, T player, float v, float v1, float v2,
float v3, float v4, float v5) {
if(GlowingEyesCapability.isToggledOn(t) && !t.isInvisible()) {
ResourceLocation eyeOverlayResource = GlowingEyesCapability.getGlowingEyesTexture(t);
if(GlowingEyesCapability.isToggledOn(player) && !player.isInvisible()) {
ResourceLocation eyeOverlayResource = DynamicTextureCache.getTexture(GlowingEyesCapability.getGlowingEyesMap(player));
if(eyeOverlayResource == null) return;

RenderType eyeRenderType = RenderType.eyes(eyeOverlayResource);
VertexConsumer vertexBuilderEye = multiBufferSource.getBuffer(eyeRenderType);

int packerOverlay = LivingEntityRenderer.getOverlayCoords(t, 0);
int packerOverlay = LivingEntityRenderer.getOverlayCoords(player, 0);

ModelPart head = this.getParentModel().head;
head.render(poseStack, vertexBuilderEye, i, packerOverlay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.Event;

public class RenderManager {
static <T extends Player, Q extends EntityModel<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package me.andreasmelone.glowingeyes.client.util;

import com.mojang.blaze3d.platform.NativeImage;
import me.andreasmelone.glowingeyes.GlowingEyes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.resources.ResourceLocation;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class DynamicTextureCache {
private DynamicTextureCache() {
}

private static final Map<Map<Point, Color>, ResourceLocation> cache = new HashMap<>();

public static ResourceLocation getTexture(Map<Point, Color> glowingEyesMap) {
ResourceLocation texture = cache.get(glowingEyesMap);
if (texture != null) {
return texture;
}

texture = createTexture(glowingEyesMap);
cache.put(glowingEyesMap, texture);
return texture;
}

public static void clear() {
for(ResourceLocation texture : cache.values()) {
Minecraft.getInstance().getTextureManager().release(texture);
}
cache.clear();
}

private static ResourceLocation createTexture(Map<Point, Color> glowingEyesMap) {
BufferedImage image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
for (Map.Entry<Point, Color> entry : glowingEyesMap.entrySet()) {
Point point = entry.getKey();
Color color = entry.getValue();
image.setRGB(point.x + 8, point.y + 8, color.getRGB());
}

NativeImage nativeImage = GuiUtil.toNativeImage(image);
DynamicTexture dynamicTexture = new DynamicTexture(nativeImage);
return Minecraft.getInstance().getTextureManager().register(GlowingEyes.MOD_ID + "_" + UUID.randomUUID(), dynamicTexture);
}

private static <K, V> boolean areEqual(Map<K, V> map1, Map<K, V> map2) {
if (map1.size() != map2.size()) {
return false;
}

for (Map.Entry<K, V> entry : map1.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
if (!map2.containsKey(key) || !map2.get(key).equals(value)) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package me.andreasmelone.glowingeyes.client.util;

import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.Gui;
import net.minecraft.resources.ResourceLocation;

import java.awt.*;
import java.awt.image.BufferedImage;

public class GuiUtil {
/**
Expand All @@ -21,4 +23,20 @@ public static void drawBackground(PoseStack poseStack, ResourceLocation backgrou
// Draw the background texture
Gui.blit(poseStack, x, y, 0, 0, width, height, 256, 256);
}

public static NativeImage toNativeImage(BufferedImage image) {
NativeImage nativeImage = new NativeImage(image.getWidth(), image.getHeight(), true);
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
int argb = image.getRGB(x, y);
// native textures use BGR instead of RGB so we have to convert the color
Color bgr = new Color(argb);
bgr = new Color(bgr.getBlue(), bgr.getGreen(), bgr.getRed());

nativeImage.setPixelRGBA(x, y, bgr.getRGB());
}
}

return nativeImage;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.andreasmelone.glowingeyes.common;
package me.andreasmelone.glowingeyes.server;

import me.andreasmelone.glowingeyes.common.capability.data.PlayerDataCapability;
import me.andreasmelone.glowingeyes.common.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.common.packets.PacketManager;
import me.andreasmelone.glowingeyes.server.capability.data.PlayerDataCapability;
import me.andreasmelone.glowingeyes.server.capability.eyes.GlowingEyesCapability;
import me.andreasmelone.glowingeyes.server.packets.PacketManager;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.player.PlayerEvent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.andreasmelone.glowingeyes.common.capability.data;
package me.andreasmelone.glowingeyes.server.capability.data;

import java.util.Set;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.andreasmelone.glowingeyes.common.capability.data;
package me.andreasmelone.glowingeyes.server.capability.data;

import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.capabilities.Capability;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.andreasmelone.glowingeyes.common.capability.data;
package me.andreasmelone.glowingeyes.server.capability.data;

import me.andreasmelone.glowingeyes.GlowingEyes;
import net.minecraft.core.Direction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.andreasmelone.glowingeyes.common.capability.data;
package me.andreasmelone.glowingeyes.server.capability.data;

import java.util.HashSet;
import java.util.Set;
Expand Down
Loading

0 comments on commit 9a99c20

Please sign in to comment.