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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations