mirror of
https://github.com/GTNewHorizons/Draconic-Evolution.git
synced 2026-11-21 20:52:19 +00:00
02/01/2015
This commit is contained in:
1 parent
7727e41ed3
commit
f1cb44c391
20 files changed
+705
-104
No files matched your search
+51
-20
@@ -1,12 +1,10 @@
|
||||
package com.brandon3055.draconicevolution.client.interfaces.componentguis;
|
||||
|
||||
import com.brandon3055.draconicevolution.client.interfaces.guicomponents.*;
|
||||
import com.brandon3055.draconicevolution.client.interfaces.manual.GuiButtonAHeight;
|
||||
import com.brandon3055.draconicevolution.common.container.DummyContainer;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigValue;
|
||||
import com.brandon3055.draconicevolution.common.utills.LogHelper;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigField;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -17,9 +15,11 @@ import net.minecraft.util.ResourceLocation;
|
||||
*/
|
||||
public class GUIToolConfig extends GUIBase {
|
||||
|
||||
EntityPlayer player;
|
||||
public EntityPlayer player;
|
||||
private static final ResourceLocation inventoryTexture = new ResourceLocation(References.RESOURCESPREFIX + "textures/gui/ToolConfig.png");
|
||||
|
||||
private int screenLevel = 0;
|
||||
|
||||
public GUIToolConfig(EntityPlayer player) {
|
||||
super(new DummyContainer(), 198, 89);
|
||||
this.player = player;
|
||||
@@ -30,25 +30,19 @@ public class GUIToolConfig extends GUIBase {
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
buttonList.add(new GuiButtonAHeight(0, guiLeft + 3, guiTop + 25, 20, 12, "<="));
|
||||
((GuiButton)buttonList.get(0)).visible = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
((GuiButton)buttonList.get(0)).visible = false;
|
||||
collection.removeGroup("LIST_SCREEN");
|
||||
collection.setOnlyGroupEnabled("INV_SCREEN");
|
||||
collection.setGroupEnabled("BACKGROUND", true);
|
||||
LogHelper.info("button");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentCollection assembleComponents() {
|
||||
ComponentCollection c = new ComponentCollection(0, 0, xSize, ySize);
|
||||
ComponentCollection c = new ComponentCollection(0, 0, xSize, ySize, this);
|
||||
c.addComponent(new ComponentBackground(0, 0, 198, 89, inventoryTexture)).setGroup("BACKGROUND");
|
||||
c.addComponent(new ComponentButton(3, 26, 20, 12, 0, this, "<=", "Back")).setGroup("BUTTONS").setName("BACK_BUTTON");
|
||||
c.addComponent(new ComponentFieldAdjuster(4, 34, null, this)).setGroup("FIELD_BUTTONS").setName("FIELD_CONFIG_BUTTON_ARRAY");
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -67,13 +61,14 @@ public class GUIToolConfig extends GUIBase {
|
||||
collection.addComponent(new ComponentConfigItemButton(6, 7 + y * 19, 39 - y, player)).setGroup("INV_SCREEN");
|
||||
}
|
||||
|
||||
collection.setOnlyGroupEnabled("INV_SCREEN");
|
||||
collection.setGroupEnabled("BACKGROUND", true);
|
||||
setLevel(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
super.mouseClicked(x, y, button);
|
||||
if (buttonPressed) return;
|
||||
|
||||
|
||||
int fieldOffsetX = 24;
|
||||
int fieldOffsetY = 5;
|
||||
@@ -82,19 +77,55 @@ public class GUIToolConfig extends GUIBase {
|
||||
if (component.isEnabled() && component instanceof ComponentConfigItemButton && component.isMouseOver(x - this.guiLeft, y - this.guiTop) && ((ComponentConfigItemButton) component).hasValidItem){
|
||||
ItemStack stack = player.inventory.getStackInSlot(((ComponentConfigItemButton) component).slot);
|
||||
if (stack == null || !(stack.getItem() instanceof IConfigurableItem)) return;
|
||||
buttonPressed = true;
|
||||
IConfigurableItem item = (IConfigurableItem)stack.getItem();
|
||||
|
||||
for (ItemConfigValue field : item.getFields(stack, ((ComponentConfigItemButton) component).slot)){
|
||||
collection.addComponent(new ComponentFieldButton(fieldOffsetX, fieldOffsetY, player, field)).setGroup("LIST_SCREEN");
|
||||
setLevel(1);
|
||||
for (ItemConfigField field : item.getFields(stack, ((ComponentConfigItemButton) component).slot)){
|
||||
collection.addComponent(new ComponentFieldButton(fieldOffsetX, fieldOffsetY, player, field, this)).setGroup("LIST_SCREEN");
|
||||
fieldOffsetY += 12;
|
||||
}
|
||||
|
||||
collection.addComponent(new ComponentItemRenderer(3, 5, stack)).setGroup("LIST_SCREEN");
|
||||
collection.setOnlyGroupEnabled("LIST_SCREEN");
|
||||
collection.setGroupEnabled("BACKGROUND", true);
|
||||
((GuiButton)buttonList.get(0)).visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonClicked(int id) {
|
||||
super.buttonClicked(id);
|
||||
|
||||
if (id == 0 && screenLevel > 0){//button back
|
||||
setLevel(screenLevel - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLevel(int level){
|
||||
this.screenLevel = level;
|
||||
|
||||
if (level == 0){//inv screen
|
||||
collection.schedulRemoval("LIST_SCREEN");
|
||||
collection.setOnlyGroupEnabled("INV_SCREEN");
|
||||
collection.setGroupEnabled("BACKGROUND", true);
|
||||
collection.setComponentEnabled("BACK_BUTTON", false);
|
||||
}
|
||||
else if (level == 1){//list screen
|
||||
collection.setOnlyGroupEnabled("LIST_SCREEN");
|
||||
collection.setGroupEnabled("BACKGROUND", true);
|
||||
collection.setComponentEnabled("BACK_BUTTON", true);
|
||||
if (collection.getComponent("BACK_BUTTON") != null) collection.getComponent("BACK_BUTTON").setY(26);
|
||||
}
|
||||
else if (level == 2){//field screen
|
||||
collection.setOnlyGroupEnabled("FIELD_BUTTONS");
|
||||
collection.setGroupEnabled("BACKGROUND", true);
|
||||
collection.setComponentEnabled("BACK_BUTTON", true);
|
||||
if (collection.getComponent("BACK_BUTTON") != null) collection.getComponent("BACK_BUTTON").setY(3);
|
||||
}
|
||||
}
|
||||
|
||||
public void editField(ItemConfigField field){
|
||||
((ComponentFieldAdjuster) collection.getComponent("FIELD_CONFIG_BUTTON_ARRAY")).field = field;
|
||||
setLevel(2);
|
||||
}
|
||||
}
|
||||
+6
@@ -30,6 +30,7 @@ public abstract class ComponentBase extends Gui {
|
||||
public int width;
|
||||
/** The height of the screen object. */
|
||||
public int height;
|
||||
public String name;
|
||||
|
||||
public ComponentBase(int x, int y) {
|
||||
this.x = x;
|
||||
@@ -47,6 +48,11 @@ public abstract class ComponentBase extends Gui {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ComponentBase setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
+77
-3
@@ -1,36 +1,110 @@
|
||||
package com.brandon3055.draconicevolution.client.interfaces.guicomponents;
|
||||
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Brandon on 1/01/2015.
|
||||
*/
|
||||
public class ComponentButton extends ComponentBase {
|
||||
private static final ResourceLocation widgets = new ResourceLocation(References.RESOURCESPREFIX + "textures/gui/Widgets.png");
|
||||
protected static final ResourceLocation buttonTextures = new ResourceLocation("textures/gui/widgets.png");
|
||||
|
||||
|
||||
public int buttonId;
|
||||
public GUIBase gui;
|
||||
public int xSize;
|
||||
public int ySize;
|
||||
public int packedFGColour;
|
||||
public String displayString;
|
||||
public String hoverText;
|
||||
|
||||
public ComponentButton(int x, int y) {
|
||||
public ComponentButton(int x, int y, int xSize, int ySize, int id, GUIBase gui, String displayString) {
|
||||
super(x, y);
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.buttonId = id;
|
||||
this.gui = gui;
|
||||
this.displayString = displayString;
|
||||
}
|
||||
|
||||
public ComponentButton(int x, int y, int xSize, int ySize, int id, GUIBase gui, String displayString, String hoverText) {
|
||||
this(x, y, xSize, ySize, id, gui, displayString);
|
||||
this.hoverText = hoverText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 0;
|
||||
return xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 0;
|
||||
return ySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
//FontRenderer fontrenderer = minecraft.fontRenderer;
|
||||
minecraft.getTextureManager().bindTexture(buttonTextures);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
int k = isMouseOver(mouseX, mouseY) ? 2 : 1;
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
this.drawTexturedModalRect(this.x, this.y, 0, 46 + k * 20, this.xSize / 2, this.ySize);
|
||||
this.drawTexturedModalRect(this.x + this.xSize / 2, this.y, 200 - this.xSize / 2, 46 + k * 20, this.xSize / 2, this.ySize);
|
||||
if (this.ySize < 20){
|
||||
|
||||
this.drawTexturedModalRect(x, y+3, 0, (46 + k * 20)+20-ySize+3, xSize / 2, ySize-3);
|
||||
this.drawTexturedModalRect(x + xSize / 2, y+3, 200 - xSize / 2, (46 + k * 20)+20-ySize+3, xSize / 2, ySize-3);
|
||||
}
|
||||
//this.mouseDragged(minecraft, mouseX, mouseY);
|
||||
int l = 14737632;
|
||||
|
||||
if (packedFGColour != 0)
|
||||
{
|
||||
l = packedFGColour;
|
||||
}
|
||||
else if (!this.enabled)
|
||||
{
|
||||
l = 10526880;
|
||||
}
|
||||
else if (isMouseOver(mouseX, mouseY))
|
||||
{
|
||||
l = 16777120;
|
||||
}
|
||||
this.drawCenteredString(fontRendererObj, this.displayString, this.x + this.xSize / 2, this.y + (this.ySize - 8) / 2, l);
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderForground(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFinal(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
if (isMouseOver(mouseX, mouseY) && hoverText != null){
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(hoverText);
|
||||
drawHoveringText(list, mouseX + offsetX, mouseY + offsetY + 10, fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int button) {
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
gui.buttonClicked(buttonId);
|
||||
}
|
||||
}
|
||||
+33
-3
@@ -13,12 +13,15 @@ public class ComponentCollection extends ComponentBase {
|
||||
protected List<ComponentBase> components = new ArrayList<ComponentBase>();
|
||||
protected int xSize;
|
||||
protected int ySize;
|
||||
protected List<String> deadGroups = new ArrayList<String>();
|
||||
protected GUIBase gui;
|
||||
|
||||
|
||||
public ComponentCollection(int x, int y, int xSize, int ySize) {
|
||||
public ComponentCollection(int x, int y, int xSize, int ySize, GUIBase gui) {
|
||||
super(x, y);
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,19 +71,27 @@ public class ComponentCollection extends ComponentBase {
|
||||
if (isComponentEnabled(component)) {
|
||||
component.renderFinal(minecraft, offsetX + this.x, offsetY + this.y, mouseX - this.x, mouseY - this.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int button) {
|
||||
for (ComponentBase component : components){
|
||||
if (component.isEnabled() && component.isMouseOver(x, y)) {
|
||||
if (!gui.buttonPressed && component.isEnabled() && component.isMouseOver(x, y)) {
|
||||
component.mouseClicked(x, y, button);
|
||||
}
|
||||
}
|
||||
//removeScheduled();
|
||||
}
|
||||
|
||||
public List<ComponentBase> getComponents() { return components; }
|
||||
|
||||
public ComponentBase getComponent(String name){
|
||||
for (ComponentBase component : components){
|
||||
if (component.name != null && component.name.equals(name)) return component;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setGroupEnabled(String group, boolean enabled){
|
||||
for (ComponentBase component : components){
|
||||
if (component.getGroup().equals(group)) {
|
||||
@@ -101,6 +112,14 @@ public class ComponentCollection extends ComponentBase {
|
||||
}
|
||||
}
|
||||
|
||||
public void setComponentEnabled(String name, boolean enabled){
|
||||
for (ComponentBase component : components){
|
||||
if (component.name != null && component.name.equals(name)) {
|
||||
component.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeGroup(String group){
|
||||
List<ComponentBase> list = new ArrayList<ComponentBase>();
|
||||
for (ComponentBase component : components){
|
||||
@@ -116,4 +135,15 @@ public class ComponentCollection extends ComponentBase {
|
||||
component.setWorldAndResolution(mc, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeScheduled(){
|
||||
if (!deadGroups.isEmpty()){
|
||||
for (String s : deadGroups) removeGroup(s);
|
||||
deadGroups.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void schedulRemoval(String group){
|
||||
deadGroups.add(group);
|
||||
}
|
||||
}
|
||||
+15
-1
@@ -2,12 +2,16 @@ package com.brandon3055.draconicevolution.client.interfaces.guicomponents;
|
||||
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigField;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Brandon on 29/12/2014.
|
||||
*/
|
||||
@@ -22,7 +26,7 @@ public class ComponentConfigItemButton extends ComponentBase {
|
||||
super(x, y);
|
||||
this.slot = slot;
|
||||
this.inventory = player.inventory;
|
||||
if (inventory.getStackInSlot(slot) != null && inventory.getStackInSlot(slot).getItem() instanceof IConfigurableItem) hasValidItem = true;//todo && instanceof IConfigurableItem
|
||||
if (inventory.getStackInSlot(slot) != null && inventory.getStackInSlot(slot).getItem() instanceof IConfigurableItem && !((IConfigurableItem) inventory.getStackInSlot(slot).getItem()).getFields(inventory.getStackInSlot(slot), slot).isEmpty()) hasValidItem = true;//todo && instanceof IConfigurableItem
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,6 +56,16 @@ public class ComponentConfigItemButton extends ComponentBase {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFinal(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
if (isMouseOver(mouseX, mouseY) && hasValidItem){
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<ItemConfigField> fields = ((IConfigurableItem)inventory.getStackInSlot(slot).getItem()).getFields(inventory.getStackInSlot(slot), slot);
|
||||
for (ItemConfigField field : fields) list.add(field.getLocalizedName() + ": " + field.value);
|
||||
drawHoveringText(list, mouseX + offsetX, mouseY + offsetY + 10, fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int button) {
|
||||
if (hasValidItem){
|
||||
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
package com.brandon3055.draconicevolution.client.interfaces.guicomponents;
|
||||
|
||||
import com.brandon3055.draconicevolution.client.interfaces.componentguis.GUIToolConfig;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.utills.DataUtills;
|
||||
import com.brandon3055.draconicevolution.common.utills.GuiHelper;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigField;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Created by Brandon on 1/01/2015.
|
||||
*/
|
||||
public class ComponentFieldAdjuster extends ComponentBase {
|
||||
private static final ResourceLocation widgets = new ResourceLocation(References.RESOURCESPREFIX + "textures/gui/Widgets.png");
|
||||
protected static final ResourceLocation buttonTextures = new ResourceLocation("textures/gui/widgets.png");
|
||||
|
||||
public ItemConfigField field;
|
||||
public GUIToolConfig gui;
|
||||
|
||||
public ComponentFieldAdjuster(int x, int y, ItemConfigField field, GUIToolConfig gui) {
|
||||
super(x, y);
|
||||
this.field = field;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 190;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
if (field == null) return;
|
||||
minecraft.getTextureManager().bindTexture(buttonTextures);
|
||||
|
||||
if (isBoolean())
|
||||
{
|
||||
renderButton((getWidth() / 2) - 30, 0, 60, 20, GuiHelper.isInRect(x + (getWidth() / 2) - 30, y, 60, 20, mouseX - offsetX, mouseY - offsetY));
|
||||
}else if (isDecimal() || isNonDecimal())
|
||||
{
|
||||
renderButton((getWidth() / 2) - 39, 3, 26, 14, GuiHelper.isInRect(x + (getWidth() / 2) - 39, y + 3, 26, 14, mouseX - offsetX, mouseY - offsetY));
|
||||
renderButton((getWidth() / 2) - 67, 3, 26, 14, GuiHelper.isInRect(x + (getWidth() / 2) - 67, y + 3, 26, 14, mouseX - offsetX, mouseY - offsetY));
|
||||
renderButton((getWidth() / 2) - 95, 3, 26, 14, GuiHelper.isInRect(x + (getWidth() / 2) - 95, y + 3, 26, 14, mouseX - offsetX, mouseY - offsetY));
|
||||
|
||||
renderButton((getWidth() / 2) + 12, 3, 26, 14, GuiHelper.isInRect(x + (getWidth() / 2) + 12, y + 3, 26, 14, mouseX - offsetX, mouseY - offsetY));
|
||||
renderButton((getWidth() / 2) + 40, 3, 26, 14, GuiHelper.isInRect(x + (getWidth() / 2) + 40, y + 3, 26, 14, mouseX - offsetX, mouseY - offsetY));
|
||||
renderButton((getWidth() / 2) + 68, 3, 26, 14, GuiHelper.isInRect(x + (getWidth() / 2) + 68, y + 3, 26, 14, mouseX - offsetX, mouseY - offsetY));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderForground(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
if (field == null) return;
|
||||
String s = field.name;
|
||||
String s2 = String.valueOf(field.value);
|
||||
if (field.datatype == References.DOUBLE_ID) {
|
||||
double d = (Double)field.value;
|
||||
s2 = String.valueOf((double)Math.round(d*100f) / 100D);
|
||||
}
|
||||
if (field.datatype == References.FLOAT_ID) {
|
||||
float d = (Float)field.value;
|
||||
s2 = String.valueOf((double)Math.round((double)(d*100f)) / 100D);
|
||||
}
|
||||
int centre = fontRendererObj.getStringWidth(s) / 2;
|
||||
int centre2 = fontRendererObj.getStringWidth(s2) / 2;
|
||||
fontRendererObj.drawString(s, x + getWidth() / 2 - centre, y - 12, 0x00000);
|
||||
fontRendererObj.drawStringWithShadow(s2, x + getWidth() / 2 - centre2, y + 6, 0xffffff);
|
||||
|
||||
if (isDecimal() || isNonDecimal())
|
||||
{
|
||||
fontRendererObj.drawString("+++", 8, y + 6, 0x000000);
|
||||
fontRendererObj.drawString("++", 40, y + 6, 0x000000);
|
||||
fontRendererObj.drawString("+", 70, y + 6, 0x000000);
|
||||
fontRendererObj.drawString("-", 121, y + 6, 0x000000);
|
||||
fontRendererObj.drawString("--", 147, y + 6, 0x000000);
|
||||
fontRendererObj.drawString("---", 172, y + 6, 0x000000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFinal(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
if (field == null) return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int button) {
|
||||
if (field == null) return;
|
||||
|
||||
if (!isBoolean())
|
||||
{
|
||||
if (GuiHelper.isInRect(this.x + (getWidth() / 2) - 39, this.y + 3, 26, 14, x, y))
|
||||
{//+
|
||||
incroment(1);
|
||||
} else if (GuiHelper.isInRect(this.x + (getWidth() / 2) - 67, this.y + 3, 26, 14, x, y))
|
||||
{//++
|
||||
incroment(10);
|
||||
} else if (GuiHelper.isInRect(this.x + (getWidth() / 2) - 95, this.y + 3, 26, 14, x, y))
|
||||
{//+++
|
||||
incroment(100);
|
||||
} else if (GuiHelper.isInRect(this.x + (getWidth() / 2) + 12, this.y + 3, 26, 14, x, y))
|
||||
{//-
|
||||
incroment(-1);
|
||||
} else if (GuiHelper.isInRect(this.x + (getWidth() / 2) + 40, this.y + 3, 26, 14, x, y))
|
||||
{//--
|
||||
incroment(-10);
|
||||
} else if (GuiHelper.isInRect(this.x + (getWidth() / 2) + 68, this.y + 3, 26, 14, x, y))
|
||||
{//---
|
||||
incroment(-100);
|
||||
}
|
||||
}
|
||||
else if (GuiHelper.isInRect(this.x + (getWidth() / 2) - 30, this.y, 60, 20, x, y)){
|
||||
incroment(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void incroment(int multiplyer){
|
||||
switch (field.datatype){
|
||||
case References.BYTE_ID:
|
||||
byte b = (Byte)field.value;
|
||||
b += (Byte)field.incroment * (byte)multiplyer;
|
||||
if (b > (Byte)field.max) b = (Byte) field.max;
|
||||
if (b < (Byte)field.min) b = (Byte) field.min;
|
||||
field.value = b;
|
||||
break;
|
||||
case References.SHORT_ID:
|
||||
short s = (Short)field.value;
|
||||
s += (Short)field.incroment * (short)multiplyer;
|
||||
if (s > (Short)field.max) s = (Short) field.max;
|
||||
if (s < (Short)field.min) s = (Short) field.min;
|
||||
field.value = s;
|
||||
break;
|
||||
case References.INT_ID:
|
||||
int i = (Integer)field.value;
|
||||
i += (Integer)field.incroment * multiplyer;
|
||||
if (i > (Integer)field.max) i = (Integer) field.max;
|
||||
if (i < (Integer)field.min) i = (Integer) field.min;
|
||||
field.value = i;
|
||||
break;
|
||||
case References.LONG_ID:
|
||||
long l = (Long)field.value;
|
||||
l += (Long)field.incroment * (long)multiplyer;
|
||||
if (l > (Long)field.max) l = (Long) field.max;
|
||||
if (l < (Long)field.min) l = (Long) field.min;
|
||||
field.value = l;
|
||||
break;
|
||||
case References.FLOAT_ID:
|
||||
float f = (Float)field.value;
|
||||
f += (Float)field.incroment * (float)multiplyer;
|
||||
f *= 100F;
|
||||
f = Math.round(f);
|
||||
f /= 100F;
|
||||
if (f > (Float)field.max) f = (Float) field.max;
|
||||
if (f < (Float)field.min) f = (Float) field.min;
|
||||
field.value = f;
|
||||
break;
|
||||
case References.DOUBLE_ID:
|
||||
double d = (Double)field.value;
|
||||
d += (Double)field.incroment * (double)multiplyer;
|
||||
if (d > (Double)field.max) d = (Double) field.max;
|
||||
if (d < (Double)field.min) d = (Double) field.min;
|
||||
field.value = d;
|
||||
break;
|
||||
case References.BOOLEAN_ID:
|
||||
field.value = !(Boolean)field.value;
|
||||
break;
|
||||
}
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
ItemStack stack = gui.player.inventory.getStackInSlot(field.slot);
|
||||
if (stack != null && stack.getItem() instanceof IConfigurableItem){
|
||||
DataUtills.writeObjectToItem(stack, field.value, field.datatype, field.name);
|
||||
}
|
||||
field.sendChanges();
|
||||
}
|
||||
|
||||
public void renderButton(int offsetX, int offsetY, int xSize, int ySize, boolean highlighted){
|
||||
int k = highlighted ? 2 : 1;
|
||||
int x = this.x + offsetX;
|
||||
int y = this.y + offsetY;
|
||||
|
||||
this.drawTexturedModalRect(x, y, 0, 46 + k * 20, xSize /2, 20 - Math.max(0, 20 - ySize));
|
||||
this.drawTexturedModalRect(x + xSize / 2, y, 200 - xSize / 2, 46 + k * 20, xSize / 2, 20 - Math.max(0, 20-ySize));
|
||||
|
||||
if (ySize < 20){
|
||||
this.drawTexturedModalRect(x, y+3, 0, (46 + k * 20)+20-ySize+3, xSize -1, ySize-3);
|
||||
this.drawTexturedModalRect(x + xSize / 2, y+3, 200 - xSize / 2, (46 + k * 20)+20-ySize+3, xSize / 2, ySize-3);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBoolean(){ return field.datatype == References.BOOLEAN_ID; }
|
||||
|
||||
private boolean isNonDecimal(){ return field.datatype == References.INT_ID || field.datatype == References.SHORT_ID || field.datatype == References.BYTE_ID; }
|
||||
|
||||
private boolean isDecimal(){ return field.datatype == References.FLOAT_ID || field.datatype == References.DOUBLE_ID; }
|
||||
}
|
||||
+27
-6
@@ -1,8 +1,12 @@
|
||||
package com.brandon3055.draconicevolution.client.interfaces.guicomponents;
|
||||
|
||||
import com.brandon3055.draconicevolution.client.interfaces.componentguis.GUIToolConfig;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigValue;
|
||||
import com.brandon3055.draconicevolution.common.utills.DataUtills;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigField;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -15,19 +19,21 @@ import java.util.List;
|
||||
*/
|
||||
public class ComponentFieldButton extends ComponentBase {
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation(References.RESOURCESPREFIX + "textures/gui/Widgets.png");
|
||||
private static final ResourceLocation widgets = new ResourceLocation(References.RESOURCESPREFIX + "textures/gui/Widgets.png");
|
||||
|
||||
public EntityPlayer player;
|
||||
public int slot;
|
||||
public ItemStack stack;
|
||||
public ItemConfigValue field;
|
||||
public ItemConfigField field;
|
||||
public GUIToolConfig gui;
|
||||
|
||||
public ComponentFieldButton(int x, int y, EntityPlayer player, ItemConfigValue field) {
|
||||
public ComponentFieldButton(int x, int y, EntityPlayer player, ItemConfigField field, GUIToolConfig gui) {
|
||||
super(x, y);
|
||||
this.player = player;
|
||||
this.slot = field.slot;
|
||||
this.stack = player.inventory.getStackInSlot(slot);
|
||||
this.field = field;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +48,7 @@ public class ComponentFieldButton extends ComponentBase {
|
||||
|
||||
@Override
|
||||
public void renderBackground(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(widgets);
|
||||
|
||||
if (!isMouseOver(mouseX - offsetX, mouseY - offsetY))
|
||||
{
|
||||
@@ -64,7 +70,7 @@ public class ComponentFieldButton extends ComponentBase {
|
||||
|
||||
@Override
|
||||
public void renderForground(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
drawString(fontRendererObj, field.name, x + offsetX + 2, y + offsetY + (getHeight() / 2) - (fontRendererObj.FONT_HEIGHT / 2), 0xffffff);
|
||||
drawString(fontRendererObj, field.getLocalizedName(), x + offsetX + 2, y + offsetY + (getHeight() / 2) - (fontRendererObj.FONT_HEIGHT / 2), 0xffffff);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -76,4 +82,19 @@ public class ComponentFieldButton extends ComponentBase {
|
||||
drawHoveringText(list, mouseX + offsetX, mouseY + offsetY + 10, fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int button) {
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
if (field.datatype == References.BOOLEAN_ID){
|
||||
field.value = !(Boolean) field.value;
|
||||
field.sendChanges();
|
||||
ItemStack stack = gui.player.inventory.getStackInSlot(field.slot);
|
||||
if (stack != null && stack.getItem() instanceof IConfigurableItem){
|
||||
DataUtills.writeObjectToItem(stack, field.value, field.datatype, field.name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
gui.editField(field);
|
||||
}
|
||||
}
|
||||
+11
@@ -15,6 +15,8 @@ import org.lwjgl.opengl.GL12;
|
||||
public abstract class GUIBase extends GuiContainer {
|
||||
|
||||
protected ComponentCollection collection;
|
||||
/**used to prevent multiple buttons being pressed wen overlapping components are changed*/
|
||||
protected boolean buttonPressed = false;
|
||||
|
||||
public GUIBase(Container container, int xSize, int ySize) {
|
||||
super(container);
|
||||
@@ -110,4 +112,13 @@ public abstract class GUIBase extends GuiContainer {
|
||||
collection.setWorldAndResolution(mc, width, height);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
collection.removeScheduled();
|
||||
buttonPressed = false;
|
||||
}
|
||||
|
||||
public void buttonClicked(int id){buttonPressed = true;}
|
||||
}
|
||||
@@ -105,6 +105,7 @@ public class CommonProxy {
|
||||
DraconicEvolution.network.registerMessage(TileObjectPacket.Handler.class, TileObjectPacket.class, 6, Side.CLIENT);
|
||||
DraconicEvolution.network.registerMessage(MountUpdatePacket.Handler.class, MountUpdatePacket.class, 7, Side.CLIENT);
|
||||
DraconicEvolution.network.registerMessage(MountUpdatePacket.Handler.class, MountUpdatePacket.class, 8, Side.SERVER);
|
||||
DraconicEvolution.network.registerMessage(ItemConfigPacket.Handler.class, ItemConfigPacket.class, 9, Side.SERVER);
|
||||
}
|
||||
|
||||
public void registerTileEntities() {
|
||||
|
||||
@@ -33,6 +33,8 @@ public class FMLEventHandler {
|
||||
if (event.phase != TickEvent.Phase.START)return;
|
||||
EntityPlayer player = event.player;
|
||||
|
||||
//Reset Walk Speed----------------------------------------------------------------------------------------------
|
||||
|
||||
if (walkSpeed == null){
|
||||
walkSpeed = ReflectionHelper.findField(PlayerCapabilities.class, "walkSpeed", "g", "field_75097_g");
|
||||
walkSpeed.setAccessible(true);
|
||||
@@ -49,6 +51,8 @@ public class FMLEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
//Apply Hill Step-----------------------------------------------------------------------------------------------
|
||||
|
||||
if (player.worldObj.isRemote) {
|
||||
boolean highStepListed = playersWithUphillStep.contains(player.getDisplayName()) && player.stepHeight >= 1f;
|
||||
boolean hasHighStep = ArmorEffectHandler.getHasHighStep(player);
|
||||
@@ -64,22 +68,24 @@ public class FMLEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
//Apply Swiftness-----------------------------------------------------------------------------------------------
|
||||
|
||||
if (ArmorEffectHandler.getHasSwiftness(player)) {
|
||||
int i = ArmorEffectHandler.getSwiftnessLevel(player);
|
||||
|
||||
float percentIncrease = (i + 1) * 0.05f;
|
||||
|
||||
float percentIncrease = ArmorEffectHandler.getSwiftnessMultiplier(player) * ((i + 1) * 0.05f);
|
||||
|
||||
if ((player.onGround || player.capabilities.isFlying) && player.moveForward > 0F)
|
||||
player.moveFlying(0F, 1F, player.capabilities.isFlying ? (percentIncrease / 2.0f) : percentIncrease);
|
||||
|
||||
}
|
||||
|
||||
//Apply Flight--------------------------------------------------------------------------------------------------
|
||||
|
||||
if (ArmorEffectHandler.getHasFlight(player)) {
|
||||
playersWithFlight.put(player, true);
|
||||
player.capabilities.allowFlying = true;
|
||||
if (ArmorEffectHandler.getFlightLock(player)) player.capabilities.isFlying = true;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
+12
-1
@@ -69,7 +69,7 @@ public class MinecraftForgeEventHandler {
|
||||
if (ArmorEffectHandler.getHasJumpBoost(player))
|
||||
{
|
||||
int i = ArmorEffectHandler.getJumpLevel(player);
|
||||
event.entityLiving.motionY += (0.1f) * (2 + i);
|
||||
event.entityLiving.motionY += ArmorEffectHandler.getJumpMultiplier(player) * ((0.1f) * (2 + i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,6 +233,17 @@ public class MinecraftForgeEventHandler {
|
||||
@SubscribeEvent
|
||||
public void itemTooltipEvent(ItemTooltipEvent event) {
|
||||
if (ConfigHandler.showUnlocalizedNames) event.toolTip.add(event.itemStack.getUnlocalizedName());
|
||||
if (DraconicEvolution.debug && event.itemStack.hasTagCompound()){
|
||||
String s = event.itemStack.getTagCompound().toString();
|
||||
int escape = 0;
|
||||
while (s.contains(",")){
|
||||
event.toolTip.add(s.substring(0, s.indexOf(",")+1));
|
||||
s = s.substring(s.indexOf(",")+1, s.length());
|
||||
|
||||
if (escape++ >= 100) break;
|
||||
}
|
||||
event.toolTip.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
+25
-6
@@ -1,6 +1,7 @@
|
||||
package com.brandon3055.draconicevolution.common.items.armor;
|
||||
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemNBTHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -14,37 +15,55 @@ public class ArmorEffectHandler {
|
||||
// slotLeggs = 2;
|
||||
// slotBoots = 1;
|
||||
|
||||
//Flight------------------------------------------------------------------------------------------------------------
|
||||
public static boolean getHasFlight(EntityPlayer player){
|
||||
return isDraconicArmor(player, 3) && ((IEnergyContainerItem)player.getEquipmentInSlot(3).getItem()).extractEnergy(player.getEquipmentInSlot(3), 80, !player.capabilities.isFlying) == 80;
|
||||
return isDraconicArmor(player, 3);// && ((IEnergyContainerItem)player.getEquipmentInSlot(3).getItem()).extractEnergy(player.getEquipmentInSlot(3), 80, !player.capabilities.isFlying) == 80;
|
||||
}
|
||||
|
||||
public static boolean getFlightLock(EntityPlayer player){
|
||||
return ItemNBTHelper.getBoolean(player.getEquipmentInSlot(3), "ArmorFlightLock", false);
|
||||
}
|
||||
|
||||
//Swiftness---------------------------------------------------------------------------------------------------------
|
||||
public static boolean getHasSwiftness(EntityPlayer player){
|
||||
return isDraconicArmor(player, 2) || isWyvernArmor(player, 2);
|
||||
}
|
||||
|
||||
public static int getSwiftnessLevel(EntityPlayer player){
|
||||
int i = isWyvernArmor(player, 2) ? 1 : isDraconicArmor(player, 2) ? 2 : 0;
|
||||
return player.isSprinting() ? i * 2 : i;
|
||||
int i = isWyvernArmor(player, 2) ? 2 : isDraconicArmor(player, 2) ? 4 : 0;
|
||||
return (player.isSprinting() || !ItemNBTHelper.getBoolean(player.getEquipmentInSlot(2), "ArmorSprintOnly", false)) ? i * 2 : i;
|
||||
}
|
||||
|
||||
public static float getSwiftnessMultiplier(EntityPlayer player){
|
||||
return ItemNBTHelper.getFloat(player.getEquipmentInSlot(2), "ArmorSpeedMult", 1f);
|
||||
}
|
||||
|
||||
//Jump Boost--------------------------------------------------------------------------------------------------------
|
||||
public static boolean getHasJumpBoost(EntityPlayer player){
|
||||
return (isDraconicArmor(player, 1) || isWyvernArmor(player, 1)) && extractEnergy(player, (getJumpLevel(player)+1)*80, 1);
|
||||
}
|
||||
|
||||
public static int getJumpLevel(EntityPlayer player){
|
||||
int i = isWyvernArmor(player, 1) ? 1 : isDraconicArmor(player, 1) ? 2 : 0;
|
||||
return player.isSprinting() ? i * 2 : i;
|
||||
int i = isWyvernArmor(player, 1) ? 2 : isDraconicArmor(player, 1) ? 4 : 0;
|
||||
return (player.isSprinting() || !ItemNBTHelper.getBoolean(player.getEquipmentInSlot(1), "ArmorSprintOnly", false)) ? i * 2 : i;
|
||||
}
|
||||
|
||||
public static float getJumpMultiplier(EntityPlayer player){
|
||||
return ItemNBTHelper.getFloat(player.getEquipmentInSlot(1), "ArmorJumpMult", 1f);
|
||||
}
|
||||
|
||||
//Fire Immunity-----------------------------------------------------------------------------------------------------
|
||||
public static boolean getFireImunity(EntityPlayer player){
|
||||
if (isDraconicArmor(player, 3) && extractEnergy(player, 80, 3)) return true;
|
||||
return (isWyvernArmor(player, 1) && isWyvernArmor(player, 2) && isWyvernArmor(player, 3) && isWyvernArmor(player, 4));
|
||||
}
|
||||
|
||||
//Hill Step---------------------------------------------------------------------------------------------------------
|
||||
public static boolean getHasHighStep(EntityPlayer player){
|
||||
return isDraconicArmor(player, 1);
|
||||
return isDraconicArmor(player, 1) && ItemNBTHelper.getBoolean(player.getEquipmentInSlot(1), "ArmorHillStep", true);
|
||||
}
|
||||
|
||||
//Armor & Energy----------------------------------------------------------------------------------------------------
|
||||
public static boolean isWyvernArmor(EntityPlayer player, int slot){
|
||||
int slotType = 4 - slot;
|
||||
ItemStack armor = player.getEquipmentInSlot(slot);
|
||||
|
||||
+16
-17
@@ -7,7 +7,7 @@ import com.brandon3055.draconicevolution.common.entity.EntityPersistentItem;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.InfoHelper;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigValue;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigField;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemNBTHelper;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
@@ -52,11 +52,6 @@ public class DraconicArmor extends ItemArmor implements ISpecialArmor, IEnergyCo
|
||||
this.setUnlocalizedName(name);
|
||||
this.setCreativeTab(DraconicEvolution.tabToolsWeapons);
|
||||
GameRegistry.registerItem(this, name);
|
||||
|
||||
// fieldsHelm.put("NVActive", References.BOOLEAN_ID);
|
||||
// fieldsChest.put("FlightLock", References.BOOLEAN_ID);
|
||||
// fieldsLeggs.put("SpeedMult", References.FLOAT_ID);
|
||||
// fieldsLeggs.put("JumpMult", References.FLOAT_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -173,8 +168,8 @@ public class DraconicArmor extends ItemArmor implements ISpecialArmor, IEnergyCo
|
||||
if (stack.getItem() == ModItems.draconicHelm) {
|
||||
if (world.isRemote) return;
|
||||
if (this.getEnergyStored(stack) >= 5000 && clearNegativeEffects(player)) this.extractEnergy(stack, 5000, false);
|
||||
if (player.worldObj.getBlockLightValue((int)Math.floor(player.posX), (int) player.posY, (int)Math.floor(player.posZ)) < 5)
|
||||
player.addPotionEffect(new PotionEffect(16, 210, 0, true));
|
||||
if (player.worldObj.getBlockLightValue((int)Math.floor(player.posX), (int) player.posY, (int)Math.floor(player.posZ)) < 5 && ItemNBTHelper.getBoolean(stack, "ArmorNVActive", false))
|
||||
player.addPotionEffect(new PotionEffect(16, 419, 0, true));
|
||||
else if (player.isPotionActive(16)) player.removePotionEffect(16);
|
||||
|
||||
}
|
||||
@@ -266,21 +261,25 @@ public class DraconicArmor extends ItemArmor implements ISpecialArmor, IEnergyCo
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemConfigValue> getFields(ItemStack stack, int slot) {
|
||||
List<ItemConfigValue> list = new ArrayList<ItemConfigValue>();
|
||||
public List<ItemConfigField> getFields(ItemStack stack, int slot) {
|
||||
List<ItemConfigField> list = new ArrayList<ItemConfigField>();
|
||||
if (armorType == 0)
|
||||
list.add(new ItemConfigValue(References.BOOLEAN_ID, slot, "ArmorNVActive").readFromItem(stack));
|
||||
list.add(new ItemConfigField(References.BOOLEAN_ID, slot, "ArmorNVActive").readFromItem(stack, false));
|
||||
else if (armorType == 1)
|
||||
{
|
||||
list.add(new ItemConfigValue(References.BOOLEAN_ID, slot, "ArmorFlightLock").readFromItem(stack));
|
||||
list.add(new ItemConfigValue(References.FLOAT_ID, slot, "ArmorFlightLock2").readFromItem(stack));
|
||||
list.add(new ItemConfigValue(References.INT_ID, slot, "ArmorFlightLock3").readFromItem(stack));
|
||||
list.add(new ItemConfigValue(References.STRING_ID, slot, "ArmorFlightLock4").readFromItem(stack));
|
||||
list.add(new ItemConfigField(References.BOOLEAN_ID, slot, "ArmorFlightLock").readFromItem(stack, false));
|
||||
}
|
||||
else if (armorType == 2)
|
||||
list.add(new ItemConfigValue(References.FLOAT_ID, slot, "ArmorSpeedMult").readFromItem(stack));
|
||||
{
|
||||
list.add(new ItemConfigField(References.FLOAT_ID, slot, "ArmorSpeedMult").setMinMaxAndIncromente(0f, 1f, 0.01f).readFromItem(stack, 1F));
|
||||
list.add(new ItemConfigField(References.BOOLEAN_ID, slot, "ArmorSprintOnly").readFromItem(stack, false));
|
||||
}
|
||||
else if (armorType == 3)
|
||||
list.add(new ItemConfigValue(References.FLOAT_ID, slot, "ArmorJumpMult").readFromItem(stack));
|
||||
{
|
||||
list.add(new ItemConfigField(References.FLOAT_ID, slot, "ArmorJumpMult").setMinMaxAndIncromente(0f, 1f, 0.01f).readFromItem(stack, 1f));
|
||||
list.add(new ItemConfigField(References.BOOLEAN_ID, slot, "ArmorSprintOnly").readFromItem(stack, false));
|
||||
list.add(new ItemConfigField(References.BOOLEAN_ID, slot, "ArmorHillStep").readFromItem(stack, true));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -5,7 +5,9 @@ import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.common.ModItems;
|
||||
import com.brandon3055.draconicevolution.common.entity.EntityPersistentItem;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.InfoHelper;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigField;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemNBTHelper;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -24,12 +26,13 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ISpecialArmor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Brandon on 3/07/2014.
|
||||
*/
|
||||
public class WyvernArmor extends ItemArmor implements ISpecialArmor, IEnergyContainerItem{
|
||||
public class WyvernArmor extends ItemArmor implements ISpecialArmor, IEnergyContainerItem, IConfigurableItem{
|
||||
private IIcon helmIcon;
|
||||
private IIcon chestIcon;
|
||||
private IIcon leggsIcon;
|
||||
@@ -226,4 +229,19 @@ public class WyvernArmor extends ItemArmor implements ISpecialArmor, IEnergyCont
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemConfigField> getFields(ItemStack stack, int slot) {
|
||||
List<ItemConfigField> list = new ArrayList<ItemConfigField>();
|
||||
if (armorType == 2)
|
||||
{
|
||||
list.add(new ItemConfigField(References.FLOAT_ID, slot, "ArmorSpeedMult").setMinMaxAndIncromente(0f, 1f, 0.01f).readFromItem(stack, 1F));
|
||||
list.add(new ItemConfigField(References.BOOLEAN_ID, slot, "ArmorSprintOnly").readFromItem(stack, false));
|
||||
}
|
||||
else if (armorType == 3)
|
||||
{
|
||||
list.add(new ItemConfigField(References.FLOAT_ID, slot, "ArmorJumpMult").setMinMaxAndIncromente(0f, 1f, 0.01f).readFromItem(stack, 1f));
|
||||
list.add(new ItemConfigField(References.BOOLEAN_ID, slot, "ArmorSprintOnly").readFromItem(stack, false));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.brandon3055.draconicevolution.common.network;
|
||||
|
||||
import com.brandon3055.draconicevolution.common.utills.DataUtills;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
import com.brandon3055.draconicevolution.common.utills.ItemConfigField;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemConfigPacket implements IMessage
|
||||
{
|
||||
public byte datatype;
|
||||
public int slot;
|
||||
public Object value;
|
||||
public String name;
|
||||
|
||||
public ItemConfigPacket() {}
|
||||
|
||||
public ItemConfigPacket(ItemConfigField field) {
|
||||
this.datatype = (byte)field.datatype;
|
||||
this.slot = field.slot;
|
||||
this.value = field.value;
|
||||
this.name = field.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf bytes){
|
||||
this.datatype = bytes.readByte();
|
||||
this.slot = bytes.readInt();
|
||||
this.name = ByteBufUtils.readUTF8String(bytes);
|
||||
this.value = DataUtills.readObjectFromBytes(bytes, datatype);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf bytes){
|
||||
bytes.writeByte(datatype);
|
||||
bytes.writeInt(slot);
|
||||
ByteBufUtils.writeUTF8String(bytes, name);
|
||||
DataUtills.writeObjectToBytes(bytes, datatype, value);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<ItemConfigPacket, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(ItemConfigPacket message, MessageContext ctx) {
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
if (message.slot >= player.inventory.getSizeInventory() || message.slot < 0) return null;
|
||||
ItemStack stack = player.inventory.getStackInSlot(message.slot);
|
||||
if (stack != null && stack.getItem() instanceof IConfigurableItem) DataUtills.writeObjectToItem(stack, message.value, message.datatype, message.name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,29 @@ public class DataUtills {
|
||||
}
|
||||
}
|
||||
|
||||
public static Object readObjectFromItem(ItemStack stack, int dataType, String name, Object defaultExpected){
|
||||
switch (dataType){
|
||||
case References.BYTE_ID:
|
||||
return ItemNBTHelper.getByte(stack, name, (Byte)defaultExpected);
|
||||
case References.SHORT_ID:
|
||||
return ItemNBTHelper.getShort(stack, name, (Short)defaultExpected);
|
||||
case References.INT_ID:
|
||||
return ItemNBTHelper.getInteger(stack, name, (Integer)defaultExpected);
|
||||
case References.LONG_ID:
|
||||
return ItemNBTHelper.getLong(stack, name, (Long)defaultExpected);
|
||||
case References.FLOAT_ID:
|
||||
return ItemNBTHelper.getFloat(stack, name, (Float)defaultExpected);
|
||||
case References.DOUBLE_ID:
|
||||
return ItemNBTHelper.getDouble(stack, name, (Double)defaultExpected);
|
||||
//case References.CHAR_ID:
|
||||
case References.STRING_ID:
|
||||
return ItemNBTHelper.getString(stack, name, (String)defaultExpected);
|
||||
case References.BOOLEAN_ID:
|
||||
return ItemNBTHelper.getBoolean(stack, name, (Boolean)defaultExpected);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object readObjectFromItem(ItemStack stack, int dataType, String name){
|
||||
switch (dataType){
|
||||
case References.BYTE_ID:
|
||||
|
||||
+1
-1
@@ -13,5 +13,5 @@ public interface IConfigurableItem {
|
||||
//
|
||||
// int getDataType(String name);
|
||||
|
||||
List<ItemConfigValue> getFields(ItemStack stack, int slot);
|
||||
List<ItemConfigField> getFields(ItemStack stack, int slot);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.brandon3055.draconicevolution.common.utills;
|
||||
|
||||
import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.network.ItemConfigPacket;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
/**
|
||||
* Created by Brandon on 29/12/2014.
|
||||
*/
|
||||
public class ItemConfigField {
|
||||
|
||||
public Object value;
|
||||
public int slot;
|
||||
public int datatype;
|
||||
public String name;
|
||||
public int fieldid;
|
||||
public Object max;
|
||||
public Object min;
|
||||
public Object incroment;
|
||||
|
||||
|
||||
public ItemConfigField(int datatype, int slot, String name){
|
||||
this.slot = slot;
|
||||
this.datatype = datatype;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ItemConfigField(int datatype, Object value, int slot, String name){
|
||||
this.value = value;
|
||||
this.slot = slot;
|
||||
this.datatype = datatype;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ItemConfigField setMinMaxAndIncromente(Object min, Object max, Object incroment){
|
||||
this.max = max;
|
||||
this.min = min;
|
||||
this.incroment = incroment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getLocalizedName() { return StatCollector.translateToLocal("button.de." + name + ".name"); }
|
||||
|
||||
// public void writeToItem(ItemStack stack){
|
||||
// DataUtills.writeObjectToItem(stack, value, datatype, name);
|
||||
// }
|
||||
|
||||
public ItemConfigField readFromItem(ItemStack stack, Object defaultExpected){
|
||||
value = DataUtills.readObjectFromItem(stack, datatype, name, defaultExpected);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void sendChanges(){
|
||||
DraconicEvolution.network.sendToServer(new ItemConfigPacket(this));
|
||||
}
|
||||
|
||||
public int castToInt(){
|
||||
switch (datatype){
|
||||
case References.BYTE_ID:
|
||||
return (int) (Byte) value;
|
||||
case References.SHORT_ID:
|
||||
return (int) (Short) value;
|
||||
case References.INT_ID:
|
||||
return (Integer) value;
|
||||
case References.LONG_ID:
|
||||
long l = (Long) value;
|
||||
return (int) l;
|
||||
case References.FLOAT_ID:
|
||||
float f = (Float) value;
|
||||
return (int) f;
|
||||
case References.DOUBLE_ID:
|
||||
double d = (Double) value;
|
||||
return (int) d;
|
||||
case References.BOOLEAN_ID:
|
||||
return (Boolean) value ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public double castToDouble(){
|
||||
switch (datatype){
|
||||
case References.BYTE_ID:
|
||||
return (double) (Byte) value;
|
||||
case References.SHORT_ID:
|
||||
return (double) (Short) value;
|
||||
case References.INT_ID:
|
||||
return (double) (Integer) value;
|
||||
case References.LONG_ID:
|
||||
long l = (Long) value;
|
||||
return (double) l;
|
||||
case References.FLOAT_ID:
|
||||
float f = (Float) value;
|
||||
return (double) f;
|
||||
case References.DOUBLE_ID:
|
||||
return (Double) value;
|
||||
case References.BOOLEAN_ID:
|
||||
return (Boolean) value ? 1D : 0D;
|
||||
}
|
||||
return 0D;
|
||||
}
|
||||
|
||||
|
||||
// public static int getTypeFromItem(ItemStack stack, String name) {
|
||||
// if (stack != null && stack.getItem() instanceof IConfigurableItem) return ((IConfigurableItem) stack.getItem()).getDataType(name);
|
||||
// return 0;
|
||||
// }
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.brandon3055.draconicevolution.common.utills;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by Brandon on 29/12/2014.
|
||||
*/
|
||||
public class ItemConfigValue {
|
||||
|
||||
public Object value;
|
||||
public int slot;
|
||||
public int datatype;
|
||||
public String name;
|
||||
public int fieldid;
|
||||
|
||||
public ItemConfigValue(int datatype, int slot, String name){
|
||||
this.slot = slot;
|
||||
this.datatype = datatype;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ItemConfigValue(int datatype, Object value, int slot, String name){
|
||||
this.value = value;
|
||||
this.slot = slot;
|
||||
this.datatype = datatype;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// public void writeToItem(ItemStack stack){
|
||||
// DataUtills.writeObjectToItem(stack, value, datatype, name);
|
||||
// }
|
||||
|
||||
public ItemConfigValue readFromItem(ItemStack stack){
|
||||
value = DataUtills.readObjectFromItem(stack, datatype, name);
|
||||
return this;
|
||||
}
|
||||
|
||||
// public static int getTypeFromItem(ItemStack stack, String name) {
|
||||
// if (stack != null && stack.getItem() instanceof IConfigurableItem) return ((IConfigurableItem) stack.getItem()).getDataType(name);
|
||||
// return 0;
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user