Skip to content

Commit

Permalink
Finally got around to fixing #17
Browse files Browse the repository at this point in the history
Added support for IItemHandlers
  • Loading branch information
EdwinMindcraft committed Mar 19, 2018
1 parent 72f0121 commit c19a15b
Show file tree
Hide file tree
Showing 13 changed files with 2,501 additions and 2,491 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ buildscript {
}
}
repositories {
maven {
url "http://dvs1.progwml6.com/files/maven"
}
maven {
url = "http://dvs1.progwml6.com/files/maven"
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.matthewprenger.cursegradle'
Expand Down
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#Sat Dec 24 21:55:56 PST 2016
mcmapping=snapshot_20161111
version=1.5.0C
build_number=6
build_number=7
jei_version=3.7.8.+
mcversion=1.10.2
mod_name=ArsMagica2
mod_name=ArsMagica2
Binary file added libs/Chameleon-1.10.2-2.3.0.jar
Binary file not shown.
Binary file added libs/StorageDrawers-1.10.2-3.7.7.jar
Binary file not shown.
208 changes: 98 additions & 110 deletions src/main/java/am2/client/gui/GuiFlickerHabitat.java
Original file line number Diff line number Diff line change
@@ -1,110 +1,98 @@
package am2.client.gui;

import org.lwjgl.opengl.GL11;

import am2.api.ArsMagicaAPI;
import am2.api.flickers.AbstractFlickerFunctionality;
import am2.common.blocks.tileentity.TileEntityFlickerHabitat;
import am2.common.container.ContainerFlickerHabitat;
import am2.common.power.PowerNodeRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

/**
* @author Zero, Mithion
*/
public class GuiFlickerHabitat extends GuiContainer{

private static final ResourceLocation background = new ResourceLocation("arsmagica2", "textures/gui/FlickerHabitat.png");
private final TileEntityFlickerHabitat flickerHabitat;

/**
* @param par1Container
*/
public GuiFlickerHabitat(EntityPlayer player, TileEntityFlickerHabitat tileEntityFlickerHabitat){
super(new ContainerFlickerHabitat(player, tileEntityFlickerHabitat));
flickerHabitat = tileEntityFlickerHabitat;
xSize = 176;
ySize = 166;
}

/* (non-Javadoc)
* @see net.minecraft.client.gui.inventory.GuiContainer#drawGuiContainerBackgroundLayer(float, int, int)
*/
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j){
mc.renderEngine.bindTexture(background);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int l = (width - xSize) / 2;
int i1 = (height - ySize) / 2;
drawTexturedModalRect(l, i1, 0, 0, xSize, ySize);
}

@Override
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_){
super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_);

GlStateManager.enableBlend();
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

ItemStack stack = flickerHabitat.getStackInSlot(0);

if (stack == null) return;

AbstractFlickerFunctionality func = ArsMagicaAPI.getFlickerFocusRegistry().getObjectById(stack.getItemDamage());

if (func == null)
return;

String colorCode = Minecraft.getMinecraft().theWorld.isBlockIndirectlyGettingPowered(flickerHabitat.getPos()) > 0 ? "\2474" : "\2472";

int yPos = 5;
String curLine = "";

if (func.RequiresPower()){
curLine = I18n.format("am2.gui.flicker_needspower");
}else{
curLine = I18n.format("am2.gui.flicker_doesntneedpower");
}

drawCenteredString(curLine, yPos);
yPos += 12 * (int)Math.ceil(this.fontRendererObj.getStringWidth(curLine) / 170.0f);

drawCenteredString(
String.format(
I18n.format("am2.gui.flicker_powerperop"),
String.format("%s%d\2470", colorCode, func.PowerPerOperation())),
yPos);

yPos += 12;

boolean powered = PowerNodeRegistry.For(flickerHabitat.getWorld()).checkPower(flickerHabitat, func.PowerPerOperation());

if (yPos > 40)
yPos += 27;

drawCenteredString(
String.format(
I18n.format("am2.gui.flicker_optime"),
String.format("%s%.2f\2470", colorCode,
func.TimeBetweenOperation(powered, flickerHabitat.getNearbyUpgrades()) / 20.0f
)), yPos);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.disableBlend();
}

private void drawCenteredString(String s, int yCoord){
int w = this.fontRendererObj.getStringWidth(s);
int xPos = this.xSize / 2 - w / 2;
if (w > 170){
xPos = 3;
}
this.fontRendererObj.drawSplitString(s, xPos, yCoord, 170, 0);
}

}
package am2.client.gui;

import org.lwjgl.opengl.GL11;

import am2.api.ArsMagicaAPI;
import am2.api.flickers.AbstractFlickerFunctionality;
import am2.common.blocks.tileentity.TileEntityFlickerHabitat;
import am2.common.container.ContainerFlickerHabitat;
import am2.common.power.PowerNodeRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

/**
* @author Zero, Mithion
*/
public class GuiFlickerHabitat extends GuiContainer{

private static final ResourceLocation background = new ResourceLocation("arsmagica2", "textures/gui/FlickerHabitat.png");
private final TileEntityFlickerHabitat flickerHabitat;

public GuiFlickerHabitat(EntityPlayer player, TileEntityFlickerHabitat tileEntityFlickerHabitat){
super(new ContainerFlickerHabitat(player, tileEntityFlickerHabitat));
flickerHabitat = tileEntityFlickerHabitat;
xSize = 176;
ySize = 166;
}

/* (non-Javadoc)
* @see net.minecraft.client.gui.inventory.GuiContainer#drawGuiContainerBackgroundLayer(float, int, int)
*/
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j){
mc.renderEngine.bindTexture(background);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int l = (width - xSize) / 2;
int i1 = (height - ySize) / 2;
drawTexturedModalRect(l, i1, 0, 0, xSize, ySize);
}

@Override
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_){
super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_);

GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);

ItemStack stack = flickerHabitat.getStackInSlot(0);

if (stack == null) return;

AbstractFlickerFunctionality func = ArsMagicaAPI.getFlickerFocusRegistry().getObjectById(stack.getItemDamage());

if (func == null)
return;

String colorCode = Minecraft.getMinecraft().theWorld.isBlockIndirectlyGettingPowered(flickerHabitat.getPos()) > 0 ? "\2474" : "\2472";

int yPos = 5;
String curLine;

if (func.RequiresPower()){
curLine = I18n.format("am2.gui.flicker_needspower");
}else{
curLine = I18n.format("am2.gui.flicker_doesntneedpower");
}

drawCenteredString(curLine, yPos);
yPos += 12 * (int)Math.ceil(this.fontRendererObj.getStringWidth(curLine) / 170.0f);

drawCenteredString(I18n.format("am2.gui.flicker_powerperop", String.format("%s%d\2470", colorCode, func.PowerPerOperation())), yPos);

yPos += 12;

boolean powered = PowerNodeRegistry.For(flickerHabitat.getWorld()).checkPower(flickerHabitat, func.PowerPerOperation());

if (yPos > 40)
yPos += 27;

drawCenteredString(I18n.format("am2.gui.flicker_optime", String.format("%s%.2f\2470", colorCode, func.TimeBetweenOperation(powered, flickerHabitat.getNearbyUpgrades()) / 20.0f)), yPos);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.disableBlend();
}

private void drawCenteredString(String s, int yCoord){
int w = this.fontRendererObj.getStringWidth(s);
int xPos = this.xSize / 2 - w / 2;
if (w > 170){
xPos = 3;
}
this.fontRendererObj.drawSplitString(s, xPos, yCoord, 170, 0);
}

}
Loading

0 comments on commit c19a15b

Please sign in to comment.