Search in sources :

Example 21 with MinestuckPacket

use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.

the class SkaianetHandler method resetGivenItems.

public static void resetGivenItems() {
    for (SburbConnection c : connections) {
        for (int i = 0; i < c.givenItemList.length; i++) c.givenItemList[i] = false;
        c.unregisteredItems = new NBTTagList();
        EditData data = ServerEditHandler.getData(c);
        if (data != null) {
            MinestuckPacket packet = MinestuckPacket.makePacket(Type.SERVER_EDIT, c.givenItemList);
            MinestuckChannelHandler.sendToPlayer(packet, data.getEditor());
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) EditData(com.mraof.minestuck.editmode.EditData) MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket)

Example 22 with MinestuckPacket

use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.

the class SkaiaClient method sendCloseRequest.

public static void sendCloseRequest(TileEntityComputer te, int otherPlayer, boolean isClient) {
    MinestuckPacket packet = MinestuckPacket.makePacket(Type.SBURB_CLOSE, te.ownerId, otherPlayer, isClient);
    MinestuckChannelHandler.sendToServer(packet);
}
Also used : MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket)

Example 23 with MinestuckPacket

use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.

the class SkaiaClient method requestData.

/**
 * Called by a computer on interact. If it doesn't have the sufficient information,
 * returns false and sends a request about that information.
 * @param computer The computer. Will save this variable for later if it sends a request.
 * @return If it currently has the necessary information.
 */
public static boolean requestData(TileEntityComputer computer) {
    boolean b = openServers.get(computer.ownerId) != null;
    if (!b) {
        MinestuckPacket packet = MinestuckPacket.makePacket(Type.SBURB_INFO, computer.ownerId);
        MinestuckChannelHandler.sendToServer(packet);
        te = computer;
    }
    return b;
}
Also used : MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket)

Example 24 with MinestuckPacket

use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.

the class CaptchaDeckHandler method getItem.

public static void getItem(EntityPlayerMP player, int index, boolean asCard) {
    Modus modus = getModus(player);
    if (modus == null)
        return;
    ItemStack stack = modus.getItem(index, asCard);
    if (!stack.isEmpty()) {
        ItemStack otherStack = player.getHeldItemMainhand();
        if (otherStack.isEmpty())
            player.setHeldItem(EnumHand.MAIN_HAND, stack);
        else if (canMergeItemStacks(stack, otherStack)) {
            otherStack.grow(stack.getCount());
            stack.setCount(0);
        } else {
            boolean placed = false;
            for (int i = 0; i < player.inventory.mainInventory.size(); i++) {
                otherStack = player.inventory.mainInventory.get(i);
                if (otherStack.isEmpty())
                    player.inventory.mainInventory.set(i, stack.copy());
                else if (canMergeItemStacks(stack, otherStack))
                    otherStack.grow(stack.getCount());
                else
                    continue;
                stack.setCount(0);
                placed = true;
                player.inventory.markDirty();
                player.inventoryContainer.detectAndSendChanges();
                break;
            }
            if (!placed)
                launchAnyItem(player, stack);
        }
    }
    MinestuckPacket packet = MinestuckPacket.makePacket(MinestuckPacket.Type.CAPTCHA, CaptchaDeckPacket.DATA, writeToNBT(modus));
    MinestuckChannelHandler.sendToPlayer(packet, player);
}
Also used : ItemStack(net.minecraft.item.ItemStack) MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket)

Example 25 with MinestuckPacket

use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.

the class ServerEditHandler method reset.

/**
 * Called when the server stops editing the clients house.
 * @param damageSource If the process was cancelled by the decoy taking damage, this parameter will be the damage source. Else null.
 * @param damage If the damageSource isn't null, this is the damage taken, else this parameter is ignored.
 * @param data editdata to identify the editmode session
 */
public static void reset(DamageSource damageSource, float damage, EditData data) {
    if (data == null)
        return;
    list.remove(data);
    EntityPlayerMP player = data.player;
    player.closeScreen();
    EntityDecoy decoy = data.decoy;
    if (player.dimension != decoy.dimension)
        if (!Teleport.teleportEntity(player, decoy.dimension, null)) {
            list.add(data);
            throw new IllegalStateException("Was not able to reset editmode player for " + player.getName() + "! Likely caused by mod collision.");
        }
    data.connection.useCoordinates = true;
    data.connection.posX = player.posX;
    data.connection.posZ = player.posZ;
    player.setGameType(decoy.gameType);
    player.connection.setPlayerLocation(decoy.posX, decoy.posY, decoy.posZ, decoy.rotationYaw, decoy.rotationPitch);
    player.capabilities.readCapabilitiesFromNBT(decoy.capabilities);
    player.sendPlayerAbilities();
    player.fallDistance = 0;
    player.setHealth(decoy.getHealth());
    NBTTagCompound nbt = new NBTTagCompound();
    decoy.foodStats.writeNBT(nbt);
    player.getFoodStats().readNBT(nbt);
    data.connection.inventory = player.inventory.writeToNBT(new NBTTagList());
    player.inventory.copyInventory(decoy.inventory);
    decoy.markedForDespawn = true;
    MinestuckPacket packet = MinestuckPacket.makePacket(Type.SERVER_EDIT);
    MinestuckChannelHandler.sendToPlayer(packet, player);
    if (damageSource != null && damageSource.getImmediateSource() != player)
        player.attackEntityFrom(damageSource, damage);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) EntityDecoy(com.mraof.minestuck.entity.EntityDecoy) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket)

Aggregations

MinestuckPacket (com.mraof.minestuck.network.MinestuckPacket)29 ItemStack (net.minecraft.item.ItemStack)5 SburbConnection (com.mraof.minestuck.network.skaianet.SburbConnection)3 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 EntityDecoy (com.mraof.minestuck.entity.EntityDecoy)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 EditData (com.mraof.minestuck.editmode.EditData)1 Modus (com.mraof.minestuck.inventory.captchalouge.Modus)1 TransportalizerPacket (com.mraof.minestuck.network.TransportalizerPacket)1 GristType (com.mraof.minestuck.util.GristType)1 MinestuckPlayerData (com.mraof.minestuck.util.MinestuckPlayerData)1 ArrayList (java.util.ArrayList)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 MinecraftServer (net.minecraft.server.MinecraftServer)1