Repacking portions of CoFHLib into EE3 so as not to have a hard dependency on CoFHLib. This is with permission from KingLemming, and eventually will have supporting documentation to indicate proper ownership/etc

This commit is contained in:
Pahimar 2014-11-14 22:37:30 -05:00
parent b97b79a45c
commit 966b6a6200
39 changed files with 3387 additions and 4 deletions

View file

@ -30,7 +30,7 @@ public class Sounds
private static final String CHALK_PREFIX = "chalk_";
private static final int CHALK_SOUNDS_COUNT = 11;
public static final String getRandomChalkSound()
public static String getRandomChalkSound()
{
return String.format("%s%s", CHALK_PREFIX, random.nextInt(CHALK_SOUNDS_COUNT) + 1);
}

View file

@ -55,7 +55,6 @@ public final class Textures
{
private static final String SYMBOL_TEXTURE_LOCATION = "textures/glyphs/";
public static final ResourceLocation BASE_CIRCLE = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transBaseCircle.png");
public static final ResourceLocation DOT = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transDot.png");
public static final ResourceLocation LINE = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transLine.png");

View file

@ -140,8 +140,7 @@ public class SerializationHelper
}
jsonReader.endArray();
jsonReader.close();
}
catch (FileNotFoundException e)
} catch (FileNotFoundException ignored)
{
}
catch (IOException e)

View file

@ -0,0 +1,173 @@
package com.pahimar.repackage.cofh.lib.audio;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.audio.ISound;
import net.minecraft.util.ResourceLocation;
/**
* Generic ISound class with lots of constructor functionality. Required because - of course - Mojang has no generic that lets you specify *any* arguments for
* this.
*
* @author skyboy
*/
@SideOnly(Side.CLIENT)
public class SoundBase implements ISound {
protected AttenuationType attenuation;
protected final ResourceLocation sound;
protected float volume;
protected float pitch;
protected float x;
protected float y;
protected float z;
protected boolean repeat;
protected int repeatDelay;
public SoundBase(String sound) {
this(sound, 0);
}
public SoundBase(String sound, float volume) {
this(sound, volume, 0);
}
public SoundBase(String sound, float volume, float pitch) {
this(sound, volume, pitch, false, 0);
}
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay) {
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
}
public SoundBase(String sound, float volume, float pitch, double x, double y, double z) {
this(sound, volume, pitch, false, 0, x, y, z);
}
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
}
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation) {
this(new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
}
public SoundBase(ResourceLocation sound) {
this(sound, 0);
}
public SoundBase(ResourceLocation sound, float volume) {
this(sound, volume, 0);
}
public SoundBase(ResourceLocation sound, float volume, float pitch) {
this(sound, volume, pitch, false, 0);
}
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay) {
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
}
public SoundBase(ResourceLocation sound, float volume, float pitch, double x, double y, double z) {
this(sound, volume, pitch, false, 0, x, y, z);
}
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
}
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z,
AttenuationType attenuation) {
this.attenuation = attenuation;
this.sound = sound;
this.volume = volume;
this.pitch = pitch;
this.x = (float) x;
this.y = (float) y;
this.z = (float) z;
this.repeat = repeat;
this.repeatDelay = repeatDelay;
}
public SoundBase(SoundBase other) {
this.attenuation = other.attenuation;
this.sound = other.sound;
this.volume = other.volume;
this.pitch = other.pitch;
this.x = other.x;
this.y = other.y;
this.z = other.z;
this.repeat = other.repeat;
this.repeatDelay = other.repeatDelay;
}
@Override
public AttenuationType getAttenuationType() {
return attenuation;
}
@Override
public ResourceLocation getPositionedSoundLocation() {
return sound;
}
@Override
public float getVolume() {
return volume;
}
@Override
public float getPitch() {
return pitch;
}
@Override
public float getXPosF() {
return x;
}
@Override
public float getYPosF() {
return y;
}
@Override
public float getZPosF() {
return z;
}
@Override
public boolean canRepeat() {
return repeat;
}
@Override
public int getRepeatDelay() {
return repeatDelay;
}
}

View file

