use of am2.items.ItemKeystone.KeystoneCombination in project ArsMagica2 by Mithion.
the class ContainerKeystone method getCurrentMatchedCombination.
public KeystoneCombination getCurrentMatchedCombination() {
int savedCombos = ItemsCommonProxy.keystone.numCombinations(keystoneStack);
int[] curMeta = new int[InventoryKeyStone.inventorySize];
for (int c = 0; c < InventoryKeyStone.inventorySize; ++c) {
ItemStack stack = keyStoneInventory.getStackInSlot(c);
curMeta[c] = stack != null ? stack.getItemDamage() : -1;
}
for (int i = 0; i < savedCombos; ++i) {
KeystoneCombination currentCombo = ItemsCommonProxy.keystone.getCombinationAt(keystoneStack, i);
if (currentCombo.metas.length < InventoryKeyStone.inventorySize)
continue;
boolean match = true;
for (int c = 0; c < InventoryKeyStone.inventorySize; ++c) {
match &= curMeta[c] == currentCombo.metas[c];
}
if (match)
return currentCombo;
}
return null;
}
use of am2.items.ItemKeystone.KeystoneCombination in project ArsMagica2 by Mithion.
the class GuiKeystone method drawGuiContainerForegroundLayer.
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
int l = (width - xSize) / 2;
int i1 = (height - ySize) / 2;
mc.renderEngine.bindTexture(new ResourceLocation("textures/atlas/items.png"));
int numCombos = Math.min(ItemsCommonProxy.keystone.numCombinations(((ContainerKeystone) this.inventorySlots).getKeystoneStack()), comboScrollOffset + 9);
int cx = xSize;
int cy = 13;
Tessellator t = Tessellator.instance;
KeystoneCombination matchedCombo = ((ContainerKeystone) this.inventorySlots).getCurrentMatchedCombination();
for (int i = comboScrollOffset; i < numCombos; ++i) {
KeystoneCombination combo = ItemsCommonProxy.keystone.getCombinationAt(((ContainerKeystone) this.inventorySlots).getKeystoneStack(), i);
if (matchedCombo != null && combo.equals(matchedCombo)) {
currentCombination = i;
for (int n = 0; n < combo.metas.length; ++n) {
if (combo.metas[n] > -1) {
IIcon icon = AMGuiIcons.selectedRunes;
AMGuiHelper.DrawIconAtXY(icon, cx, cy, this.zLevel, 16, 16, true);
}
cx += 18;
}
mc.renderEngine.bindTexture(new ResourceLocation("textures/atlas/items.png"));
cx = xSize;
}
for (int n = 0; n < combo.metas.length; ++n) {
if (combo.metas[n] > -1) {
IIcon icon = ItemsCommonProxy.rune.getIconFromDamage(combo.metas[n]);
AMGuiHelper.DrawIconAtXY(icon, cx, cy, this.zLevel, 16, 16, true);
}
cx += 18;
}
cy += 18;
cx = xSize;
}
mc.renderEngine.bindTexture(extras);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F);
//special slot(s)
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
int index = ((ContainerKeystone) this.inventorySlots).specialSlotIndex - 32;
int x = 8 + 18 * index;
int y = (((ContainerKeystone) this.inventorySlots).runebagSlot > -1) ? 216 : 179;
drawTexturedModalRect(x, y, 0, 20, 16, 16);
if (((ContainerKeystone) this.inventorySlots).runebagSlot > -1) {
index = ((ContainerKeystone) this.inventorySlots).runebagSlot;
x = 8 + 18 * (index % 9);
y = index < 9 ? 216 : 140 + 18 * (int) Math.floor(index / 9f);
drawTexturedModalRect(x, y, 0, 20, 16, 16);
}
GL11.glDisable(GL11.GL_BLEND);
combinationName.drawTextBox();
if (AMGuiHelper.instance.getSlowTicker() < displayTime) {
fontRendererObj.drawSplitString(displayMessage, -90, 0, 90, displayColor);
} else {
displayTime = 0;
}
if (matchedCombo != null) {
combinationName.setText(matchedCombo.name);
}
if (hoveredCombo > -1) {
KeystoneCombination combo = ItemsCommonProxy.keystone.getCombinationAt(((ContainerKeystone) this.inventorySlots).getKeystoneStack(), hoveredCombo);
ArrayList<String> lines = new ArrayList<String>();
lines.add(combo.name);
lines.add("\2477\247o" + StatCollector.translateToLocal("am2.gui.keystoneComboClick"));
lines.add("\2477\247o" + StatCollector.translateToLocal("am2.gui.keystoneComboClick2") + "\247r");
AMGuiHelper.drawHoveringText(lines, par1 - 25, par2 + 18, Minecraft.getMinecraft().fontRenderer, this.xSize, this.ySize);
}
}
use of am2.items.ItemKeystone.KeystoneCombination in project ArsMagica2 by Mithion.
the class GuiKeystone method actionPerformed.
@Override
protected void actionPerformed(GuiButton button) {
if (button == scrollBar) {
comboScrollOffset = Math.round(scrollBar.getShiftedValue());
return;
}
if (button == addCombination) {
if (combinationName.getText() == null || combinationName.getText().trim().equals("")) {
displayMessage = StatCollector.translateToLocal("am2.gui.nameRequired");
displayTime = AMGuiHelper.instance.getSlowTicker() + 3;
displayColor = 0xff0000;
} else {
displayMessage = StatCollector.translateToLocal("am2.gui.comboStored");
displayTime = AMGuiHelper.instance.getSlowTicker() + 3;
displayColor = 0x00ff00;
int[] metas = new int[InventoryKeyStone.inventorySize];
for (int i = 0; i < InventoryKeyStone.inventorySize; ++i) {
ItemStack stack = this.keystoneInventory.getStackInSlot(i);
metas[i] = stack != null ? stack.getItemDamage() : -1;
}
AMDataWriter writer = new AMDataWriter();
writer.add(true);
writer.add(combinationName.getText());
for (int i = 0; i < metas.length; ++i) writer.add(metas[i]);
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SAVE_KEYSTONE_COMBO, writer.generate());
ItemsCommonProxy.keystone.addCombination(((ContainerKeystone) this.inventorySlots).getKeystoneStack(), combinationName.getText(), metas);
recalculateSlider();
}
} else if (button == forgetCombination) {
KeystoneCombination matchedCombo = ((ContainerKeystone) this.inventorySlots).getCurrentMatchedCombination();
if (matchedCombo == null) {
displayMessage = StatCollector.translateToLocal("am2.gui.comboNotSaved");
displayTime = AMGuiHelper.instance.getSlowTicker() + 3;
displayColor = 0xff0000;
} else {
displayMessage = StatCollector.translateToLocal("am2.gui.comboRemoved");
displayTime = AMGuiHelper.instance.getSlowTicker() + 3;
displayColor = 0x00ff00;
combinationName.setText("");
AMDataWriter writer = new AMDataWriter();
writer.add(false);
writer.add(matchedCombo.name);
for (int i = 0; i < matchedCombo.metas.length; ++i) writer.add(matchedCombo.metas[i]);
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SAVE_KEYSTONE_COMBO, writer.generate());
ItemsCommonProxy.keystone.removeCombination(((ContainerKeystone) this.inventorySlots).getKeystoneStack(), matchedCombo.name);
recalculateSlider();
}
} else {
int numCombinatons = ItemsCommonProxy.keystone.numCombinations(((ContainerKeystone) this.inventorySlots).getKeystoneStack());
int originalCombo = currentCombination;
boolean changed = false;
boolean skipped = false;
if (numCombinatons == 0)
return;
if (numCombinatons == 1) {
currentCombination = 0;
if (((ContainerKeystone) this.inventorySlots).setInventoryToCombination(currentCombination))
changed = true;
} else {
if (button == nextCombination) {
currentCombination++;
if (currentCombination >= numCombinatons)
currentCombination = 0;
while (currentCombination != originalCombo) {
if (!((ContainerKeystone) this.inventorySlots).setInventoryToCombination(currentCombination)) {
currentCombination++;
if (currentCombination >= numCombinatons)
currentCombination = 0;
skipped = true;
} else {
changed = true;
break;
}
}
} else if (button == prevCombination) {
currentCombination--;
if (currentCombination < 0)
currentCombination = numCombinatons - 1;
while (currentCombination != originalCombo) {
if (!((ContainerKeystone) this.inventorySlots).setInventoryToCombination(currentCombination)) {
currentCombination--;
if (currentCombination < 0)
currentCombination = numCombinatons - 1;
skipped = true;
} else {
changed = true;
break;
}
}
}
}
if (!changed) {
displayMessage = StatCollector.translateToLocal("am2.gui.comboMissingRunes");
displayTime = AMGuiHelper.instance.getSlowTicker() + 3;
displayColor = 0xff0000;
} else if (skipped) {
displayMessage = StatCollector.translateToLocal("am2.gui.oneOrMoreSkipped");
displayTime = AMGuiHelper.instance.getSlowTicker() + 3;
displayColor = 0xff0000;
}
}
}
use of am2.items.ItemKeystone.KeystoneCombination in project ArsMagica2 by Mithion.
the class ContainerKeystone method setInventoryToCombination.
public boolean setInventoryToCombination(int comboIndex) {
KeystoneCombination combo = ItemsCommonProxy.keystone.getCombinationAt(keystoneStack, comboIndex);
if (combo == null)
return false;
if (!inventoryContainsAllMetas(combo.metas))
return false;
if (player.worldObj.isRemote) {
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SET_KEYSTONE_COMBO, new AMDataWriter().add(comboIndex).generate());
return true;
}
int matchIndex = 0;
int searchIndex = 0;
while (matchIndex < combo.metas.length && searchIndex < InventoryKeyStone.inventorySize + (runeBag != null ? InventoryRuneBag.inventorySize : 0)) {
IInventory searchInventory = searchIndex >= InventoryKeyStone.inventorySize ? runeBag : keyStoneInventory;
int inventoryIndex = searchIndex >= InventoryKeyStone.inventorySize ? searchIndex - InventoryKeyStone.inventorySize : searchIndex;
ItemStack stack = searchInventory.getStackInSlot(inventoryIndex);
if (stack != null && stack.getItemDamage() == combo.metas[matchIndex]) {
swapInventorySlots(keyStoneInventory, searchInventory, matchIndex, inventoryIndex);
matchIndex++;
searchIndex = matchIndex;
continue;
} else if (stack == null && combo.metas[matchIndex] == -1) {
swapInventorySlots(keyStoneInventory, searchInventory, matchIndex, inventoryIndex);
matchIndex++;
searchIndex = matchIndex;
continue;
}
searchIndex++;
}
this.detectAndSendChanges();
return true;
}
Aggregations