Search in sources :

Example 1 with MinestuckPacket

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

the class ClientEditHandler method onKeyPressed.

public static void onKeyPressed() {
    MinestuckPacket packet = MinestuckPacket.makePacket(Type.CLIENT_EDIT);
    MinestuckChannelHandler.sendToServer(packet);
}
Also used : MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket)

Example 2 with MinestuckPacket

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

the class ServerEditHandler method onBlockPlaced.

@SubscribeEvent(priority = EventPriority.LOW)
public void onBlockPlaced(BlockEvent.PlaceEvent event) {
    if (getData(event.getPlayer()) != null) {
        EditData data = getData(event.getPlayer());
        if (// If the event was cancelled server side and not client side, notify the client.
        event.isCanceled()) {
            MinestuckPacket packet = MinestuckPacket.makePacket(Type.SERVER_EDIT, data.connection.givenItems());
            MinestuckChannelHandler.sendToPlayer(packet, event.getPlayer());
            return;
        }
        ItemStack stack = event.getItemInHand();
        if (DeployList.containsItemStack(stack)) {
            SburbConnection c = data.connection;
            GristSet cost = c.givenItems()[DeployList.getOrdinal(stack)] ? DeployList.getSecondaryCost(stack) : DeployList.getPrimaryCost(stack);
            c.givenItems()[DeployList.getOrdinal(stack)] = true;
            if (!c.isMain())
                SkaianetHandler.giveItems(c.getClientIdentifier());
            if (!cost.isEmpty()) {
                GristHelper.decrease(c.getClientIdentifier(), cost);
                MinestuckPlayerTracker.updateGristCache(data.connection.getClientIdentifier());
            }
            event.getPlayer().inventory.mainInventory.set(event.getPlayer().inventory.currentItem, ItemStack.EMPTY);
        } else {
            GristHelper.decrease(data.connection.getClientIdentifier(), GristRegistry.getGristConversion(stack));
            MinestuckPlayerTracker.updateGristCache(data.connection.getClientIdentifier());
        }
    }
}
Also used : MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with MinestuckPacket

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

the class ServerEditHandler method newServerEditor.

public static void newServerEditor(EntityPlayerMP player, PlayerIdentifier computerOwner, PlayerIdentifier computerTarget) {
    if (player.isRiding())
        // Don't want to bother making the decoy able to ride anything right now.
        return;
    SburbConnection c = SkaianetHandler.getClientConnection(computerTarget);
    if (c != null && c.getServerIdentifier().equals(computerOwner) && getData(c) == null && getData(player) == null) {
        Debug.info("Activating edit mode on player \"" + player.getName() + "\", target player: \"" + computerTarget + "\".");
        EntityDecoy decoy = new EntityDecoy((WorldServer) player.world, player);
        EditData data = new EditData(decoy, player, c);
        if (!c.enteredGame()) {
            c.centerX = c.getClientData().getX();
            c.centerZ = c.getClientData().getZ();
        }
        if (!setPlayerStats(player, c)) {
            player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to activate edit mode."));
            return;
        }
        if (c.inventory != null)
            player.inventory.readFromNBT(c.inventory);
        decoy.world.spawnEntity(decoy);
        list.add(data);
        MinestuckPacket packet = MinestuckPacket.makePacket(Type.SERVER_EDIT, computerTarget, c.centerX, c.centerZ, c.givenItems());
        MinestuckChannelHandler.sendToPlayer(packet, player);
        MinestuckPlayerTracker.updateGristCache(c.getClientIdentifier());
    }
}
Also used : EntityDecoy(com.mraof.minestuck.entity.EntityDecoy) MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 4 with MinestuckPacket

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

the class CaptchaDeckHandler method captchalougeItem.

public static void captchalougeItem(EntityPlayerMP player) {
    ItemStack stack = player.getHeldItemMainhand();
    Modus modus = getModus(player);
    if (modus != null && !stack.isEmpty()) {
        boolean card1 = false, card2 = true;
        if (stack.getItem() == MinestuckItems.captchaCard && stack.hasTagCompound() && !stack.getTagCompound().getBoolean("punched")) {
            ItemStack newStack = AlchemyRecipeHandler.getDecodedItem(stack);
            if (!newStack.isEmpty()) {
                card1 = true;
                stack = newStack;
                card2 = modus.increaseSize();
            }
        }
        if (modus.putItemStack(stack)) {
            if (!card2)
                launchAnyItem(player, new ItemStack(MinestuckItems.captchaCard, 1));
            stack = player.getHeldItemMainhand();
            if (card1 && stack.getCount() > 1)
                stack.shrink(1);
            else
                player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
        } else if (card1 && card2) {
            launchAnyItem(player, stack);
            stack = player.getHeldItemMainhand();
            if (stack.getCount() == 1)
                player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
            else
                stack.shrink(1);
        }
        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 5 with MinestuckPacket

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

the class CaptchaDeckHandler method useItem.

public static void useItem(EntityPlayerMP player) {
    if (!(player.openContainer instanceof ContainerCaptchaDeck))
        return;
    ContainerCaptchaDeck container = (ContainerCaptchaDeck) player.openContainer;
    if (container.inventory.getStackInSlot(0).isEmpty())
        return;
    ItemStack item = container.inventory.getStackInSlot(0);
    Modus modus = getModus(player);
    ResourceLocation type = getType(item);
    if (type != null) {
        if (modus == null) {
            MinestuckPlayerData.PlayerData data = MinestuckPlayerData.getData(player);
            modus = createInstance(type, Side.SERVER);
            modus.player = player;
            modus.initModus(null, data.givenModus ? 0 : MinestuckConfig.initialModusSize);
            data.givenModus = true;
            setModus(player, modus);
            container.inventory.setInventorySlotContents(0, ItemStack.EMPTY);
        } else {
            Modus oldModus = modus;
            ResourceLocation oldType = getType(oldModus.getClass());
            if (type.equals(oldType))
                return;
            modus = createInstance(type, Side.SERVER);
            modus.player = player;
            if (modus.canSwitchFrom(oldModus))
                modus.initModus(oldModus.getItems(), oldModus.getSize());
            else {
                for (ItemStack content : oldModus.getItems()) if (!content.isEmpty())
                    launchAnyItem(player, content);
                modus.initModus(null, oldModus.getSize());
            }
            setModus(player, modus);
            container.inventory.setInventorySlotContents(0, getItem(oldType));
        }
    } else if (item.getItem().equals(MinestuckItems.captchaCard) && (!item.hasTagCompound() || !item.getTagCompound().getBoolean("punched")) && modus != null) {
        ItemStack content = AlchemyRecipeHandler.getDecodedItem(item);
        int failed = 0;
        for (int i = 0; i < item.getCount(); i++) if (!modus.increaseSize())
            failed++;
        if (content != null)
            for (int i = 0; i < item.getCount() - failed; i++) {
                ItemStack toPut = content.copy();
                if (!modus.putItemStack(toPut))
                    launchItem(player, toPut);
            }
        if (failed == 0)
            container.inventory.setInventorySlotContents(0, ItemStack.EMPTY);
        else
            item.setCount(failed);
    }
    if (modus != null) {
        MinestuckPacket packet = MinestuckPacket.makePacket(MinestuckPacket.Type.CAPTCHA, CaptchaDeckPacket.DATA, writeToNBT(modus));
        MinestuckChannelHandler.sendToPlayer(packet, player);
    }
}
Also used : MinestuckPlayerData(com.mraof.minestuck.util.MinestuckPlayerData) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) 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