@ -0,0 +1,692 @@
package com.pahimar.repackage.cofh.lib.gui;
import com.pahimar.repackage.cofh.lib.audio.SoundBase;
import com.pahimar.repackage.cofh.lib.gui.element.ElementBase;
import com.pahimar.repackage.cofh.lib.gui.element.TabBase;
import com.pahimar.repackage.cofh.lib.gui.slot.SlotFalseCopy;
import com.pahimar.repackage.cofh.lib.render.RenderHelper;
import com.pahimar.repackage.cofh.lib.util.helpers.StringHelper;
import cpw.mods.fml.client.FMLClientHandler;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
* Base class for a modular GUIs. Works with Elements {@link ElementBase} and Tabs {@link TabBase} which are both modular elements.
*
* @author King Lemming
*/
public abstract class GuiBase extends GuiContainer {
public static final SoundHandler guiSoundManager = FMLClientHandler.instance().getClient().getSoundHandler();
protected boolean drawTitle = true;
protected boolean drawInventory = true;
protected int mouseX = 0;
protected int mouseY = 0;
protected int lastIndex = -1;
protected String name;
protected ResourceLocation texture;
public ArrayList<TabBase> tabs = new ArrayList<TabBase>();
protected ArrayList<ElementBase> elements = new ArrayList<ElementBase>();
protected List<String> tooltip = new LinkedList<String>();
protected boolean tooltips = true;
// protected boolean tooltips = !Loader.isModLoaded("NotEnoughItems");
public static void playSound(String name, float volume, float pitch) {
guiSoundManager.playSound(new SoundBase(name, volume, pitch));
}
public GuiBase(Container container) {
super(container);
}
public GuiBase(Container container, ResourceLocation texture) {
super(container);
this.texture = texture;
}
@Override
public void initGui() {
super.initGui();
tabs.clear();
elements.clear();
}
@Override
public void drawScreen(int x, int y, float partialTick) {
updateElementInformation();
super.drawScreen(x, y, partialTick);
if (tooltips && mc.thePlayer.inventory.getItemStack() == null) {
addTooltips(tooltip);
drawTooltip(tooltip);
}
mouseX = x - guiLeft;
mouseY = y - guiTop;
updateElements();
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y) {
if (drawTitle) {
fontRendererObj.drawString(StringHelper.localize(name), getCenteredOffset(StringHelper.localize(name)), 6, 0x404040);
}
if (drawInventory) {
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 3, 0x404040);
}
drawElements(0, true);
drawTabs(0, true);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
mouseX = x - guiLeft;
mouseY = y - guiTop;
GL11.glPushMatrix();
GL11.glTranslatef(guiLeft, guiTop, 0.0F);
drawElements(partialTick, false);
drawTabs(partialTick, false);
GL11.glPopMatrix();
}
@Override
protected void keyTyped(char characterTyped, int keyPressed) {
for (int i = elements.size(); i-- > 0; ) {
ElementBase c = elements.get(i);
if (!c.isVisible() || !c.isEnabled()) {
continue;
}
if (c.onKeyTyped(characterTyped, keyPressed)) {
return;
}
}
super.keyTyped(characterTyped, keyPressed);
}
@Override
public void handleMouseInput() {
int x = Mouse.getEventX() * width / mc.displayWidth;
int y = height - Mouse.getEventY() * height / mc.displayHeight - 1;
mouseX = x - guiLeft;
mouseY = y - guiTop;
int wheelMovement = Mouse.getEventDWheel();
if (wheelMovement != 0) {
for (int i = elements.size(); i-- > 0; ) {
ElementBase c = elements.get(i);
if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mouseX, mouseY)) {
continue;
}
if (c.onMouseWheel(mouseX, mouseY, wheelMovement)) {
return;
}
}
TabBase tab = getTabAtPosition(mouseX, mouseY);
if (tab != null && tab.onMouseWheel(mouseX, mouseY, wheelMovement)) {
return;
}
}
super.handleMouseInput();
}
@Override
protected void mouseClicked(int mX, int mY, int mouseButton) {
mX -= guiLeft;
mY -= guiTop;
for (int i = elements.size(); i-- > 0; ) {
ElementBase c = elements.get(i);
if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mX, mY)) {
continue;
}
if (c.onMousePressed(mX, mY, mouseButton)) {
return;
}
}
TabBase tab = getTabAtPosition(mX, mY);
if (tab != null && !tab.onMousePressed(mX, mY, mouseButton)) {
for (int i = tabs.size(); i-- > 0; ) {
TabBase other = tabs.get(i);
if (other != tab && other.open && other.side == tab.side) {
other.toggleOpen();
}
}
tab.toggleOpen();
return;
}
mX += guiLeft;
mY += guiTop;
// TODO: Look into a better solution for this.
if (tab != null) {
xSize += tab.currentWidth;
}
super.mouseClicked(mX, mY, mouseButton);
if (tab != null) {
xSize -= tab.currentWidth;
}
}
@Override
protected void mouseMovedOrUp(int mX, int mY, int mouseButton) {
mX -= guiLeft;
mY -= guiTop;
if (mouseButton >= 0 && mouseButton <= 2) { // 0:left, 1:right, 2: middle
for (int i = elements.size(); i-- > 0; ) {
ElementBase c = elements.get(i);
if (!c.isVisible() || !c.isEnabled()) { // no bounds checking on mouseUp events
continue;
}
c.onMouseReleased(mX, mY);
}
}
mX += guiLeft;
mY += guiTop;
super.mouseMovedOrUp(mX, mY, mouseButton);
}
@Override
protected void mouseClickMove(int mX, int mY, int lastClick, long timeSinceClick) {
Slot slot = getSlotAtPosition(mX, mY);
ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
if (this.field_147007_t && slot != null && itemstack != null && slot instanceof SlotFalseCopy) {
if (lastIndex != slot.slotNumber) {
lastIndex = slot.slotNumber;
this.handleMouseClick(slot, slot.slotNumber, 0, 0);
}
} else {
lastIndex = -1;
super.mouseClickMove(mX, mY, lastClick, timeSinceClick);
}
}
public Slot getSlotAtPosition(int xCoord, int yCoord) {
for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(k);
if (this.isMouseOverSlot(slot, xCoord, yCoord)) {
return slot;
}
}
return null;
}
public boolean isMouseOverSlot(Slot theSlot, int xCoord, int yCoord) {
return this.func_146978_c(theSlot.xDisplayPosition, theSlot.yDisplayPosition, 16, 16, xCoord, yCoord);
}
/**
* Draws the elements for this GUI.
*/
protected void drawElements(float partialTick, boolean foreground) {
if (foreground) {
for (int i = 0; i < elements.size(); i++) {
ElementBase element = elements.get(i);
if (element.isVisible()) {
element.drawForeground(mouseX, mouseY);
}
}
} else {
for (int i = 0; i < elements.size(); i++) {
ElementBase element = elements.get(i);
if (element.isVisible()) {
element.drawBackground(mouseX, mouseY, partialTick);
}
}
}
}
/**
* Draws the tabs for this GUI. Handles Tab open/close animation.
*/
protected void drawTabs(float partialTick, boolean foreground) {
if (foreground) {
return; // TODO:
}
int yPosRight = 4;
int yPosLeft = 4;
for (int i = 0; i < tabs.size(); i++) {
TabBase tab = tabs.get(i);
tab.update();
if (!tab.isVisible()) {
continue;
}
// TODO: convert these over to foreground/background (maybe logic for top/bottom tabs?)
if (tab.side == TabBase.LEFT) {
tab.draw(0, yPosLeft);
yPosLeft += tab.currentHeight;
} else {
tab.draw(xSize, yPosRight);
yPosRight += tab.currentHeight;
}
}
}
/**
* Called by NEI if installed
*/
// @Override
public List<String> handleTooltip(int mousex, int mousey, List<String> tooltip) {
if (mc.thePlayer.inventory.getItemStack() == null) {
addTooltips(tooltip);
}
return tooltip;
}
public void addTooltips(List<String> tooltip) {
TabBase tab = getTabAtPosition(mouseX, mouseY);
if (tab != null) {
tab.addTooltip(tooltip);
}
ElementBase element = getElementAtPosition(mouseX, mouseY);
if (element != null) {
element.addTooltip(tooltip);
}
}
/* ELEMENTS */
public ElementBase addElement(ElementBase element) {
elements.add(element);
return element;
}
public TabBase addTab(TabBase tab) {
int yOffset = 4;
for (int i = 0; i < tabs.size(); i++) {
if (tabs.get(i).side == tab.side && tabs.get(i).isVisible()) {
yOffset += tabs.get(i).currentHeight;
}
}
tab.setPosition(tab.side == TabBase.LEFT ? 0 : xSize, yOffset);
tabs.add(tab);
if (TabTracker.getOpenedLeftTab() != null && tab.getClass().equals(TabTracker.getOpenedLeftTab())) {
tab.setFullyOpen();
} else if (TabTracker.getOpenedRightTab() != null && tab.getClass().equals(TabTracker.getOpenedRightTab())) {
tab.setFullyOpen();
}
return tab;
}
protected ElementBase getElementAtPosition(int mX, int mY) {
for (int i = elements.size(); i-- > 0; ) {
ElementBase element = elements.get(i);
if (element.intersectsWith(mX, mY)) {
return element;
}
}
return null;
}
protected TabBase getTabAtPosition(int mX, int mY) {
int xShift = 0;
int yShift = 4;
for (int i = 0; i < tabs.size(); i++) {
TabBase tab = tabs.get(i);
if (!tab.isVisible() || tab.side == TabBase.RIGHT) {
continue;
}
tab.currentShiftX = xShift;
tab.currentShiftY = yShift;
if (tab.intersectsWith(mX, mY, xShift, yShift)) {
return tab;
}
yShift += tab.currentHeight;
}
xShift = xSize;
yShift = 4;
for (int i = 0; i < tabs.size(); i++) {
TabBase tab = tabs.get(i);
if (!tab.isVisible() || tab.side == TabBase.LEFT) {
continue;
}
tab.currentShiftX = xShift;
tab.currentShiftY = yShift;
if (tab.intersectsWith(mX, mY, xShift, yShift)) {
return tab;
}
yShift += tab.currentHeight;
}
return null;
}
protected final void updateElements() {
for (int i = elements.size(); i-- > 0; ) {
ElementBase c = elements.get(i);
if (c.isVisible() && c.isEnabled()) {
c.update(mouseX, mouseY);
}
}
}
protected void updateElementInformation() {
}
public void handleElementButtonClick(String buttonName, int mouseButton) {
}
/* HELPERS */
public void bindTexture(ResourceLocation texture) {
mc.renderEngine.bindTexture(texture);
}
/**
* Abstract method to retrieve icons by name from a registry. You must override this if you use any of the String methods below.
*/
public IIcon getIcon(String name) {
return null;
}
/**
* Essentially a placeholder method for tabs to use should they need to draw a button.
*/
public void drawButton(IIcon icon, int x, int y, int spriteSheet, int mode) {
drawIcon(icon, x, y, spriteSheet);
}
public void drawButton(String iconName, int x, int y, int spriteSheet, int mode) {
drawButton(getIcon(iconName), x, y, spriteSheet, mode);
}
/**
* Simple method used to draw a fluid of arbitrary size.
*/
public void drawFluid(int x, int y, FluidStack fluid, int width, int height) {
if (fluid == null || fluid.getFluid() == null) {
return;
}
RenderHelper.setBlockTextureSheet();
RenderHelper.setColor3ub(fluid.getFluid().getColor(fluid));
drawTiledTexture(x, y, fluid.getFluid().getIcon(fluid), width, height);
}
public void drawTiledTexture(int x, int y, IIcon icon, int width, int height) {
int i = 0;
int j = 0;
int drawHeight = 0;
int drawWidth = 0;
for (i = 0; i < width; i += 16) {
for (j = 0; j < height; j += 16) {
drawWidth = Math.min(width - i, 16);
drawHeight = Math.min(height - j, 16);
drawScaledTexturedModelRectFromIcon(x + i, y + j, icon, drawWidth, drawHeight);
}
}
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
}
public void drawIcon(IIcon icon, int x, int y, int spriteSheet) {
if (spriteSheet == 0) {
RenderHelper.setBlockTextureSheet();
} else {
RenderHelper.setItemTextureSheet();
}
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
drawTexturedModelRectFromIcon(x, y, icon, 16, 16);
}
public void drawIcon(String iconName, int x, int y, int spriteSheet) {
drawIcon(getIcon(iconName), x, y, spriteSheet);
}
public void drawSizedModalRect(int x1, int y1, int x2, int y2, int color) {
int temp;
if (x1 < x2) {
temp = x1;
x1 = x2;
x2 = temp;
}
if (y1 < y2) {
temp = y1;
y1 = y2;
y2 = temp;
}
float a = (color >> 24 & 255) / 255.0F;
float r = (color >> 16 & 255) / 255.0F;
float g = (color >> 8 & 255) / 255.0F;
float b = (color & 255) / 255.0F;
Tessellator tessellator = Tessellator.instance;
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(r, g, b, a);
tessellator.startDrawingQuads();
tessellator.addVertex(x1, y2, this.zLevel);
tessellator.addVertex(x2, y2, this.zLevel);
tessellator.addVertex(x2, y1, this.zLevel);
tessellator.addVertex(x1, y1, this.zLevel);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
public void drawSizedTexturedModalRect(int x, int y, int u, int v, int width, int height, float texW, float texH) {
float texU = 1 / texW;
float texV = 1 / texH;
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, (u + 0) * texU, (v + height) * texV);
tessellator.addVertexWithUV(x + width, y + height, this.zLevel, (u + width) * texU, (v + height) * texV);
tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, (u + width) * texU, (v + 0) * texV);
tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, (u + 0) * texU, (v + 0) * texV);
tessellator.draw();
}
public void drawScaledTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height) {
if (icon == null) {
return;
}
double minU = icon.getMinU();
double maxU = icon.getMaxU();
double minV = icon.getMinV();
double maxV = icon.getMaxV();
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, minU, minV + (maxV - minV) * height / 16F);
tessellator.addVertexWithUV(x + width, y + height, this.zLevel, minU + (maxU - minU) * width / 16F, minV + (maxV - minV) * height / 16F);
tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, minU + (maxU - minU) * width / 16F, minV);
tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, minU, minV);
tessellator.draw();
}
public void drawTooltip(List<String> list) {
drawTooltipHoveringText(list, mouseX + guiLeft, mouseY + guiTop, fontRendererObj);
tooltip.clear();
}
@SuppressWarnings("rawtypes")
protected void drawTooltipHoveringText(List list, int x, int y, FontRenderer font) {
if (list == null || list.isEmpty()) {
return;
}
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
int k = 0;
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
String s = (String) iterator.next();
int l = font.getStringWidth(s);
if (l > k) {
k = l;
}
}
int i1 = x + 12;
int j1 = y - 12;
int k1 = 8;
if (list.size() > 1) {
k1 += 2 + (list.size() - 1) * 10;
}
if (i1 + k > this.width) {
i1 -= 28 + k;
}
if (j1 + k1 + 6 > this.height) {
j1 = this.height - k1 - 6;
}
this.zLevel = 300.0F;
itemRender.zLevel = 300.0F;
int l1 = -267386864;
this.drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1);
this.drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1);
this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1);
this.drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1);
this.drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1);
int i2 = 1347420415;
int j2 = (i2 & 16711422) >> 1 | i2 & -16777216;
this.drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2);
this.drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2);
this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2);
this.drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2);
for (int k2 = 0; k2 < list.size(); ++k2) {
String s1 = (String) list.get(k2);
font.drawStringWithShadow(s1, i1, j1, -1);
if (k2 == 0) {
j1 += 2;
}
j1 += 10;
}
this.zLevel = 0.0F;
itemRender.zLevel = 0.0F;
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
/**
* Passthrough method for tab use.
*/
public void mouseClicked(int mouseButton) {
super.mouseClicked(guiLeft + mouseX, guiTop + mouseY, mouseButton);
}
public FontRenderer getFontRenderer() {
return fontRendererObj;
}
protected int getCenteredOffset(String string) {
return this.getCenteredOffset(string, xSize);
}
protected int getCenteredOffset(String string, int xWidth) {
return (xWidth - fontRendererObj.getStringWidth(string)) / 2;
}
public int getGuiLeft() {
return guiLeft;
}
public int getGuiTop() {
return guiTop;
}
public int getMouseX() {
return mouseX;
}
public int getMouseY() {
return mouseY;
}
public void overlayRecipe() {
}
}

