Skip to content

Commit

Permalink
Add compatibility for Vampirism blood vision
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldexun committed Feb 9, 2024
1 parent dc5239a commit 3d1e502
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependencies {
includedDependencies 'meldexun:ReflectionUtil:1.0.0@jar'
buildDependencies 'curse.maven:FairyLights-233342:3068499'
buildDependencies 'curse.maven:ValkyrienSkies-258371:3286262'
buildDependencies 'curse.maven:Vampirism-233029:2890062'

implementation "org.spongepowered:mixin:${mixin_version}"
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/meldexun/renderlib/RenderLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RenderLib {
public static final Logger LOGGER = LogManager.getLogger(MODID);
public static boolean isFairyLightsInstalled;
public static boolean isValkyrienSkiesInstalled;
public static boolean isVampirismInstalled;

@EventHandler
public void onFMLConstructionEvent(FMLConstructionEvent event) {
Expand All @@ -41,6 +42,7 @@ public void onFMLConstructionEvent(FMLConstructionEvent event) {
public void onFMLPostInitializationEvent(FMLPostInitializationEvent event) {
isFairyLightsInstalled = Loader.isModLoaded("fairylights");
isValkyrienSkiesInstalled = Loader.isModLoaded("valkyrienskies");
isVampirismInstalled = Loader.isModLoaded("vampirism");
}

@SubscribeEvent
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/meldexun/renderlib/integration/Vampirism.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package meldexun.renderlib.integration;

import java.lang.reflect.Field;
import java.util.Enumeration;
import java.util.concurrent.ConcurrentHashMap;

import de.teamlapen.vampirism.client.render.RenderHandler;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.EventBus;

public class Vampirism {

private static RenderHandler renderHandler;
static {
try {
Field listenersField = EventBus.class.getDeclaredField("listeners");
listenersField.setAccessible(true);
@SuppressWarnings("unchecked")
Enumeration<Object> keys = ((ConcurrentHashMap<Object, ?>) listenersField.get(MinecraftForge.EVENT_BUS)).keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof RenderHandler) {
renderHandler = (RenderHandler) key;
break;
}
}
if (renderHandler == null) {
throw new NullPointerException();
}
} catch (Exception e) {
throw new UnsupportedOperationException("Failed to find de.teamlapen.vampirism.client.render.RenderHandler instance", e);
}
}

public static void onRenderLivingPost(EntityLivingBase entity) {
renderHandler.onRenderLivingPost(new RenderLivingEvent.Post<>(entity, null, 0.0F, 0.0D, 0.0D, 0.0D));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import meldexun.renderlib.api.IEntityRendererCache;
import meldexun.renderlib.api.ILoadable;
import meldexun.renderlib.integration.FairyLights;
import meldexun.renderlib.integration.Vampirism;
import meldexun.renderlib.util.EntityUtil;
import meldexun.renderlib.util.RenderUtil;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -48,6 +49,9 @@ public void setup(ICamera frustum, float partialTicks, double camX, double camY,

if (this.isOcclusionCulled(entity)) {
this.occludedEntities++;
if (RenderLib.isVampirismInstalled && entity instanceof EntityLivingBase) {
Vampirism.onRenderLivingPost((EntityLivingBase) entity);
}
} else {
this.renderedEntities++;

Expand Down

0 comments on commit 3d1e502

Please sign in to comment.