Search in sources :

Example 1 with AMDataWriter

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;
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) ExtendedProperties(am2.playerextensions.ExtendedProperties) AMDataWriter(am2.network.AMDataWriter) ItemSpellBook(am2.items.ItemSpellBook)

Example 2 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)

Example 3 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 4 with AMDataWriter

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);
    }
}
Also used : KeyValuePair(am2.utility.KeyValuePair) ItemStack(net.minecraft.item.ItemStack) AMDataWriter(am2.network.AMDataWriter)

Example 5 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)

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