View file

@ -0,0 +1,10 @@
package com.pahimar.repackage.cofh.lib.gui;
import net.minecraft.client.gui.GuiScreen;
public class GuiBook extends GuiScreen {
protected int mouseX = 0;
protected int mouseY = 0;
}

View file

@ -0,0 +1,67 @@
package com.pahimar.repackage.cofh.lib.gui;
public class GuiColor {
private final int _color;
public GuiColor(int color) {
_color = color;
}
public GuiColor(int r, int g, int b) {
this(r, g, b, 255);
}
public GuiColor(int r, int g, int b, int a) {
_color = (b & 0xFF) | (g & 0xFF) << 8 | (r & 0xFF) << 16 | (a & 0xFF) << 24;
}
public int getColor() {
return _color;
}
public int getIntR() {
return (_color >> 16) & 0xFF;
}
public int getIntG() {
return (_color >> 8) & 0xFF;
}
public int getIntB() {
return (_color >> 0) & 0xFF;
}
public int getIntA() {
return (_color >> 24) & 0xFF;
}
public float getFloatR() {
return ((_color >> 16) & 0xFF) / 0xFF;
}
public float getFloatG() {
return ((_color >> 8) & 0xFF) / 0xFF;
}
public float getFloatB() {
return ((_color >> 0) & 0xFF) / 0xFF;
}
public float getFloatA() {
return ((_color >> 24) & 0xFF) / 0xFF;
}
}

View file

@ -0,0 +1,15 @@
package com.pahimar.repackage.cofh.lib.gui;
import com.pahimar.ee3.reference.Textures;
public class GuiProps {
/* GUI */
public static final String PATH_GFX = Textures.RESOURCE_PREFIX + "textures/";
public static final String PATH_ARMOR = PATH_GFX + "armor/";
public static final String PATH_GUI = PATH_GFX + "gui/";
public static final String PATH_RENDER = PATH_GFX + "blocks/";
public static final String PATH_ELEMENTS = PATH_GUI + "elements/";
public static final String PATH_ICON = PATH_GUI + "icons/";
}

View file

@ -0,0 +1,35 @@
package com.pahimar.repackage.cofh.lib.gui;
import com.pahimar.repackage.cofh.lib.gui.element.TabBase;
/**
* Keeps track of which tabs should be open by default when a player opens a GUI.
*
* @author King Lemming
*/
public class TabTracker {
private static Class<? extends TabBase> openedLeftTab;
private static Class<? extends TabBase> openedRightTab;
public static Class<? extends TabBase> getOpenedLeftTab() {
return openedLeftTab;
}
public static Class<? extends TabBase> getOpenedRightTab() {
return openedRightTab;
}
public static void setOpenedLeftTab(Class<? extends TabBase> tabClass) {
openedLeftTab = tabClass;
}
public static void setOpenedRightTab(Class<? extends TabBase> tabClass) {
openedRightTab = tabClass;
}
}

View file

@ -0,0 +1,196 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.ResourceLocation;
import java.util.List;
/**
* Base class for a modular GUI element. Has self-contained rendering methods and a link back to the {@link GuiBase} it is a part of.
*
* @author King Lemming
*/
public abstract class ElementBase {
protected GuiBase gui;
protected ResourceLocation texture;
protected int posX;
protected int posY;
protected int sizeX;
protected int sizeY;
protected int texW = 256;
protected int texH = 256;
protected String name;
private boolean visible = true;
private boolean enabled = true;
public ElementBase(GuiBase gui, int posX, int posY) {
this.gui = gui;
this.posX = posX;
this.posY = posY;
}
public ElementBase(GuiBase gui, int posX, int posY, int width, int height) {
this.gui = gui;
this.posX = posX;
this.posY = posY;
this.sizeX = width;
this.sizeY = height;
}
public ElementBase setName(String name) {
this.name = name;
return this;
}
public ElementBase setPosition(int posX, int posY) {
this.posX = posX;
this.posY = posY;
return this;
}
public ElementBase setSize(int sizeX, int sizeY) {
this.sizeX = sizeX;
this.sizeY = sizeY;
return this;
}
public ElementBase setTexture(String texture, int texW, int texH) {
this.texture = new ResourceLocation(texture);
this.texW = texW;
this.texH = texH;
return this;
}
public final ElementBase setVisible(boolean visible) {
this.visible = visible;
return this;
}
public boolean isVisible() {
return visible;
}
public final ElementBase setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}
public boolean isEnabled() {
return enabled;
}
public void update(int mouseX, int mouseY) {
update();
}
public void update() {
}
public abstract void drawBackground(int mouseX, int mouseY, float gameTicks);
public abstract void drawForeground(int mouseX, int mouseY);
public void addTooltip(List<String> list) {
}
public void drawModalRect(int x, int y, int width, int height, int color) {
gui.drawSizedModalRect(x, y, width, height, color);
}
public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height) {
gui.drawSizedTexturedModalRect(x, y, u, v, width, height, texW, texH);
}
public void drawCenteredString(FontRenderer fontRenderer, String text, int x, int y, int color) {
fontRenderer.drawStringWithShadow(text, x - fontRenderer.getStringWidth(text) / 2, y, color);
}
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
return false;
}
public void onMouseReleased(int mouseX, int mouseY) {
}
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
return false;
}
public boolean onKeyTyped(char characterTyped, int keyPressed) {
return false;
}
public boolean intersectsWith(int mouseX, int mouseY) {
return mouseX >= this.posX && mouseX <= this.posX + this.sizeX && mouseY >= this.posY && mouseY <= this.posY + this.sizeY;
}
public final String getName() {
return name;
}
public final GuiBase getContainerScreen() {
return gui;
}
public final FontRenderer getFontRenderer() {
return gui.getFontRenderer();
}
/**
* This method is relative to the GUI's y coordinate
*/
public final int getPosY() {
return posY;
}
/**
* This method is relative to the GUI's x coordinate
*/
public final int getPosX() {
return posX;
}
public final int getHeight() {
return sizeY;
}
public final int getWidth() {
return sizeX;
}
}

View file

