use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.
the class TileEntityInscriptionTable method resetSpellNameAndIcon.
public void resetSpellNameAndIcon(ItemStack stack, EntityPlayer player) {
if (worldObj.isRemote) {
AMDataWriter writer = new AMDataWriter();
writer.add(xCoord);
writer.add(yCoord);
writer.add(zCoord);
writer.add(RESET_NAME);
writer.add(player.getEntityId());
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.INSCRIPTION_TABLE_UPDATE, writer.generate());
}
stack.setItemDamage(0);
stack.func_135074_t();
}
use of am2.network.AMDataWriter 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.network.AMDataWriter 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;
}
use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.
the class SpellHelper method applyStackStage.
public SpellCastResult applyStackStage(ItemStack stack, EntityLivingBase caster, EntityLivingBase target, double x, double y, double z, int side, World world, boolean consumeMBR, boolean giveXP, int ticksUsed) {
if (caster.isPotionActive(BuffList.silence.id))
return SpellCastResult.SILENCED;
ItemStack parsedStack = SpellUtils.instance.constructSpellStack(stack);
if (SpellUtils.instance.numStages(parsedStack) == 0) {
return SpellCastResult.SUCCESS;
}
ISpellShape shape = SpellUtils.instance.getShapeForStage(parsedStack, 0);
ItemSpellBase item = (ItemSpellBase) parsedStack.getItem();
if (SkillTreeManager.instance.isSkillDisabled(shape))
return SpellCastResult.EFFECT_FAILED;
if (!(caster instanceof EntityPlayer)) {
consumeMBR = false;
}
SpellCastingEvent.Pre checkEvent = null;
if (consumeMBR) {
checkEvent = preSpellCast(parsedStack, caster, false);
if (checkEvent.castResult != SpellCastResult.SUCCESS) {
if (checkEvent.castResult == SpellCastResult.NOT_ENOUGH_MANA && caster.worldObj.isRemote && caster instanceof EntityPlayer) {
AMCore.proxy.flashManaBar();
}
SpellCastingEvent.Post event = new SpellCastingEvent().new Post(parsedStack, (ItemSpellBase) parsedStack.getItem(), caster, checkEvent.manaCost, checkEvent.burnout, false, checkEvent.castResult);
MinecraftForge.EVENT_BUS.post(event);
return checkEvent.castResult;
}
}
SpellCastResult result = SpellCastResult.MALFORMED_SPELL_STACK;
if (shape != null) {
result = shape.beginStackStage(item, parsedStack, caster, target, world, x, y, z, side, giveXP, ticksUsed);
if (!world.isRemote) {
AMDataWriter writer = new AMDataWriter();
writer.add(parsedStack);
writer.add(caster.getEntityId());
if (target != null) {
writer.add(true);
writer.add(target.getEntityId());
} else {
writer.add(false);
}
writer.add(x).add(y).add(z);
writer.add(side);
writer.add(ticksUsed);
AMNetHandler.INSTANCE.sendPacketToAllClientsNear(world.provider.dimensionId, x, y, z, 32, AMPacketIDs.SPELL_CAST, writer.generate());
}
}
float manaCost = 0;
float burnout = 0;
if (consumeMBR) {
manaCost = checkEvent.manaCost;
burnout = checkEvent.burnout;
if (result == SpellCastResult.SUCCESS_REDUCE_MANA) {
result = SpellCastResult.SUCCESS;
manaCost *= 0.2f;
burnout *= 0.2f;
}
}
if (result == SpellCastResult.SUCCESS) {
if (consumeMBR) {
ExtendedProperties.For(caster).deductMana(manaCost);
ExtendedProperties.For(caster).addBurnout(burnout);
}
if (world.isRemote) {
String sfx = shape.getSoundForAffinity(SpellUtils.instance.mainAffinityFor(parsedStack), parsedStack, null);
if (sfx != null) {
if (!shape.isChanneled()) {
world.playSound(caster.posX, caster.posY, caster.posZ, sfx, 0.4f, world.rand.nextFloat() * 0.1F + 0.9F, false);
} else {
//SoundHelper.instance.loopSound(world, (float)x, (float)y, (float)z, sfx, 0.6f);
}
}
}
}
SpellCastingEvent.Post event = new SpellCastingEvent().new Post(parsedStack, (ItemSpellBase) parsedStack.getItem(), caster, manaCost, burnout, false, result);
MinecraftForge.EVENT_BUS.post(event);
return result;
}
use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.
the class AffinityData method getUpdateData.
private byte[] getUpdateData() {
AMDataWriter writer = new AMDataWriter();
writer.add(this.entity.getEntityId());
writer.add(affinityDepths.get(Affinity.AIR.ordinal()));
writer.add(affinityDepths.get(Affinity.LIGHTNING.ordinal()));
writer.add(affinityDepths.get(Affinity.ARCANE.ordinal()));
writer.add(affinityDepths.get(Affinity.FIRE.ordinal()));
writer.add(affinityDepths.get(Affinity.ENDER.ordinal()));
writer.add(affinityDepths.get(Affinity.EARTH.ordinal()));
writer.add(affinityDepths.get(Affinity.ICE.ordinal()));
writer.add(affinityDepths.get(Affinity.NATURE.ordinal()));
writer.add(affinityDepths.get(Affinity.WATER.ordinal()));
writer.add(affinityDepths.get(Affinity.LIFE.ordinal()));
writer.add(diminishingReturns);
writer.add(isLocked);
this.hasUpdate = false;
this.forcingSync = false;
return writer.generate();
}
Aggregations