-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #892 from bonii-xx/new_pr2
Rework Stencil Table
- Loading branch information
Showing
12 changed files
with
327 additions
and
65 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tconstruct.library.client; | ||
|
||
public class GuiElement { | ||
public final int buttonIconX; | ||
public final int buttonIconY; | ||
public final String domain; | ||
public final String texture; | ||
|
||
public GuiElement(int buttonIconX, int buttonIconY, String domain, String texture) { | ||
this.buttonIconX = buttonIconX; | ||
this.buttonIconY = buttonIconY; | ||
this.domain = domain; | ||
this.texture = texture; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/tconstruct/library/client/StencilGuiElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package tconstruct.library.client; | ||
|
||
public class StencilGuiElement extends GuiElement { | ||
public final int stencilIndex; | ||
|
||
public StencilGuiElement(int buttonIconX, int buttonIconY, int stencilIndex, String domain, String texture) { | ||
super(buttonIconX, buttonIconY, domain, texture); | ||
|
||
this.stencilIndex = stencilIndex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 2 additions & 9 deletions
11
src/main/java/tconstruct/library/client/ToolGuiElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
package tconstruct.library.client; | ||
|
||
public class ToolGuiElement | ||
public class ToolGuiElement extends GuiElement | ||
{ | ||
public final int slotType; | ||
public final int buttonIconX; | ||
public final int buttonIconY; | ||
public final int[] iconsX; | ||
public final int[] iconsY; | ||
public final String title; | ||
public final String body; | ||
public final String domain; | ||
public final String texture; | ||
|
||
public ToolGuiElement(int st, int bx, int by, int[] xi, int[] yi, String t, String b, String d, String tex) | ||
{ | ||
super(bx, by, d, tex); | ||
slotType = st; | ||
buttonIconX = bx; | ||
buttonIconY = by; | ||
iconsX = xi; | ||
iconsY = yi; | ||
title = t; | ||
body = b; | ||
domain = d; | ||
texture = tex; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/tconstruct/library/crafting/StencilBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package tconstruct.library.crafting; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.oredict.OreDictionary; | ||
|
||
import java.util.*; | ||
|
||
public class StencilBuilder { | ||
public static StencilBuilder instance = new StencilBuilder(); | ||
|
||
public List<ItemStack> blanks = new LinkedList<ItemStack>(); // i wish ItemStack would support equals so i could use a Set here... | ||
public List<ItemStack> stencils = new ArrayList<ItemStack>(); | ||
|
||
/** | ||
* Returns whether the given ItemStack is a blank pattern and therefore usable for stencil crafting. | ||
*/ | ||
public static boolean isBlank(ItemStack stack) | ||
{ | ||
for(ItemStack blank : instance.blanks) | ||
if(OreDictionary.itemMatches(stack, blank, false)) // this has nothing to do with the oredictionary. | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
public static void registerBlankStencil(ItemStack itemStack) | ||
{ | ||
instance.blanks.add(itemStack); | ||
} | ||
|
||
public static void registerStencil(Item item, int meta) | ||
{ | ||
instance.stencils.add(new ItemStack(item, 1, meta)); | ||
} | ||
|
||
public static void registerStencil(ItemStack pattern) | ||
{ | ||
instance.stencils.add(pattern); | ||
} | ||
|
||
public static List<ItemStack> getStencils() { return instance.stencils; } | ||
|
||
/** | ||
* Returns the index of the given stencil. If no stencil is found, returns -1. | ||
*/ | ||
public static int getIndex(ItemStack stencil) { | ||
for(int i = 0; i < instance.stencils.size(); i++) | ||
if(OreDictionary.itemMatches(stencil, getStencil(i), false)) | ||
return i; | ||
|
||
return -1; | ||
} | ||
|
||
// returns the stencil with the given index | ||
public static ItemStack getStencil(int num) { | ||
if(num >= instance.stencils.size()) | ||
return null; | ||
|
||
return instance.stencils.get(num).copy(); | ||
} | ||
|
||
public static int getStencilCount() { return instance.stencils.size(); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package tconstruct.tools.gui; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.util.ResourceLocation; | ||
import org.lwjgl.opengl.GL11; | ||
import tconstruct.library.client.StencilGuiElement; | ||
import tconstruct.library.client.ToolGuiElement; | ||
|
||
public class GuiButtonStencil extends GuiButton{ | ||
/** | ||
* True for pointing right (next page), false for pointing left (previous | ||
* page). | ||
*/ | ||
int textureX; | ||
int textureY; | ||
public String texture; | ||
public StencilGuiElement element; | ||
private static ResourceLocation background; | ||
|
||
public GuiButtonStencil(int id, int posX, int posY, int texX, int texY, String domain, String tex, StencilGuiElement e) | ||
{ | ||
super(id, posX, posY, 18, 18, ""); | ||
textureX = texX; | ||
textureY = texY; | ||
texture = tex; | ||
element = e; | ||
background = new ResourceLocation(domain, tex); | ||
} | ||
|
||
/** | ||
* Draws this button to the screen. | ||
*/ | ||
@Override | ||
public void drawButton (Minecraft mc, int mouseX, int mouseY) | ||
{ | ||
if (this.visible) | ||
{ | ||
boolean var4 = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; | ||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); | ||
mc.getTextureManager().bindTexture(background); | ||
|
||
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; | ||
int var5 = this.getHoverState(this.field_146123_n); | ||
int index = 18 * getHoverState(field_146123_n); | ||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 144 + index * 2, 234, 18, 18); | ||
this.drawTexturedModalRect(this.xPosition, this.yPosition, textureX * 18, textureY * 18, 18, 18); | ||
} | ||
} | ||
} |
Oops, something went wrong.