@ -0,0 +1,138 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.render.RenderHelper;
import com.pahimar.repackage.cofh.lib.util.helpers.StringHelper;
import java.util.List;
public class ElementButton extends ElementBase {
int sheetX;
int sheetY;
int hoverX;
int hoverY;
int disabledX = 0;
int disabledY = 0;
boolean tooltipLocalized = false;
String tooltip;
public ElementButton(GuiBase gui, int posX, int posY, String name, int sheetX, int sheetY, int hoverX, int hoverY, int sizeX, int sizeY, String texture) {
super(gui, posX, posY);
setName(name);
setSize(sizeX, sizeY);
setTexture(texture, texW, texH);
this.sheetX = sheetX;
this.sheetY = sheetY;
this.hoverX = hoverX;
this.hoverY = hoverY;
}
public ElementButton(GuiBase gui, int posX, int posY, String name, int sheetX, int sheetY, int hoverX, int hoverY, int disabledX, int disabledY, int sizeX,
int sizeY, String texture) {
super(gui, posX, posY);
setName(name);
setSize(sizeX, sizeY);
setTexture(texture, texW, texH);
this.sheetX = sheetX;
this.sheetY = sheetY;
this.hoverX = hoverX;
this.hoverY = hoverY;
this.disabledX = disabledX;
this.disabledY = disabledY;
}
public ElementButton clearToolTip() {
this.tooltip = null;
return this;
}
public ElementButton setToolTip(String tooltip) {
this.tooltip = tooltip;
return this;
}
public ElementButton setToolTipLocalized(boolean localized) {
this.tooltipLocalized = localized;
return this;
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
RenderHelper.bindTexture(texture);
if (isEnabled()) {
if (intersectsWith(mouseX, mouseY)) {
drawTexturedModalRect(posX, posY, hoverX, hoverY, sizeX, sizeY);
} else {
drawTexturedModalRect(posX, posY, sheetX, sheetY, sizeX, sizeY);
}
} else {
drawTexturedModalRect(posX, posY, disabledX, disabledY, sizeX, sizeY);
}
}
@Override
public void drawForeground(int mouseX, int mouseY) {
}
@Override
public void addTooltip(List<String> list) {
if (tooltip != null) {
if (tooltipLocalized) {
list.add(tooltip);
} else {
list.add(StringHelper.localize(tooltip));
}
}
}
@Override
public boolean onMousePressed(int x, int y, int mouseButton) {
if (isEnabled()) {
gui.handleElementButtonClick(getName(), mouseButton);
return true;
}
return false;
}
public void setSheetX(int pos) {
sheetX = pos;
}
public void setSheetY(int pos) {
sheetY = pos;
}
public void setHoverX(int pos) {
hoverX = pos;
}
public void setHoverY(int pos) {
hoverY = pos;
}
public void setActive() {
setEnabled(true);
}
public void setDisabled() {
setEnabled(false);
}
}

View file

@ -0,0 +1,84 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.GuiProps;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
public abstract class ElementButtonManaged extends ElementBase {
public static final ResourceLocation HOVER = new ResourceLocation(GuiProps.PATH_ELEMENTS + "Button_Hover.png");
public static final ResourceLocation ENABLED = new ResourceLocation(GuiProps.PATH_ELEMENTS + "Button_Enabled.png");
public static final ResourceLocation DISABLED = new ResourceLocation(GuiProps.PATH_ELEMENTS + "Button_Disabled.png");
private String _text;
public ElementButtonManaged(GuiBase containerScreen, int posX, int posY, int sizeX, int sizeY, String text) {
super(containerScreen, posX, posY, sizeX, sizeY);
_text = text;
}
public void setText(String text) {
_text = text;
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
if (!isEnabled()) {
gui.bindTexture(DISABLED);
} else if (intersectsWith(mouseX, mouseY)) {
gui.bindTexture(HOVER);
} else {
gui.bindTexture(ENABLED);
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
drawTexturedModalRect(posX, posY, 0, 0, sizeX / 2, sizeY / 2);
drawTexturedModalRect(posX, posY + sizeY / 2, 0, 256 - sizeY / 2, sizeX / 2, sizeY / 2);
drawTexturedModalRect(posX + sizeX / 2, posY, 256 - sizeX / 2, 0, sizeX / 2, sizeY / 2);
drawTexturedModalRect(posX + sizeX / 2, posY + sizeY / 2, 256 - sizeX / 2, 256 - sizeY / 2, sizeX / 2, sizeY / 2);
}
@Override
public void drawForeground(int mouseX, int mouseY) {
String text = getFontRenderer().trimStringToWidth(_text, sizeX - 4);
drawCenteredString(getFontRenderer(), text, posX + sizeX / 2, posY + (sizeY - 8) / 2, getTextColor(mouseX, mouseY));
}
protected int getTextColor(int mouseX, int mouseY) {
if (!isEnabled()) {
return -6250336;
} else if (intersectsWith(mouseX, mouseY)) {
return 16777120;
} else {
return 14737632;
}
}
@Override
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
GuiBase.playSound("random.click", 1.0F, 1.0F);
if (mouseButton == 0) {
onClick();
} else if (mouseButton == 1) {
onRightClick();
} else if (mouseButton == 2) {
onMiddleClick();
}
return true;
}
public abstract void onClick();
public void onRightClick() {
}
public void onMiddleClick() {
}
}

View file

@ -0,0 +1,73 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import java.util.HashMap;
import java.util.Map;
public abstract class ElementButtonOption extends ElementButtonManaged {
private final Map<Integer, String> _values = new HashMap<Integer, String>();
private int _currentValue = 0;
private int _maxValue;
public ElementButtonOption(GuiBase containerScreen, int x, int y, int width, int height) {
super(containerScreen, x, y, width, height, "");
}
public void setValue(int value, String label) {
_values.put(value, label);
if (value > _maxValue) {
_maxValue = value;
}
}
@Override
public void onClick() {
int nextValue = _currentValue;
do {
nextValue++;
if (nextValue > _maxValue) {
nextValue = 0;
}
} while (_values.get(nextValue) == null);
setSelectedIndex(nextValue);
}
@Override
public void onRightClick() {
int nextValue = _currentValue;
do {
nextValue--;
if (nextValue < 0) {
nextValue = _maxValue;
}
} while (_values.get(nextValue) == null);
setSelectedIndex(nextValue);
}
public int getSelectedIndex() {
return _currentValue;
}
public void setSelectedIndex(int index) {
_currentValue = index;
setText(_values.get(_currentValue));
onValueChanged(_currentValue, _values.get(_currentValue));
}
public String getValue() {
return _values.get(_currentValue);
}
public abstract void onValueChanged(int value, String label);
}

View file

@ -0,0 +1,63 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.render.RenderHelper;
public class ElementDualScaled extends ElementBase {
public int quantity;
public int mode;
public boolean background = true;
public ElementDualScaled(GuiBase gui, int posX, int posY) {
super(gui, posX, posY);
}
public ElementDualScaled setBackground(boolean background) {
this.background = background;
return this;
}
public ElementDualScaled setMode(int mode) {
this.mode = mode;
return this;
}
public ElementDualScaled setQuantity(int quantity) {
this.quantity = quantity;
return this;
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
RenderHelper.bindTexture(texture);
if (background) {
drawTexturedModalRect(posX, posY, 0, 0, sizeX, sizeY);
}
switch (mode) {
case 0:
// vertical bottom -> top
drawTexturedModalRect(posX, posY + sizeY - quantity, sizeX, sizeY - quantity, sizeX, quantity);
return;
case 1:
// horizontal left -> right
drawTexturedModalRect(posX, posY, sizeX, 0, quantity, sizeY);
return;
case 2:
// horizontal right -> left
drawTexturedModalRect(posX + sizeX - quantity, posY, sizeX + sizeX - quantity, 0, quantity, sizeY);
}
}
@Override
public void drawForeground(int mouseX, int mouseY) {
}
}

View file

@ -0,0 +1,32 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import net.minecraftforge.fluids.FluidStack;
public class ElementFluid extends ElementBase {
public FluidStack fluid;
public ElementFluid(GuiBase gui, int posX, int posY) {
super(gui, posX, posY);
}
public ElementFluid setFluid(FluidStack fluid) {
this.fluid = fluid;
return this;
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
gui.drawFluid(posX, posY, fluid, sizeX, sizeY);
}
@Override
public void drawForeground(int mouseX, int mouseY) {
}
}

View file

@ -0,0 +1,84 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.GuiProps;
import com.pahimar.repackage.cofh.lib.render.RenderHelper;
import com.pahimar.repackage.cofh.lib.util.helpers.StringHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.IFluidTank;
import java.util.List;
public class ElementFluidTank extends ElementBase {
public static final ResourceLocation DEFAULT_TEXTURE = new ResourceLocation(GuiProps.PATH_ELEMENTS + "FluidTank.png");
public static final int DEFAULT_SCALE = 60;
protected IFluidTank tank;
protected int gaugeType;
public ElementFluidTank(GuiBase gui, int posX, int posY, IFluidTank tank) {
super(gui, posX, posY);
this.tank = tank;
this.texture = DEFAULT_TEXTURE;
this.texW = 64;
this.texH = 64;
this.sizeX = 16;
this.sizeY = DEFAULT_SCALE;
}
public ElementFluidTank(GuiBase gui, int posX, int posY, IFluidTank tank, String texture) {
super(gui, posX, posY);
this.tank = tank;
this.texture = new ResourceLocation(texture);
this.texW = 64;
this.texH = 64;
this.sizeX = 16;
this.sizeY = DEFAULT_SCALE;
}
public ElementFluidTank setGauge(int gaugeType) {
this.gaugeType = gaugeType;
return this;
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
int amount = getScaled();
gui.drawFluid(posX, posY + sizeY - amount, tank.getFluid(), sizeX, amount);
RenderHelper.bindTexture(texture);
drawTexturedModalRect(posX, posY, 32 + gaugeType * 16, 1, sizeX, sizeY);
}
@Override
public void drawForeground(int mouseX, int mouseY) {
}
@Override
public void addTooltip(List<String> list) {
if (tank.getFluid() != null && tank.getFluidAmount() > 0) {
list.add(StringHelper.getFluidName(tank.getFluid()));
}
list.add("" + tank.getFluidAmount() + " / " + tank.getCapacity() + " mB");
}
protected int getScaled() {
if (tank.getCapacity() <= 0) {
return sizeY;
}
return tank.getFluidAmount() * sizeY / tank.getCapacity();
}
}

