Search in sources :

Example 1 with AMDataReader

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

the class ExtendedProperties method handleDataPacket.

public boolean handleDataPacket(byte[] data) {
    AMDataReader rdr = new AMDataReader(data, false);
    int entID = rdr.getInt();
    if (entID != this.entity.getEntityId()) {
        return false;
    }
    int flags = rdr.getInt();
    if ((flags & UPD_BITFLAG) == UPD_BITFLAG) {
        this.bitFlag = rdr.getByte();
    }
    if ((flags & UPD_CURRENT_MANA_FATIGUE) == UPD_CURRENT_MANA_FATIGUE) {
        this.currentMana = rdr.getFloat();
        this.currentFatigue = rdr.getFloat();
    }
    if ((flags & UPD_MAGIC_LEVEL) == UPD_MAGIC_LEVEL) {
        this.magicLevel = rdr.getInt();
        float newMagicXP = rdr.getFloat();
        if (entity.worldObj.isRemote && newMagicXP != magicXP) {
            AMGuiHelper.instance.showMagicXPBar();
        }
        this.magicXP = newMagicXP;
    }
    if ((flags & UPD_MARK) == UPD_MARK) {
        this.markX = rdr.getDouble();
        this.markY = rdr.getDouble();
        this.markZ = rdr.getDouble();
        this.markDimension = rdr.getInt();
        this.setMarkSet(rdr.getBoolean());
    }
    if ((flags & UPD_MAX_MANA_FATIGUE) == UPD_MAX_MANA_FATIGUE) {
        this.maxMana = rdr.getFloat();
        this.maxFatigue = rdr.getFloat();
    }
    if ((flags & UPD_NUM_SUMMONS) == UPD_NUM_SUMMONS) {
        this.numSummons = rdr.getInt();
    }
    if ((flags & UPD_BETA_PARTICLES) == UPD_BETA_PARTICLES && entity instanceof EntityPlayer && AMCore.proxy.playerTracker.hasAA((EntityPlayer) entity)) {
        this.AuraIndex = rdr.getInt();
        this.AuraBehaviour = rdr.getInt();
        this.AuraScale = rdr.getFloat();
        this.AuraAlpha = rdr.getFloat();
        this.AuraColorRandomize = rdr.getBoolean();
        this.AuraColorDefault = rdr.getBoolean();
        this.AuraColor = rdr.getInt();
        this.AuraDelay = rdr.getInt();
        this.AuraQuantity = rdr.getInt();
        this.AuraSpeed = rdr.getFloat();
    }
    if ((flags & UPD_CONTINGENCY) == UPD_CONTINGENCY) {
        this.contingencyType = ContingencyTypes.values()[rdr.getInt()];
        if (this.contingencyType != ContingencyTypes.NONE) {
            this.contingencyStack = rdr.getItemStack();
        }
    }
    if ((flags & UPD_MANALINK) == UPD_MANALINK) {
        this.manaLinks.clear();
        int numLinks = rdr.getInt();
        for (int i = 0; i < numLinks; ++i) {
            Entity e = entity.worldObj.getEntityByID(rdr.getInt());
            if (e != null && e instanceof EntityLivingBase)
                updateManaLink((EntityLivingBase) e);
        }
    }
    if ((flags & UPD_DISABLE_GRAVITY) == UPD_DISABLE_GRAVITY) {
        this.disableGravity = rdr.getBoolean();
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) AMDataReader(am2.network.AMDataReader)

Example 2 with AMDataReader

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

the class AffinityData method handlePacketData.

public boolean handlePacketData(byte[] data) {
    AMDataReader rdr = new AMDataReader(data, false);
    int entID = rdr.getInt();
    if (entID != this.entity.getEntityId()) {
        return false;
    }
    affinityDepths.put(Affinity.AIR.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.LIGHTNING.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.ARCANE.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.FIRE.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.ENDER.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.EARTH.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.ICE.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.NATURE.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.WATER.ordinal(), rdr.getFloat());
    affinityDepths.put(Affinity.LIFE.ordinal(), rdr.getFloat());
    diminishingReturns = rdr.getFloat();
    isLocked = rdr.getBoolean();
    updateHighestAffinities();
    return true;
}
Also used : AMDataReader(am2.network.AMDataReader)

Example 3 with AMDataReader

use of am2.network.AMDataReader 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 4 with AMDataReader

use of am2.network.AMDataReader 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)

Example 5 with AMDataReader

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

the class FlickerOperatorContainment method getLastRadius.

protected int getLastRadius(IFlickerController habitat) {
    byte[] meta = habitat.getMetadata(this);
    if (meta == null || meta.length == 0)
        return BASE_RADIUS;
    AMDataReader rdr = new AMDataReader(meta, false);
    return rdr.getInt();
}
Also used : AMDataReader(am2.network.AMDataReader)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)14 AMDataReader (am2.network.AMDataReader)10 Entity (net.minecraft.entity.Entity)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 AMVector3 (am2.api.math.AMVector3)2 IPowerNode (am2.api.power.IPowerNode)2 AMDataWriter (am2.network.AMDataWriter)2 ItemStack (net.minecraft.item.ItemStack)2 World (net.minecraft.world.World)2 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)1 TileEntityArmorImbuer (am2.blocks.tileentities.TileEntityArmorImbuer)1 TileEntityCalefactor (am2.blocks.tileentities.TileEntityCalefactor)1 TileEntityCraftingAltar (am2.blocks.tileentities.TileEntityCraftingAltar)1 TileEntityInscriptionTable (am2.blocks.tileentities.TileEntityInscriptionTable)1 TileEntityLectern (am2.blocks.tileentities.TileEntityLectern)1 TileEntityMagiciansWorkbench (am2.blocks.tileentities.TileEntityMagiciansWorkbench)1 TileEntityObelisk (am2.blocks.tileentities.TileEntityObelisk)1 TileEntityParticleEmitter (am2.blocks.tileentities.TileEntityParticleEmitter)1 IArsMagicaBoss (am2.bosses.IArsMagicaBoss)1