Search in sources :

Example 1 with IMessage

use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project SilentGems by SilentChaos512.

the class MessageToggleChaosGem method handleMessage.

@Override
public IMessage handleMessage(MessageContext context) {
    if (context.side != Side.SERVER)
        return null;
    EntityPlayer player = context.getServerHandler().player;
    Predicate<ItemStack> predicate = s -> s.getItem() instanceof ItemChaosGem;
    ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
    stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
    for (ItemStack stack : stacks) {
        if (stack.getItem() instanceof ItemChaosGem) {
            ItemChaosGem item = (ItemChaosGem) stack.getItem();
            item.setEnabled(stack, !item.isEnabled(stack));
            if (item.isEnabled(stack))
                item.applyEffects(stack, player);
            else
                item.removeEffects(stack, player);
            if (!all)
                return null;
        }
    }
    return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) Predicate(com.google.common.base.Predicate) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) Message(net.silentchaos512.gems.network.Message) PlayerHelper(net.silentchaos512.lib.util.PlayerHelper) BaublesCompat(net.silentchaos512.gems.compat.BaublesCompat) ItemChaosGem(net.silentchaos512.gems.item.ItemChaosGem) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) ItemChaosGem(net.silentchaos512.gems.item.ItemChaosGem) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IMessage

use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project BuildCraft by BuildCraft.

the class TileAssemblyTable method sendRecipeStateToServer.

public void sendRecipeStateToServer(AssemblyInstruction instruction, EnumAssemblyRecipeState state) {
    IMessage message = createMessage(NET_RECIPE_STATE, (buffer) -> {
        buffer.writeString(instruction.recipe.getRegistryName().toString());
        buffer.writeItemStack(instruction.output);
        buffer.writeInt(state.ordinal());
    });
    MessageManager.sendToServer(message);
}
Also used : IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage)

Example 3 with IMessage

use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project BuildCraft by BuildCraft.

the class TileBC_Neptune method createAndSendMessage.

public final void createAndSendMessage(int id, EntityPlayerMP player, IPayloadWriter writer) {
    if (hasWorld()) {
        IMessage message = createMessage(id, writer);
        MessageManager.sendTo(message, player);
    }
}
Also used : IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage)

Example 4 with IMessage

use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project BuildCraft by BuildCraft.

the class TileZonePlanner method sendLayerToServer.

public void sendLayerToServer(int index) {
    IMessage message = createMessage(NET_PLAN_CHANGE, (buffer) -> {
        buffer.writeShort(index);
        layers[index].writeToByteBuf(buffer);
    });
    MessageManager.sendToServer(message);
}
Also used : IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage)

Example 5 with IMessage

use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project pnc-repressurized by TeamPneumatic.

the class NetworkHandler method getSplitMessages.

private static List<IMessage> getSplitMessages(IMessage message) {
    ByteBuf buf = Unpooled.buffer();
    message.toBytes(buf);
    byte[] bytes = buf.array();
    if (bytes.length < MAX_PAYLOAD_SIZE) {
        return Collections.singletonList(message);
    } else {
        List<IMessage> messages = new ArrayList<>();
        messages.add(new PacketMultiHeader(buf.writerIndex(), message.getClass().getName()));
        int offset = 0;
        while (offset < buf.writerIndex()) {
            messages.add(new PacketMultiPart(Arrays.copyOfRange(bytes, offset, Math.min(offset + MAX_PAYLOAD_SIZE, buf.writerIndex()))));
            offset += MAX_PAYLOAD_SIZE;
        }
        return messages;
    }
}
Also used : IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

IMessage (net.minecraftforge.fml.common.network.simpleimpl.IMessage)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 Predicate (com.google.common.base.Predicate)2 ItemStack (net.minecraft.item.ItemStack)2 MessageContext (net.minecraftforge.fml.common.network.simpleimpl.MessageContext)2 Side (net.minecraftforge.fml.relauncher.Side)2 BaublesCompat (net.silentchaos512.gems.compat.BaublesCompat)2 Message (net.silentchaos512.gems.network.Message)2 ItemStackList (net.silentchaos512.lib.collection.ItemStackList)2 PlayerHelper (net.silentchaos512.lib.util.PlayerHelper)2 MultiToolLeftClickMessage (com.cjm721.overloaded.network.packets.MultiToolLeftClickMessage)1 ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 ModItems (net.silentchaos512.gems.init.ModItems)1 ItemChaosGem (net.silentchaos512.gems.item.ItemChaosGem)1