View file

@ -0,0 +1,323 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.GuiColor;
import com.pahimar.repackage.cofh.lib.gui.element.listbox.IListBoxElement;
import com.pahimar.repackage.cofh.lib.util.helpers.StringHelper;
import net.minecraft.client.renderer.Tessellator;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import static org.lwjgl.opengl.GL11.*;
public abstract class ElementListBox extends ElementBase {
public int borderColor = new GuiColor(120, 120, 120, 255).getColor();
public int backgroundColor = new GuiColor(0, 0, 0, 255).getColor();
public int selectedLineColor = new GuiColor(0, 0, 0, 255).getColor();
public int textColor = new GuiColor(150, 150, 150, 255).getColor();
public int selectedTextColor = new GuiColor(255, 255, 255, 255).getColor();
private final int _marginTop = 2;
private final int _marginLeft = 2;
private final int _marginRight = 2;
private final int _marginBottom = 2;
private final List<IListBoxElement> _elements = new LinkedList<IListBoxElement>();
private int _firstIndexDisplayed;
private int _selectedIndex;
private int scrollHoriz;
public ElementListBox(GuiBase containerScreen, int x, int y, int width, int height) {
super(containerScreen, x, y, width, height);
}
public void add(IListBoxElement element) {
_elements.add(element);
}
public void add(Collection<? extends IListBoxElement> elements) {
_elements.addAll(elements);
}
public void remove(IListBoxElement element) {
_elements.remove(element);
}
public void removeAt(int index) {
_elements.remove(index);
}
public int getInternalWidth() {
int width = 0;
for (int i = 0; i < _elements.size(); i++) {
width = Math.max(_elements.get(i).getWidth(), width);
}
return width;
}
public int getInternalHeight() {
int height = 0;
for (int i = 0; i < _elements.size(); i++) {
height += _elements.get(i).getHeight();
}
return height;
}
public int getContentWidth() {
return sizeX - _marginLeft - _marginRight;
}
public int getContentHeight() {
return sizeY - _marginTop - _marginBottom;
}
public int getContentTop() {
return posY + _marginTop;
}
public int getContentLeft() {
return posX + _marginLeft;
}
public final int getContentBottom() {
return getContentTop() + getContentHeight();
}
public final int getContentRight() {
return getContentLeft() + getContentWidth();
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor);
drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor);
}
@Override
public void drawForeground(int mouseX, int mouseY) {
int heightDrawn = 0;
int nextElement = _firstIndexDisplayed;
glDisable(GL_LIGHTING);
glPushMatrix();
glDisable(GL_TEXTURE_2D);
glEnable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilMask(1);
glColorMask(false, false, false, false);
glDepthMask(false);
Tessellator.instance.startDrawingQuads();
Tessellator.instance.addVertex(getContentLeft(), getContentBottom(), 0);
Tessellator.instance.addVertex(getContentRight(), getContentBottom(), 0);
Tessellator.instance.addVertex(getContentRight(), getContentTop(), 0);
Tessellator.instance.addVertex(getContentLeft(), getContentTop(), 0);
Tessellator.instance.draw();
glEnable(GL_TEXTURE_2D);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilMask(0);
glColorMask(true, true, true, true);
glDepthMask(true);
glTranslated(-scrollHoriz, 0, 0);
int e = _elements.size();
while (nextElement < e && heightDrawn <= getContentHeight()) {
if (nextElement == _selectedIndex) {
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, selectedLineColor, selectedTextColor);
} else {
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, backgroundColor, textColor);
}
heightDrawn += _elements.get(nextElement).getHeight();
nextElement++;
}
glDisable(GL_STENCIL_TEST);
glPopMatrix();
}
@Override
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
int heightChecked = 0;
for (int i = _firstIndexDisplayed; i < _elements.size(); i++) {
if (heightChecked > getContentHeight()) {
break;
}
int elementHeight = _elements.get(i).getHeight();
if (getContentTop() + heightChecked <= mouseY && getContentTop() + heightChecked + elementHeight >= mouseY) {
setSelectedIndex(i);
onElementClicked(_elements.get(i));
break;
}
heightChecked += elementHeight;
}
return true;
}
@Override
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
if (StringHelper.isControlKeyDown()) {
if (movement > 0) {
scrollLeft();
} else if (movement < 0) {
scrollRight();
}
} else {
if (movement > 0) {
scrollUp();
} else if (movement < 0) {
scrollDown();
}
}
return true;
}
public void scrollDown() {
int heightDisplayed = 0;
int elementsDisplayed = 0;
for (int i = _firstIndexDisplayed; i < _elements.size(); i++) {
if (heightDisplayed + _elements.get(i).getHeight() > sizeY) {
break;
}
heightDisplayed += _elements.get(i).getHeight();
elementsDisplayed++;
}
if (_firstIndexDisplayed + elementsDisplayed < _elements.size()) {
_firstIndexDisplayed++;
}
onScrollV(_firstIndexDisplayed);
}
public void scrollUp() {
if (_firstIndexDisplayed > 0) {
_firstIndexDisplayed--;
}
onScrollV(_firstIndexDisplayed);
}
public void scrollLeft() {
scrollHoriz = Math.max(scrollHoriz - 15, 0);
onScrollH(scrollHoriz);
}
public void scrollRight() {
scrollHoriz = Math.min(scrollHoriz + 15, getLastScrollPositionH());
onScrollH(scrollHoriz);
}
public int getLastScrollPosition() {
int position = _elements.size() - 1;
int heightUsed = _elements.get(position).getHeight();
while (position > 0 && heightUsed < sizeY) {
position--;
heightUsed += _elements.get(position).getHeight();
}
return position + 1;
}
public int getLastScrollPositionH() {
return Math.max(getInternalWidth() - getContentWidth(), 0);
}
public int getSelectedIndex() {
return _selectedIndex;
}
public int getIndexOf(Object value) {
for (int i = 0; i < _elements.size(); i++) {
if (_elements.get(i).getValue().equals(value)) {
return i;
}
}
return -1;
}
public IListBoxElement getSelectedElement() {
return _elements.get(_selectedIndex);
}
public void setSelectedIndex(int index) {
if (index >= 0 && index < _elements.size() && index != _selectedIndex) {
_selectedIndex = index;
onSelectionChanged(_selectedIndex, getSelectedElement());
}
}
public IListBoxElement getElement(int index) {
return _elements.get(index);
}
public int getElementCount() {
return _elements.size();
}
public void scrollToV(int index) {
if (index >= 0 && index < _elements.size()) {
_firstIndexDisplayed = index;
}
}
public void scrollToH(int index) {
if (index >= 0 && index < getLastScrollPositionH()) {
scrollHoriz = index;
}
}
protected void onElementClicked(IListBoxElement element) {
}
protected void onScrollV(int newStartIndex) {
}
protected void onScrollH(int newStartIndex) {
}
protected abstract void onSelectionChanged(int newIndex, IListBoxElement newElement);
}

View file

@ -0,0 +1,40 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.render.RenderHelper;
/**
* Basic element which can render an arbitrary texture.
*
* @author King Lemming
*/
public class ElementSimple extends ElementBase {
int texU = 0;
int texV = 0;
public ElementSimple(GuiBase gui, int posX, int posY) {
super(gui, posX, posY);
}
public ElementSimple setTextureOffsets(int u, int v) {
texU = u;
texV = v;
return this;
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
RenderHelper.bindTexture(texture);
drawTexturedModalRect(posX, posY, texU, texV, sizeX, sizeY);
}
@Override
public void drawForeground(int mouseX, int mouseY) {
}
}

View file

