Search in sources :

Example 21 with AMDataWriter

use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.

the class TileEntityInscriptionTable method GetUpdatePacketForServer.

private byte[] GetUpdatePacketForServer() {
    AMDataWriter writer = new AMDataWriter();
    writer.add(FULL_UPDATE);
    writer.add(this.currentPlayerUsing == null);
    if (this.currentPlayerUsing != null)
        writer.add(this.currentPlayerUsing.getEntityId());
    writer.add(this.currentRecipe.size());
    for (int i = 0; i < this.currentRecipe.size(); ++i) {
        ISpellPart part = this.currentRecipe.get(i);
        int id = part.getID();
        if (part instanceof ISpellComponent)
            id += SkillManager.COMPONENT_OFFSET;
        else if (part instanceof ISpellModifier)
            id += SkillManager.MODIFIER_OFFSET;
        writer.add(id);
    }
    writer.add(this.shapeGroups.size());
    for (ArrayList<ISpellPart> shapeGroup : this.shapeGroups) {
        int[] groupData = new int[shapeGroup.size()];
        for (int i = 0; i < shapeGroup.size(); ++i) {
            groupData[i] = SkillManager.instance.getShiftedPartID(shapeGroup.get(i));
        }
        writer.add(groupData);
    }
    writer.add(currentSpellName);
    writer.add(currentSpellIsReadOnly);
    return writer.generate();
}
Also used : AMDataWriter(am2.network.AMDataWriter)

Example 22 with AMDataWriter

use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.

the class TileEntityInscriptionTable method sendDataToServer.

private void sendDataToServer() {
    AMDataWriter writer = new AMDataWriter();
    writer.add(xCoord);
    writer.add(yCoord);
    writer.add(zCoord);
    writer.add(GetUpdatePacketForServer());
    AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.INSCRIPTION_TABLE_UPDATE, writer.generate());
}
Also used : AMDataWriter(am2.network.AMDataWriter)

Example 23 with AMDataWriter

use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.

the class ContainerSpellCustomization method sendPacketToServer.

public boolean sendPacketToServer() {
    if (!name.equals("") && iconIndex > -1) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(inventoryPlayer.player.getEntityId());
        writer.add(iconIndex);
        writer.add(name);
        AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SPELL_CUSTOMIZE, writer.generate());
        return true;
    }
    return false;
}
Also used : AMDataWriter(am2.network.AMDataWriter)

Example 24 with AMDataWriter

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;
}
Also used : ItemSpellBase(am2.api.spell.ItemSpellBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SpellCastResult(am2.api.spell.enums.SpellCastResult) ItemStack(net.minecraft.item.ItemStack) SpellCastingEvent(am2.api.events.SpellCastingEvent) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) AMDataWriter(am2.network.AMDataWriter)

Example 25 with AMDataWriter

use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.

the class TileEntityCraftingAltar method setCrafting.

private void setCrafting(boolean crafting) {
    this.isCrafting = crafting;
    if (!worldObj.isRemote) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(xCoord);
        writer.add(yCoord);
        writer.add(zCoord);
        writer.add(CRAFTING_CHANGED);
        writer.add(crafting);
        AMNetHandler.INSTANCE.sendPacketToAllClientsNear(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 32, AMPacketIDs.CRAFTING_ALTAR_DATA, writer.generate());
    }
    if (crafting) {
        allAddedItems.clear();
        currentAddedItems.clear();
        spellDef.clear();
        for (ArrayList<KeyValuePair<ISpellPart, byte[]>> groups : shapeGroups) groups.clear();
        //find otherworld auras
        IPowerNode[] nodes = PowerNodeRegistry.For(worldObj).getAllNearbyNodes(worldObj, new AMVector3(this), PowerTypes.DARK);
        for (IPowerNode node : nodes) {
            if (node instanceof TileEntityOtherworldAura) {
                ((TileEntityOtherworldAura) node).setActive(true, this);
                break;
            }
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) KeyValuePair(am2.utility.KeyValuePair) AMDataWriter(am2.network.AMDataWriter) IPowerNode(am2.api.power.IPowerNode)

Aggregations

AMDataWriter (am2.network.AMDataWriter)38 ItemStack (net.minecraft.item.ItemStack)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 AMVector3 (am2.api.math.AMVector3)3 TileEntity (net.minecraft.tileentity.TileEntity)3 SkillLearnedEvent (am2.api.events.SkillLearnedEvent)2 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)2 KeystoneCombination (am2.items.ItemKeystone.KeystoneCombination)2 AMDataReader (am2.network.AMDataReader)2 ExtendedProperties (am2.playerextensions.ExtendedProperties)2 KeyValuePair (am2.utility.KeyValuePair)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 SpellCastingEvent (am2.api.events.SpellCastingEvent)1 IPowerNode (am2.api.power.IPowerNode)1 ItemSpellBase (am2.api.spell.ItemSpellBase)1 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)1 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)1 SkillPointTypes (am2.api.spell.enums.SkillPointTypes)1 SpellCastResult (am2.api.spell.enums.SpellCastResult)1