use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.
the class ClientTickHandler method checkMouseDWheel.
private void checkMouseDWheel() {
if (this.mouseWheelValue != 0 && this.currentSlot > -1) {
Minecraft.getMinecraft().thePlayer.inventory.currentItem = this.currentSlot;
ItemStack stack = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem();
if (checkForTKMove(stack)) {
ExtendedProperties props = ExtendedProperties.For(Minecraft.getMinecraft().thePlayer);
if (this.mouseWheelValue > 0 && props.TK_Distance < 10) {
props.TK_Distance += 0.5f;
} else if (this.mouseWheelValue < 0 && props.TK_Distance > 0.3) {
props.TK_Distance -= 0.5f;
}
LogHelper.debug("TK Distance: %.2f", props.TK_Distance);
props.syncTKDistance();
} else if (stack.getItem() instanceof ItemSpellBook && Minecraft.getMinecraft().thePlayer.isSneaking()) {
ItemSpellBook isb = (ItemSpellBook) stack.getItem();
if (this.mouseWheelValue != 0) {
byte subID = 0;
if (this.mouseWheelValue < 0) {
isb.SetNextSlot(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem());
subID = ItemSpellBook.ID_NEXT_SPELL;
} else {
isb.SetPrevSlot(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem());
subID = ItemSpellBook.ID_PREV_SPELL;
}
// send packet to server
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SPELLBOOK_CHANGE_ACTIVE_SLOT, new AMDataWriter().add(subID).add(Minecraft.getMinecraft().thePlayer.getEntityId()).add(Minecraft.getMinecraft().thePlayer.inventory.currentItem).generate());
}
}
this.currentSlot = -1;
this.mouseWheelValue = 0;
}
}
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;
}
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;
}
use of am2.network.AMDataWriter in project ArsMagica2 by Mithion.
the class TileEntityInscriptionTable method createSpellForPlayer.
public void createSpellForPlayer(EntityPlayer player) {
if (worldObj.isRemote) {
AMDataWriter writer = new AMDataWriter();
writer.add(xCoord);
writer.add(yCoord);
writer.add(zCoord);
writer.add(MAKE_SPELL);
writer.add(player.getEntityId());
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.INSCRIPTION_TABLE_UPDATE, writer.generate());
} else {
ArrayList<ArrayList<KeyValuePair<ISpellPart, byte[]>>> shapeGroupSetup = new ArrayList<ArrayList<KeyValuePair<ISpellPart, byte[]>>>();
ArrayList<KeyValuePair<ISpellPart, byte[]>> curRecipeSetup = new ArrayList<KeyValuePair<ISpellPart, byte[]>>();
for (ArrayList<ISpellPart> arr : shapeGroups) {
shapeGroupSetup.add(new ArrayList<KeyValuePair<ISpellPart, byte[]>>());
for (ISpellPart part : arr) {
shapeGroupSetup.get(shapeGroupSetup.size() - 1).add(new KeyValuePair<ISpellPart, byte[]>(part, new byte[0]));
}
}
for (ISpellPart part : currentRecipe) {
curRecipeSetup.add(new KeyValuePair<ISpellPart, byte[]>(part, new byte[0]));
}
ItemStack stack = SpellUtils.instance.createSpellStack(shapeGroupSetup, curRecipeSetup);
stack.stackTagCompound.setString("suggestedName", currentSpellName);
player.inventory.addItemStackToInventory(stack);
}
}
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());
}
Aggregations