@ -0,0 +1,129 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.GuiColor;
import org.lwjgl.opengl.GL11;
import static com.pahimar.repackage.cofh.lib.gui.element.ElementButtonManaged.*;
public abstract class ElementSlider extends ElementBase {
protected int _value;
protected int _valueMax;
protected int _sliderWidth;
protected int _sliderHeight;
protected boolean _isDragging;
public int borderColor = new GuiColor(120, 120, 120, 255).getColor();
public int backgroundColor = new GuiColor(0, 0, 0, 255).getColor();
protected ElementSlider(GuiBase containerScreen, int x, int y, int width, int height, int maxValue) {
super(containerScreen, x, y, width, height);
_valueMax = maxValue;
}
public ElementSlider setColor(int backgroundColor, int borderColor) {
this.borderColor = borderColor;
this.backgroundColor = backgroundColor;
return this;
}
public ElementSlider setSliderSize(int width, int height) {
_sliderWidth = width;
_sliderHeight = height;
return this;
}
public void setValue(int value) {
if (value != _value && value >= 0 && value <= _valueMax) {
_value = value;
onValueChanged(_value);
}
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor);
drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor);
}
@Override
public void drawForeground(int mouseX, int mouseY) {
int sliderWidth = _sliderWidth;
int sliderHeight = _sliderHeight;
int sliderX = posX + getSliderX();
int sliderY = posY + getSliderY();
if (!isEnabled()) {
gui.bindTexture(DISABLED);
} else if (isHovering(mouseX, mouseY)) {
gui.bindTexture(HOVER);
} else {
gui.bindTexture(ENABLED);
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
drawTexturedModalRect(sliderX, sliderY, 0, 0, sliderWidth / 2, sliderHeight / 2);
drawTexturedModalRect(sliderX, sliderY + sliderHeight / 2, 0, 256 - sliderHeight / 2, sliderWidth / 2, sliderHeight / 2);
drawTexturedModalRect(sliderX + sliderWidth / 2, sliderY, 256 - sliderWidth / 2, 0, sliderWidth / 2, sliderHeight / 2);
drawTexturedModalRect(sliderX + sliderWidth / 2, sliderY + sliderHeight / 2, 256 - sliderWidth / 2, 256 - sliderHeight / 2, sliderWidth / 2,
sliderHeight / 2);
}
protected boolean isHovering(int x, int y) {
return intersectsWith(x, y);
}
public int getSliderX() {
return 0;
}
public int getSliderY() {
return 0;
}
@Override
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
_isDragging = mouseButton == 0;
return true;
}
@Override
public void onMouseReleased(int mouseX, int mouseY) {
_isDragging = false;
}
@Override
public void update(int mouseX, int mouseY) {
if (_isDragging) {
dragSlider(mouseX - posX, mouseY - posY);
}
}
protected abstract void dragSlider(int x, int y);
@Override
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
if (movement > 0) {
setValue(_value - 1);
} else if (movement < 0) {
setValue(_value + 1);
}
return true;
}
public abstract void onValueChanged(int value);
}

View file

@ -0,0 +1,212 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.GuiProps;
import com.pahimar.repackage.cofh.lib.gui.TabTracker;
import com.pahimar.repackage.cofh.lib.render.RenderHelper;
import com.pahimar.repackage.cofh.lib.util.Rectangle4i;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
/**
* Base class for a tab element. Has self-contained rendering methods and a link back to the {@link GuiBase} it is a part of.
*
* @author King Lemming
*/
public abstract class TabBase extends ElementBase {
public static int tabExpandSpeed = 8;
public static int LEFT = 0;
public static int RIGHT = 1;
public boolean open;
public boolean fullyOpen;
public int side = RIGHT;
public int headerColor = 0xe1c92f;
public int subheaderColor = 0xaaafb8;
public int textColor = 0x000000;
public int backgroundColor = 0xffffff;
public int currentShiftX = 0;
public int currentShiftY = 0;
public int minWidth = 22;
public int maxWidth = 124;
public int currentWidth = minWidth;
public int minHeight = 22;
public int maxHeight = 22;
public int currentHeight = minHeight;
public static final ResourceLocation DEFAULT_TEXTURE_LEFT = new ResourceLocation(GuiProps.PATH_ELEMENTS + "Tab_Left.png");
public static final ResourceLocation DEFAULT_TEXTURE_RIGHT = new ResourceLocation(GuiProps.PATH_ELEMENTS + "Tab_Right.png");
public TabBase(GuiBase gui) {
super(gui, 0, 0);
texture = DEFAULT_TEXTURE_RIGHT;
}
public TabBase(GuiBase gui, int side) {
super(gui, 0, 0);
this.side = side;
if (side == LEFT) {
texture = DEFAULT_TEXTURE_LEFT;
} else {
texture = DEFAULT_TEXTURE_RIGHT;
}
}
public void draw(int x, int y) {
posX = x;
posY = y;
draw();
}
public void draw() {
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
}
@Override
public void drawForeground(int mouseX, int mouseY) {
}
@Override
public void update() {
if (open && currentWidth < maxWidth) {
currentWidth += tabExpandSpeed;
} else if (!open && currentWidth > minWidth) {
currentWidth -= tabExpandSpeed;
}
if (currentWidth > maxWidth) {
currentWidth = maxWidth;
} else if (currentWidth < minWidth) {
currentWidth = minWidth;
}
if (open && currentHeight < maxHeight) {
currentHeight += tabExpandSpeed;
} else if (!open && currentHeight > minHeight) {
currentHeight -= tabExpandSpeed;
}
if (currentHeight > maxHeight) {
currentHeight = maxHeight;
} else if (currentHeight < minHeight) {
currentHeight = minHeight;
}
if (!fullyOpen && open && currentWidth == maxWidth && currentHeight == maxHeight) {
setFullyOpen();
}
}
protected void drawBackground() {
float colorR = (backgroundColor >> 16 & 255) / 255.0F;
float colorG = (backgroundColor >> 8 & 255) / 255.0F;
float colorB = (backgroundColor & 255) / 255.0F;
GL11.glColor4f(colorR, colorG, colorB, 1.0F);
RenderHelper.bindTexture(texture);
int xPosition = posX();
gui.drawTexturedModalRect(xPosition, posY + 4, 0, 256 - currentHeight + 4, 4, currentHeight - 4);
gui.drawTexturedModalRect(xPosition + 4, posY, 256 - currentWidth + 4, 0, currentWidth - 4, 4);
gui.drawTexturedModalRect(xPosition, posY, 0, 0, 4, 4);
gui.drawTexturedModalRect(xPosition + 4, posY + 4, 256 - currentWidth + 4, 256 - currentHeight + 4, currentWidth - 4, currentHeight - 4);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
}
protected void drawTabIcon(String iconName) {
gui.drawIcon(iconName, posXOffset(), posY + 3, 1);
}
/**
* Shortcut to correct for the proper X position.
*/
protected int posX() {
if (side == LEFT) {
return posX - currentWidth;
}
return posX;
}
/**
* Corrects for shadowing differences in tabs to ensure that they always look nice - used in font rendering, typically.
*/
protected int posXOffset() {
return posX() + offset();
}
protected int offset() {
return (side == LEFT ? 4 : 2);
}
public boolean intersectsWith(int mouseX, int mouseY, int shiftX, int shiftY) {
if (side == LEFT) {
if (mouseX <= shiftX && mouseX >= shiftX - currentWidth && mouseY >= shiftY && mouseY <= shiftY + currentHeight) {
return true;
}
} else if (mouseX >= shiftX && mouseX <= shiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + currentHeight) {
return true;
}
return false;
}
public boolean isFullyOpened() {
return fullyOpen;
}
public void setFullyOpen() {
open = true;
currentWidth = maxWidth;
currentHeight = maxHeight;
fullyOpen = true;
}
public void toggleOpen() {
if (open) {
open = false;
if (side == LEFT) {
TabTracker.setOpenedLeftTab(null);
} else {
TabTracker.setOpenedRightTab(null);
}
fullyOpen = false;
} else {
open = true;
if (side == LEFT) {
TabTracker.setOpenedLeftTab(this.getClass());
} else {
TabTracker.setOpenedRightTab(this.getClass());
}
}
}
public Rectangle4i getBounds() {
return new Rectangle4i(posX() + gui.getGuiLeft(), posY + gui.getGuiTop(), currentWidth, currentHeight);
}
}

View file

@ -0,0 +1,14 @@
package com.pahimar.repackage.cofh.lib.gui.element.listbox;
import com.pahimar.repackage.cofh.lib.gui.element.ElementListBox;
public interface IListBoxElement {
public int getHeight();
public int getWidth();
public Object getValue();
public void draw(ElementListBox listBox, int x, int y, int backColor, int textColor);
}

View file

@ -0,0 +1,39 @@
package com.pahimar.repackage.cofh.lib.gui.element.listbox;
import com.pahimar.repackage.cofh.lib.gui.element.ElementListBox;
import net.minecraft.client.Minecraft;
public class ListBoxElementText implements IListBoxElement {
private final String _text;
public ListBoxElementText(String text) {
_text = text;
}
@Override
public Object getValue() {
return _text;
}
@Override
public int getHeight() {
return 10;
}
@Override
public int getWidth() {
return Minecraft.getMinecraft().fontRenderer.getStringWidth(_text);
}
@Override
public void draw(ElementListBox listBox, int x, int y, int backColor, int textColor) {
listBox.getFontRenderer().drawStringWithShadow(_text, x, y, textColor);
}
}

View file

@ -0,0 +1,26 @@
package com.pahimar.repackage.cofh.lib.gui.element.listbox;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.element.ElementSlider;
public abstract class SliderHorizontal extends ElementSlider {
protected SliderHorizontal(GuiBase containerScreen, int x, int y, int width, int height, int maxValue) {
super(containerScreen, x, y, width, height, maxValue);
setSliderSize(maxValue == 0 ? width : Math.max(width / maxValue, 9), height);
}
@Override
public int getSliderX() {
return Math.min(_valueMax == 0 ? 0 : (sizeX - _sliderWidth) * _value / _valueMax, sizeX - _sliderWidth);
}
@Override
public void dragSlider(int v, int y) {
v += Math.round(_sliderWidth * (v / (float) sizeX - 0.5f));
setValue(_valueMax * v / sizeX);
}
}

