Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ dependencies {
implementation('com.github.GTNewHorizons:GT5-Unofficial:5.09.52.467:dev') {
exclude group: "com.github.GTNewHorizons", module: "Galacticraft"
}
implementation('com.github.GTNewHorizons:TinkersConstruct:1.14.58-GTNH:dev')
implementation('com.github.GTNewHorizons:NotEnoughItems:2.8.93-GTNH:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.9.54:dev')
api('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package micdoodle8.mods.galacticraft.api.client.tabs;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public abstract class AbstractTab extends GuiButton {

ResourceLocation texture = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
ItemStack renderStack;
RenderItem itemRenderer = new RenderItem();

public AbstractTab(int id, int posX, int posY, ItemStack renderStack) {
super(id, posX, posY, 28, 32, "");
this.renderStack = renderStack;
}

@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
drawButton(mc, this.renderStack, false);
}

/**
* Draws inventory tab
*
* @param mc
* @param tabIcon Item to use as tab icon
* @param enableItemIconDepthTest whether to enable GL_DEPTH_TEST for rendering the item icon
*/

protected void drawButton(Minecraft mc, ItemStack tabIcon, boolean enableItemIconDepthTest) {
if (this.visible) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

int yTexPos = this.enabled ? 2 : 32;
int ySize = this.enabled ? 25 : 32;
int xOffset = this.id == 2 ? 0 : 1;
int yPos = this.yPosition + (this.enabled ? 3 : 0);

mc.renderEngine.bindTexture(this.texture);
this.drawTexturedModalRect(this.xPosition, yPos, xOffset * 28, yTexPos, 28, ySize);

RenderHelper.enableGUIStandardItemLighting();
this.zLevel = 100.0F;
this.itemRenderer.zLevel = 100.0F;
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
if (enableItemIconDepthTest) GL11.glEnable(GL11.GL_DEPTH_TEST);
this.itemRenderer.renderItemAndEffectIntoGUI(
mc.fontRenderer,
mc.renderEngine,
tabIcon,
xPosition + 6,
yPosition + 8);
this.itemRenderer
.renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, tabIcon, xPosition + 6, yPosition + 8);
if (enableItemIconDepthTest) GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
this.itemRenderer.zLevel = 0.0F;
this.zLevel = 0.0F;
RenderHelper.disableStandardItemLighting();
}
}

@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
boolean inWindow = this.enabled && this.visible
&& mouseX >= this.xPosition
&& mouseY >= this.yPosition
&& mouseX < this.xPosition + this.width
&& mouseY < this.yPosition + this.height;

if (inWindow) {
this.onTabClicked();
}

return inWindow;
}

public abstract void onTabClicked();

public abstract boolean shouldAddToList();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package micdoodle8.mods.galacticraft.api.client.tabs;

import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;

public class InventoryTabVanilla extends AbstractTab {

public InventoryTabVanilla() {
super(0, 0, 0, new ItemStack(Blocks.crafting_table));
}

@Override
public void onTabClicked() {
TabRegistry.openInventoryGui();
}

@Override
public boolean shouldAddToList() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package micdoodle8.mods.galacticraft.api.client.tabs;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.network.play.client.C0DPacketCloseWindow;
import net.minecraftforge.client.event.GuiScreenEvent;

import codechicken.nei.NEIClientConfig;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TabRegistry {

private static final ArrayList<AbstractTab> tabList = new ArrayList<>();

public static void registerTab(AbstractTab tab) {
tabList.add(tab);
}

public static ArrayList<AbstractTab> getTabList() {
return tabList;
}

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void guiPostInit(GuiScreenEvent.InitGuiEvent.Post event) {
if ((event.gui instanceof GuiInventory)) {
int xSize = 176;
int ySize = 166;
int guiLeft = (event.gui.width - xSize) / 2;
int guiTop = (event.gui.height - ySize) / 2;
guiLeft += getPotionOffset();

updateTabValues(guiLeft, guiTop, InventoryTabVanilla.class);
addTabsToList(event.gui.buttonList);
}
}

private static final Minecraft mc = FMLClientHandler.instance().getClient();

public static void openInventoryGui() {
mc.thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(mc.thePlayer.openContainer.windowId));
GuiInventory inventory = new GuiInventory(mc.thePlayer);
mc.displayGuiScreen(inventory);
}

public static void updateTabValues(int cornerX, int cornerY, Class<?> selectedButton) {
int count = 2;
for (AbstractTab t : tabList) {
if (t.shouldAddToList()) {
t.id = count;
t.xPosition = cornerX + (count - 2) * 28;
t.yPosition = cornerY - 28;
t.enabled = !t.getClass().equals(selectedButton);
count++;
}
}
}

public static void addTabsToList(List buttonList) {
for (AbstractTab tab : tabList) {
if (tab.shouldAddToList()) {
buttonList.add(tab);
}
}
}

public static int getPotionOffset() {
// If at least one potion is active...
if (!mc.thePlayer.getActivePotionEffects().isEmpty()) {
if (Loader.isModLoaded("NotEnoughItems")) {
try {
if (NEIClientConfig.isHidden() || !NEIClientConfig.isEnabled()) {
// If NEI is disabled or hidden, offset the tabs by 60
return 60;
}
} catch (Exception ignored) {}
} else {
// If NEI is not installed, offset the tabs
return 60;
}
}
// No potions, no offset needed
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
version = Constants.VERSION,
acceptedMinecraftVersions = "[1.7.10]",
useMetadata = true,
dependencies = "required-after:NotEnoughItems;before:GalaxySpace;after:IC2;after:TConstruct;after:Mantle;after:BuildCraft|Core;after:BuildCraft|Energy;after:PlayerAPI@[1.3,);after:gtnhlib@[0.3.1,);",
dependencies = "required-after:NotEnoughItems;before:GalaxySpace;after:IC2;after:Mantle;after:BuildCraft|Core;after:BuildCraft|Energy;after:PlayerAPI@[1.3,);after:gtnhlib@[0.3.1,);",
guiFactory = "micdoodle8.mods.galacticraft.core.client.gui.screen.ConfigGuiFactoryCore")
public class GalacticraftCore {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import org.lwjgl.opengl.GL12;

import cpw.mods.fml.common.Loader;
import micdoodle8.mods.galacticraft.api.client.tabs.AbstractTab;
import micdoodle8.mods.galacticraft.api.client.tabs.TabRegistry;
import micdoodle8.mods.galacticraft.core.GalacticraftCore;
import micdoodle8.mods.galacticraft.core.client.gui.screen.InventoryTabGalacticraft;
import micdoodle8.mods.galacticraft.core.inventory.ContainerExtendedInventory;
import micdoodle8.mods.galacticraft.core.inventory.InventoryExtended;
import tconstruct.client.tabs.AbstractTab;
import tconstruct.client.tabs.TabRegistry;

public class GuiExtendedInventory extends InventoryEffectRenderer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import net.minecraft.item.ItemStack;

import cpw.mods.fml.client.FMLClientHandler;
import micdoodle8.mods.galacticraft.api.client.tabs.AbstractTab;
import micdoodle8.mods.galacticraft.core.GalacticraftCore;
import micdoodle8.mods.galacticraft.core.items.GCItems;
import micdoodle8.mods.galacticraft.core.network.PacketSimple;
import micdoodle8.mods.galacticraft.core.network.PacketSimple.EnumSimplePacket;
import micdoodle8.mods.galacticraft.core.proxy.ClientProxyCore;
import tconstruct.client.tabs.AbstractTab;

public class InventoryTabGalacticraft extends AbstractTab {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import micdoodle8.mods.galacticraft.api.client.tabs.InventoryTabVanilla;
import micdoodle8.mods.galacticraft.api.client.tabs.TabRegistry;
import micdoodle8.mods.galacticraft.api.entity.ICameraZoomEntity;
import micdoodle8.mods.galacticraft.api.event.client.CelestialBodyRenderEvent;
import micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket;
Expand Down Expand Up @@ -160,8 +162,6 @@
import micdoodle8.mods.galacticraft.core.util.VersionUtil;
import micdoodle8.mods.galacticraft.core.wrappers.BlockMetaList;
import micdoodle8.mods.galacticraft.core.wrappers.PlayerGearData;
import tconstruct.client.tabs.InventoryTabVanilla;
import tconstruct.client.tabs.TabRegistry;

public class ClientProxyCore extends CommonProxyCore {

Expand Down Expand Up @@ -343,6 +343,7 @@ public static void registerHandlers() {
ClientRegistry.registerKeyBinding(KeyHandlerClient.openFuelGui);
ClientRegistry.registerKeyBinding(KeyHandlerClient.toggleAdvGoggles);
MinecraftForge.EVENT_BUS.register(GalacticraftCore.proxy);
MinecraftForge.EVENT_BUS.register(new TabRegistry());
}

public static void registerTileEntityRenderers() {
Expand Down Expand Up @@ -384,7 +385,7 @@ public static void registerBlockHandlers() {
}

public static void registerInventoryTabs() {
if (!Loader.isModLoaded("TConstruct") && TabRegistry.getTabList().size() < 1) {
if (TabRegistry.getTabList().size() < 1) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this ever be false? Also, this won't work when having TConstruct installed - having two tabregistries is not really feasible, they'd compete for the same rendering space. Possibly an option to pull those tabs into GTNHLib? Either that or fall back to tconstruct dynamically. Architecturally cleaner is to avoid that code duplication though.

TabRegistry.registerTab(new InventoryTabVanilla());
}
TabRegistry.registerTab(new InventoryTabGalacticraft());
Expand Down
Loading