Skip to content

Commit

Permalink
Spirit leap names
Browse files Browse the repository at this point in the history
  • Loading branch information
Sychic authored and Sychic committed Feb 7, 2021
1 parent 4c0abc3 commit 5615b9f
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/skytils/skytilsmod/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public class Config extends Vigilant {
)
public boolean showGriffinBurrows = false;

@Property(
type = PropertyType.SWITCH,
name = "Spirit Leap Names",
description = "Shows names next to the head when you click",
category = "Dungeons",
subcategory = "Quality of Life"
)
public boolean spiritLeapNames = false;

@Property(
type = PropertyType.SWITCH,
name = "Show Hidden Fels",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
package skytils.skytilsmod.features.impl.dungeons;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.opengl.GL11;
import skytils.skytilsmod.Skytils;
import skytils.skytilsmod.utils.Utils;

import java.awt.*;
import java.lang.reflect.Field;
import java.util.List;

public class DungeonsFeatures {

// Show hidden fels
@SubscribeEvent
public void onRenderLivingPre(RenderLivingEvent.Pre event) {
if (Utils.inDungeons) {
Expand All @@ -15,4 +34,80 @@ public void onRenderLivingPre(RenderLivingEvent.Pre event) {
}
}
}

// Spirit leap names
@SubscribeEvent
public void onGuiDrawPost(GuiScreenEvent.DrawScreenEvent.Post event) {
if (!Utils.inSkyblock) return;
if (event.gui instanceof GuiChest) {
Minecraft mc = Minecraft.getMinecraft();
GuiChest inventory = (GuiChest) event.gui;
Container containerChest = inventory.inventorySlots;
if (containerChest instanceof ContainerChest) {
ScaledResolution sr = new ScaledResolution(mc);
FontRenderer fr = mc.fontRendererObj;
int guiLeft = (sr.getScaledWidth() - 176) / 2;
int guiTop = (sr.getScaledHeight() - 222) / 2;

List<Slot> invSlots = inventory.inventorySlots.inventorySlots;
String displayName = ((ContainerChest) containerChest).getLowerChestInventory().getDisplayName().getUnformattedText().trim();
int chestSize = inventory.inventorySlots.inventorySlots.size();

if (Skytils.config.spiritLeapNames && Utils.inDungeons && displayName.equals("Spirit Leap")) {
int people = 0;
for (Slot slot : invSlots) {
if (slot.inventory == mc.thePlayer.inventory) continue;
if (slot.getHasStack()) {
ItemStack item = slot.getStack();
if (item.getItem() == Items.skull) {
people++;
String name = item.getDisplayName();

//slot is 16x16
int x = guiLeft + slot.xDisplayPosition + 8;
int y = guiTop + slot.yDisplayPosition;
// Move down when chest isn't 6 rows
if (chestSize != 90) y += (6 - (chestSize - 36) / 9) * 9;

if (people % 2 != 0) {
y -= 15;
} else {
y += 20;
}

String text = fr.trimStringToWidth(name, 32);
x -= fr.getStringWidth(text) / 2;

boolean shouldDrawBkg = true;
if (Loader.isModLoaded("notenoughupdates")) {
try {
Class<?> neuClass = Class.forName("io.github.moulberry.notenoughupdates.NotEnoughUpdates");
Field neuInstance = neuClass.getDeclaredField("INSTANCE");
Object neu = neuInstance.get(null);
Field neuConfig = neuClass.getDeclaredField("config");
Object config = neuConfig.get(neu);
Field improvedSBMenu = config.getClass().getDeclaredField("improvedSBMenu");
Object improvedSBMenuS = improvedSBMenu.get(config);
Field enableSbMenus = improvedSBMenuS.getClass().getDeclaredField("enableSbMenus");
boolean customGuiEnabled = enableSbMenus.getBoolean(improvedSBMenuS);
if (customGuiEnabled) shouldDrawBkg = false;
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) {
}
}

GL11.glPushMatrix();
GL11.glTranslated(0, 0, 10);
if (shouldDrawBkg) Gui.drawRect(x - 2, y - 2, x + fr.getStringWidth(text) + 2, y + fr.FONT_HEIGHT + 2, new Color(47, 40, 40).getRGB());
fr.drawStringWithShadow(text, x, y, new Color(255, 255,255).getRGB());
GL11.glTranslated(0, 0, -10);
GL11.glPopMatrix();

}
}
}
}
}
}
}

}
42 changes: 42 additions & 0 deletions src/main/java/skytils/skytilsmod/mixins/MixinGuiContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package skytils.skytilsmod.mixins;

import skytils.skytilsmod.Skytils;
import skytils.skytilsmod.utils.Utils;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GuiContainer.class)
public class MixinGuiContainer {

@Shadow public Container inventorySlots;

@Inject(method = "drawSlot", at = @At("HEAD"), cancellable = true)
private void onDrawSlot(Slot slot, CallbackInfo ci) {
if (!Utils.inSkyblock) return;
Container container = this.inventorySlots;
if (container instanceof ContainerChest) {
ContainerChest cc = (ContainerChest) container;
String displayName = cc.getLowerChestInventory().getDisplayName().getUnformattedText().trim();
if (slot.getHasStack()) {
ItemStack item = slot.getStack();
if (Skytils.config.spiritLeapNames && displayName.equals("Spirit Leap")) {
if (item.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane)) {
ci.cancel();
return;
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/mixins.skytils.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"MixinNetHandlerPlayClient",
"MixinNetworkManager",
"MixinPlayerControllerMP",
"MixinRenderBlaze"
"MixinRenderBlaze",
"MixinGuiContainer"
],
"verbose": true
}

0 comments on commit 5615b9f

Please sign in to comment.