View file

@ -0,0 +1,26 @@
package com.pahimar.repackage.cofh.lib.gui.element.listbox;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.element.ElementSlider;
public abstract class SliderVertical extends ElementSlider {
protected SliderVertical(GuiBase containerScreen, int x, int y, int width, int height, int maxValue) {
super(containerScreen, x, y, width, height, maxValue);
setSliderSize(width, maxValue == 0 ? height : Math.max(height / maxValue, 9));
}
@Override
public int getSliderY() {
return Math.min(_valueMax == 0 ? 0 : (sizeY - _sliderHeight) * _value / _valueMax, sizeY - _sliderHeight);
}
@Override
public void dragSlider(int x, int v) {
v += Math.round(_sliderHeight * (v / (float) sizeY - 0.5f));
setValue(_valueMax * v / sizeY);
}
}

View file

@ -0,0 +1,17 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.item.ItemStack;
/**
* Interface used in conjunction with {@link SlotValidated}.
*
* @author King Lemming
*/
public interface ISlotValidator {
/**
* Essentially a passthrough so an arbitrary criterion can be checked against.
*/
boolean isItemValid(ItemStack stack);
}

View file

@ -0,0 +1,27 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
* Slot that will only accept ItemStacks whose items are a subclass of the given class.
*/
public class SlotAcceptAssignable extends Slot {
protected Class<? extends Item> clazz;
public SlotAcceptAssignable(IInventory inventory, int index, int x, int y, Class<? extends Item> c) {
super(inventory, index, x, y);
clazz = c;
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack != null && clazz.isInstance(stack.getItem());
}
}

View file

@ -0,0 +1,35 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
/**
* Slot that will only accept ItemStacks when the IInventory returns true from isItemValidForSlot.
* <p/>
* If an ISidedInventory, canInsertItem (from side 6 (UNKNOWN)) must also return true.
*/
public class SlotAcceptInsertable extends SlotAcceptValid {
protected ISidedInventory sidedInv;
public SlotAcceptInsertable(IInventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
if (inventory instanceof ISidedInventory) {
sidedInv = (ISidedInventory) inventory;
} else {
sidedInv = null;
}
}
@Override
public boolean isItemValid(ItemStack stack) {
boolean valid = super.isItemValid(stack);
return valid && sidedInv != null ? sidedInv.canInsertItem(slotNumber, stack, 6) : valid;
}
}

View file

@ -0,0 +1,23 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* Slot that will only accept ItemStacks when the IInventory returns true from isItemValidForSlot.
*/
public class SlotAcceptValid extends Slot {
public SlotAcceptValid(IInventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack != null && this.inventory.isItemValidForSlot(this.slotNumber, stack);
}
}

View file

@ -0,0 +1,32 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
/**
* Crafting result slot where the result cannot be removed.
*
* @author King Lemming
*/
public class SlotCraftingLocked extends SlotCrafting {
public SlotCraftingLocked(EntityPlayer player, IInventory craftMatrix, IInventory inventory, int index, int x, int y) {
super(player, craftMatrix, inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack stack) {
return false;
}
@Override
public boolean canTakeStack(EntityPlayer player) {
return false;
}
}

View file

@ -0,0 +1,45 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* Slot which copies an ItemStack when clicked on, does not decrement the ItemStack on the cursor.
*
* @author King Lemming
*/
public class SlotFalseCopy extends Slot {
public int slotIndex = 0;
public SlotFalseCopy(IInventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
slotIndex = index;
}
@Override
public boolean canTakeStack(EntityPlayer player) {
return false;
}
@Override
public boolean isItemValid(ItemStack stack) {
return true;
}
@Override
public void putStack(ItemStack stack) {
if (stack != null) {
stack.stackSize = 1;
}
this.inventory.setInventorySlotContents(this.slotIndex, stack);
this.onSlotChanged();
}
}

View file

@ -0,0 +1,57 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* Slot that will redirect inserts to another inventory slot (other than index), but not be visible.
* <p/>
* Used primarily for containers that have a larger internal inventory than external (e.g., DeepStorageUnit)
*/
public class SlotInvisible extends Slot {
protected final int slotIndex;
public SlotInvisible(IInventory inventory, int index, int x, int y, int slot) {
super(inventory, index, x, y);
slotIndex = slot;
}
@Override
public void putStack(ItemStack stack) {
this.inventory.setInventorySlotContents(slotIndex, stack);
this.onSlotChanged();
}
@Override
public ItemStack getStack() {
return null;
}
@Override
public ItemStack decrStackSize(int par1) {
return null;
}
@Override
public boolean canTakeStack(EntityPlayer p) {
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean func_111238_b() {
return false;
}
}

View file

@ -0,0 +1,24 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* Slot that will only accept Potions.
*/
public class SlotPotion extends Slot {
public SlotPotion(IInventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack != null && stack.getItem().equals(Items.potionitem);
}
}

View file

@ -0,0 +1,23 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* Slot that will only accept Potion Ingredients.
*/
public class SlotPotionIngredient extends Slot {
public SlotPotionIngredient(IInventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack != null && stack.getItem().isPotionIngredient(stack);
}
}

View file

@ -0,0 +1,23 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* Slot which players can only remove items from.
*/
public class SlotRemoveOnly extends Slot {
public SlotRemoveOnly(IInventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack stack) {
return false;
}
}

View file

@ -0,0 +1,28 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* A slot where the input can be validated based on any arbitrary criteria by using a passthrough method to an {@link ISlotValidator}.
*
* @author King Lemming
*/
public class SlotValidated extends Slot {
ISlotValidator validator;
public SlotValidated(ISlotValidator validator, IInventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
this.validator = validator;
}
@Override
public boolean isItemValid(ItemStack stack) {
return validator.isItemValid(stack);
}
}

View file

@ -0,0 +1,58 @@
package com.pahimar.repackage.cofh.lib.gui.slot;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* A slot that can only be used to display an item, not edited. Can optionally not highlight when moused over.
*/
public class SlotViewOnly extends Slot {
protected boolean showHighlight;
public SlotViewOnly(IInventory inventory, int index, int x, int y) {
this(inventory, index, x, y, false);
}
public SlotViewOnly(IInventory inventory, int index, int x, int y, boolean highlight) {
super(inventory, index, x, y);
showHighlight = highlight;
}
@Override
public void putStack(ItemStack stack) {
}
@Override
public ItemStack decrStackSize(int par1) {
return null;
}
@Override
public boolean canTakeStack(EntityPlayer p) {
return false;
}
@Override
public boolean isItemValid(ItemStack stack) {
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean func_111238_b() {
return showHighlight;
}
}

View file

@ -0,0 +1,177 @@
package com.pahimar.repackage.cofh.lib.render;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
/**
* Contains various helper functions to assist with rendering.
*
* @author King Lemming
*/
public final class RenderHelper {
public static final double RENDER_OFFSET = 1.0D / 1024.0D;
public static final ResourceLocation MC_BLOCK_SHEET = new ResourceLocation("textures/atlas/blocks.png");
public static final ResourceLocation MC_ITEM_SHEET = new ResourceLocation("textures/atlas/items.png");
public static final ResourceLocation MC_FONT_DEFAULT = new ResourceLocation("textures/font/ascii.png");
public static final ResourceLocation MC_FONT_ALTERNATE = new ResourceLocation("textures/font/ascii_sga.png");
public static final ResourceLocation MC_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
private RenderHelper() {
}
public static final TextureManager engine() {
return Minecraft.getMinecraft().renderEngine;
}
public static final Tessellator tessellator() {
return Tessellator.instance;
}
public static void setColor3ub(int color) {
GL11.glColor3ub((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF));
}
public static void setColor4ub(int color) {
GL11.glColor4ub((byte) (color >> 24 & 0xFF), (byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF));
}
public static void resetColor() {
GL11.glColor4f(1F, 1F, 1F, 1F);
}
public static void renderItemAsBlock(RenderBlocks renderer, ItemStack item, double translateX, double translateY, double translateZ) {
renderTextureAsBlock(renderer, item.getIconIndex(), translateX, translateY, translateZ);
}
public static void renderTextureAsBlock(RenderBlocks renderer, IIcon texture, double translateX, double translateY, double translateZ) {
Tessellator tessellator = Tessellator.instance;
Block block = Blocks.stone;
if (texture == null) {
return;
}
renderer.setRenderBoundsFromBlock(block);
GL11.glTranslated(translateX, translateY, translateZ);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1.0F, 0.0F);
renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, texture);
tessellator.setNormal(0.0F, 1.0F, 0.0F);
renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, texture);
tessellator.setNormal(0.0F, 0.0F, -1.0F);
renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, texture);
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, texture);
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, texture);
tessellator.setNormal(1.0F, 0.0F, 0.0F);
renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, texture);
tessellator.draw();
}
public static void renderItemIn2D(IIcon icon) {
ItemRenderer.renderItemIn2D(Tessellator.instance, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(), icon.getIconWidth(),
icon.getIconHeight(), 0.0625F);
}
public static void renderIcon(IIcon icon, double z) {
Tessellator.instance.startDrawingQuads();
Tessellator.instance.addVertexWithUV(0, 16, z, icon.getMinU(), icon.getMaxV());
Tessellator.instance.addVertexWithUV(16, 16, z, icon.getMaxU(), icon.getMaxV());
Tessellator.instance.addVertexWithUV(16, 0, z, icon.getMaxU(), icon.getMinV());
Tessellator.instance.addVertexWithUV(0, 0, z, icon.getMinU(), icon.getMinV());
Tessellator.instance.draw();
}
public static void renderIcon(double x, double y, double z, IIcon icon, int width, int height) {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(x, y + height, z, icon.getMinU(), icon.getMaxV());
tessellator.addVertexWithUV(x + width, y + height, z, icon.getMaxU(), icon.getMaxV());
tessellator.addVertexWithUV(x + width, y, z, icon.getMaxU(), icon.getMinV());
tessellator.addVertexWithUV(x, y, z, icon.getMinU(), icon.getMinV());
tessellator.draw();
}
public static final IIcon getFluidTexture(Fluid fluid) {
if (fluid == null) {
return FluidRegistry.LAVA.getIcon();
}
return fluid.getIcon();
}
public static final IIcon getFluidTexture(FluidStack fluid) {
if (fluid == null || fluid.getFluid() == null || fluid.getFluid().getIcon(fluid) == null) {
return FluidRegistry.LAVA.getIcon();
}
return fluid.getFluid().getIcon(fluid);
}
public static final void bindItemTexture(ItemStack stack) {
engine().bindTexture(stack.getItemSpriteNumber() == 0 ? MC_BLOCK_SHEET : MC_ITEM_SHEET);
}
public static final void bindTexture(ResourceLocation texture) {
engine().bindTexture(texture);
}
public static final void setBlockTextureSheet() {
bindTexture(MC_BLOCK_SHEET);
}
public static final void setItemTextureSheet() {
bindTexture(MC_ITEM_SHEET);
}
public static final void setDefaultFontTextureSheet() {
bindTexture(MC_FONT_DEFAULT);
}
public static final void setSGAFontTextureSheet() {
bindTexture(MC_FONT_ALTERNATE);
}
public static final void enableGUIStandardItemLighting() {
net.minecraft.client.renderer.RenderHelper.enableGUIStandardItemLighting();
}
}

