Search in sources :

Example 6 with AMDataWriter

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

the class ExtendedProperties method handleExtendedPropertySync.

public void handleExtendedPropertySync() {
    if (!entity.worldObj.isRemote && !this.getHasDoneFullSync()) {
        this.setFullSync();
    }
    if (!entity.worldObj.isRemote && this.getHasUpdate()) {
        byte[] data = this.getUpdateData();
        AMNetHandler.INSTANCE.sendPacketToAllClientsNear(entity.dimension, entity.posX, entity.posY, entity.posZ, 32, AMPacketIDs.SYNC_EXTENDED_PROPS, data);
    }
    if (entity.worldObj.isRemote) {
        if (this.detectPossibleDesync()) {
            AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.POSSIBLE_CLIENT_EXPROP_DESYNC, new AMDataWriter().add(entity.getEntityId()).generate());
        }
    }
}
Also used : AMDataWriter(am2.network.AMDataWriter)

Example 7 with AMDataWriter

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

the class ExtendedProperties method getAuraData.

public byte[] getAuraData() {
    AMDataWriter writer = new AMDataWriter();
    writer.add(this.AuraIndex);
    writer.add(this.AuraBehaviour);
    writer.add(this.AuraScale);
    writer.add(this.AuraAlpha);
    writer.add(this.AuraColorRandomize);
    writer.add(this.AuraColorDefault);
    writer.add(this.AuraColor);
    writer.add(this.AuraDelay);
    writer.add(this.AuraQuantity);
    writer.add(this.AuraSpeed);
    return writer.generate();
}
Also used : AMDataWriter(am2.network.AMDataWriter)

Example 8 with AMDataWriter

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

the class SkillData method getUpdateData.

private byte[] getUpdateData() {
    AMDataWriter writer = new AMDataWriter();
    writer.add(CLIENT_SYNC);
    writer.add(this.entity.getEntityId());
    writer.add(updateFlags);
    writer.add(this.primaryTree != null);
    if (this.primaryTree != null)
        writer.add(this.primaryTree.ordinal());
    if ((updateFlags & KNOWN_SHAPE_UPDATE) == KNOWN_SHAPE_UPDATE) {
        writer.add(shapesKnown.size());
        for (Integer i : shapesKnown) {
            writer.add(i);
        }
    }
    if ((updateFlags & KNOWN_COMPONENT_UPDATE) == KNOWN_COMPONENT_UPDATE) {
        writer.add(componentsKnown.size());
        for (Integer i : componentsKnown) {
            writer.add(i);
        }
    }
    if ((updateFlags & KNOWN_MODIFIER_UPDATE) == KNOWN_MODIFIER_UPDATE) {
        writer.add(modifiersKnown.size());
        for (Integer i : modifiersKnown) {
            writer.add(i);
        }
    }
    if ((updateFlags & KNOWN_TALENTS_UPDATE) == KNOWN_TALENTS_UPDATE) {
        writer.add(talentsKnown.size());
        for (Integer i : talentsKnown) {
            writer.add(i);
        }
    }
    if ((updateFlags & NUM_SPELL_POINTS) == NUM_SPELL_POINTS) {
        writer.add(this.spellPoints[0]);
        writer.add(this.spellPoints[1]);
        writer.add(this.spellPoints[2]);
        writer.add(this.spellPoints[3]);
    }
    this.updateFlags = 0;
    this.forcingSync = false;
    return writer.generate();
}
Also used : AMDataWriter(am2.network.AMDataWriter)

Example 9 with AMDataWriter

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

the class FlickerOperatorLight method DoOperation.