View file

@ -0,0 +1,117 @@
package com.pahimar.repackage.cofh.lib.util;
/**
* Generic rectangle class.
*
* @author Chicken Bones
*/
public class Rectangle4i {
public int x;
public int y;
public int w;
public int h;
public Rectangle4i() {
}
public Rectangle4i(int x, int y, int w, int h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
public int x1() {
return x;
}
public int y1() {
return y;
}
public int x2() {
return x + w - 1;
}
public int y2() {
return y + h - 1;
}
public void set(int x, int y, int w, int h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
public Rectangle4i offset(int dx, int dy) {
x += dx;
y += dy;
return this;
}
public Rectangle4i include(int px, int py) {
if (px < x) {
expand(px - x, 0);
}
if (px >= x + w) {
expand(px - x - w + 1, 0);
}
if (py < y) {
expand(0, py - y);
}
if (py >= y + h) {
expand(0, py - y - h + 1);
}
return this;
}
public Rectangle4i include(Rectangle4i r) {
include(r.x, r.y);
return include(r.x2(), r.y2());
}
public Rectangle4i expand(int px, int py) {
if (px > 0) {
w += px;
} else {
x += px;
w -= px;
}
if (py > 0) {
h += py;
} else {
y += py;
h -= py;
}
return this;
}
public boolean contains(int px, int py) {
return x <= px && px < x + w && y <= py && py < y + h;
}
public boolean intersects(Rectangle4i r) {
return r.x + r.w > x && r.x < x + w && r.y + r.h > y && r.y < y + h;
}
public int area() {
return w * h;
}
}

View file

@ -0,0 +1,228 @@
package com.pahimar.repackage.cofh.lib.util.helpers;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.input.Keyboard;
import java.util.List;
/**
* Contains various helper functions to assist with String manipulation.
*
* @author King Lemming
*/
public final class StringHelper {
private StringHelper() {
}
/* KEY HELPERS */
public static boolean isAltKeyDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
}
public static boolean isControlKeyDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
}
public static boolean isShiftKeyDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
}
/* FORMAT HELPERS */
public static int getSplitStringHeight(FontRenderer fontRenderer, String input, int width) {
@SuppressWarnings("rawtypes")
List stringRows = fontRenderer.listFormattedStringToWidth(input, width);
return stringRows.size() * fontRenderer.FONT_HEIGHT;
}
public static String camelCase(String input) {
return input.substring(0, 1).toLowerCase() + input.substring(1);
}
public static String titleCase(String input) {
return input.substring(0, 1).toUpperCase() + input.substring(1);
}
public static String localize(String key) {
return StatCollector.translateToLocal(key);
}
public static String getFluidName(FluidStack stack) {
Fluid fluid = stack.getFluid();
String name = "" + END;
if (fluid.getRarity() == EnumRarity.uncommon) {
name += YELLOW;
} else if (fluid.getRarity() == EnumRarity.rare) {
name += BRIGHT_BLUE;
} else if (fluid.getRarity() == EnumRarity.epic) {
name += PINK;
}
name += fluid.getLocalizedName(stack) + END;
return name;
}
public static String getFluidName(FluidStack stack, String defaultName) {
if (stack == null) {
return defaultName;
}
return getFluidName(stack);
}
public static String getItemName(ItemStack stack) {
String name = "" + END;
if (stack.getRarity() == EnumRarity.uncommon) {
name += YELLOW;
} else if (stack.getRarity() == EnumRarity.rare) {
name += BRIGHT_BLUE;
} else if (stack.getRarity() == EnumRarity.epic) {
name += PINK;
}
name += stack.getDisplayName() + END;
return name;
}
public static String getScaledNumber(long number) {
return getScaledNumber(number, 2);
}
public static String getScaledNumber(long number, int minDigits) {
String numString = "";
int numMod = 10 ^ minDigits;
if (number > 100000000 * numMod) {
numString += number / 1000000000 + "G";
} else if (number > 100000 * numMod) {
numString += number / 1000000 + "M";
} else if (number > 100 * numMod) {
numString += number / 1000 + "k";
} else {
numString += number;
}
return numString;
}
/* ITEM TEXT HELPERS */
public static String getActivationText(String key) {
return BRIGHT_BLUE + localize(key) + END;
}
public static String getDeactivationText(String key) {
return YELLOW + localize(key) + END;
}
public static String getInfoText(String key) {
return BRIGHT_GREEN + localize(key) + END;
}
public static String getFlavorText(String key) {
return WHITE + ITALIC + localize(key) + END;
}
public static String getRarity(int level) {
switch (level) {
case 2:
return StringHelper.YELLOW;
case 3:
return StringHelper.BRIGHT_BLUE;
default:
return StringHelper.LIGHT_GRAY;
}
}
public static String shiftForDetails() {
return LIGHT_GRAY + localize("info.cofh.hold") + " " + YELLOW + ITALIC + localize("info.cofh.shift") + " " + END + LIGHT_GRAY
+ localize("info.cofh.forDetails") + END;
}
/* TUTORIAL TAB HELPERS */
public static String tutorialTabAugment() {
return localize("info.cofh.tutorial.tabAugment");
}
public static String tutorialTabConfiguration() {
return localize("info.cofh.tutorial.tabConfiguration.0");
}
public static String tutorialTabOperation() {
return localize("info.cofh.tutorial.tabConfiguration.1");
}
public static String tutorialTabRedstone() {
return localize("info.cofh.tutorial.tabRedstone");
}
public static String tutorialTabSecurity() {
return localize("info.cofh.tutorial.tabSecurity");
}
public static String tutorialTabFluxRequired() {
return localize("info.cofh.tutorial.fluxRequired");
}
/**
* When formatting a string, always apply color before font modification.
*/
public static final String BLACK = (char) 167 + "0";
public static final String BLUE = (char) 167 + "1";
public static final String GREEN = (char) 167 + "2";
public static final String TEAL = (char) 167 + "3";
public static final String RED = (char) 167 + "4";
public static final String PURPLE = (char) 167 + "5";
public static final String ORANGE = (char) 167 + "6";
public static final String LIGHT_GRAY = (char) 167 + "7";
public static final String GRAY = (char) 167 + "8";
public static final String LIGHT_BLUE = (char) 167 + "9";
public static final String BRIGHT_GREEN = (char) 167 + "a";
public static final String BRIGHT_BLUE = (char) 167 + "b";
public static final String LIGHT_RED = (char) 167 + "c";
public static final String PINK = (char) 167 + "d";
public static final String YELLOW = (char) 167 + "e";
public static final String WHITE = (char) 167 + "f";
public static final String OBFUSCATED = (char) 167 + "k";
public static final String BOLD = (char) 167 + "l";
public static final String STRIKETHROUGH = (char) 167 + "m";
public static final String UNDERLINE = (char) 167 + "n";
public static final String ITALIC = (char) 167 + "o";
public static final String END = (char) 167 + "r";
public static final String[] ROMAN_NUMERAL = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};
public static boolean displayShiftForDetail = true;
public static boolean displayStackCount = false;
}