@Override
public boolean DoOperation(World worldObj, IFlickerController habitat, boolean powered) {
    if (!worldObj.isRemote) {
        int radius = 16;
        int yRadius = radius / 4;
        int checksPerOperation = 8;
        int checkX = ((TileEntity) habitat).xCoord - radius;
        int checkY = ((TileEntity) habitat).yCoord - yRadius;
        int checkZ = ((TileEntity) habitat).zCoord - radius;
        byte[] meta = habitat.getMetadata(this);
        if (meta.length != 0) {
            AMDataReader rdr = new AMDataReader(meta, false);
            checkX = rdr.getInt();
            checkY = rdr.getInt();
            checkZ = rdr.getInt();
        }
        for (int i = 0; i < checksPerOperation; ++i) {
            int light = worldObj.getBlockLightValue(checkX, checkY, checkZ);
            if (light < 10 && worldObj.isAirBlock(checkX, checkY, checkZ)) {
                worldObj.setBlock(checkX, checkY, checkZ, BlocksCommonProxy.invisibleUtility, 10, 2);
            }
            checkX++;
            if (checkX > ((TileEntity) habitat).xCoord + radius) {
                checkX = ((TileEntity) habitat).xCoord - radius;
                checkY++;
                if (checkY > ((TileEntity) habitat).yCoord + yRadius) {
                    checkY = ((TileEntity) habitat).yCoord - yRadius;
                    checkZ++;
                    if (checkZ > ((TileEntity) habitat).zCoord + radius) {
                        checkZ = ((TileEntity) habitat).zCoord - radius;
                    }
                }
            }
        }
        AMDataWriter writer = new AMDataWriter();
        writer.add(checkX).add(checkY).add(checkZ);
        habitat.setMetadata(this, writer.generate());
    } else {
        AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "sparkle", ((TileEntity) habitat).xCoord + 0.5, ((TileEntity) habitat).yCoord + 1, ((TileEntity) habitat).zCoord + 0.5);
        if (particle != null) {
            particle.addRandomOffset(0.5, 0.4, 0.5);
            particle.AddParticleController(new ParticleFloatUpward(particle, 0, 0.02f, 1, false));
            particle.AddParticleController(new ParticleFadeOut(particle, 1, false).setFadeSpeed(0.05f));
            particle.setMaxAge(20);
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMParticle(am2.particles.AMParticle) AMDataReader(am2.network.AMDataReader) ParticleFadeOut(am2.particles.ParticleFadeOut) ParticleFloatUpward(am2.particles.ParticleFloatUpward) AMDataWriter(am2.network.AMDataWriter)

Example 10 with AMDataWriter

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

the class FlickerOperatorFelledOak method getPlantLocation.

private AMVector3 getPlantLocation(World worldObj, IFlickerController habitat, ItemStack sapling) {
    if (sapling.getItem() instanceof ItemBlock == false)
        return null;
    TileEntity te = (TileEntity) habitat;
    byte[] data = habitat.getMetadata(this);
    AMVector3 offset = null;
    if (data == null || data.length == 0) {
        offset = new AMVector3(te.xCoord - radius_horiz, te.yCoord - radius_vert, te.zCoord - radius_horiz);
    } else {
        AMDataReader reader = new AMDataReader(data, false);
        offset = new AMVector3(reader.getInt(), te.yCoord - radius_vert, reader.getInt());
    }
    Block treeBlock = ((ItemBlock) sapling.getItem()).field_150939_a;
    for (int i = (int) offset.x; i <= te.xCoord + radius_horiz; i += 2) {
        for (int k = (int) offset.z; k <= te.zCoord + radius_horiz; k += 2) {
            for (int j = (int) offset.y; j <= te.yCoord + radius_vert; ++j) {
                Block block = worldObj.getBlock(i, j, k);
                if (block.isReplaceable(worldObj, i, j, k) && treeBlock.canPlaceBlockAt(worldObj, i, j, k)) {
                    AMDataWriter writer = new AMDataWriter();
                    writer.add(i).add(k);
                    habitat.setMetadata(this, writer.generate());
                    return new AMVector3(i, j, k);
                }
            }
        }
    }
    AMDataWriter writer = new AMDataWriter();
    writer.add(te.xCoord - radius_horiz).add(te.zCoord - radius_horiz);
    habitat.setMetadata(this, writer.generate());
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) AMDataReader(am2.network.AMDataReader) ItemBlock(net.minecraft.item.ItemBlock) AMDataWriter(am2.network.AMDataWriter)

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